@Nullable public Object getData(String dataId) { Object data = myPaletteWindow.getData(dataId); if (data != null) return data; Project project = CommonDataKeys.PROJECT.getData(myPaletteWindow); return myGroup.getData(project, dataId); }
@Override public void run() { if (myState == KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE) { resetState(); final DataContext dataContext = myContext.getDataContext(); StatusBar.Info.set( null, dataContext == null ? null : CommonDataKeys.PROJECT.getData(dataContext)); } }
public boolean processAction(final InputEvent e, @NotNull ActionProcessor processor) { ActionManagerEx actionManager = ActionManagerEx.getInstanceEx(); final Project project = CommonDataKeys.PROJECT.getData(myContext.getDataContext()); final boolean dumb = project != null && DumbService.getInstance(project).isDumb(); List<AnActionEvent> nonDumbAwareAction = new ArrayList<AnActionEvent>(); List<AnAction> actions = myContext.getActions(); for (final AnAction action : actions) { Presentation presentation = myPresentationFactory.getPresentation(action); // Mouse modifiers are 0 because they have no any sense when action is invoked via keyboard final AnActionEvent actionEvent = processor.createEvent( e, myContext.getDataContext(), ActionPlaces.MAIN_MENU, presentation, ActionManager.getInstance()); ActionUtil.performDumbAwareUpdate(action, actionEvent, true); if (dumb && !action.isDumbAware()) { if (!Boolean.FALSE.equals( presentation.getClientProperty(ActionUtil.WOULD_BE_ENABLED_IF_NOT_DUMB_MODE))) { nonDumbAwareAction.add(actionEvent); } continue; } if (!presentation.isEnabled()) { continue; } processor.onUpdatePassed(e, action, actionEvent); ((DataManagerImpl.MyDataContext) myContext.getDataContext()) .setEventCount(IdeEventQueue.getInstance().getEventCount(), this); actionManager.fireBeforeActionPerformed(action, actionEvent.getDataContext(), actionEvent); Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(actionEvent.getDataContext()); if (component != null && !component.isShowing()) { return true; } processor.performAction(e, action, actionEvent); actionManager.fireAfterActionPerformed(action, actionEvent.getDataContext(), actionEvent); return true; } if (!nonDumbAwareAction.isEmpty()) { showDumbModeWarningLaterIfNobodyConsumesEvent( e, nonDumbAwareAction.toArray(new AnActionEvent[nonDumbAwareAction.size()])); } return false; }
protected DialogWrapperPeerImpl( @NotNull DialogWrapper wrapper, @Nullable Project project, boolean canBeParent, @NotNull DialogWrapper.IdeModalityType ideModalityType) { myWrapper = wrapper; myTypeAheadCallback = myWrapper.isTypeAheadEnabled() ? new ActionCallback() : null; myWindowManager = null; Application application = ApplicationManager.getApplication(); if (application != null && application.hasComponent(WindowManager.class)) { myWindowManager = (WindowManagerEx) WindowManager.getInstance(); } Window window = null; if (myWindowManager != null) { if (project == null) { //noinspection deprecation project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext()); } myProject = project; window = myWindowManager.suggestParentWindow(project); if (window == null) { Window focusedWindow = myWindowManager.getMostRecentFocusedWindow(); if (focusedWindow instanceof IdeFrameImpl) { window = focusedWindow; } } if (window == null) { IdeFrame[] frames = myWindowManager.getAllProjectFrames(); for (IdeFrame frame : frames) { if (frame instanceof IdeFrameImpl && ((IdeFrameImpl) frame).isActive()) { window = (IdeFrameImpl) frame; break; } } } } Window owner; if (window != null) { owner = window; } else { if (!isHeadless()) { owner = JOptionPane.getRootFrame(); } else { owner = null; } } createDialog(owner, canBeParent, ideModalityType); }
private boolean inSecondStrokeInProgressState() { KeyEvent e = myContext.getInputEvent(); // when any key is released, we stop waiting for the second stroke if (KeyEvent.KEY_RELEASED == e.getID()) { myFirstKeyStroke = null; setState(KeyState.STATE_INIT); Project project = CommonDataKeys.PROJECT.getData(myContext.getDataContext()); StatusBar.Info.set(null, project); return false; } KeyStroke originalKeyStroke = KeyStroke.getKeyStrokeForEvent(e); KeyStroke keyStroke = getKeyStrokeWithoutMouseModifiers(originalKeyStroke); updateCurrentContext( myContext.getFoundComponent(), new KeyboardShortcut(myFirstKeyStroke, keyStroke), myContext.isModalContext()); // consume the wrong second stroke and keep on waiting if (myContext.getActions().isEmpty()) { return true; } // finally user had managed to enter the second keystroke, so let it be processed Project project = CommonDataKeys.PROJECT.getData(myContext.getDataContext()); StatusBarEx statusBar = (StatusBarEx) WindowManager.getInstance().getStatusBar(project); if (processAction(e, myActionProcessor)) { if (statusBar != null) { statusBar.setInfo(null); } return true; } else { return false; } }
@Override @NotNull protected DefaultActionGroup createPopupActionGroup(final JComponent button) { final DefaultActionGroup allActionsGroup = new DefaultActionGroup(); final Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(button)); if (project != null) { final RunManagerEx runManager = RunManagerEx.getInstanceEx(project); allActionsGroup.add( ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_RUN_CONFIGURATIONS)); allActionsGroup.add(new SaveTemporaryAction()); allActionsGroup.addSeparator(); RunnerAndConfigurationSettings selected = RunManager.getInstance(project).getSelectedConfiguration(); if (selected != null) { ExecutionTarget activeTarget = ExecutionTargetManager.getActiveTarget(project); for (ExecutionTarget eachTarget : ExecutionTargetManager.getTargetsToChooseFor(project, selected)) { allActionsGroup.add( new SelectTargetAction(project, eachTarget, eachTarget.equals(activeTarget))); } allActionsGroup.addSeparator(); } final ConfigurationType[] types = runManager.getConfigurationFactories(); for (ConfigurationType type : types) { final DefaultActionGroup actionGroup = new DefaultActionGroup(); Map<String, List<RunnerAndConfigurationSettings>> structure = runManager.getStructure(type); for (Map.Entry<String, List<RunnerAndConfigurationSettings>> entry : structure.entrySet()) { DefaultActionGroup group = entry.getKey() != null ? new DefaultActionGroup(entry.getKey(), true) : actionGroup; group.getTemplatePresentation().setIcon(AllIcons.Nodes.Folder); for (RunnerAndConfigurationSettings settings : entry.getValue()) { group.add(new SelectConfigAction(settings, project)); } if (group != actionGroup) { actionGroup.add(group); } } allActionsGroup.add(actionGroup); allActionsGroup.addSeparator(); } } return allActionsGroup; }
@Nullable private ToolWindow getWindow(AnActionEvent event) { if (myWindow != null) return myWindow; Project project = CommonDataKeys.PROJECT.getData(event.getDataContext()); if (project == null) return null; ToolWindowManager manager = ToolWindowManager.getInstance(project); final ToolWindow window = manager.getToolWindow(manager.getActiveToolWindowId()); if (window == null) return null; final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(event.getDataContext()); if (context == null) return null; return SwingUtilities.isDescendingFrom(window.getComponent(), context) ? window : null; }
private void reset( final Keymap keymap, final QuickList[] allQuickLists, String filter, @Nullable KeyboardShortcut shortcut) { myKeymap = keymap; final PathsKeeper pathsKeeper = new PathsKeeper(); pathsKeeper.storePaths(); myRoot.removeAllChildren(); ActionManager actionManager = ActionManager.getInstance(); Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myComponent)); Group mainGroup = ActionsTreeUtil.createMainGroup( project, myKeymap, allQuickLists, filter, true, ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut, filter, true)); if ((filter != null && filter.length() > 0 || shortcut != null) && mainGroup.initIds().isEmpty()) { mainGroup = ActionsTreeUtil.createMainGroup( project, myKeymap, allQuickLists, filter, false, ActionsTreeUtil.isActionFiltered(actionManager, myKeymap, shortcut, filter, false)); } myRoot = ActionsTreeUtil.createNode(mainGroup); myMainGroup = mainGroup; MyModel model = (MyModel) myTree.getModel(); model.setRoot(myRoot); model.nodeStructureChanged(myRoot); pathsKeeper.restorePaths(); }
public void saveSize() { if (myDimensionServiceKey != null && myInitialSize != null && myOpened) { // myInitialSize can be null only if dialog is disposed before first // showing final Project projectGuess = CommonDataKeys.PROJECT.getData( DataManager.getInstance().getDataContext(MyDialog.this)); // Save location Point location = getLocation(); DimensionService.getInstance().setLocation(myDimensionServiceKey, location, projectGuess); // Save size Dimension size = getSize(); if (!myInitialSize.equals(size)) { DimensionService.getInstance().setSize(myDimensionServiceKey, size, projectGuess); } myOpened = false; } }
private boolean inInitState() { Component focusOwner = myContext.getFocusOwner(); boolean isModalContext = myContext.isModalContext(); DataContext dataContext = myContext.getDataContext(); KeyEvent e = myContext.getInputEvent(); // http://www.jetbrains.net/jira/browse/IDEADEV-12372 if (myLeftCtrlPressed && myRightAltPressed && focusOwner != null && e.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.ALT_MASK)) { if (Registry.is("actionSystem.force.alt.gr")) { return false; } final InputContext inputContext = focusOwner.getInputContext(); if (inputContext != null) { Locale locale = inputContext.getLocale(); if (locale != null) { @NonNls final String language = locale.getLanguage(); if (ALT_GR_LAYOUTS.contains(language)) { // don't search for shortcuts return false; } } } } KeyStroke originalKeyStroke = KeyStroke.getKeyStrokeForEvent(e); KeyStroke keyStroke = getKeyStrokeWithoutMouseModifiers(originalKeyStroke); if (myKeyGestureProcessor.processInitState()) { return true; } if (SystemInfo.isMac) { boolean keyTyped = e.getID() == KeyEvent.KEY_TYPED; boolean hasMnemonicsInWindow = e.getID() == KeyEvent.KEY_PRESSED && hasMnemonicInWindow(focusOwner, e.getKeyCode()) || keyTyped && hasMnemonicInWindow(focusOwner, e.getKeyChar()); boolean imEnabled = IdeEventQueue.getInstance().isInputMethodEnabled(); if (e.getModifiersEx() == InputEvent.ALT_DOWN_MASK && (hasMnemonicsInWindow || !imEnabled && keyTyped)) { setPressedWasProcessed(true); setState(KeyState.STATE_PROCESSED); return false; } } updateCurrentContext(focusOwner, new KeyboardShortcut(keyStroke, null), isModalContext); if (myContext.getActions().isEmpty()) { // there's nothing mapped for this stroke return false; } if (myContext.isHasSecondStroke()) { myFirstKeyStroke = keyStroke; final ArrayList<Pair<AnAction, KeyStroke>> secondKeyStrokes = getSecondKeystrokeActions(); final Project project = CommonDataKeys.PROJECT.getData(dataContext); StringBuilder message = new StringBuilder(); message.append(KeyMapBundle.message("prefix.key.pressed.message")); message.append(' '); for (int i = 0; i < secondKeyStrokes.size(); i++) { Pair<AnAction, KeyStroke> pair = secondKeyStrokes.get(i); if (i > 0) message.append(", "); message.append(pair.getFirst().getTemplatePresentation().getText()); message.append(" ("); message.append(KeymapUtil.getKeystrokeText(pair.getSecond())); message.append(")"); } StatusBar.Info.set(message.toString(), project); mySecondStrokeTimeout.cancelAllRequests(); mySecondStrokeTimeout.addRequest( mySecondStrokeTimeoutRunnable, Registry.intValue("actionSystem.secondKeystrokeTimeout")); if (Registry.is("actionSystem.secondKeystrokeAutoPopupEnabled")) { mySecondKeystrokePopupTimeout.cancelAllRequests(); if (secondKeyStrokes.size() > 1) { final DataContext oldContext = myContext.getDataContext(); mySecondKeystrokePopupTimeout.addRequest( new Runnable() { @Override public void run() { if (myState == KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE) { StatusBar.Info.set(null, CommonDataKeys.PROJECT.getData(oldContext)); new SecondaryKeystrokePopup(myFirstKeyStroke, secondKeyStrokes, oldContext) .showInBestPositionFor(oldContext); } } }, Registry.intValue("actionSystem.secondKeystrokePopupTimeout")); } } setState(KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE); return true; } else { return processAction(e, myActionProcessor); } }
@Override @SuppressWarnings("deprecation") public void show() { myFocusTrackback = new FocusTrackback(getDialogWrapper(), getParent(), true); final DialogWrapper dialogWrapper = getDialogWrapper(); boolean isAutoAdjustable = dialogWrapper.isAutoAdjustable(); Point location = null; if (isAutoAdjustable) { pack(); Dimension packedSize = getSize(); Dimension minSize = getMinimumSize(); setSize( Math.max(packedSize.width, minSize.width), Math.max(packedSize.height, minSize.height)); setSize( (int) (getWidth() * dialogWrapper.getHorizontalStretch()), (int) (getHeight() * dialogWrapper.getVerticalStretch())); // Restore dialog's size and location myDimensionServiceKey = dialogWrapper.getDimensionKey(); if (myDimensionServiceKey != null) { final Project projectGuess = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(this)); location = DimensionService.getInstance().getLocation(myDimensionServiceKey, projectGuess); Dimension size = DimensionService.getInstance().getSize(myDimensionServiceKey, projectGuess); if (size != null) { myInitialSize = new Dimension(size); _setSizeForLocation(myInitialSize.width, myInitialSize.height, location); } } if (myInitialSize == null) { myInitialSize = getSize(); } } if (location == null) { location = dialogWrapper.getInitialLocation(); } if (location != null) { setLocation(location); } else { setLocationRelativeTo(getOwner()); } if (isAutoAdjustable) { final Rectangle bounds = getBounds(); ScreenUtil.fitToScreen(bounds); setBounds(bounds); } addWindowListener( new WindowAdapter() { @Override public void windowActivated(WindowEvent e) { final DialogWrapper wrapper = getDialogWrapper(); if (wrapper != null && myFocusTrackback != null) { myFocusTrackback.cleanParentWindow(); myFocusTrackback.registerFocusComponent( new FocusTrackback.ComponentQuery() { @Override public Component getComponent() { return wrapper.getPreferredFocusedComponent(); } }); } } @Override public void windowDeactivated(WindowEvent e) { if (!isModal()) { final Ref<IdeFocusManager> focusManager = new Ref<IdeFocusManager>(null); Project project = getProject(); if (project != null && !project.isDisposed()) { focusManager.set(getFocusManager()); focusManager .get() .doWhenFocusSettlesDown( new Runnable() { @Override public void run() { disposeFocusTrackbackIfNoChildWindowFocused(focusManager.get()); } }); } else { disposeFocusTrackbackIfNoChildWindowFocused(focusManager.get()); } } } @Override public void windowOpened(WindowEvent e) { if (!SystemInfo.isMacOSLion) return; Window window = e.getWindow(); if (window instanceof Dialog) { ID _native = MacUtil.findWindowForTitle(((Dialog) window).getTitle()); if (_native != null && _native.intValue() > 0) { // see MacMainFrameDecorator // NSCollectionBehaviorFullScreenAuxiliary = 1 << 8 Foundation.invoke(_native, "setCollectionBehavior:", 1 << 8); } } } }); if (Registry.is("actionSystem.fixLostTyping")) { final IdeEventQueue queue = IdeEventQueue.getInstance(); if (queue != null) { queue.getKeyEventDispatcher().resetState(); } // if (myProject != null) { // Project project = myProject.get(); // if (project != null && !project.isDisposed() && project.isInitialized()) { // // IdeFocusManager.findInstanceByComponent(this).requestFocus(new // MyFocusCommand(dialogWrapper), true); // } // } } if (SystemInfo.isMac && myProject != null && Registry.is("ide.mac.fix.dialog.showing") && !dialogWrapper.isModalProgress()) { final IdeFrame frame = WindowManager.getInstance().getIdeFrame(myProject.get()); AppIcon.getInstance().requestFocus(frame); } setBackground(UIUtil.getPanelBackground()); final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); if (app != null && !app.isLoaded() && Splash.BOUNDS != null) { final Point loc = getLocation(); loc.y = Splash.BOUNDS.y + Splash.BOUNDS.height; setLocation(loc); } super.show(); }