private void registerShortcut( @NotNull String actionId, @NotNull ShortcutSet shortcut, @NotNull JComponent component) { final AnAction action = ActionManager.getInstance().getAction(actionId); if (action != null) { action.registerCustomShortcutSet(shortcut, component, this); } }
private void registerFileChooserShortcut( @NonNls final String baseActionId, @NonNls final String fileChooserActionId) { final JTree tree = myFileSystemTree.getTree(); final AnAction syncAction = ActionManager.getInstance().getAction(fileChooserActionId); AnAction original = ActionManager.getInstance().getAction(baseActionId); syncAction.registerCustomShortcutSet(original.getShortcutSet(), tree, myDisposable); }
public static void registerActionShortcuts( final List<AnAction> actions, final JComponent component) { for (AnAction action : actions) { if (action.getShortcutSet() != null) { action.registerCustomShortcutSet(action.getShortcutSet(), component); } } }
private void registerCustomShortcuts(DirDiffToolbarActions actions, JComponent component) { for (AnAction action : actions.getChildren(null)) { if (action instanceof ShortcutProvider) { final ShortcutSet shortcut = ((ShortcutProvider) action).getShortcut(); if (shortcut != null) { action.registerCustomShortcutSet(shortcut, component); } } } }
protected void buildToolBar(final DefaultActionGroup toolBarGroup) { myDiffAction = new DumbAwareAction() { public void update(AnActionEvent e) { e.getPresentation().setEnabled(canShowDiff()); } public void actionPerformed(AnActionEvent e) { showDiff(); } }; ActionUtil.copyFrom(myDiffAction, "ChangesView.Diff"); myDiffAction.registerCustomShortcutSet(myViewer, null); toolBarGroup.add(myDiffAction); }
protected void init() { addActionsTo(myToolbarGroup); myToolbarGroup.add(new MyCloseAction()); myToolbarGroup.add(ActionManager.getInstance().getAction(IdeActions.ACTION_CONTEXT_HELP)); ActionToolbar toolbar = ActionManager.getInstance() .createActionToolbar( ActionPlaces.FILEHISTORY_VIEW_TOOLBAR, myToolbarGroup, !myVerticalToolbar); JComponent centerPanel = createCenterPanel(); toolbar.setTargetComponent(centerPanel); for (AnAction action : myToolbarGroup.getChildren(null)) { action.registerCustomShortcutSet(action.getShortcutSet(), centerPanel); } add(centerPanel, BorderLayout.CENTER); if (myVerticalToolbar) { add(toolbar.getComponent(), BorderLayout.WEST); } else { add(toolbar.getComponent(), BorderLayout.NORTH); } }
private DefaultActionGroup createActionGroup() { DefaultActionGroup actionGroup = new DefaultActionGroup(); if (ApplicationManager.getApplication() == null || Pico.isUnitTest()) return actionGroup; addRefreshAction(actionGroup); myOpenFileAction = new OpenFileAction(myTree, myIdeFacade); myOpenFileAction.registerCustomShortcutSet( new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0)), myTree); AnAction diffAction = new DiffAction(myTree) { protected User getUser() { return myUser; } }; diffAction.registerCustomShortcutSet(CommonShortcuts.getDiff(), myTree); actionGroup.add(myOpenFileAction); actionGroup.add(diffAction); addToggleReadOnlyAction(actionGroup); return actionGroup; }
public ClasspathPanelImpl(ModuleConfigurationState state) { super(new BorderLayout()); myState = state; myModel = new ClasspathTableModel(state, getStructureConfigurableContext()); myEntryTable = new JBTable(myModel) { @Override protected TableRowSorter<TableModel> createRowSorter(TableModel model) { return new DefaultColumnInfoBasedRowSorter(model) { @Override public void toggleSortOrder(int column) { if (isSortable(column)) { SortKey oldKey = ContainerUtil.getFirstItem(getSortKeys()); SortOrder oldOrder; if (oldKey == null || oldKey.getColumn() != column) { oldOrder = SortOrder.UNSORTED; } else { oldOrder = oldKey.getSortOrder(); } setSortKeys( Collections.singletonList(new SortKey(column, getNextSortOrder(oldOrder)))); } } }; } }; myEntryTable.setShowGrid(false); myEntryTable.setDragEnabled(false); myEntryTable.setIntercellSpacing(new Dimension(0, 0)); myEntryTable.setDefaultRenderer( ClasspathTableItem.class, new TableItemRenderer(getStructureConfigurableContext())); myEntryTable.setDefaultRenderer( Boolean.class, new ExportFlagRenderer(myEntryTable.getDefaultRenderer(Boolean.class))); JComboBox scopeEditor = new ComboBox(new EnumComboBoxModel<DependencyScope>(DependencyScope.class)); myEntryTable.setDefaultEditor(DependencyScope.class, new DefaultCellEditor(scopeEditor)); myEntryTable.setDefaultRenderer( DependencyScope.class, new ComboBoxTableRenderer<DependencyScope>(DependencyScope.values()) { @Override protected String getTextFor(@NotNull final DependencyScope value) { return value.getDisplayName(); } }); myEntryTable.setTransferHandler( new TransferHandler() { @Nullable @Override protected Transferable createTransferable(JComponent c) { OrderEntry entry = getSelectedEntry(); if (entry == null) return null; String text = entry.getPresentableName(); return new TextTransferable(text); } @Override public int getSourceActions(JComponent c) { return COPY; } }); myEntryTable .getSelectionModel() .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); new SpeedSearchBase<JBTable>(myEntryTable) { @Override public int getSelectedIndex() { return myEntryTable.getSelectedRow(); } @Override protected int convertIndexToModel(int viewIndex) { return myEntryTable.convertRowIndexToModel(viewIndex); } @Override public Object[] getAllElements() { final int count = myModel.getRowCount(); Object[] elements = new Object[count]; for (int idx = 0; idx < count; idx++) { elements[idx] = myModel.getItem(idx); } return elements; } @Override public String getElementText(Object element) { return getCellAppearance( (ClasspathTableItem<?>) element, getStructureConfigurableContext(), false) .getText(); } @Override public void selectElement(Object element, String selectedText) { final int count = myModel.getRowCount(); for (int row = 0; row < count; row++) { if (element.equals(myModel.getItem(row))) { final int viewRow = myEntryTable.convertRowIndexToView(row); myEntryTable.getSelectionModel().setSelectionInterval(viewRow, viewRow); TableUtil.scrollSelectionToVisible(myEntryTable); break; } } } }; setFixedColumnWidth(ClasspathTableModel.EXPORT_COLUMN); setFixedColumnWidth(ClasspathTableModel.SCOPE_COLUMN); // leave space for combobox border myEntryTable.registerKeyboardAction( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final int[] selectedRows = myEntryTable.getSelectedRows(); boolean currentlyMarked = true; for (final int selectedRow : selectedRows) { final ClasspathTableItem<?> item = getItemAt(selectedRow); if (selectedRow < 0 || !item.isExportable()) { return; } currentlyMarked &= item.isExported(); } for (final int selectedRow : selectedRows) { getItemAt(selectedRow).setExported(!currentlyMarked); } myModel.fireTableDataChanged(); TableUtil.selectRows(myEntryTable, selectedRows); } }, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), WHEN_FOCUSED); myEditButton = new AnActionButton( ProjectBundle.message("module.classpath.button.edit"), null, IconUtil.getEditIcon()) { @Override public void actionPerformed(@NotNull AnActionEvent e) { doEdit(); } @Override public boolean isEnabled() { ClasspathTableItem<?> selectedItem = getSelectedItem(); return selectedItem != null && selectedItem.isEditable(); } @Override public boolean isDumbAware() { return true; } }; add(createTableWithButtons(), BorderLayout.CENTER); if (myEntryTable.getRowCount() > 0) { myEntryTable.getSelectionModel().setSelectionInterval(0, 0); } new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { navigate(true); return true; } }.installOn(myEntryTable); DefaultActionGroup actionGroup = new DefaultActionGroup(); final AnAction navigateAction = new AnAction(ProjectBundle.message("classpath.panel.navigate.action.text")) { @Override public void actionPerformed(@NotNull AnActionEvent e) { navigate(false); } @Override public void update(@NotNull AnActionEvent e) { final Presentation presentation = e.getPresentation(); presentation.setEnabled(false); final OrderEntry entry = getSelectedEntry(); if (entry != null && entry.isValid()) { if (!(entry instanceof ModuleSourceOrderEntry)) { presentation.setEnabled(true); } } } }; navigateAction.registerCustomShortcutSet( ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE).getShortcutSet(), myEntryTable); actionGroup.add(myEditButton); actionGroup.add(myRemoveButton); actionGroup.add(navigateAction); actionGroup.add(new InlineModuleDependencyAction(this)); actionGroup.add(new MyFindUsagesAction()); actionGroup.add(new AnalyzeDependencyAction()); addChangeLibraryLevelAction(actionGroup, LibraryTablesRegistrar.PROJECT_LEVEL); addChangeLibraryLevelAction(actionGroup, LibraryTablesRegistrar.APPLICATION_LEVEL); addChangeLibraryLevelAction(actionGroup, LibraryTableImplUtil.MODULE_LEVEL); PopupHandler.installPopupHandler( myEntryTable, actionGroup, ActionPlaces.UNKNOWN, ActionManager.getInstance()); }
@NotNull private JBPopup createUsagePopup( @NotNull final List<Usage> usages, @NotNull final UsageInfoToUsageConverter.TargetElementsDescriptor descriptor, @NotNull Set<UsageNode> visibleNodes, @NotNull final FindUsagesHandler handler, final Editor editor, @NotNull final RelativePoint popupPosition, final int maxUsages, @NotNull final UsageViewImpl usageView, @NotNull final FindUsagesOptions options, @NotNull final JTable table, @NotNull final UsageViewPresentation presentation, @NotNull final AsyncProcessIcon processIcon, boolean hadMoreSeparator) { table.setRowHeight(PlatformIcons.CLASS_ICON.getIconHeight() + 2); table.setShowGrid(false); table.setShowVerticalLines(false); table.setShowHorizontalLines(false); table.setTableHeader(null); table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); table.setIntercellSpacing(new Dimension(0, 0)); PopupChooserBuilder builder = new PopupChooserBuilder(table); final String title = presentation.getTabText(); if (title != null) { String result = getFullTitle(usages, title, hadMoreSeparator, visibleNodes.size() - 1, true); builder.setTitle(result); builder.setAdText(getSecondInvocationTitle(options, handler)); } builder.setMovable(true).setResizable(true); builder.setItemChoosenCallback( new Runnable() { @Override public void run() { int[] selected = table.getSelectedRows(); for (int i : selected) { Object value = table.getValueAt(i, 0); if (value instanceof UsageNode) { Usage usage = ((UsageNode) value).getUsage(); if (usage == MORE_USAGES_SEPARATOR) { appendMoreUsages(editor, popupPosition, handler, maxUsages); return; } navigateAndHint(usage, null, handler, popupPosition, maxUsages, options); } } } }); final JBPopup[] popup = new JBPopup[1]; KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut(); if (shortcut != null) { new DumbAwareAction() { @Override public void actionPerformed(AnActionEvent e) { popup[0].cancel(); showDialogAndFindUsages(handler, popupPosition, editor, maxUsages); } }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table); } shortcut = getShowUsagesShortcut(); if (shortcut != null) { new DumbAwareAction() { @Override public void actionPerformed(AnActionEvent e) { popup[0].cancel(); searchEverywhere(options, handler, editor, popupPosition, maxUsages); } }.registerCustomShortcutSet(new CustomShortcutSet(shortcut.getFirstKeyStroke()), table); } InplaceButton settingsButton = createSettingsButton( handler, popupPosition, editor, maxUsages, new Runnable() { @Override public void run() { popup[0].cancel(); } }); ActiveComponent spinningProgress = new ActiveComponent() { @Override public void setActive(boolean active) {} @Override public JComponent getComponent() { return processIcon; } }; builder.setCommandButton(new CompositeActiveComponent(spinningProgress, settingsButton)); DefaultActionGroup toolbar = new DefaultActionGroup(); usageView.addFilteringActions(toolbar); toolbar.add(UsageGroupingRuleProviderImpl.createGroupByFileStructureAction(usageView)); toolbar.add( new AnAction( "Open Find Usages Toolwindow", "Show all usages in a separate toolwindow", AllIcons.Toolwindows.ToolWindowFind) { { AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_USAGES); setShortcutSet(action.getShortcutSet()); } @Override public void actionPerformed(AnActionEvent e) { hideHints(); popup[0].cancel(); FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(usageView.getProject())) .getFindUsagesManager(); findUsagesManager.findUsages( handler.getPrimaryElements(), handler.getSecondaryElements(), handler, options, FindSettings.getInstance().isSkipResultsWithOneUsage()); } }); ActionToolbar actionToolbar = ActionManager.getInstance() .createActionToolbar(ActionPlaces.USAGE_VIEW_TOOLBAR, toolbar, true); actionToolbar.setReservePlaceAutoPopupIcon(false); final JComponent toolBar = actionToolbar.getComponent(); toolBar.setOpaque(false); builder.setSettingButton(toolBar); popup[0] = builder.createPopup(); JComponent content = popup[0].getContent(); myWidth = (int) (toolBar.getPreferredSize().getWidth() + new JLabel( getFullTitle( usages, title, hadMoreSeparator, visibleNodes.size() - 1, true)) .getPreferredSize() .getWidth() + settingsButton.getPreferredSize().getWidth()); myWidth = -1; for (AnAction action : toolbar.getChildren(null)) { action.unregisterCustomShortcutSet(usageView.getComponent()); action.registerCustomShortcutSet(action.getShortcutSet(), content); } return popup[0]; }
private void registerTreeActionShortcut(@NonNls final String actionId) { final JTree tree = myFileSystemTree.getTree(); final AnAction action = ActionManager.getInstance().getAction(actionId); action.registerCustomShortcutSet(action.getShortcutSet(), tree, myDisposable); }
public MainWatchPanel(Project project, DebuggerStateManager stateManager) { super(project, stateManager); final WatchDebuggerTree watchTree = getWatchTree(); final AnAction removeWatchesAction = ActionManager.getInstance().getAction(DebuggerActions.REMOVE_WATCH); removeWatchesAction.registerCustomShortcutSet(CommonShortcuts.DELETE, watchTree); final AnAction newWatchAction = ActionManager.getInstance().getAction(DebuggerActions.NEW_WATCH); newWatchAction.registerCustomShortcutSet(CommonShortcuts.INSERT, watchTree); final ClickListener mouseListener = new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { AnAction editWatchAction = ActionManager.getInstance().getAction(DebuggerActions.EDIT_WATCH); Presentation presentation = editWatchAction.getTemplatePresentation().clone(); DataContext context = DataManager.getInstance().getDataContext(watchTree); AnActionEvent actionEvent = new AnActionEvent( null, context, "WATCH_TREE", presentation, ActionManager.getInstance(), 0); editWatchAction.actionPerformed(actionEvent); return true; } }; ListenerUtil.addClickListener(watchTree, mouseListener); final AnAction editWatchAction = ActionManager.getInstance().getAction(DebuggerActions.EDIT_WATCH); editWatchAction.registerCustomShortcutSet( new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)), watchTree); registerDisposable( new Disposable() { public void dispose() { ListenerUtil.removeClickListener(watchTree, mouseListener); removeWatchesAction.unregisterCustomShortcutSet(watchTree); newWatchAction.unregisterCustomShortcutSet(watchTree); editWatchAction.unregisterCustomShortcutSet(watchTree); } }); DnDManager.getInstance() .registerTarget( new DnDNativeTarget() { public boolean update(final DnDEvent aEvent) { Object object = aEvent.getAttachedObject(); if (object == null) return true; String add = DebuggerBundle.message("watchs.add.text"); if (object.getClass().isArray()) { Class<?> type = object.getClass().getComponentType(); if (DebuggerTreeNodeImpl.class.isAssignableFrom(type)) { aEvent.setHighlighting( myTree, DnDEvent.DropTargetHighlightingType.RECTANGLE | DnDEvent.DropTargetHighlightingType.TEXT); aEvent.setDropPossible( add, new DropActionHandler() { public void performDrop(final DnDEvent aEvent) { addWatchesFrom((DebuggerTreeNodeImpl[]) aEvent.getAttachedObject()); } }); } } else if (object instanceof EventInfo) { EventInfo info = (EventInfo) object; final String text = info.getTextForFlavor(DataFlavor.stringFlavor); if (text != null) { aEvent.setHighlighting( myTree, DnDEvent.DropTargetHighlightingType.RECTANGLE | DnDEvent.DropTargetHighlightingType.TEXT); aEvent.setDropPossible( add, new DropActionHandler() { public void performDrop(final DnDEvent aEvent) { addWatchesFrom(text); } }); } } return true; } public void drop(final DnDEvent aEvent) {} public void cleanUpOnLeave() {} public void updateDraggedImage( final Image image, final Point dropPoint, final Point imageOffset) {} }, myTree); }
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()); }
private AnAction createRecentFindUsagesAction() { AnAction action = ActionManager.getInstance().getAction(SHOW_RECENT_FIND_USAGES_ACTION_ID); action.registerCustomShortcutSet(action.getShortcutSet(), getComponent()); return action; }