Search in sources :

Example 1 with RunContentWithExecutorListener

use of com.intellij.execution.ui.RunContentWithExecutorListener in project intellij-community by JetBrains.

the class TreeInplaceEditor method show.

public final void show() {
    LOG.assertTrue(myInplaceEditorComponent == null, "editor is not released");
    final JTree tree = getTree();
    tree.scrollPathToVisible(getNodePath());
    final JRootPane rootPane = tree.getRootPane();
    if (rootPane == null) {
        return;
    }
    final JLayeredPane layeredPane = rootPane.getLayeredPane();
    Rectangle bounds = getEditorBounds();
    if (bounds == null) {
        return;
    }
    Point layeredPanePoint = SwingUtilities.convertPoint(tree, bounds.x, bounds.y, layeredPane);
    final JComponent inplaceEditorComponent = createInplaceEditorComponent();
    myInplaceEditorComponent = inplaceEditorComponent;
    LOG.assertTrue(inplaceEditorComponent != null);
    setInplaceEditorBounds(inplaceEditorComponent, layeredPanePoint.x, layeredPanePoint.y, bounds.width, bounds.height);
    layeredPane.add(inplaceEditorComponent, new Integer(250));
    myRemoveActions.add(() -> layeredPane.remove(inplaceEditorComponent));
    inplaceEditorComponent.validate();
    inplaceEditorComponent.paintImmediately(0, 0, inplaceEditorComponent.getWidth(), inplaceEditorComponent.getHeight());
    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
        IdeFocusManager.getGlobalInstance().requestFocus(getPreferredFocusedComponent(), true);
    });
    final ComponentAdapter componentListener = new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            final Project project = getProject();
            ApplicationManager.getApplication().invokeLater(() -> {
                if (!isShown() || project == null || project.isDisposed()) {
                    return;
                }
                JTree tree1 = getTree();
                JLayeredPane layeredPane1 = tree1.getRootPane().getLayeredPane();
                Rectangle bounds1 = getEditorBounds();
                if (bounds1 == null) {
                    return;
                }
                Point layeredPanePoint1 = SwingUtilities.convertPoint(tree1, bounds1.x, bounds1.y, layeredPane1);
                setInplaceEditorBounds(inplaceEditorComponent, layeredPanePoint1.x, layeredPanePoint1.y, bounds1.width, bounds1.height);
                inplaceEditorComponent.revalidate();
            });
        }

        @Override
        public void componentHidden(ComponentEvent e) {
            cancelEditing();
        }
    };
    final HierarchyListener hierarchyListener = e -> {
        if (!tree.isShowing()) {
            cancelEditing();
        }
    };
    tree.addHierarchyListener(hierarchyListener);
    tree.addComponentListener(componentListener);
    rootPane.addComponentListener(componentListener);
    myRemoveActions.add(() -> {
        tree.removeHierarchyListener(hierarchyListener);
        tree.removeComponentListener(componentListener);
        rootPane.removeComponentListener(componentListener);
    });
    getProject().getMessageBus().connect(myDisposable).subscribe(RunContentManager.TOPIC, new RunContentWithExecutorListener() {

        @Override
        public void contentSelected(@Nullable RunContentDescriptor descriptor, @NotNull Executor executor) {
            cancelEditing();
        }

        @Override
        public void contentRemoved(@Nullable RunContentDescriptor descriptor, @NotNull Executor executor) {
            cancelEditing();
        }
    });
    final JComponent editorComponent = getEditorComponent();
    editorComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enterStroke");
    editorComponent.getActionMap().put("enterStroke", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            doOKAction();
        }
    });
    editorComponent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escapeStroke");
    editorComponent.getActionMap().put("escapeStroke", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            cancelEditing();
        }
    });
    final Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
    SwingUtilities.invokeLater(() -> {
        if (!isShown())
            return;
        defaultToolkit.addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK);
    });
    myRemoveActions.add(() -> defaultToolkit.removeAWTEventListener(this));
    onShown();
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) RunContentManager(com.intellij.execution.ui.RunContentManager) TreePath(javax.swing.tree.TreePath) LookupManager(com.intellij.codeInsight.lookup.LookupManager) Executor(com.intellij.execution.Executor) Editor(com.intellij.openapi.editor.Editor) Disposable(com.intellij.openapi.Disposable) JBPopup(com.intellij.openapi.ui.popup.JBPopup) RunContentWithExecutorListener(com.intellij.execution.ui.RunContentWithExecutorListener) ArrayList(java.util.ArrayList) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) ComboPopup(javax.swing.plaf.basic.ComboPopup) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) java.awt.event(java.awt.event) Disposer(com.intellij.openapi.util.Disposer) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) RunContentWithExecutorListener(com.intellij.execution.ui.RunContentWithExecutorListener) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor)

Example 2 with RunContentWithExecutorListener

use of com.intellij.execution.ui.RunContentWithExecutorListener in project intellij-community by JetBrains.

the class PyDataViewToolWindowFactory method createToolWindowContent.

@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
    PyDataView.getInstance(project).init(toolWindow);
    final MessageBusConnection connection = project.getMessageBus().connect(project);
    connection.subscribe(XDebuggerManager.TOPIC, new ChangeContentXDebuggerManagerListener(project));
    connection.subscribe(RunContentManager.TOPIC, new RunContentWithExecutorListener() {

        @Override
        public void contentSelected(@Nullable RunContentDescriptor descriptor, @NotNull Executor executor) {
            if (!(executor instanceof DefaultDebugExecutor)) {
                return;
            }
            if (descriptor == null) {
                return;
            }
            ProcessHandler handler = descriptor.getProcessHandler();
            if (handler == null) {
                return;
            }
            PyDataView.getInstance(project).updateTabs(handler);
        }

        @Override
        public void contentRemoved(@Nullable RunContentDescriptor descriptor, @NotNull Executor executor) {
        }
    });
    addPythonConsoleListener(project);
    ((ToolWindowEx) toolWindow).setAdditionalGearActions(new DefaultActionGroup(new ColoredByDefaultAction()));
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) ToolWindowEx(com.intellij.openapi.wm.ex.ToolWindowEx) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Executor(com.intellij.execution.Executor) RunContentWithExecutorListener(com.intellij.execution.ui.RunContentWithExecutorListener) ProcessHandler(com.intellij.execution.process.ProcessHandler) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup)

Aggregations

Executor (com.intellij.execution.Executor)2 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)2 RunContentWithExecutorListener (com.intellij.execution.ui.RunContentWithExecutorListener)2 LookupManager (com.intellij.codeInsight.lookup.LookupManager)1 LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)1 DefaultDebugExecutor (com.intellij.execution.executors.DefaultDebugExecutor)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 RunContentManager (com.intellij.execution.ui.RunContentManager)1 Disposable (com.intellij.openapi.Disposable)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)1 Disposer (com.intellij.openapi.util.Disposer)1 IdeFocusManager (com.intellij.openapi.wm.IdeFocusManager)1 ToolWindowEx (com.intellij.openapi.wm.ex.ToolWindowEx)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1