List of usage examples for com.intellij.openapi.actionSystem.ex ActionManagerEx getInstanceEx
public static ActionManagerEx getInstanceEx()
From source file:be.janickreynders.shortcuttranslator.ShortcutTranslatorDialog.java
License:Open Source License
private AnAction getAction(String actionId) { return ActionManagerEx.getInstanceEx().getAction(actionId); }
From source file:com.android.tools.idea.monitor.MonitorPanel.java
License:Apache License
@NotNull private ActionToolbarImpl setupToolbar(@NotNull ActionGroup actions, @NotNull BaseMonitorView monitor) { DefaultActionGroup viewActions = new DefaultActionGroup(); viewActions.addAll(actions);// w w w . ja v a2 s.c om viewActions.add(new MonitorMoveAction(this, monitor, -1)); viewActions.add(new MonitorMoveAction(this, monitor, 1)); viewActions.add(new MinimizeAction(this, monitor)); ActionToolbarImpl toolbar = new ActionToolbarImpl(ActionPlaces.UNKNOWN, viewActions, true, false, DataManager.getInstance(), ActionManagerEx.getInstanceEx(), KeymapManagerEx.getInstanceEx()); toolbar.setBorder(BorderFactory.createEmptyBorder()); toolbar.setMinimumSize(new Dimension(0, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE.height)); toolbar.setPreferredSize( new Dimension(Integer.MAX_VALUE, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE.height)); toolbar.setMaximumSize(toolbar.getPreferredSize()); return toolbar; }
From source file:com.android.tools.idea.rendering.errors.ui.RenderErrorPanel.java
License:Apache License
public RenderErrorPanel() { super(new BorderLayout()); myModel = new RenderErrorModel(Collections.emptyList()); myHtmlDetailPane = new JEditorPane(UIUtil.HTML_MIME, EMPTY_HTML_BODY); myHtmlDetailPane.setEditable(false); myHtmlDetailPane.addHyperlinkListener(e -> { // TODO: Currently all issues share a common hyperlink listener for now so just get any of them. Different issues // should be able to have different handlers HyperlinkListener listener = myModel.getElementAt(0).getHyperlinkListener(); if (listener != null) { listener.hyperlinkUpdate(e); }/*w w w . java 2 s . c om*/ }); myHtmlDetailPane.setContentType(UIUtil.HTML_MIME); myHtmlDetailPane.setMargin(JBUI.insets(10)); myList = new JBList(); // Set a prototype to allow us do measurements of the list //noinspection unchecked myList.setPrototypeCellValue(RenderErrorModel.Issue.builder().setSummary("Prototype").build()); myList.setCellRenderer(new ColoredListCellRenderer<RenderErrorModel.Issue>() { @Override protected void customizeCellRenderer(JList list, @NotNull RenderErrorModel.Issue value, int index, boolean selected, boolean hasFocus) { Icon icon = getSeverityIcon(value.getSeverity()); if (icon != null) { setIcon(icon); } append(value.getSummary()); } }); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myList.addListSelectionListener(e -> { int selectedIndex = myList.getSelectedIndex(); if (selectedIndex != -1) { HtmlBuilder htmlBuilder = new HtmlBuilder(); RenderErrorModel.Issue selectedIssue = (RenderErrorModel.Issue) myList.getModel() .getElementAt(selectedIndex); htmlBuilder.addHtml(selectedIssue.getHtmlContent()).newline(); try { myHtmlDetailPane.read(new StringReader(htmlBuilder.getHtml()), null); HtmlBuilderHelper.fixFontStyles(myHtmlDetailPane); myHtmlDetailPane.setCaretPosition(0); } catch (IOException e1) { setEmptyHtmlDetail(); } } else { setEmptyHtmlDetail(); } revalidate(); repaint(); }); ActionToolbarImpl toolbar = new ActionToolbarImpl(ActionPlaces.UNKNOWN, getActionGroup(), true, false, DataManager.getInstance(), ActionManagerEx.getInstanceEx(), KeymapManagerEx.getInstanceEx()); toolbar.setLayoutPolicy(NOWRAP_LAYOUT_POLICY); toolbar.setBorder(JBUI.Borders.empty()); Box titlePanel = Box.createHorizontalBox(); myTitleLabel = new JBLabel(TITLE, SwingConstants.LEFT); myTitleLabel.setBorder(JBUI.Borders.empty(0, 5, 0, 20)); myTitleLabel .setPreferredSize(new Dimension(Short.MAX_VALUE, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE.height)); myTitleLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { // Double clicking the title bar is the same as clicking the minimize action MinimizeAction minimizeAction = new MinimizeAction(); AnActionEvent event = AnActionEvent.createFromAnAction(minimizeAction, e, "unknown", DataManager.getInstance().getDataContext(myTitleLabel)); ActionUtil.performActionDumbAware(minimizeAction, event); } } }); titlePanel.add(myTitleLabel); titlePanel.add(toolbar.getComponent()); titlePanel.setMaximumSize(new Dimension(Short.MAX_VALUE, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE.height)); myListScrollPane = createScrollPane(myList); // We display a minimum of 3 issues and a maximum of 5. When there are more than 5 issues, a scrollbar is displayed myListScrollPane.setMinimumSize(JBUI.size(0, myList.getFixedCellHeight() * 3)); myListScrollPane.setPreferredSize(JBUI.size(Short.MAX_VALUE, myList.getFixedCellHeight() * 3)); myListScrollPane.setMaximumSize(JBUI.size(Short.MAX_VALUE, myList.getFixedCellHeight() * 5)); myListScrollPane.setBorder(JBUI.Borders.empty()); myHtmlScrollPane = createScrollPane(myHtmlDetailPane); myHtmlScrollPane.setBorder(JBUI.Borders.customLine(UIUtil.getPanelBackground(), 5, 0, 0, 0)); Box rootPanel = Box.createVerticalBox(); titlePanel.setAlignmentX(CENTER_ALIGNMENT); myListScrollPane.setAlignmentX(CENTER_ALIGNMENT); myHtmlScrollPane.setAlignmentX(CENTER_ALIGNMENT); rootPanel.add(titlePanel); rootPanel.add(myListScrollPane); rootPanel.add(myHtmlScrollPane); add(rootPanel); isMinimized = PropertiesComponent.getInstance().getBoolean(PROPERTY_MINIMIZED, false); myListScrollPane.setVisible(!isMinimized); myHtmlScrollPane.setVisible(!isMinimized); updateTitlebarStyle(); }
From source file:com.chrisrm.idea.ui.MTTitlePane.java
License:Open Source License
private void installSubcomponents() { int decorationStyle = getWindowDecorationStyle(); if (decorationStyle == JRootPane.FRAME) { createActions();/*from w ww. j av a 2 s .c o m*/ myMenuBar = createMenuBar(); if (myRootPane instanceof IdeRootPane) { myIdeMenu = new IdeMenuBar(ActionManagerEx.getInstanceEx(), DataManager.getInstance()); add(myIdeMenu); } add(myMenuBar); createButtons(); add(myHelpButton); add(myIconifyButton); add(myToggleButton); add(myCloseButton); } else if (decorationStyle == JRootPane.PLAIN_DIALOG || decorationStyle == JRootPane.INFORMATION_DIALOG || decorationStyle == JRootPane.ERROR_DIALOG || decorationStyle == JRootPane.COLOR_CHOOSER_DIALOG || decorationStyle == JRootPane.FILE_CHOOSER_DIALOG || decorationStyle == JRootPane.QUESTION_DIALOG || decorationStyle == JRootPane.WARNING_DIALOG) { createActions(); createButtons(); add(myHelpButton); add(myCloseButton); } }
From source file:com.intellij.codeInsight.AutoPopupController.java
License:Apache License
private void setupListeners() { ActionManagerEx.getInstanceEx().addAnActionListener(new AnActionListener() { @Override//from w w w. ja v a2 s. c o m public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) { cancelAllRequest(); } @Override public void beforeEditorTyping(char c, DataContext dataContext) { cancelAllRequest(); } @Override public void afterActionPerformed(final AnAction action, final DataContext dataContext, AnActionEvent event) { } }, this); IdeEventQueue.getInstance().addActivityListener(new Runnable() { @Override public void run() { cancelAllRequest(); } }, this); }
From source file:com.intellij.codeInsight.daemon.impl.actions.ShowErrorDescriptionAction.java
License:Apache License
private static void changeState() { if (Comparing.strEqual(ActionManagerEx.getInstanceEx().getPrevPreformedActionId(), IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)) { shouldShowDescription = descriptionShown; } else {/*from ww w.ja v a2s . c om*/ shouldShowDescription = false; descriptionShown = true; } }
From source file:com.intellij.codeInsight.documentation.DocumentationManager.java
License:Apache License
public DocumentationManager(final Project project, ActionManagerEx managerEx) { super(project); myActionManagerEx = managerEx;/*from w w w .j a v a 2s . c o m*/ final AnActionListener actionListener = new AnActionListener() { @Override public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) { final JBPopup hint = getDocInfoHint(); if (hint != null) { if (action instanceof HintManagerImpl.ActionToIgnore) { ((AbstractPopup) hint).focusPreferredComponent(); return; } if (action instanceof ListScrollingUtil.ListScrollAction) return; if (action == myActionManagerEx.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN)) return; if (action == myActionManagerEx.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP)) return; if (action == myActionManagerEx.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_PAGE_DOWN)) return; if (action == myActionManagerEx.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_PAGE_UP)) return; if (action == ActionManagerEx.getInstanceEx().getAction(IdeActions.ACTION_EDITOR_ESCAPE)) return; if (ActionPlaces.JAVADOC_INPLACE_SETTINGS.equals(event.getPlace())) return; if (action instanceof BaseNavigateToSourceAction) return; closeDocHint(); } } @Override public void beforeEditorTyping(char c, DataContext dataContext) { final JBPopup hint = getDocInfoHint(); if (hint != null && LookupManager.getActiveLookup(myEditor) == null) { hint.cancel(); } } @Override public void afterActionPerformed(final AnAction action, final DataContext dataContext, AnActionEvent event) { } }; myActionManagerEx.addAnActionListener(actionListener, project); myUpdateDocAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, myProject); }
From source file:com.intellij.codeInsight.documentation.DocumentationManager.java
License:Apache License
private void showInPopup(@NotNull final PsiElement element, boolean requestFocus, PopupUpdateProcessor updateProcessor, final PsiElement originalElement, @Nullable final Runnable closeCallback) { final DocumentationComponent component = new DocumentationComponent(this); component.setNavigateCallback(new Consumer<PsiElement>() { @Override// www . j av a 2 s . com public void consume(PsiElement psiElement) { final AbstractPopup jbPopup = (AbstractPopup) getDocInfoHint(); if (jbPopup != null) { final String title = getTitle(psiElement, false); jbPopup.setCaption(title); } } }); Processor<JBPopup> pinCallback = new Processor<JBPopup>() { @Override public boolean process(JBPopup popup) { createToolWindow(element, originalElement); myToolWindow.setAutoHide(false); popup.cancel(); return false; } }; ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { createToolWindow(element, originalElement); final JBPopup hint = getDocInfoHint(); if (hint != null && hint.isVisible()) hint.cancel(); } }; List<Pair<ActionListener, KeyStroke>> actions = ContainerUtil.newSmartList(); AnAction quickDocAction = ActionManagerEx.getInstanceEx().getAction(IdeActions.ACTION_QUICK_JAVADOC); for (Shortcut shortcut : quickDocAction.getShortcutSet().getShortcuts()) { if (!(shortcut instanceof KeyboardShortcut)) continue; actions.add(Pair.create(actionListener, ((KeyboardShortcut) shortcut).getFirstKeyStroke())); } boolean hasLookup = LookupManager.getActiveLookup(myEditor) != null; final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component) .setProject(element.getProject()).addListener(updateProcessor).addUserData(updateProcessor) .setKeyboardActions(actions).setDimensionServiceKey(myProject, JAVADOC_LOCATION_AND_SIZE, false) .setResizable(true).setMovable(true).setRequestFocus(requestFocus) .setCancelOnClickOutside(!hasLookup) // otherwise selecting lookup items by mouse would close the doc .setTitle(getTitle(element, false)).setCouldPin(pinCallback).setModalContext(false) .setCancelCallback(new Computable<Boolean>() { @Override public Boolean compute() { myCloseOnSneeze = false; if (closeCallback != null) { closeCallback.run(); } if (fromQuickSearch()) { ((ChooseByNameBase.JPanelProvider) myPreviouslyFocused.getParent()).unregisterHint(); } Disposer.dispose(component); myEditor = null; myPreviouslyFocused = null; return Boolean.TRUE; } }).setKeyEventHandler(new BooleanFunction<KeyEvent>() { @Override public boolean fun(KeyEvent e) { if (myCloseOnSneeze) { closeDocHint(); } if ((AbstractPopup.isCloseRequest(e) && getDocInfoHint() != null)) { closeDocHint(); return true; } return false; } }).createPopup(); component.setHint(hint); if (myEditor == null) { // subsequent invocation of javadoc popup from completion will have myEditor == null because of cancel invoked, // so reevaluate the editor for proper popup placement Lookup lookup = LookupManager.getInstance(myProject).getActiveLookup(); myEditor = lookup != null ? lookup.getEditor() : null; } fetchDocInfo(getDefaultCollector(element, originalElement), component); myDocInfoHintRef = new WeakReference<JBPopup>(hint); if (fromQuickSearch() && myPreviouslyFocused != null) { ((ChooseByNameBase.JPanelProvider) myPreviouslyFocused.getParent()).registerHint(hint); } }
From source file:com.intellij.codeInsight.generation.CommentByLineCommentHandler.java
License:Apache License
@RequiredDispatchThread @Override//from www .j av a 2s . c o m public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { if (!CodeInsightUtilBase.prepareEditorForWrite(editor)) return; myProject = project; myFile = file.getViewProvider().getPsi(file.getViewProvider().getBaseLanguage()); myEditor = editor; PsiElement context = InjectedLanguageManager.getInstance(myFile.getProject()).getInjectionHost(myFile); if (context != null && (context.textContains('\'') || context.textContains('\"'))) { String s = context.getText(); if (StringUtil.startsWith(s, "\"") || StringUtil.startsWith(s, "\'")) { myFile = context.getContainingFile(); myEditor = editor instanceof EditorWindow ? ((EditorWindow) editor).getDelegate() : editor; } } myDocument = myEditor.getDocument(); if (!FileDocumentManager.getInstance().requestWriting(myDocument, project)) { return; } PsiDocumentManager.getInstance(project).commitDocument(myDocument); FeatureUsageTracker.getInstance().triggerFeatureUsed("codeassists.comment.line"); myCodeStyleManager = CodeStyleManager.getInstance(myProject); final SelectionModel selectionModel = myEditor.getSelectionModel(); boolean hasSelection = selectionModel.hasSelection(); myStartOffset = selectionModel.getSelectionStart(); myEndOffset = selectionModel.getSelectionEnd(); FoldRegion fold = myEditor.getFoldingModel().getCollapsedRegionAtOffset(myStartOffset); if (fold != null && fold.shouldNeverExpand() && fold.getStartOffset() == myStartOffset && fold.getEndOffset() == myEndOffset) { // Foldings that never expand are automatically selected, so the fact it is selected must not interfer with commenter's logic hasSelection = false; } if (myDocument.getTextLength() == 0) return; while (true) { int lastLineEnd = myDocument.getLineEndOffset(myDocument.getLineNumber(myEndOffset)); FoldRegion collapsedAt = myEditor.getFoldingModel().getCollapsedRegionAtOffset(lastLineEnd); if (collapsedAt != null) { final int endOffset = collapsedAt.getEndOffset(); if (endOffset <= myEndOffset) { break; } myEndOffset = endOffset; } else { break; } } boolean wholeLinesSelected = !hasSelection || myStartOffset == myDocument .getLineStartOffset(myDocument.getLineNumber(myStartOffset)) && myEndOffset == myDocument.getLineEndOffset(myDocument.getLineNumber(myEndOffset - 1)) + 1; boolean startingNewLineComment = !hasSelection && isLineEmpty(myDocument.getLineNumber(myStartOffset)) && !Comparing.equal(IdeActions.ACTION_COMMENT_LINE, ActionManagerEx.getInstanceEx().getPrevPreformedActionId()); doComment(); if (startingNewLineComment) { final Commenter commenter = myCommenters[0]; if (commenter != null) { String prefix; if (commenter instanceof SelfManagingCommenter) { prefix = ((SelfManagingCommenter) commenter).getCommentPrefix(myStartLine, myDocument, myCommenterStateMap.get((SelfManagingCommenter) commenter)); if (prefix == null) prefix = ""; // TODO } else { prefix = commenter.getLineCommentPrefix(); if (prefix == null) prefix = commenter.getBlockCommentPrefix(); } int lineStart = myDocument.getLineStartOffset(myStartLine); lineStart = CharArrayUtil.shiftForward(myDocument.getCharsSequence(), lineStart, " \t"); lineStart += prefix.length(); lineStart = CharArrayUtil.shiftForward(myDocument.getCharsSequence(), lineStart, " \t"); if (lineStart > myDocument.getTextLength()) lineStart = myDocument.getTextLength(); myEditor.getCaretModel().moveToOffset(lineStart); myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); } } else { if (!hasSelection) { // Don't tweak caret position if we're already located on the last document line. LogicalPosition position = myEditor.getCaretModel().getLogicalPosition(); if (position.line < myDocument.getLineCount() - 1) { int verticalShift = 1 + myEditor.getSoftWrapModel().getSoftWrapsForLine(position.line).size() - position.softWrapLinesOnCurrentLogicalLine; myEditor.getCaretModel().moveCaretRelatively(0, verticalShift, false, false, true); } } else { if (wholeLinesSelected) { selectionModel.setSelection(myStartOffset, selectionModel.getSelectionEnd()); } } } }
From source file:com.intellij.codeInsight.highlighting.HighlightManagerImpl.java
License:Apache License
@Override public void projectOpened() { AnActionListener anActionListener = new MyAnActionListener(); ActionManagerEx.getInstanceEx().addAnActionListener(anActionListener, myProject); DocumentListener documentListener = new DocumentAdapter() { @Override/* ww w . java2 s . co m*/ public void documentChanged(DocumentEvent event) { Document document = event.getDocument(); Editor[] editors = EditorFactory.getInstance().getEditors(document); for (Editor editor : editors) { Map<RangeHighlighter, HighlightInfo> map = getHighlightInfoMap(editor, false); if (map == null) return; ArrayList<RangeHighlighter> highlightersToRemove = new ArrayList<RangeHighlighter>(); for (RangeHighlighter highlighter : map.keySet()) { HighlightInfo info = map.get(highlighter); if (!info.editor.getDocument().equals(document)) continue; if ((info.flags & HIDE_BY_TEXT_CHANGE) != 0) { highlightersToRemove.add(highlighter); } } for (RangeHighlighter highlighter : highlightersToRemove) { removeSegmentHighlighter(editor, highlighter); } } } }; EditorFactory.getInstance().getEventMulticaster().addDocumentListener(documentListener, myProject); }