com.intellij.openapi.fileEditor.FileEditorStateLevel Java Examples

The following examples show how to use com.intellij.openapi.fileEditor.FileEditorStateLevel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CsvTableEditorSwingTest.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
public void testBasics() {
    assertEquals(CsvTableEditor.EDITOR_NAME, fileEditor.getName());
    assertEquals(fileEditor, fileEditor.getCurrentLocation());
    assertInstanceOf(fileEditor.getState(FileEditorStateLevel.FULL), CsvTableEditorState.class);
    assertInstanceOf(fileEditor.getState(FileEditorStateLevel.NAVIGATION), CsvTableEditorState.class);
    assertInstanceOf(fileEditor.getState(FileEditorStateLevel.UNDO), CsvTableEditorState.class);

    CsvTableEditorState myState = new CsvTableEditorState();
    fileEditor.setState(myState);
    assertEquals(myState, fileEditor.getState(FileEditorStateLevel.FULL));

    assertEquals(false, fileEditor.isModified());
    assertEquals(true, fileEditor.isValid());
    assertEquals(null, fileEditor.getBackgroundHighlighter());

    StructureViewBuilder structureViewBuilder = StructureViewBuilder.PROVIDER.getStructureViewBuilder(myFixture.getFile().getFileType(), myFixture.getFile().getVirtualFile(), this.getProject());
    assertInstanceOf(fileEditor.getStructureViewBuilder(), structureViewBuilder.getClass());

    assertEquals(myFixture.getFile().getVirtualFile(), fileEditor.getFile());
    assertEquals(this.getProject(), fileEditor.getProject());
    assertNotNull(fileEditor.getDataHandler());
    assertNotNull(fileEditor.getComponent());
    assertEquals(fileEditor.getTable(), fileEditor.getPreferredFocusedComponent());
}
 
Example #2
Source File: DesktopPsiAwareTextEditorProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public TextEditorState getStateImpl(final Project project, @Nonnull final Editor editor, @Nonnull final FileEditorStateLevel level) {
  final TextEditorState state = super.getStateImpl(project, editor, level);
  // Save folding only on FULL level. It's very expensive to commit document on every
  // type (caused by undo).
  if (FileEditorStateLevel.FULL == level) {
    // Folding
    if (project != null && !project.isDisposed() && !editor.isDisposed() && project.isInitialized()) {
      state.setFoldingState(CodeFoldingManager.getInstance(project).saveFoldingState(editor));
    }
    else {
      state.setFoldingState(null);
    }
  }

  return state;
}
 
Example #3
Source File: UndoRedo.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean restore(EditorAndState pair, boolean onlyIfDiffers) {
  if (myEditor == null ||
      !myEditor.isValid() || // editor can be invalid if underlying file is deleted during undo (e.g. after undoing scratch file creation)
      pair == null || pair.getEditor() == null) {
    return false;
  }

  // we cannot simply compare editors here because of the following scenario:
  // 1. make changes in editor for file A
  // 2. move caret
  // 3. close editor
  // 4. re-open editor for A via Ctrl-E
  // 5. undo -> position is not affected, because instance created in step 4 is not the same!!!
  if (!myEditor.getClass().equals(pair.getEditor().getClass())) {
    return false;
  }

  // If current editor state isn't equals to remembered state then
  // we have to try to restore previous state. But sometime it's
  // not possible to restore it. For example, it's not possible to
  // restore scroll proportion if editor doesn not have scrolling any more.
  FileEditorState currentState = myEditor.getState(FileEditorStateLevel.UNDO);
  if (onlyIfDiffers && currentState.equals(pair.getState())) {
    return false;
  }

  myEditor.setState(pair.getState());
  return true;
}
 
Example #4
Source File: DesktopAsyncEditorLoader.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
TextEditorState getEditorState(@Nonnull FileEditorStateLevel level) {
  ApplicationManager.getApplication().assertIsDispatchThread();


  TextEditorState state = myProvider.getStateImpl(myProject, myEditor, level);
  if (!isDone() && myDelayedState != null) {
    state.setDelayedFoldState(myDelayedState::getFoldingState);
  }
  return state;
}
 
Example #5
Source File: TextEditorState.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
  if (!(otherState instanceof TextEditorState)) return false;
  TextEditorState other = (TextEditorState)otherState;
  return level == FileEditorStateLevel.NAVIGATION
         && CARETS != null && CARETS.length == 1
         && other.CARETS != null && other.CARETS.length == 1
         && Math.abs(CARETS[0].LINE - other.CARETS[0].LINE) < MIN_CHANGE_DISTANCE;
}
 
