git: replace ProjectComponent with StartupActivity

GitOrigin-RevId: db494873fd6420e137705a016330e7b385f89ef1
This commit is contained in:
Aleksey Pivovarov
2019-05-03 16:27:42 +03:00
committed by intellij-monorepo-bot
parent 0ce0222078
commit a0cdca1981
2 changed files with 21 additions and 21 deletions

View File

@@ -269,6 +269,7 @@
<lang.commenter language="GitIgnore" implementationClass="com.intellij.openapi.vcs.changes.ignore.lang.IgnoreCommenter"/>
<!--END Git ignore lang-->
<postStartupActivity implementation="git4idea.conflicts.GitConflictsToolWindowManager$Starter"/>
</extensions>
<extensionPoints>
@@ -278,10 +279,4 @@
interface="git4idea.push.GitPushProcessCustomizationFactory" />
<extensionPoint qualifiedName="Git4Idea.GitCheckinExplicitMovementProvider" interface="git4idea.checkin.GitCheckinExplicitMovementProvider"/>
</extensionPoints>
<project-components>
<component>
<implementation-class>git4idea.conflicts.GitConflictsToolWindowManager</implementation-class>
</component>
</project-components>
</idea-plugin>

View File

@@ -1,11 +1,12 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package git4idea.conflicts;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentI;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
@@ -18,38 +19,35 @@ import git4idea.repo.GitRepositoryManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class GitConflictsToolWindowManager implements ProjectComponent {
public class GitConflictsToolWindowManager {
public static final String TAB_NAME = "Conflicts";
@NotNull private final Project myProject;
@NotNull private final ChangesViewContentI myContentManager;
@NotNull private final GitRepositoryManager myRepositoryManager;
private final MergingUpdateQueue myQueue;
@Nullable private Content myContent;
public GitConflictsToolWindowManager(@NotNull Project project,
@NotNull ChangesViewContentI contentManager,
@NotNull GitRepositoryManager repositoryManager) {
public GitConflictsToolWindowManager(@NotNull Project project) {
myProject = project;
myContentManager = contentManager;
myRepositoryManager = repositoryManager;
myQueue = new MergingUpdateQueue("GitConflictsToolWindowManager", 300, true, null, myProject);
}
project.getMessageBus().connect().subscribe(GitConflictsHolder.CONFLICTS_CHANGE, new GitConflictsHolder.ConflictsListener() {
private void init() {
myProject.getMessageBus().connect().subscribe(GitConflictsHolder.CONFLICTS_CHANGE, new GitConflictsHolder.ConflictsListener() {
@Override
public void conflictsChanged(@NotNull GitRepository repository) {
myQueue.queue(Update.create("update", () -> updateToolWindow()));
}
});
ApplicationManager.getApplication().invokeLater(() -> updateToolWindow());
}
private void updateToolWindow() {
if (!Registry.is("git.merge.conflicts.toolwindow")) return;
boolean hasConflicts = ContainerUtil.exists(myRepositoryManager.getRepositories(),
boolean hasConflicts = ContainerUtil.exists(GitRepositoryManager.getInstance(myProject).getRepositories(),
repo -> !repo.getConflictsHolder().getConflicts().isEmpty());
if (hasConflicts && myContent == null) {
GitConflictsView panel = new GitConflictsView(myProject);
@@ -59,11 +57,18 @@ public class GitConflictsToolWindowManager implements ProjectComponent {
myContent.setCloseable(false);
myContent.setPreferredFocusedComponent(() -> panel.getPreferredFocusableComponent());
Disposer.register(myContent, panel);
myContentManager.addContent(myContent);
ChangesViewContentManager.getInstance(myProject).addContent(myContent);
}
if (!hasConflicts && myContent != null) {
myContentManager.removeContent(myContent);
ChangesViewContentManager.getInstance(myProject).removeContent(myContent);
myContent = null;
}
}
public static class Starter implements StartupActivity, DumbAware {
@Override
public void runActivity(@NotNull Project project) {
new GitConflictsToolWindowManager(project).init();
}
}
}