com.intellij.openapi.fileEditor.impl.text.TextEditorState Java Examples

The following examples show how to use com.intellij.openapi.fileEditor.impl.text.TextEditorState. 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: TextEditorProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public FileEditorState readState(@Nonnull Element element, @Nonnull Project project, @Nonnull VirtualFile file) {
  TextEditorState state = new TextEditorState();

  try {
    List<Element> caretElements = element.getChildren(CARET_ELEMENT);
    if (caretElements.isEmpty()) {
      state.CARETS = new TextEditorState.CaretState[]{readCaretInfo(element)};
    }
    else {
      state.CARETS = new TextEditorState.CaretState[caretElements.size()];
      for (int i = 0; i < caretElements.size(); i++) {
        state.CARETS[i] = readCaretInfo(caretElements.get(i));
      }
    }

    String verticalScrollProportion = element.getAttributeValue(RELATIVE_CARET_POSITION_ATTR);
    state.RELATIVE_CARET_POSITION = verticalScrollProportion == null ? 0 : Integer.parseInt(verticalScrollProportion);
  }
  catch (NumberFormatException ignored) {
  }

  return state;
}
 
Example #2
Source File: TextEditorProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void writeState(@Nonnull FileEditorState _state, @Nonnull Project project, @Nonnull Element element) {
  TextEditorState state = (TextEditorState)_state;

  element.setAttribute(RELATIVE_CARET_POSITION_ATTR, Integer.toString(state.RELATIVE_CARET_POSITION));
  if (state.CARETS != null) {
    for (TextEditorState.CaretState caretState : state.CARETS) {
      Element e = new Element(CARET_ELEMENT);
      e.setAttribute(LINE_ATTR, Integer.toString(caretState.LINE));
      e.setAttribute(COLUMN_ATTR, Integer.toString(caretState.COLUMN));
      e.setAttribute(LEAN_FORWARD_ATTR, Boolean.toString(caretState.LEAN_FORWARD));
      e.setAttribute(SELECTION_START_LINE_ATTR, Integer.toString(caretState.SELECTION_START_LINE));
      e.setAttribute(SELECTION_START_COLUMN_ATTR, Integer.toString(caretState.SELECTION_START_COLUMN));
      e.setAttribute(SELECTION_END_LINE_ATTR, Integer.toString(caretState.SELECTION_END_LINE));
      e.setAttribute(SELECTION_END_COLUMN_ATTR, Integer.toString(caretState.SELECTION_END_COLUMN));
      element.addContent(e);
    }
  }
}
 
Example #3
Source File: CsvFileEditorTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public void testCsvEditorStateReadsAndWritesStates() {
    TextEditor textEditor = getCurrentTextEditor();

    FileEditorProvider[] fileEditorProviders = FileEditorProviderManager.getInstance().getProviders(myFixture.getProject(), myFixture.getFile().getVirtualFile());
    CsvFileEditorProvider fileEditorProvider = (CsvFileEditorProvider)fileEditorProviders[0];
    Element dummy = new Element("dummy");

    FileEditorState state = fileEditorProvider.readState(dummy, this.getProject(), myFixture.getFile().getVirtualFile());
    assertInstanceOf(state, TextEditorState.class);
    textEditor.setState(state);
    fileEditorProvider.writeState(state, this.getProject(), dummy);

    disposeTextEditor(textEditor);
}
 
Example #4
Source File: TextEditorProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static TextEditorState.CaretState readCaretInfo(Element element) {
  TextEditorState.CaretState caretState = new TextEditorState.CaretState();
  caretState.LINE = parseWithDefault(element, LINE_ATTR);
  caretState.COLUMN = parseWithDefault(element, COLUMN_ATTR);
  caretState.LEAN_FORWARD = parseBooleanWithDefault(element, LEAN_FORWARD_ATTR);
  caretState.SELECTION_START_LINE = parseWithDefault(element, SELECTION_START_LINE_ATTR);
  caretState.SELECTION_START_COLUMN = parseWithDefault(element, SELECTION_START_COLUMN_ATTR);
  caretState.SELECTION_END_LINE = parseWithDefault(element, SELECTION_END_LINE_ATTR);
  caretState.SELECTION_END_COLUMN = parseWithDefault(element, SELECTION_END_COLUMN_ATTR);
  return caretState;
}
 
Example #5
Source File: TextEditorProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static TextEditorState.CaretState createCaretState(LogicalPosition caretPosition, LogicalPosition selectionStartPosition, LogicalPosition selectionEndPosition) {
  TextEditorState.CaretState caretState = new TextEditorState.CaretState();
  caretState.LINE = getLine(caretPosition);
  caretState.COLUMN = getColumn(caretPosition);
  caretState.LEAN_FORWARD = caretPosition != null && caretPosition.leansForward;
  caretState.SELECTION_START_LINE = getLine(selectionStartPosition);
  caretState.SELECTION_START_COLUMN = getColumn(selectionStartPosition);
  caretState.SELECTION_END_LINE = getLine(selectionEndPosition);
  caretState.SELECTION_END_COLUMN = getColumn(selectionEndPosition);
  return caretState;
}
 
Example #6
Source File: HttpFileEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public FileEditorState getState(@Nonnull final FileEditorStateLevel level) {
  final TextEditor textEditor = myPanel.getFileEditor();
  if (textEditor != null) {
    return textEditor.getState(level);
  }
  return new TextEditorState();
}
 
Example #7
Source File: HttpFileEditorProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public FileEditorState readState(@Nonnull final Element sourceElement, @Nonnull final Project project, @Nonnull final VirtualFile file) {
  return new TextEditorState();
}