Example #6
Source File: DesktopEditorWithProviderComposite.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public HistoryEntry currentStateAsHistoryEntry() {
  final FileEditor[] editors = getEditors();
  final FileEditorState[] states = new FileEditorState[editors.length];
  for (int j = 0; j < states.length; j++) {
    states[j] = editors[j].getState(FileEditorStateLevel.FULL);
    LOG.assertTrue(states[j] != null);
  }
  final int selectedProviderIndex = ArrayUtil.find(editors, getSelectedEditor());
  LOG.assertTrue(selectedProviderIndex != -1);
  final FileEditorProvider[] providers = getProviders();
  return HistoryEntry.createLight(getFile(), providers, states, providers[selectedProviderIndex]);
}
 
Example #7
Source File: SandFileEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public FileEditorState getState(@Nonnull FileEditorStateLevel level) {
  return FileEditorState.INSTANCE;
}
 
Example #8
Source File: CsvTableEditorState.java    From intellij-csv-validator with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canBeMergedWith(FileEditorState fileEditorState, FileEditorStateLevel fileEditorStateLevel) {
    return false;
}
 
Example #9
Source File: WebTextEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public FileEditorState getState(@Nonnull FileEditorStateLevel level) {
  return null;
}
 
Example #10
Source File: UndoRedo.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean execute(boolean drop, boolean isInsideStartFinishGroup) {
  if (!myUndoableGroup.isUndoable()) {
    reportCannotUndo(CommonBundle.message("cannot.undo.error.contains.nonundoable.changes.message"),
                     myUndoableGroup.getAffectedDocuments());
    return false;
  }

  Set<DocumentReference> clashing = getStackHolder().collectClashingActions(myUndoableGroup);
  if (!clashing.isEmpty()) {
    reportCannotUndo(CommonBundle.message("cannot.undo.error.other.affected.files.changed.message"), clashing);
    return false;
  }


  if (!isInsideStartFinishGroup && myUndoableGroup.shouldAskConfirmation(isRedo())) {
    if (!askUser()) return false;
  }
  else {
    if (restore(getBeforeState(), true)) {
      setBeforeState(new EditorAndState(myEditor, myEditor.getState(FileEditorStateLevel.UNDO)));
      return true;
    }
  }

  Collection<VirtualFile> readOnlyFiles = collectReadOnlyAffectedFiles();
  if (!readOnlyFiles.isEmpty()) {
    final Project project = myManager.getProject();
    final VirtualFile[] files = VfsUtil.toVirtualFileArray(readOnlyFiles);

    if (project == null) {
      return false;
    }

    final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
    if (operationStatus.hasReadonlyFiles()) {
      return false;
    }
  }

  Collection<Document> readOnlyDocuments = collectReadOnlyDocuments();
  if (!readOnlyDocuments.isEmpty()) {
    for (Document document : readOnlyDocuments) {
      document.fireReadOnlyModificationAttempt();
    }
    return false;
  }

  getStackHolder().removeFromStacks(myUndoableGroup);
  if (!drop) {
    getReverseStackHolder().addToStacks(myUndoableGroup);
  }

  performAction();

  restore(getAfterState(), false);

  return true;
}
 
Example #11
Source File: TransferableFileEditorStateSupport.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private static TransferableFileEditorState getEditorState(@Nonnull FileEditor editor) {
  FileEditorState state = editor.getState(FileEditorStateLevel.FULL);
  return state instanceof TransferableFileEditorState ? (TransferableFileEditorState)state : null;
}
 
Example #12
Source File: UIFormEditor.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
@NotNull
public FileEditorState getState(@NotNull final FileEditorStateLevel ignored) {
	return MY_EDITOR_STATE;
}
 
Example #13
Source File: UIFormEditor.java    From MavenHelper with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
	return false;
}
 
Example #14
Source File: CSharpAssemblyFileEditor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public FileEditorState getState(@Nonnull FileEditorStateLevel fileEditorStateLevel)
{
	return FileEditorState.INSTANCE;
}
 
Example #15
Source File: NoSqlDatabaseDataEditor.java    From nosql4idea with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public FileEditorState getState(@NotNull FileEditorStateLevel level) {
    return FileEditorState.INSTANCE;
}
 
Example #16
Source File: MindMapFileEditorState.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean canBeMergedWith(FileEditorState fileEditorState, FileEditorStateLevel fileEditorStateLevel) {
  return false;
}
 
Example #17
Source File: MindMapDocumentEditor.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public FileEditorState getState(@Nonnull FileEditorStateLevel fileEditorStateLevel) {
  return MindMapFileEditorState.DUMMY;
}
 
Example #18
Source File: WeaveEditor.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
@Override
public FileEditorState getState(@NotNull FileEditorStateLevel level) {
    return textEditor.getState(level);
}