Java Code Examples for com.intellij.openapi.editor.Editor#putUserData()

The following examples show how to use com.intellij.openapi.editor.Editor#putUserData() . 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: SmartEnterProcessorWithFixers.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean process(@Nonnull final Project project, @Nonnull final Editor editor, @Nonnull final PsiFile psiFile) {
  final Document document = editor.getDocument();
  final String textForRollback = document.getText();
  try {
    editor.putUserData(SMART_ENTER_TIMESTAMP, editor.getDocument().getModificationStamp());
    myFirstErrorOffset = Integer.MAX_VALUE;
    process(project, editor, psiFile, 0);
  }
  catch (TooManyAttemptsException e) {
    document.replaceString(0, document.getTextLength(), textForRollback);
  }
  finally {
    editor.putUserData(SMART_ENTER_TIMESTAMP, null);
  }
  return true;
}
 
Example 2
Source File: TemplateManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static TemplateState getTemplateState(@Nonnull Editor editor) {
  TemplateState templateState = editor.getUserData(TEMPLATE_STATE_KEY);
  if (templateState != null && templateState.isDisposed()) {
    editor.putUserData(TEMPLATE_STATE_KEY, null);
    return null;
  }
  return templateState;
}
 
Example 3
Source File: SelectOccurrencesActionHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected static boolean isWholeWordSearch(Editor editor) {
  if (!isRepeatedActionInvocation()) {
    editor.putUserData(WHOLE_WORDS, null);
  }
  Boolean value = editor.getUserData(WHOLE_WORDS);
  return value != null;
}
 
Example 4
Source File: EditorFoldingInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static EditorFoldingInfo get(@Nonnull Editor editor) {
  EditorFoldingInfo info = editor.getUserData(KEY);
  if (info == null){
    info = new EditorFoldingInfo();
    editor.putUserData(KEY, info);
  }
  return info;
}
 
Example 5
Source File: TemplateManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void clearTemplateState(@Nonnull Editor editor) {
  TemplateState prevState = getTemplateState(editor);
  if (prevState != null) {
    disposeState(prevState);
  }
  editor.putUserData(TEMPLATE_STATE_KEY, null);
}
 
Example 6
Source File: LSPDiagnosticsToMarkers.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@NotNull
private Map<String, RangeHighlighter[]> getAllMarkers(Editor editor) {
    Map<String, RangeHighlighter[]> allMarkers = editor.getUserData(LSP_MARKER_KEY_PREFIX);
    if (allMarkers == null) {
        allMarkers = new HashMap<>();
        editor.putUserData(LSP_MARKER_KEY_PREFIX, allMarkers);
    }
    return allMarkers;
}
 
Example 7
Source File: ParameterHintsPresentationManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void scheduleRendererUpdate(Editor editor, Inlay inlay) {
  AnimationStep step = editor.getUserData(ANIMATION_STEP);
  if (step == null) {
    editor.putUserData(ANIMATION_STEP, step = new AnimationStep(editor));
  }
  step.inlays.add(inlay);
  scheduleAnimationStep(step);
}
 
Example 8
Source File: BraceHighlightingHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private List<RangeHighlighter> getHighlightersList() {
  // braces are highlighted across the whole editor, not in each injected editor separately
  Editor editor = myEditor instanceof EditorWindow ? ((EditorWindow)myEditor).getDelegate() : myEditor;
  List<RangeHighlighter> highlighters = editor.getUserData(BRACE_HIGHLIGHTERS_IN_EDITOR_VIEW_KEY);
  if (highlighters == null) {
    highlighters = new ArrayList<>();
    editor.putUserData(BRACE_HIGHLIGHTERS_IN_EDITOR_VIEW_KEY, highlighters);
  }
  return highlighters;
}
 
Example 9
Source File: HippieWordCompletionHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static CompletionState getCompletionState(Editor editor) {
  CompletionState state = editor.getUserData(KEY_STATE);
  if (state == null) {
    state = new CompletionState();
    editor.putUserData(KEY_STATE, state);
  }

  return state;
}
 
Example 10
Source File: EditorFactoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(@Nonnull Editor editor, char charTyped, @Nonnull DataContext dataContext) {
  editor.putUserData(DesktopEditorImpl.DISABLE_CARET_SHIFT_ON_WHITESPACE_INSERTION, Boolean.TRUE);
  try {
    myDelegate.execute(editor, charTyped, dataContext);
  }
  finally {
    editor.putUserData(DesktopEditorImpl.DISABLE_CARET_SHIFT_ON_WHITESPACE_INSERTION, null);
  }
}
 
Example 11
Source File: PasteAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredWriteAction
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
  TextRange range = null;
  if (myTransferable != null) {
    TextRange[] ranges = EditorCopyPasteHelper.getInstance().pasteTransferable(editor, myTransferable);
    if (ranges != null && ranges.length == 1) {
      range = ranges[0];
    }
  }
  editor.putUserData(EditorEx.LAST_PASTED_REGION, range);
}
 
