/**
  * Updates editors' highlighters. This should be done when the opened file changes its file type.
  */
 private void updateHighlighters() {
   if (!myProject.isDisposed()) {
     final EditorHighlighter highlighter =
         EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myFile);
     ((EditorEx) myEditor).setHighlighter(highlighter);
   }
 }
 public void testCaretRowWinsOverSyntaxEvenInPresenceOfHighlighter() throws Exception {
   initText("foo");
   ((EditorEx) myEditor)
       .setHighlighter(
           new UniformHighlighter(new TextAttributes(null, Color.red, null, null, Font.PLAIN)));
   addRangeHighlighter(0, 3, 0, null, Color.blue);
   checkResult();
 }
Ejemplo n.º 3
0
 @NotNull
 protected Runnable loadEditorInBackground() {
   EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
   EditorHighlighter highlighter =
       EditorHighlighterFactory.getInstance().createEditorHighlighter(myFile, scheme, myProject);
   EditorEx editor = (EditorEx) getEditor();
   highlighter.setText(editor.getDocument().getImmutableCharSequence());
   return () -> editor.setHighlighter(highlighter);
 }
  @Override
  protected EditorEx createEditor() {
    final EditorEx ex = super.createEditor();

    if (myLanguage != null) {
      final FileType fileType = myLanguage.getAssociatedFileType();
      ex.setHighlighter(HighlighterFactory.createHighlighter(myProject, fileType));
    }
    ex.setEmbeddedIntoDialogWrapper(true);

    return ex;
  }
  private static void reinitSettings(final EditorEx editor) {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    editor.setColorsScheme(scheme);
    EditorSettings settings = editor.getSettings();
    settings.setLineNumbersShown(false);
    settings.setWhitespacesShown(false);
    settings.setLineMarkerAreaShown(false);
    settings.setIndentGuidesShown(false);
    settings.setFoldingOutlineShown(false);
    settings.setAdditionalColumnsCount(0);
    settings.setAdditionalLinesCount(0);
    settings.setRightMarginShown(true);
    settings.setRightMargin(60);
    settings.setVirtualSpace(false);

    editor.setHighlighter(new LexerEditorHighlighter(new PropertiesValueHighlighter(), scheme));
    editor.setVerticalScrollbarVisible(true);
  }
