示例#1
0
  /** @return operation that reverts the effect of the latest local operation in the given editor */
  protected Operation calcUndoOperation(SPath editor) {

    if (!undoHistory.canUndo(editor)) return new NoOperation(); // nothing to undo

    Operation lastLocal = undoHistory.getLatestLocal(editor);

    assert lastLocal != null;

    Operation undoOperation = lastLocal.invert();

    for (EditorHistoryEntry entry : undoHistory.entriesToLatestLocal(editor)) {

      Operation operation = entry.getOperation();

      undoOperation = transformation.transform(undoOperation, operation, Boolean.TRUE);

      log.debug("transformed undo: " + undoOperation);
    }

    undoHistory.replaceType(editor, lastLocal, Type.LOCAL, Type.REMOTE);
    // it is not relevant any more, so it is set remote

    undoHistory.add(editor, Type.REDOABLE, undoOperation); // save for redo

    return undoOperation;
  }
示例#2
0
        /** Updates the current local operation and adds remote operations to the undo history. */
        @Override
        public void receive(TextEditActivity textEditActivity) {

          if (!enabled) return;

          /*
           * When performing an undo/redo there are fired Activities which are
           * expected and have to be ignored when coming back.
           */
          if (expectedActivities.remove(textEditActivity)) return;

          Operation operation = textEditActivity.toOperation();

          if (!local(textEditActivity)) {
            if (currentLocalCompositeOperation != null)
              currentLocalCompositeOperation =
                  transformation.transform(
                      currentLocalCompositeOperation, operation, Boolean.FALSE);
            if (currentLocalAtomicOperation != null) {
              currentLocalAtomicOperation =
                  transformation.transform(currentLocalAtomicOperation, operation, Boolean.FALSE);
            }
            log.debug("adding remote " + operation + " to history");
            undoHistory.add(textEditActivity.getPath(), Type.REMOTE, operation);
          } else {
            if (!textEditActivity.getPath().equals(currentActiveEditor)) {
              log.error(
                  "Editor of the local TextEditActivity is not the current "
                      + "active editor. Possibly the current active editor is not"
                      + " up to date.");
              return;
            }
            updateCurrentLocalAtomicOperation(operation);
          }
          return;
        }
示例#3
0
  /** @return operation that reverts the effect of the latest undo in the given editor */
  protected Operation calcRedoOperation(SPath editor) {

    if (!undoHistory.canRedo(editor)) return new NoOperation(); // nothing to redo

    Operation lastUndo = undoHistory.getLatestRedoable(editor);

    assert lastUndo != null;

    Operation redoOperation = lastUndo.invert();

    for (EditorHistoryEntry entry : undoHistory.entriesToLatestRedoable(editor)) {

      redoOperation = transformation.transform(redoOperation, entry.getOperation(), Boolean.TRUE);
    }
    undoHistory.replaceType(editor, lastUndo, Type.REDOABLE, Type.REMOTE);
    // it is not relevant any more, so it is set remote

    undoHistory.add(editor, Type.LOCAL, redoOperation);
    log.debug("adding " + lastUndo + " (cause: redo internal)");

    return redoOperation;
  }