Search in sources :

Example 1 with ProjectManagerListener

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

the class EditorTextField method addNotify.

@Override
public void addNotify() {
    myDisposable = Disposer.newDisposable("ETF dispose");
    Disposer.register(myDisposable, this::releaseEditorLater);
    if (myProject != null) {
        ProjectManagerListener listener = new ProjectManagerListener() {

            @Override
            public void projectClosing(Project project) {
                releaseEditor(myEditor);
                myEditor = null;
            }
        };
        ProjectManager.getInstance().addProjectManagerListener(myProject, listener);
        Disposer.register(myDisposable, () -> ProjectManager.getInstance().removeProjectManagerListener(myProject, listener));
    }
    if (myEditor != null) {
        releaseEditorLater();
    }
    boolean isFocused = isFocusOwner();
    initEditor();
    super.addNotify();
    if (myNextFocusable != null) {
        myEditor.getContentComponent().setNextFocusableComponent(myNextFocusable);
        myNextFocusable = null;
    }
    revalidate();
    if (isFocused) {
        IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
            requestFocus();
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener)

Example 2 with ProjectManagerListener

use of com.intellij.openapi.project.ProjectManagerListener in project intellij-plugins by JetBrains.

the class OsmorcPostStartupActivity method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    if (project.isDefault()) {
        return;
    }
    MessageBusConnection connection = project.getMessageBus().connect();
    connection.subscribe(FacetManager.FACETS_TOPIC, new FacetManagerAdapter() {

        @Override
        public void facetAdded(@NotNull Facet facet) {
            handleFacetChange(facet, project);
        }

        @Override
        public void facetConfigurationChanged(@NotNull Facet facet) {
            handleFacetChange(facet, project);
        }
    });
    connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {

        @Override
        public void projectClosing(Project project) {
            for (Module module : ModuleManager.getInstance(project).getModules()) {
                AdditionalJARContentsWatcherManager.getInstance(module).cleanup();
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) Module(com.intellij.openapi.module.Module) FacetManagerAdapter(com.intellij.facet.FacetManagerAdapter) Facet(com.intellij.facet.Facet)

Example 3 with ProjectManagerListener

use of com.intellij.openapi.project.ProjectManagerListener in project intellij-plugins by JetBrains.

the class DesignerApplicationManager method attachProjectAndModuleListeners.

void attachProjectAndModuleListeners(Disposable parentDisposable) {
    MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(parentDisposable);
    connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {

        @Override
        public void projectClosed(Project project) {
            if (isApplicationClosed()) {
                return;
            }
            Client client = Client.getInstance();
            if (client.getRegisteredProjects().contains(project)) {
                client.closeProject(project);
            }
        }
    });
    // unregistered module is more complicated - we cannot just remove all document factories which belong to project as in case of close project
    // we must remove all document factories belong to module and all dependents (dependent may be from another module, so, we process moduleRemoved synchronous
    // one by one)
    connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleRemoved(@NotNull Project project, @NotNull Module module) {
            Client client = Client.getInstance();
            if (!client.isModuleRegistered(module)) {
                return;
            }
            if (unregisterTaskQueueProcessor == null) {
                unregisterTaskQueueProcessor = new QueueProcessor<>(module1 -> {
                    boolean hasError = true;
                    final ActionCallback callback;
                    initialRenderQueue.suspend();
                    try {
                        callback = Client.getInstance().unregisterModule(module1);
                        hasError = false;
                    } finally {
                        if (hasError) {
                            initialRenderQueue.resume();
                        }
                    }
                    callback.doWhenProcessed(() -> initialRenderQueue.resume());
                });
            }
            unregisterTaskQueueProcessor.add(module);
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) ModuleListener(com.intellij.openapi.project.ModuleListener) QueueProcessor(com.intellij.util.concurrency.QueueProcessor) ActionCallback(com.intellij.openapi.util.ActionCallback) Module(com.intellij.openapi.module.Module)

Example 4 with ProjectManagerListener

use of com.intellij.openapi.project.ProjectManagerListener in project azure-tools-for-java by Microsoft.

the class ServerExplorerToolWindowFactory method addToolbarItems.

private void addToolbarItems(ToolWindow toolWindow, final Project project, final AzureModule azureModule) {
    if (toolWindow instanceof ToolWindowEx) {
        ToolWindowEx toolWindowEx = (ToolWindowEx) toolWindow;
        try {
            Runnable forceRefreshTitleActions = () -> {
                ApplicationManager.getApplication().invokeLater(() -> {
                    try {
                        toolWindowEx.setTitleActions(new AnAction("Refresh", "Refresh Azure Nodes List", null) {

                            @Override
                            public void actionPerformed(AnActionEvent event) {
                                azureModule.load(true);
                            }

                            @Override
                            public void update(AnActionEvent e) {
                                boolean isDarkTheme = DefaultLoader.getUIHelper().isDarkTheme();
                                final String iconPath = isDarkTheme ? RefreshableNode.REFRESH_ICON_DARK : RefreshableNode.REFRESH_ICON_LIGHT;
                                e.getPresentation().setIcon(UIHelperImpl.loadIcon(iconPath));
                            }
                        }, new AzureSignInAction(), new SelectSubscriptionsAction());
                    } catch (Exception e) {
                        AzurePlugin.log(e.getMessage(), e);
                    }
                });
            };
            AuthMethodManager.getInstance().addSignInEventListener(forceRefreshTitleActions);
            AuthMethodManager.getInstance().addSignOutEventListener(forceRefreshTitleActions);
            // Remove the sign in/out listener when project close
            ProjectManager.getInstance().addProjectManagerListener(project, new ProjectManagerListener() {

                @Override
                public void projectClosing(@NotNull Project project) {
                    AuthMethodManager.getInstance().removeSignInEventListener(forceRefreshTitleActions);
                    AuthMethodManager.getInstance().removeSignOutEventListener(forceRefreshTitleActions);
                }
            });
            forceRefreshTitleActions.run();
        } catch (Exception e) {
            AzurePlugin.log(e.getMessage(), e);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) ToolWindowEx(com.intellij.openapi.wm.ex.ToolWindowEx) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) AzureSignInAction(com.microsoft.intellij.actions.AzureSignInAction) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) SelectSubscriptionsAction(com.microsoft.intellij.actions.SelectSubscriptionsAction) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 5 with ProjectManagerListener

use of com.intellij.openapi.project.ProjectManagerListener in project google-cloud-intellij by GoogleCloudPlatform.

the class GcpCheckoutProvider method clone.

private static void clone(@NotNull final Project project, @NotNull final Git git, @Nullable final Listener listener, @NotNull final VirtualFile destinationParent, @NotNull final String sourceRepositoryUrl, @NotNull final String directoryName, @NotNull final String parentDirectory, @Nullable final String gcpUserName) {
    final AtomicBoolean cloneResult = new AtomicBoolean();
    new Task.Backgroundable(project, GctBundle.message("clonefromgcp.repository", sourceRepositoryUrl)) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            GcpHttpAuthDataProvider.Context context = GcpHttpAuthDataProvider.createContext(gcpUserName);
            try {
                cloneResult.set(doClone(project, indicator, git, directoryName, parentDirectory, sourceRepositoryUrl));
            } finally {
                context.close();
            }
        }

        @Override
        public void onSuccess() {
            if (!cloneResult.get()) {
                return;
            }
            destinationParent.refresh(true, true, new Runnable() {

                @Override
                public void run() {
                    if (project.isOpen() && (!project.isDisposed()) && (!project.isDefault())) {
                        final VcsDirtyScopeManager mgr = VcsDirtyScopeManager.getInstance(project);
                        mgr.fileDirty(destinationParent);
                    }
                }
            });
            ProjectManagerListener configWriter = new ProjectManagerListener() {

                @Override
                public void projectOpened(Project project) {
                    PropertiesComponent.getInstance(project).setValue(GcpHttpAuthDataProvider.GCP_USER, gcpUserName == null ? "" : gcpUserName);
                }

                @Override
                public boolean canCloseProject(Project project) {
                    return true;
                }

                @Override
                public void projectClosed(Project project) {
                // no-op
                }

                @Override
                public void projectClosing(Project project) {
                // no-op
                }
            };
            ProjectManager.getInstance().addProjectManagerListener(configWriter);
            try {
                if (listener != null) {
                    listener.directoryCheckedOut(new File(parentDirectory, directoryName), GitVcs.getKey());
                    listener.checkoutCompleted();
                }
            } finally {
                ProjectManager.getInstance().removeProjectManagerListener(configWriter);
            }
        }
    }.queue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VcsDirtyScopeManager(com.intellij.openapi.vcs.changes.VcsDirtyScopeManager)

Aggregations

Project (com.intellij.openapi.project.Project)5 ProjectManagerListener (com.intellij.openapi.project.ProjectManagerListener)5 Module (com.intellij.openapi.module.Module)2 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)2 Facet (com.intellij.facet.Facet)1 FacetManagerAdapter (com.intellij.facet.FacetManagerAdapter)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 ModuleListener (com.intellij.openapi.project.ModuleListener)1 ActionCallback (com.intellij.openapi.util.ActionCallback)1 VcsDirtyScopeManager (com.intellij.openapi.vcs.changes.VcsDirtyScopeManager)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ToolWindowEx (com.intellij.openapi.wm.ex.ToolWindowEx)1 QueueProcessor (com.intellij.util.concurrency.QueueProcessor)1 AzureSignInAction (com.microsoft.intellij.actions.AzureSignInAction)1 SelectSubscriptionsAction (com.microsoft.intellij.actions.SelectSubscriptionsAction)1 File (java.io.File)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1