Example 12
Source File: JSGraphQLToggleVariablesAction.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public void setSelected(AnActionEvent e, boolean state) {

    final Editor variablesEditor = getVariablesEditor(e);
    if (variablesEditor != null) {

        final Editor queryEditor = variablesEditor.getUserData(JSGraphQLLanguageUIProjectService.GRAPH_QL_QUERY_EDITOR);
        if(queryEditor == null) {
            // not linked to a query editor
            return;
        }

        final ScrollingModel scroll = queryEditor.getScrollingModel();
        final int currentScroll = scroll.getVerticalScrollOffset();

        variablesEditor.putUserData(JS_GRAPH_QL_VARIABLES_MODEL, state ? Boolean.TRUE : Boolean.FALSE);
        variablesEditor.getComponent().setVisible(state);

        if (state) {
            variablesEditor.getContentComponent().grabFocus();
        } else {
            queryEditor.getContentComponent().grabFocus();
        }

        // restore scroll position after the editor has had a chance to re-layout
        ApplicationManager.getApplication().invokeLater(() -> {
            UIUtil.invokeLaterIfNeeded(() -> scroll.scrollVertically(currentScroll));
        });

    }

}
 
Example 13
Source File: CodeFoldingPass.java    From consulo with Apache License 2.0 4 votes vote down vote up
static void clearFirstTimeFlag(PsiFile file, Editor editor, Key<Boolean> key) {
  file.putUserData(key, Boolean.FALSE);
  editor.putUserData(key, Boolean.FALSE);
}
 
Example 14
Source File: HighlightCommand.java    From CppTools with Apache License 2.0 4 votes vote down vote up
private void doAddHighlighters(Editor editor, List<String> highlighterStringList, boolean overriden) {
  if (stamp != communicator.getModificationCount() || failed) return;

  final long started = System.currentTimeMillis();
  Key<THashSet<RangeHighlighter>> highlightersKey = overriden ? myOverridenHighlightersKey : myHighlightersKey;
  THashSet<RangeHighlighter> currentHighlighters = editor.getUserData(highlightersKey);
  final THashSet<RangeHighlighter> invalidMarkers;    

  if (currentHighlighters == null) {
    invalidMarkers = new THashSet<RangeHighlighter>(10000);
  } else {
    invalidMarkers = currentHighlighters;
  }

  currentHighlighters = new THashSet<RangeHighlighter>();
  editor.putUserData(highlightersKey, currentHighlighters);

  final TIntObjectHashMap<RangeHighlighter> lastOffsetToHighlightersMap = new TIntObjectHashMap<RangeHighlighter>();
  final TIntObjectHashMap<RangeHighlighter> overridenMap = new TIntObjectHashMap<RangeHighlighter>();
  final TIntObjectHashMap<RangeHighlighter> overriddingMap = new TIntObjectHashMap<RangeHighlighter>();

  for(RangeHighlighter h:invalidMarkers) {
    if (!h.isValid()) continue;

    final GutterIconRenderer gutterIconRenderer = h.getGutterIconRenderer();
    final int offset = h.getStartOffset();

    if ((!overriden && gutterIconRenderer == null)) {
      lastOffsetToHighlightersMap.put(offset, h);
    } else if (overriden && gutterIconRenderer != null) {
      final HighlightUtils.MyGutterIconRenderer myGutterIconRenderer = (HighlightUtils.MyGutterIconRenderer) gutterIconRenderer;
      final boolean overrides = myGutterIconRenderer.isOverrides();
      
      ((HighlightUtils.MyGutterIconRenderer) gutterIconRenderer).clearData();
      ((overrides)?overriddingMap:overridenMap).put(offset, h);
    }
  }

  final EditorColorsScheme colorsScheme = editor.getColorsScheme();

  for(String s: highlighterStringList) {
    processHighlighterString(editor, colorsScheme, s, overriddingMap, overridenMap, lastOffsetToHighlightersMap,
      currentHighlighters, invalidMarkers);
  }

  //System.out.println("Updated highlighters 2/5 for "+ (System.currentTimeMillis() - started));
  for(RangeHighlighter rangeHighlighter:invalidMarkers) {
    editor.getMarkupModel().removeHighlighter(rangeHighlighter);
    currentHighlighters.remove(rangeHighlighter);
  }

  long doneFor = System.currentTimeMillis() - started;
  //System.out.println("Updated highlighters 2 for "+ doneFor);
  Communicator.debug("Updated highlighters 2 for "+ doneFor);
}
 
Example 15
Source File: FoldingUpdate.java    From consulo with Apache License 2.0 4 votes vote down vote up
static void clearFoldingCache(@Nonnull Editor editor) {
  editor.putUserData(CODE_FOLDING_KEY, null);
}
 
Example 16
Source File: BreadcrumbsForceShownSettings.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean setForcedShown(@Nullable Boolean selected, @Nonnull Editor editor) {
  Boolean old = getForcedShown(editor);
  editor.putUserData(FORCED_BREADCRUMBS, selected);
  return !Objects.equals(old, selected);
}
 