Ejemplo n.º 6
0
  public static void setHighlighter(Editor editor, TemplateContext templateContext) {
    SyntaxHighlighter baseHighlighter = null;
    for (TemplateContextType type : TemplateManagerImpl.getAllContextTypes()) {
      if (templateContext.isEnabled(type)) {
        baseHighlighter = type.createHighlighter();
        if (baseHighlighter != null) break;
      }
    }
    if (baseHighlighter == null) {
      baseHighlighter = new PlainSyntaxHighlighter();
    }

    SyntaxHighlighter highlighter = createTemplateTextHighlighter(baseHighlighter);
    ((EditorEx) editor)
        .setHighlighter(
            new LexerEditorHighlighter(
                highlighter, EditorColorsManager.getInstance().getGlobalScheme()));
  }
  /**
   * @return created editor. This editor should be released by {@link #disposeEditor(Editor) }
   *     method.
   */
  @NotNull
  private Editor createEditor() {
    Editor editor = EditorFactory.getInstance().createEditor(myDocument, myProject);
    ((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
    EditorHighlighter highlighter =
        EditorHighlighterFactory.getInstance()
            .createEditorHighlighter(
                myFile, EditorColorsManager.getInstance().getGlobalScheme(), myProject);
    ((EditorEx) editor).setHighlighter(highlighter);
    ((EditorEx) editor).setFile(myFile);

    editor.addEditorMouseListener(myEditorMouseListener);
    ((EditorEx) editor).addPropertyChangeListener(myEditorPropertyChangeListener);

    ((EditorImpl) editor).setDropHandler(new FileDropHandler(editor));

    TextEditorProvider.putTextEditor(editor, myTextEditor);
    return editor;
  }
  private Editor createEditor() {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Document doc =
        myFile == null
            ? editorFactory.createDocument(myTemplate == null ? "" : myTemplate.getText())
            : PsiDocumentManager.getInstance(myFile.getProject()).getDocument(myFile);
    Editor editor =
        myProject == null
            ? editorFactory.createEditor(doc)
            : editorFactory.createEditor(doc, myProject);

    EditorSettings editorSettings = editor.getSettings();
    editorSettings.setVirtualSpace(false);
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setIndentGuidesShown(false);
    editorSettings.setLineNumbersShown(false);
    editorSettings.setFoldingOutlineShown(false);
    editorSettings.setAdditionalColumnsCount(3);
    editorSettings.setAdditionalLinesCount(3);

    EditorColorsScheme scheme = editor.getColorsScheme();
    scheme.setColor(EditorColors.CARET_ROW_COLOR, null);

    editor
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              @Override
              public void documentChanged(DocumentEvent e) {
                onTextChanged();
              }
            });

    ((EditorEx) editor).setHighlighter(createHighlighter());
    mySplitter.setFirstComponent(editor.getComponent());
    return editor;
  }
  private void updatePreview() {
    ConnectionHandler connectionHandler = variablesBundle.getActiveConnection();
    Project project = connectionHandler.getProject();

    String previewText =
        variablesBundle.prepareStatementText(connectionHandler, this.statementText, true);

    for (StatementExecutionVariableValueForm variableValueForm : variableValueForms) {
      String errorText = variablesBundle.getError(variableValueForm.getVariable());
      if (errorText == null) variableValueForm.hideErrorLabel();
      else variableValueForm.showErrorLabel(errorText);
    }

    if (previewDocument == null) {
      PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project);

      SQLFile selectStatementFile =
          (SQLFile)
              psiFileFactory.createFileFromText(
                  "filter.sql",
                  connectionHandler.getLanguageDialect(SQLLanguage.INSTANCE),
                  previewText);

      selectStatementFile.setActiveConnection(connectionHandler);
      selectStatementFile.setCurrentSchema(variablesBundle.getCurrentSchema());
      previewDocument = DocumentUtil.getDocument(selectStatementFile);

      viewer = (EditorEx) EditorFactory.getInstance().createViewer(previewDocument, project);
      viewer.setEmbeddedIntoDialogWrapper(true);
      JScrollPane viewerScrollPane = viewer.getScrollPane();
      SyntaxHighlighter syntaxHighlighter =
          connectionHandler.getLanguageDialect(SQLLanguage.INSTANCE).getSyntaxHighlighter();
      EditorColorsScheme colorsScheme = viewer.getColorsScheme();
      viewer.setHighlighter(HighlighterFactory.createHighlighter(syntaxHighlighter, colorsScheme));
      viewer.setBackgroundColor(colorsScheme.getColor(ColorKey.find("CARET_ROW_COLOR")));
      viewerScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      viewerScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
      // viewerScrollPane.setBorder(null);
      viewerScrollPane.setViewportBorder(
          new LineBorder(CompatibilityUtil.getEditorBackgroundColor(viewer), 4, false));

      EditorSettings settings = viewer.getSettings();
      settings.setFoldingOutlineShown(false);
      settings.setLineMarkerAreaShown(false);
      settings.setLineNumbersShown(false);
      settings.setVirtualSpace(false);
      settings.setDndEnabled(false);
      settings.setAdditionalLinesCount(2);
      settings.setRightMarginShown(false);
      previewPanel.add(viewer.getComponent(), BorderLayout.CENTER);

    } else {
      final String finalPreviewText = previewText;

      new WriteActionRunner() {
        public void run() {
          previewDocument.setText(finalPreviewText);
        }
      }.start();
    }
  }
  private void setupComponents() {
    setupEditorDefault(myConsoleEditor);
    setupEditorDefault(myHistoryViewer);
    myConsoleEditor.addEditorMouseListener(
        EditorActionUtil.createEditorPopupHandler(IdeActions.GROUP_CONSOLE_EDITOR_POPUP));
    //noinspection PointlessBooleanExpression,ConstantConditions
    if (SEPARATOR_THICKNESS > 0 && myShowSeparatorLine) {
      myHistoryViewer
          .getComponent()
          .setBorder(new SideBorder(JBColor.LIGHT_GRAY, SideBorder.BOTTOM));
    }
    myHistoryViewer.getComponent().setMinimumSize(new Dimension(0, 0));
    myHistoryViewer.getComponent().setPreferredSize(new Dimension(0, 0));
    myConsoleEditor.getSettings().setAdditionalLinesCount(2);
    myConsoleEditor.setHighlighter(
        EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myVirtualFile));
    myHistoryViewer.setCaretEnabled(false);
    myConsoleEditor.setHorizontalScrollbarVisible(true);
    final VisibleAreaListener areaListener =
        new VisibleAreaListener() {
          public void visibleAreaChanged(VisibleAreaEvent e) {
            final int offset = myConsoleEditor.getScrollingModel().getHorizontalScrollOffset();
            final ScrollingModel model = myHistoryViewer.getScrollingModel();
            final int historyOffset = model.getHorizontalScrollOffset();
            if (historyOffset != offset) {
              try {
                model.disableAnimation();
                model.scrollHorizontally(offset);
              } finally {
                model.enableAnimation();
              }
            }
          }
        };
    myConsoleEditor.getScrollingModel().addVisibleAreaListener(areaListener);
    final DocumentAdapter docListener =
        new DocumentAdapter() {
          @Override
          public void documentChanged(final DocumentEvent e) {
            queueUiUpdate(false);
          }
        };
    myEditorDocument.addDocumentListener(docListener, this);
    myHistoryViewer.getDocument().addDocumentListener(docListener, this);

    myHistoryViewer
        .getContentComponent()
        .addKeyListener(
            new KeyAdapter() {
              public void keyTyped(KeyEvent event) {
                if (isConsoleEditorEnabled() && UIUtil.isReallyTypedEvent(event)) {
                  myConsoleEditor.getContentComponent().requestFocus();
                  myConsoleEditor.processKeyTyped(event);
                }
              }
            });
    for (AnAction action : createActions()) {
      action.registerCustomShortcutSet(action.getShortcutSet(), myConsoleEditor.getComponent());
    }
    EmptyAction.registerActionShortcuts(
        myHistoryViewer.getComponent(), myConsoleEditor.getComponent());
  }