Exemplo n.º 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;
  }
Exemplo n.º 2
0
 @Override
 public void sessionStarted(ISarosSession newSarosSession) {
   undoHistory.clear();
   newSarosSession.addActivityProvider(UndoManager.this);
   enabled = preferences.isConcurrentUndoActivated();
   eclipseHistory.addOperationApprover(operationBlocker);
   UndoManager.this.sarosSession = newSarosSession;
 }
Exemplo n.º 3
0
 /**
  * Adds the current local composite operation to the undo history (if not null) and resets it
  * afterwards.
  */
 protected void storeCurrentLocalOperation() {
   if (currentLocalCompositeOperation == null) return;
   if (currentActiveEditor == null) {
     log.warn("Cannot store current local operation. Current active editor is unknown");
     return;
   }
   undoHistory.add(currentActiveEditor, Type.LOCAL, currentLocalCompositeOperation);
   currentLocalCompositeOperation = null;
   log.debug("stored current local operation");
 }
Exemplo n.º 4
0
        @Override
        public void editorRemoved(User user, SPath closedEditor) {
          if (ObjectUtils.equals(currentActiveEditor, closedEditor)) {
            updateCurrentLocalAtomicOperation(null);
            storeCurrentLocalOperation();
            currentActiveEditor = null;
          }

          undoHistory.clearEditorHistory(closedEditor);
        }
Exemplo n.º 5
0
 @Override
 public void sessionEnded(ISarosSession oldSarosSession) {
   oldSarosSession.removeActivityProvider(UndoManager.this);
   undoHistory.clear();
   enabled = false;
   eclipseHistory.removeOperationApprover(operationBlocker);
   UndoManager.this.sarosSession = null;
   currentLocalCompositeOperation = null;
   currentLocalAtomicOperation = null;
 }
Exemplo n.º 6
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;
  }
Exemplo n.º 7
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;
        }