Examples of CMutableDocument


Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

    };
  }

  public static Line getFirstLine(LocationMapper<ContentNode> mapper, int start) {
    Point<ContentNode> point = mapper.locate(start);
    CMutableDocument doc = point.getContainer().getMutableDoc();
    LineContainers.checkNotParagraphDocument(doc);

    // get line element we are in:
    ContentNode first = LineContainers.getRelatedLineElement(doc, point);
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

  }

  @Override
  public void selectGadget() {
    if (isActive()) {
      CMutableDocument doc = element.getMutableDoc();
      element.getSelectionHelper().setSelectionPoints(
          Point.before(doc, element), Point.after(doc, element));
    }
  }
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

   * effect only when the first line of the root blip is edited and no explicit
   * title is set.
   */
  private void maybeSetOrUpdateTitle() {
    if (blipUi != null && editor != null) {
      CMutableDocument document = editor.getDocument();
      ConversationBlip editBlip = views.getBlip(blipUi);
      if (editBlip.isRoot() && !TitleHelper.hasExplicitTitle(document)) {
        Range titleRange = TitleHelper.findImplicitTitle(document);
        TitleHelper.setImplicitTitle(document, titleRange.getStart(), titleRange.getEnd());
      }
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

    // operations that have not yet been extracted by the typing extractor. The
    // problem is that we can't always safely force the typing extractor to
    // extract out those operations. Therefore, we assume that most of the time,
    // doodads are inserted via selection on a non-editing document.
    ContentRange selectionPoints = createSelectionHelper(content).getOrderedSelectionPoints();
    CMutableDocument document = content.getMutableDoc();
    ContentView view = content.getPersistentView();
    return DocumentUtil.getLocationNearSelection(document, view, selectionPoints);
  }
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

      // file again if it still makes sense (the blip in which they intended it
      // to go has been deleted, so they may not want to upload it anymore).
      return;
    }
    EditorContext context = edit.getEditor();
    CMutableDocument doc = context.getDocument();
    FocusedContentRange selection = context.getSelectionHelper().getSelectionPoints();
    Point<ContentNode> point;
    if (selection != null) {
      point = selection.getFocus();
    } else {
      // Focus was probably lost.  Bring it back.
      context.focus(false);
      selection = context.getSelectionHelper().getSelectionPoints();
      if (selection != null) {
        point = selection.getFocus();
      } else {
        // Still no selection.  Oh well, put it at the end.
        point = doc.locate(doc.size() - 1);
      }
    }
    XmlStringBuilder content = ImageThumbnail.constructXml(null, filename);
    thumbnail = ImageThumbnailWrapper.of(doc.insertXml(point, content));
  }
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

    };
  }

  public static Line getFirstLine(LocationMapper<ContentNode> mapper, int start) {
    Point<ContentNode> point = mapper.locate(start);
    CMutableDocument doc = point.getContainer().getMutableDoc();
    LineContainers.checkNotParagraphDocument(doc);

    // get line element we are in:
    ContentNode first = LineContainers.getRelatedLineElement(doc, point);
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

    return busy;
  }

  @VisibleForTesting  // For testing with p/line container.
  void extract(Element srcContainer, ContentRange previousSelection, BiasDirection cursorBias) {
    final CMutableDocument destDoc = mutableDocument;
    final OperationSequencer<Nindo> destOperationSequencer =
        operationSequencer;
    final LocationMapper<ContentNode> mapper = mutableDocument;

    Point<ContentNode> start = normalize(previousSelection.getFirst());
    Point<ContentNode> end = normalize(previousSelection.getSecond());

    // Delete content if a range was selected
    if (!previousSelection.isCollapsed()) {
      PointRange<ContentNode> range = destDoc.deleteRange(start, end);

      start = range.getFirst();
      end = range.getSecond();
    }

    Point<ContentNode> insertAt = end;
    int pos = mapper.getLocation(insertAt);

    String waveXml = null;
    String annotations = null;
    if (useSemanticCopyPaste) {
      waveXml = clipboard.maybeGetWaveXml(srcContainer);
      annotations = clipboard.maybeGetAnnotations(srcContainer);
    }

    // TODO(user): Pass in whether the pasted content is rich or play
    // TODO(patcoleman): once we have non rich-text paste, fix cursor bias correctly
    cursorBias = BiasDirection.LEFT;

    if (useSemanticCopyPaste && waveXml != null) {
      if (!waveXml.isEmpty()) {
        instrumentor.record(Action.CLIPBOARD_PASTE_FROM_WAVE);

        // initialise the XML:
        Builder builder = at(pos);
        XmlStringBuilder createdFromXmlString =
            XmlStringBuilder.createFromXmlStringWithContraints(waveXml,
                PermittedCharacters.BLIP_TEXT);

        // Strip annotations based on behaviour:
        StringMap<String> modified = annotationLogic.stripKeys(
            destDoc, pos, cursorBias, ContentType.RICH_TEXT, builder);

        double startTime = Duration.currentTimeMillis();
        // apply xml change
        MutableDocumentImpl.appendXmlToBuilder(createdFromXmlString, builder);
        double timeTaken = Duration.currentTimeMillis() - startTime;
        LOG.trace().log("time taken: " + timeTaken);

        // handle the end of annotations
        annotationLogic.unstripKeys(builder, modified.keySet(), CollectionUtils.createStringSet());
        builder.finish();
        Nindo nindo = builder.build();

        try {
          validator.maybeThrowOperationExceptionFor(nindo);

          int locationAfter = destDoc.getLocation(insertAt) + createdFromXmlString.getLength();
          destOperationSequencer.begin();
          destOperationSequencer.consume(nindo);
          destOperationSequencer.end();
          aggressiveSelectionHelper.setCaret(locationAfter);

          LOG.trace().log("annotations: " + String.valueOf(annotations));
          if (annotations != null && !annotations.isEmpty()) {
            List<RangedAnnotation<String>> deserialize =
                AnnotationSerializer.deserialize(annotations);
            for (RangedAnnotation<String> ann : deserialize) {
              destDoc.setAnnotation(pos + ann.start(), pos + ann.end(), ann.key(), ann.value());
              LOG.trace().log(
                  "pos: " + pos + "start: " + (pos + ann.start()) + " end: " + (pos + ann.end())
                      + " key: " + ann.key() + " value: " + ann.value());
            }
          }
        } catch (OperationException e) {
          LOG.error().log("Semantic paste failed");
          // Restore caret
          aggressiveSelectionHelper.setCaret(insertAt);
        }
      }
    } else {
      instrumentor.record(Action.CLIPBOARD_PASTE_FROM_OUTSIDE);

      // initialize tokenizer and builder
      RichTextTokenizer tokenizer = createTokenizer(srcContainer);
      Builder builder = at(pos);

      // handle annotation starts
      StringMap<String> modified = annotationLogic.stripKeys(
          destDoc, pos, cursorBias, ContentType.RICH_TEXT, builder);

      // parse the tokens and apply ops
      RichTextMutationBuilder mutationBuilder = new RichTextMutationBuilder(modified);
      ReadableStringSet affectedKeys =
          mutationBuilder.applyMutations(tokenizer, builder, destDoc, insertAt.getContainer());

      // close annotations and finish
      annotationLogic.unstripKeys(builder, modified.keySet(), affectedKeys);
      builder.finish();
      Nindo nindo = builder.build();

      try {
        validator.maybeThrowOperationExceptionFor(nindo);

        destOperationSequencer.begin();
        destOperationSequencer.consume(nindo);
        destOperationSequencer.end();

        int cursorLocation = pos + mutationBuilder.getLastGoodCursorOffset();
        Point<ContentNode> caret = mapper.locate(cursorLocation);
        aggressiveSelectionHelper.setCaret(caret);
      } catch (OperationException e) {
        LOG.error().log("Paste failed");
        aggressiveSelectionHelper.setCaret(insertAt);
      }
    }

    srcContainer.setInnerHTML("");

    // Restore focus back to the editor
    // TODO(user): Write a webdriver to test selection is correct after paste.
    DomHelper.focus(destDoc.getDocumentElement().getContainerNodelet());
  }
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

        editorUndoManager = EditorUndoManager.NOP_IMPL;
      }

      OperationSequencer<Nindo> undoingSequencer = new UndoableSequencer(sequencer, responsibility);

      CMutableDocument undoableDocument = content.createSequencedDocumentWrapper(undoingSequencer);

      pasteExtractor = new PasteExtractor(CommandQueue.HIGH_PRIORITY,
          aggressiveSelectionHelper,
          undoableDocument,
          content.getRenderedView(),
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

    if (focusedRange != null) {
      from = focusedRange.getFocus();
    }
    if (url != null && !url.isEmpty()) {
      XmlStringBuilder xml = GadgetXmlUtil.constructXml(url, "", user.getAddress());
      CMutableDocument document = editor.getDocument();
      if (document == null) {
        return;
      }
      if (from != -1) {
        Point<ContentNode> point = document.locate(from);
        document.insertXml(point, xml);
      } else {
        LineContainers.appendLine(document, xml);
      }
    }
  }
View Full Code Here

Examples of org.waveprotocol.wave.client.editor.content.CMutableDocument

                XmlStringBuilder xml = XmlStringBuilder.createFromXmlString(fileName);
                int to = -1;
                int docSize = editor.getDocument().size();
                if (cursorLoc != -1) {
                  // Insert the attachment at the cursor location.
                  CMutableDocument doc = editor.getDocument();
                  Point<ContentNode> point = doc.locate(cursorLoc);
                  doc.insertXml(point, xml);
                } else {
                  LineContainers.appendLine(editor.getDocument(), xml);
                }
                // Calculate the link length for the attachment.
                to = cursorLoc + editor.getDocument().size() - docSize;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.