mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-161662 VersionControl toolwindow should not be available for project with no VCS enabled
This commit is contained in:
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
*/
|
*/
|
||||||
public interface ChangesViewContentI {
|
public interface ChangesViewContentI {
|
||||||
void setUp(ToolWindow toolWindow);
|
void setUp(ToolWindow toolWindow);
|
||||||
|
boolean isAvailable();
|
||||||
void addContent(Content content);
|
void addContent(Content content);
|
||||||
void removeContent(final Content content);
|
void removeContent(final Content content);
|
||||||
void setSelectedContent(final Content content);
|
void setSelectedContent(final Content content);
|
||||||
|
|||||||
+12
-9
@@ -24,8 +24,8 @@ import com.intellij.openapi.project.Project;
|
|||||||
import com.intellij.openapi.util.Comparing;
|
import com.intellij.openapi.util.Comparing;
|
||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
import com.intellij.openapi.util.Key;
|
import com.intellij.openapi.util.Key;
|
||||||
import com.intellij.openapi.vcs.AbstractVcs;
|
|
||||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||||
|
import com.intellij.openapi.vcs.VcsDirectoryMapping;
|
||||||
import com.intellij.openapi.vcs.VcsListener;
|
import com.intellij.openapi.vcs.VcsListener;
|
||||||
import com.intellij.openapi.wm.ToolWindow;
|
import com.intellij.openapi.wm.ToolWindow;
|
||||||
import com.intellij.openapi.wm.ToolWindowId;
|
import com.intellij.openapi.wm.ToolWindowId;
|
||||||
@@ -65,6 +65,7 @@ public class ChangesViewContentManager extends AbstractProjectComponent implemen
|
|||||||
super(project);
|
super(project);
|
||||||
myVcsManager = vcsManager;
|
myVcsManager = vcsManager;
|
||||||
myVcsChangeAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, project);
|
myVcsChangeAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, project);
|
||||||
|
myProject.getMessageBus().connect().subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, myVcsListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUp(ToolWindow toolWindow) {
|
public void setUp(ToolWindow toolWindow) {
|
||||||
@@ -73,13 +74,9 @@ public class ChangesViewContentManager extends AbstractProjectComponent implemen
|
|||||||
myContentManagerListener = new MyContentManagerListener();
|
myContentManagerListener = new MyContentManagerListener();
|
||||||
contentManager.addContentManagerListener(myContentManagerListener);
|
contentManager.addContentManagerListener(myContentManagerListener);
|
||||||
|
|
||||||
myVcsManager.addVcsListener(myVcsListener);
|
|
||||||
|
|
||||||
Disposer.register(myProject, new Disposable(){
|
Disposer.register(myProject, new Disposable(){
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
contentManager.removeContentManagerListener(myContentManagerListener);
|
contentManager.removeContentManagerListener(myContentManagerListener);
|
||||||
|
|
||||||
myVcsManager.removeVcsListener(myVcsListener);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -146,11 +143,15 @@ public class ChangesViewContentManager extends AbstractProjectComponent implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateToolWindowAvailability() {
|
private void updateToolWindowAvailability() {
|
||||||
final AbstractVcs[] abstractVcses = myVcsManager.getAllActiveVcss();
|
|
||||||
ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(TOOLWINDOW_ID);
|
ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(TOOLWINDOW_ID);
|
||||||
toolWindow.setAvailable(abstractVcses.length > 0, null);
|
toolWindow.setAvailable(isAvailable(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAvailable() {
|
||||||
|
final List<VcsDirectoryMapping> mappings = myVcsManager.getDirectoryMappings();
|
||||||
|
return !mappings.isEmpty() && !mappings.get(0).isDefaultMapping() && mappings.get(0).getVcs() != null;
|
||||||
|
}
|
||||||
|
|
||||||
public void projectClosed() {
|
public void projectClosed() {
|
||||||
myVcsChangeAlarm.cancelAllRequests();
|
myVcsChangeAlarm.cancelAllRequests();
|
||||||
}
|
}
|
||||||
@@ -216,7 +217,9 @@ public class ChangesViewContentManager extends AbstractProjectComponent implemen
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (myProject.isDisposed()) return;
|
if (myProject.isDisposed()) return;
|
||||||
updateToolWindowAvailability();
|
updateToolWindowAvailability();
|
||||||
updateExtensionTabs();
|
if (myContentManager != null) {
|
||||||
|
updateExtensionTabs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, 100, ModalityState.NON_MODAL);
|
}, 100, ModalityState.NON_MODAL);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -17,6 +17,7 @@ package com.intellij.openapi.vcs.changes.ui;
|
|||||||
|
|
||||||
import com.intellij.openapi.project.DumbAware;
|
import com.intellij.openapi.project.DumbAware;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.util.Condition;
|
||||||
import com.intellij.openapi.wm.ToolWindow;
|
import com.intellij.openapi.wm.ToolWindow;
|
||||||
import com.intellij.openapi.wm.ToolWindowFactory;
|
import com.intellij.openapi.wm.ToolWindowFactory;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -24,9 +25,14 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
/**
|
/**
|
||||||
* @author Dmitry Avdeev
|
* @author Dmitry Avdeev
|
||||||
*/
|
*/
|
||||||
public class ChangesViewToolWindowFactory implements ToolWindowFactory, DumbAware {
|
public class ChangesViewToolWindowFactory implements ToolWindowFactory, DumbAware, Condition<Project> {
|
||||||
@Override
|
@Override
|
||||||
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
|
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
|
||||||
ChangesViewContentManager.getInstance(project).setUp(toolWindow);
|
ChangesViewContentManager.getInstance(project).setUp(toolWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean value(Project project) {
|
||||||
|
return ChangesViewContentManager.getInstance(project).isAvailable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -27,6 +27,11 @@ public class DummyChangesViewContentManager implements ChangesViewContentI {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addContent(final Content content) {
|
public void addContent(final Content content) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user