Search in sources :

Example 1 with ProjectManagerAdapter

use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij-community by JetBrains.

the class EventLogConsole method createLogEditor.

private Editor createLogEditor() {
    Project project = myProjectModel.getProject();
    final EditorEx editor = ConsoleViewUtil.setupConsoleEditor(project, false, false);
    editor.getSettings().setWhitespacesShown(false);
    installNotificationsFont(editor);
    myProjectModel.getProject().getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerAdapter() {

        @Override
        public void projectClosed(Project project) {
            if (project == myProjectModel.getProject()) {
                EditorFactory.getInstance().releaseEditor(editor);
            }
        }
    });
    ((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
    final ClearLogAction clearLog = new ClearLogAction(this);
    clearLog.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.CONSOLE_CLEAR_ALL).getShortcutSet(), editor.getContentComponent());
    // disabling default context menu
    editor.setContextMenuGroupId(null);
    editor.addEditorMouseListener(new EditorPopupHandler() {

        public void invokePopup(final EditorMouseEvent event) {
            final ActionManager actionManager = ActionManager.getInstance();
            DefaultActionGroup actions = createPopupActions(actionManager, clearLog, editor, event);
            final ActionPopupMenu menu = actionManager.createActionPopupMenu(ActionPlaces.EDITOR_POPUP, actions);
            final MouseEvent mouseEvent = event.getMouseEvent();
            menu.getComponent().show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
        }
    });
    return editor;
}
Also used : Project(com.intellij.openapi.project.Project) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) MouseEvent(java.awt.event.MouseEvent) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) EditorPopupHandler(com.intellij.util.EditorPopupHandler)

Example 2 with ProjectManagerAdapter

use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij-community by JetBrains.

the class ScratchFileServiceImpl method initFileOpenedListener.

private void initFileOpenedListener(MessageBus messageBus) {
    final FileEditorManagerListener editorListener = new FileEditorManagerListener() {

        @Override
        public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            if (!isEditable(file))
                return;
            RootType rootType = getRootType(file);
            if (rootType == null)
                return;
            rootType.fileOpened(file, source);
        }

        @Override
        public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
            if (Boolean.TRUE.equals(file.getUserData(FileEditorManagerImpl.CLOSING_TO_REOPEN)))
                return;
            if (!isEditable(file))
                return;
            RootType rootType = getRootType(file);
            if (rootType == null)
                return;
            rootType.fileClosed(file, source);
        }

        boolean isEditable(@NotNull VirtualFile file) {
            return FileDocumentManager.getInstance().getDocument(file) != null;
        }
    };
    ProjectManagerAdapter projectListener = new ProjectManagerAdapter() {

        @Override
        public void projectOpened(Project project) {
            project.getMessageBus().connect(project).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, editorListener);
            FileEditorManager editorManager = FileEditorManager.getInstance(project);
            for (VirtualFile virtualFile : editorManager.getOpenFiles()) {
                editorListener.fileOpened(editorManager, virtualFile);
            }
        }
    };
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        projectListener.projectOpened(project);
    }
    messageBus.connect().subscribe(ProjectManager.TOPIC, projectListener);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Project(com.intellij.openapi.project.Project) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) FileEditorManagerListener(com.intellij.openapi.fileEditor.FileEditorManagerListener) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ProjectManagerAdapter

use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij-community by JetBrains.

the class IdeStartupScripts method scheduleStartupScriptsExecution.

private static void scheduleStartupScriptsExecution() {
    List<VirtualFile> scripts = getScripts();
    LOG.info(scripts.size() + " startup script(s) found");
    if (scripts.isEmpty())
        return;
    final Future<List<Pair<VirtualFile, IdeScriptEngine>>> scriptsAndEnginesFuture = prepareScriptEnginesAsync(scripts);
    ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() {

        final AtomicBoolean myScriptsExecutionStarted = new AtomicBoolean();

        @Override
        public void projectOpened(final Project project) {
            StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> {
                if (project.isDisposed())
                    return;
                if (!myScriptsExecutionStarted.compareAndSet(false, true))
                    return;
                ProjectManager.getInstance().removeProjectManagerListener(this);
                runAllScriptsImpl(project);
            });
        }

        private void runAllScriptsImpl(@NotNull Project project) {
            try {
                for (Pair<VirtualFile, IdeScriptEngine> pair : scriptsAndEnginesFuture.get()) {
                    try {
                        if (pair.second == null) {
                            LOG.warn(pair.first.getPath() + " not supported (no script engine)");
                        } else {
                            runImpl(project, pair.first, pair.second);
                        }
                    } catch (Exception e) {
                        LOG.warn(e);
                    }
                }
            } catch (ProcessCanceledException e) {
                LOG.warn("... cancelled");
            } catch (InterruptedException e) {
                LOG.warn("... interrupted");
            } catch (Exception e) {
                LOG.error(e);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IdeScriptException(org.jetbrains.ide.script.IdeScriptException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Project(com.intellij.openapi.project.Project) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) List(java.util.List) IdeScriptEngine(org.jetbrains.ide.script.IdeScriptEngine) Pair(com.intellij.openapi.util.Pair) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 4 with ProjectManagerAdapter

use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij by bazelbuild.

the class ProjectDependencyMigration method initComponent.

@Override
public void initComponent() {
    ProjectManager projectManager = ProjectManager.getInstance();
    projectManager.addProjectManagerListener(new ProjectManagerAdapter() {

        @Override
        public void projectOpened(Project project) {
            if (Blaze.isBlazeProject(project)) {
                PluginDependencyHelper.addDependencyOnSyncPlugin(project);
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) ProjectManager(com.intellij.openapi.project.ProjectManager)

Example 5 with ProjectManagerAdapter

use of com.intellij.openapi.project.ProjectManagerAdapter in project intellij-code-outline by sitano.

the class CodeOutlinePlugin method addProjectListener.

private void addProjectListener() {
    ProjectManager pm = ProjectManager.getInstance();
    pm.addProjectManagerListener(new ProjectManagerAdapter() {

        public void projectOpened(Project project) {
            regForProject(project);
        }

        public void projectClosed(Project project) {
            unregForProject(project);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) ProjectManager(com.intellij.openapi.project.ProjectManager)

Aggregations

Project (com.intellij.openapi.project.Project)11 ProjectManagerAdapter (com.intellij.openapi.project.ProjectManagerAdapter)11 ProjectManager (com.intellij.openapi.project.ProjectManager)3 AppLifecycleListener (com.intellij.ide.AppLifecycleListener)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 Application (com.intellij.openapi.application.Application)1 EditorMouseEvent (com.intellij.openapi.editor.event.EditorMouseEvent)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Pair (com.intellij.openapi.util.Pair)1 HyperlinkAdapter (com.intellij.ui.HyperlinkAdapter)1 EditorPopupHandler (com.intellij.util.EditorPopupHandler)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1 MouseEvent (java.awt.event.MouseEvent)1 IOException (java.io.IOException)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1