public PlaybackRunner(String script, StatusCallback callback, final boolean useDirectActionCall, boolean stopOnAppDeactivation, boolean useTypingTargets) { myScript = script; myCallback = callback; myUseDirectActionCall = useDirectActionCall; myUseTypingTargets = useTypingTargets; myStopOnAppDeactivation = stopOnAppDeactivation; myAppListener = new ApplicationActivationListener.Adapter() { @Override public void applicationDeactivated(IdeFrame ideFrame) { if (myStopOnAppDeactivation) { myCallback.message(null, "App lost focus, stopping...", StatusCallback.Type.message); stop(); } } }; }
private boolean isAppActive() { Application app = ApplicationManager.getApplication(); if (app != null && myAppListener == null) { myAppListener = new ApplicationActivationListener.Adapter() { @Override public void applicationActivated(IdeFrame ideFrame) { hideProgress(ideFrame.getProject(), myCurrentProcessId); _setOkBadge(ideFrame, false); _setTextBadge(ideFrame, null); } }; app.getMessageBus().connect().subscribe(ApplicationActivationListener.TOPIC, myAppListener); } return app != null && app.isActive(); }
public void addRequest(@Nonnull final Runnable request, final int delay, boolean runWithActiveFrameOnly) { if (runWithActiveFrameOnly && !ApplicationManager.getApplication().isActive()) { final MessageBus bus = ApplicationManager.getApplication().getMessageBus(); final MessageBusConnection connection = bus.connect(this); connection.subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener() { @Override public void applicationActivated(IdeFrame ideFrame) { connection.disconnect(); addRequest(request, delay); } }); } else { addRequest(request, delay); } }
private void updateConnection() { final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); boolean value = PropertiesComponent.getInstance().getBoolean(KEY); if(value) { myConnection = app.getMessageBus().connect(); myConnection.subscribe(ApplicationActivationListener.TOPIC, myListener); } else { if(myConnection != null) { myConnection.disconnect(); } } }
public void afterValueChanged(RegistryValue value) { if (value.asBoolean()) { ourConnection = app.getMessageBus().connect(); ourConnection.subscribe(ApplicationActivationListener.TOPIC, LISTENER); } else { ourConnection.disconnect(); } }
public void addRequest(@NotNull final Runnable request, final int delay, boolean runWithActiveFrameOnly) { if (runWithActiveFrameOnly && !ApplicationManager.getApplication().isActive()) { final MessageBus bus = ApplicationManager.getApplication().getMessageBus(); final MessageBusConnection connection = bus.connect(this); connection.subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener.Adapter() { @Override public void applicationActivated(IdeFrame ideFrame) { connection.disconnect(); addRequest(request, delay); } }); } else { addRequest(request, delay); } }
public void show(final Component component, int x, int y) { if (!component.isShowing()) { //noinspection HardCodedStringLiteral throw new IllegalArgumentException("component must be shown on the screen"); } removeAll(); // Fill menu. Only after filling menu has non zero size. int x2 = Math.max(0, Math.min(x, component.getWidth() - 1)); // fit x into [0, width-1] int y2 = Math.max(0, Math.min(y, component.getHeight() - 1)); // fit y into [0, height-1] myContext = myDataContextProvider != null ? myDataContextProvider.get() : DataManager.getInstance().getDataContext(component, x2, y2); Utils.fillMenu(myGroup, this, true, myPresentationFactory, myContext, myPlace, false, false); if (getComponentCount() == 0) { return; } if (myApp != null) { if (myApp.isActive()) { Component frame = UIUtil.findUltimateParent(component); if (frame instanceof IdeFrame) { myFrame = (IdeFrame)frame; } myConnection = myApp.getMessageBus().connect(); myConnection.subscribe(ApplicationActivationListener.TOPIC, ActionPopupMenuImpl.this); } } super.show(component, x, y); }
private MountainLionNotifications() { final MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(); connection.subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener.Adapter() { @Override public void applicationActivated(IdeFrame ideFrame) { cleanupDeliveredNotifications(); } }); connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener.Adapter() { @Override public void appClosing() { cleanupDeliveredNotifications(); } }); }
private static boolean setActive(Application application, Window window) { IdeFrame ideFrame = getIdeFrameFromWindow(window); state = State.ACTIVE; LOG.debug("The app is in the active state"); if (ideFrame != null) { application.getMessageBus().syncPublisher(ApplicationActivationListener.TOPIC).applicationActivated(ideFrame); return true; } return false; }
/** * Adds IntelliJ listeners including already opened windows and * registers shutdown and debugger listeners. */ public void attachListeners() { WatchDogEventType.START_IDE.process(this); connection.subscribe(ApplicationActivationListener.TOPIC, new IntelliJActivationListener()); activityListener = new GeneralActivityListener(project.getName()); EditorFactory.getInstance().addEditorFactoryListener(editorWindowListener, parent); attachDebuggerListeners(); }
@Override public void show(final Component component, int x, int y) { if (!component.isShowing()) { //noinspection HardCodedStringLiteral throw new IllegalArgumentException("component must be shown on the screen"); } removeAll(); // Fill menu. Only after filling menu has non zero size. int x2 = Math.max(0, Math.min(x, component.getWidth() - 1)); // fit x into [0, width-1] int y2 = Math.max(0, Math.min(y, component.getHeight() - 1)); // fit y into [0, height-1] myContext = myDataContextProvider != null ? myDataContextProvider.get() : DataManager.getInstance().getDataContext(component, x2, y2); Utils.fillMenu(myGroup, this, true, myPresentationFactory, myContext, myPlace, false, false, LaterInvocator.isInModalContext()); if (getComponentCount() == 0) { return; } if (myApp != null) { if (myApp.isActive()) { Component frame = UIUtil.findUltimateParent(component); if (frame instanceof IdeFrame) { myFrame = (IdeFrame)frame; } myConnection = myApp.getMessageBus().connect(); myConnection.subscribe(ApplicationActivationListener.TOPIC, ActionPopupMenuImpl.this); } } super.show(component, x, y); }
private MountainLionNotifications() { final MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(); connection.subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener.Adapter() { @Override public void applicationActivated(IdeFrame ideFrame) { cleanupDeliveredNotifications(); } }); connection.subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() { @Override public void appClosing() { cleanupDeliveredNotifications(); } }); }
@SuppressWarnings("UnusedParameters") // the dependencies are needed to ensure correct loading order public FocusManagerImpl(ServiceManagerImpl serviceManager, WindowManager wm, UiActivityMonitor monitor) { myApp = ApplicationManager.getApplication(); myQueue = IdeEventQueue.getInstance(); myActivityMonitor = monitor; myFocusedComponentAlarm = new EdtAlarm(); myForcedFocusRequestsAlarm = new EdtAlarm(); myIdleAlarm = new EdtAlarm(); final AppListener myAppListener = new AppListener(); myApp.getMessageBus().connect().subscribe(ApplicationActivationListener.TOPIC, myAppListener); IdeEventQueue.getInstance().addDispatcher(new IdeEventQueue.EventDispatcher() { @Override public boolean dispatch(AWTEvent e) { if (e instanceof FocusEvent) { final FocusEvent fe = (FocusEvent)e; final Component c = fe.getComponent(); if (c instanceof Window || c == null) return false; Component parent = UIUtil.findUltimateParent(c); if (parent instanceof IdeFrame) { myLastFocused.put((IdeFrame)parent, c); } } else if (e instanceof WindowEvent) { Window wnd = ((WindowEvent)e).getWindow(); if (e.getID() == WindowEvent.WINDOW_CLOSED) { if (wnd instanceof IdeFrame) { myLastFocused.remove(wnd); myLastFocusedAtDeactivation.remove(wnd); } } } return false; } }, this); KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusedWindow", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getNewValue() instanceof IdeFrame) { myLastFocusedFrame = (IdeFrame)evt.getNewValue(); } } }); }
public ActionCallback run() { myStopRequested = false; myRegistryValues.clear(); final UiActivityMonitor activityMonitor = UiActivityMonitor.getInstance(); activityMonitor.clear(); activityMonitor.setActive(true); myCurrentStageDepth.clear(); myPassedStages.clear(); myContextTimestamp++; ApplicationManager.getApplication().getMessageBus().connect(ApplicationManager.getApplication()).subscribe(ApplicationActivationListener.TOPIC, myAppListener); try { myActionCallback = new ActionCallback(); myActionCallback.doWhenProcessed(new Runnable() { @Override public void run() { stop(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { activityMonitor.setActive(false); restoreRegistryValues(); } }); } }); myRobot = new Robot(); parse(); new Thread("playback runner") { @Override public void run() { if (myUseDirectActionCall) { executeFrom(0, getScriptDir()); } else { IdeEventQueue.getInstance().doWhenReady(new Runnable() { public void run() { executeFrom(0, getScriptDir()); } }); } } }.start(); } catch (AWTException e) { LOG.error(e); } return myActionCallback; }
protected JComponent createCenterPanel() { JPanel panel = new MyPanel(); myUiUpdater = new MergingUpdateQueue("FileChooserUpdater", 200, false, panel); Disposer.register(myDisposable, myUiUpdater); new UiNotifyConnector(panel, myUiUpdater); panel.setBorder(JBUI.Borders.empty()); createTree(); final DefaultActionGroup group = createActionGroup(); ActionToolbar toolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true); toolBar.setTargetComponent(panel); final JPanel toolbarPanel = new JPanel(new BorderLayout()); toolbarPanel.add(toolBar.getComponent(), BorderLayout.CENTER); myTextFieldAction = new TextFieldAction() { public void linkSelected(final LinkLabel aSource, final Object aLinkData) { toggleShowTextField(); } }; toolbarPanel.add(myTextFieldAction, BorderLayout.EAST); JPanel extraToolbarPanel = createExtraToolbarPanel(); if(extraToolbarPanel != null){ toolbarPanel.add(extraToolbarPanel, BorderLayout.SOUTH); } myPathTextFieldWrapper = new JPanel(new BorderLayout()); myPathTextFieldWrapper.setBorder(JBUI.Borders.emptyBottom(2)); myPathTextField = new FileTextFieldImpl.Vfs( FileChooserFactoryImpl.getMacroMap(), getDisposable(), new LocalFsFinder.FileChooserFilter(myChooserDescriptor, myFileSystemTree)) { protected void onTextChanged(final String newValue) { myUiUpdater.cancelAllUpdates(); updateTreeFromPath(newValue); } }; Disposer.register(myDisposable, myPathTextField); myPathTextFieldWrapper.add(myPathTextField.getField(), BorderLayout.CENTER); if (getRecentFiles().length > 0) { myPathTextFieldWrapper.add(createHistoryButton(), BorderLayout.EAST); } myNorthPanel = new JPanel(new BorderLayout()); myNorthPanel.add(toolbarPanel, BorderLayout.NORTH); updateTextFieldShowing(); panel.add(myNorthPanel, BorderLayout.NORTH); registerMouseListener(group); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myFileSystemTree.getTree()); //scrollPane.setBorder(BorderFactory.createLineBorder(new Color(148, 154, 156))); panel.add(scrollPane, BorderLayout.CENTER); panel.setPreferredSize(JBUI.size(400)); panel.add(new JLabel(DRAG_N_DROP_HINT, SwingConstants.CENTER), BorderLayout.SOUTH); ApplicationManager.getApplication().getMessageBus().connect(getDisposable()) .subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener.Adapter() { @Override public void applicationActivated(IdeFrame ideFrame) { DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_MODAL, new Runnable() { @Override public void run() { ((SaveAndSyncHandlerImpl)SaveAndSyncHandler.getInstance()).maybeRefresh(ModalityState.current()); } }); } }); return panel; }
@SuppressWarnings("UnusedParameters") // the dependencies are needed to ensure correct loading order public FocusManagerImpl(ServiceManagerImpl serviceManager, WindowManager wm, UiActivityMonitor monitor) { myApp = ApplicationManager.getApplication(); myQueue = IdeEventQueue.getInstance(); myActivityMonitor = monitor; myFocusedComponentAlaram = new EdtAlarm(); myForcedFocusRequestsAlarm = new EdtAlarm(); myIdleAlarm = new EdtAlarm(); final AppListener myAppListener = new AppListener(); myApp.getMessageBus().connect().subscribe(ApplicationActivationListener.TOPIC, myAppListener); IdeEventQueue.getInstance().addDispatcher(new IdeEventQueue.EventDispatcher() { public boolean dispatch(AWTEvent e) { if (e instanceof FocusEvent) { final FocusEvent fe = (FocusEvent)e; final Component c = fe.getComponent(); if (c instanceof Window || c == null) return false; Component parent = SwingUtilities.getWindowAncestor(c); if (parent instanceof IdeFrame) { myLastFocused.put((IdeFrame)parent, new WeakReference<Component>(c)); } } else if (e instanceof WindowEvent) { Window wnd = ((WindowEvent)e).getWindow(); if (e.getID() == WindowEvent.WINDOW_CLOSED) { if (wnd instanceof IdeFrame) { myLastFocused.remove((IdeFrame)wnd); myLastFocusedAtDeactivation.remove((IdeFrame)wnd); } } } return false; } }, this); KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusedWindow", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getNewValue() instanceof IdeFrame) { myLastFocusedFrame = (IdeFrame)evt.getNewValue(); } } }); }
public ActionCallback run() { myStopRequested = false; myRegistryValues.clear(); final UiActivityMonitor activityMonitor = UiActivityMonitor.getInstance(); activityMonitor.clear(); activityMonitor.setActive(true); myCurrentStageDepth.clear(); myPassedStages.clear(); myContextTimestamp++; ApplicationManager.getApplication().getMessageBus().connect(myOnStop).subscribe(ApplicationActivationListener.TOPIC, myAppListener); try { myActionCallback = new ActionCallback(); myActionCallback.doWhenProcessed(new Runnable() { @Override public void run() { stop(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { activityMonitor.setActive(false); restoreRegistryValues(); } }); } }); myRobot = new Robot(); parse(); new Thread() { @Override public void run() { if (myUseDirectActionCall) { executeFrom(0, getScriptDir()); } else { IdeEventQueue.getInstance().doWhenReady(new Runnable() { public void run() { executeFrom(0, getScriptDir()); } }); } } }.start(); } catch (AWTException e) { LOG.error(e); } return myActionCallback; }
@SuppressWarnings("UnusedParameters") // the dependencies are needed to ensure correct loading order public FocusManagerImpl(ServiceManagerImpl serviceManager, WindowManager wm, UiActivityMonitor monitor) { myApp = ApplicationManager.getApplication(); myQueue = IdeEventQueue.getInstance(); myActivityMonitor = monitor; myFocusedComponentAlarm = new EdtAlarm(); myForcedFocusRequestsAlarm = new EdtAlarm(); final AppListener myAppListener = new AppListener(); myApp.getMessageBus().connect().subscribe(ApplicationActivationListener.TOPIC, myAppListener); IdeEventQueue.getInstance().addDispatcher(e -> { if (e instanceof FocusEvent) { final FocusEvent fe = (FocusEvent)e; final Component c = fe.getComponent(); if (c instanceof Window || c == null) return false; Component parent = UIUtil.findUltimateParent(c); if (parent instanceof IdeFrame) { myLastFocused.put((IdeFrame)parent, c); } } else if (e instanceof WindowEvent) { Window wnd = ((WindowEvent)e).getWindow(); if (e.getID() == WindowEvent.WINDOW_CLOSED) { if (wnd instanceof IdeFrame) { myLastFocused.remove(wnd); myLastFocusedAtDeactivation.remove(wnd); } } } return false; }, this); KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusedWindow", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getNewValue() instanceof IdeFrame) { myLastFocusedFrame = (IdeFrame)evt.getNewValue(); } } }); }
public FocusDrawer() { super("focus debugger"); Application app = ApplicationManager.getApplication(); app.getMessageBus().connect().subscribe(ApplicationActivationListener.TOPIC, this); }
protected JComponent createCenterPanel() { JPanel panel = new MyPanel(); myUiUpdater = new MergingUpdateQueue("FileChooserUpdater", 200, false, panel); Disposer.register(myDisposable, myUiUpdater); new UiNotifyConnector(panel, myUiUpdater); panel.setBorder(JBUI.Borders.empty()); createTree(); final DefaultActionGroup group = createActionGroup(); ActionToolbar toolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true); toolBar.setTargetComponent(panel); final JPanel toolbarPanel = new JPanel(new BorderLayout()); toolbarPanel.add(toolBar.getComponent(), BorderLayout.CENTER); myTextFieldAction = new TextFieldAction() { public void linkSelected(final LinkLabel aSource, final Object aLinkData) { toggleShowTextField(); } }; toolbarPanel.add(myTextFieldAction, BorderLayout.EAST); JPanel extraToolbarPanel = createExtraToolbarPanel(); if (extraToolbarPanel != null) { toolbarPanel.add(extraToolbarPanel, BorderLayout.SOUTH); } myPathTextFieldWrapper = new JPanel(new BorderLayout()); myPathTextFieldWrapper.setBorder(JBUI.Borders.emptyBottom(2)); myPathTextField = new FileTextFieldImpl.Vfs(FileChooserFactoryImpl.getMacroMap(), getDisposable(), new LocalFsFinder.FileChooserFilter(myChooserDescriptor, myFileSystemTree)) { protected void onTextChanged(final String newValue) { myUiUpdater.cancelAllUpdates(); updateTreeFromPath(newValue); } }; Disposer.register(myDisposable, myPathTextField); myPathTextFieldWrapper.add(myPathTextField.getField(), BorderLayout.CENTER); if (getRecentFiles().length > 0) { myPathTextFieldWrapper.add(createHistoryButton(), BorderLayout.EAST); } myNorthPanel = new JPanel(new BorderLayout()); myNorthPanel.add(toolbarPanel, BorderLayout.NORTH); updateTextFieldShowing(); panel.add(myNorthPanel, BorderLayout.NORTH); registerMouseListener(group); JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myFileSystemTree.getTree()); //scrollPane.setBorder(BorderFactory.createLineBorder(new Color(148, 154, 156))); panel.add(scrollPane, BorderLayout.CENTER); panel.setPreferredSize(JBUI.size(400)); JLabel hintLabel = new JLabel(DRAG_N_DROP_HINT, SwingConstants.CENTER); hintLabel.setForeground(JBColor.gray); hintLabel.setFont(JBUI.Fonts.smallFont()); panel.add(hintLabel, BorderLayout.SOUTH); ApplicationManager.getApplication().getMessageBus().connect(getDisposable()) .subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener() { @Override public void applicationActivated(IdeFrame ideFrame) { ((SaveAndSyncHandlerImpl)SaveAndSyncHandler.getInstance()).maybeRefresh(ModalityState.current()); } }); return panel; }