Example 17
Source File: SelectOccurrencesActionHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected static boolean getAndResetNotFoundStatus(Editor editor) {
  boolean status = editor.getUserData(NOT_FOUND) != null;
  editor.putUserData(NOT_FOUND, null);
  return status && isRepeatedActionInvocation();
}
 
Example 18
Source File: SelectOccurrencesActionHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected static void setNotFoundStatus(Editor editor) {
  editor.putUserData(NOT_FOUND, Boolean.TRUE);
}
 
Example 19
Source File: SelectOccurrencesActionHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected static void setWholeWordSearch(Editor editor, boolean isWholeWordSearch) {
  editor.putUserData(WHOLE_WORDS, isWholeWordSearch);
}
 
Example 20
Source File: JSGraphQLLanguageUIProjectService.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
private JComponent createHeaderComponent(FileEditor fileEditor, Editor editor, VirtualFile file) {

        final JSGraphQLEditorHeaderComponent headerComponent = new JSGraphQLEditorHeaderComponent();

        // variables & settings actions
        final DefaultActionGroup settingsActions = new DefaultActionGroup();
        settingsActions.add(new GraphQLEditConfigAction());
        settingsActions.add(new JSGraphQLToggleVariablesAction());

        final JComponent settingsToolbar = createToolbar(settingsActions);
        headerComponent.add(settingsToolbar, BorderLayout.WEST);

        // query execute
        final DefaultActionGroup queryActions = new DefaultActionGroup();
        final AnAction executeGraphQLAction = ActionManager.getInstance().getAction(JSGraphQLExecuteEditorAction.class.getName());
        queryActions.add(executeGraphQLAction);
        final JComponent queryToolbar = createToolbar(queryActions);

        // configured endpoints combo box
        final List<GraphQLConfigEndpoint> endpoints = GraphQLConfigManager.getService(myProject).getEndpoints(file);
        final JSGraphQLEndpointsModel endpointsModel = new JSGraphQLEndpointsModel(endpoints, PropertiesComponent.getInstance(myProject));
        final ComboBox endpointComboBox = new ComboBox(endpointsModel);
        endpointComboBox.setToolTipText("GraphQL endpoint");
        editor.putUserData(JS_GRAPH_QL_ENDPOINTS_MODEL, endpointsModel);
        final JPanel endpointComboBoxPanel = new JPanel(new BorderLayout());
        endpointComboBoxPanel.setBorder(BorderFactory.createEmptyBorder(1, 2, 2, 2));
        endpointComboBoxPanel.add(endpointComboBox);

        // splitter to resize endpoints
        final OnePixelSplitter splitter = new OnePixelSplitter(false, .25F);
        splitter.setBorder(BorderFactory.createEmptyBorder());
        splitter.setFirstComponent(endpointComboBoxPanel);
        splitter.setSecondComponent(queryToolbar);
        splitter.setHonorComponentsMinimumSize(true);
        splitter.setAndLoadSplitterProportionKey("JSGraphQLEndpointSplitterProportion");
        splitter.setOpaque(false);
        splitter.getDivider().setOpaque(false);

        headerComponent.add(splitter, BorderLayout.CENTER);

        // variables editor
        final LightVirtualFile virtualFile = new LightVirtualFile(GRAPH_QL_VARIABLES_JSON, JsonFileType.INSTANCE, "");
        final FileEditor variablesFileEditor = PsiAwareTextEditorProvider.getInstance().createEditor(myProject, virtualFile);
        final EditorEx variablesEditor = (EditorEx) ((TextEditor) variablesFileEditor).getEditor();
        virtualFile.putUserData(IS_GRAPH_QL_VARIABLES_VIRTUAL_FILE, Boolean.TRUE);
        variablesEditor.setPlaceholder("{ variables }");
        variablesEditor.setShowPlaceholderWhenFocused(true);
        variablesEditor.getSettings().setRightMarginShown(false);
        variablesEditor.getSettings().setAdditionalLinesCount(0);
        variablesEditor.getSettings().setShowIntentionBulb(false);
        variablesEditor.getSettings().setFoldingOutlineShown(false);
        variablesEditor.getSettings().setLineNumbersShown(false);
        variablesEditor.getSettings().setLineMarkerAreaShown(false);
        variablesEditor.getSettings().setCaretRowShown(false);
        variablesEditor.putUserData(JS_GRAPH_QL_ENDPOINTS_MODEL, endpointsModel);

        // hide variables by default
        variablesEditor.getComponent().setVisible(false);

        // link the query and variables editor together
        variablesEditor.putUserData(GRAPH_QL_QUERY_EDITOR, editor);
        editor.putUserData(GRAPH_QL_VARIABLES_EDITOR, variablesEditor);

        final NonOpaquePanel variablesPanel = new NonOpaquePanel(variablesFileEditor.getComponent());
        variablesPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));

        Disposer.register(fileEditor, variablesFileEditor);

        headerComponent.add(variablesPanel, BorderLayout.SOUTH);

        return headerComponent;
    }