git4idea: Added possiblity to disable git branch widget

This commit is contained in:
Constantine Plotnikov
2010-08-02 19:03:48 +04:00
parent 0686359835
commit 2195a2f451
4 changed files with 215 additions and 86 deletions
+14
View File
@@ -207,6 +207,11 @@ public class GitVcs extends AbstractVcs<CommittedChangeList> {
* The reference tracker
*/
private GitReferenceTracker myReferenceTracker;
/**
* If true, the vcs was activated
*/
private boolean isActivated;
public static GitVcs getInstance(@NotNull Project project) {
return (GitVcs)ProjectLevelVcsManager.getInstance(project).findVcsByName(NAME);
@@ -496,6 +501,7 @@ public class GitVcs extends AbstractVcs<CommittedChangeList> {
*/
@Override
protected void activate() {
isActivated = true;
if (!myProject.isDefault() && myRootTracker == null) {
myRootTracker = new GitRootTracker(this, myProject, myRootListeners.getMulticaster());
}
@@ -519,6 +525,7 @@ public class GitVcs extends AbstractVcs<CommittedChangeList> {
*/
@Override
protected void deactivate() {
isActivated = false;
GitBranchConfigurations.getInstance(myProject).deactivate();
if (myRootTracker != null) {
myRootTracker.dispose();
@@ -768,4 +775,11 @@ public class GitVcs extends AbstractVcs<CommittedChangeList> {
final VirtualFile vcsRoot = GitUtil.getGitRoot(file);
return GitChangeUtils.getRevisionChanges(project, vcsRoot, revision.getRevisionNumber().asString(), false);
}
/**
* @return true if vcs was activated
*/
public boolean isActivated() {
return isActivated;
}
}
@@ -49,6 +49,7 @@ import git4idea.vfs.GitReferenceListener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.*;
/**
@@ -147,6 +148,10 @@ public class GitBranchConfigurations implements PersistentStateComponent<GitBran
* Listener for changes
*/
private final ChangeListAdapter myChangesListener;
/**
* If true, the widget is enabled
*/
private boolean myWidgetEnabled = true;
/**
* The constructor used to dependency injection
@@ -268,8 +273,20 @@ public class GitBranchConfigurations implements PersistentStateComponent<GitBran
}
referencesChanged();
}
if (isWidgetEnabled()) {
installWidget();
}
}
/**
* Install widget
*/
private void installWidget() {
if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
myWidgetUninstall = GitBranchesWidget.install(myProject, this);
final Runnable r = GitBranchesWidget.install(myProject, this);
synchronized (myStateLock) {
myWidgetUninstall = r;
}
}
}
@@ -279,10 +296,18 @@ public class GitBranchConfigurations implements PersistentStateComponent<GitBran
public void deactivate() {
myVcs.removeGitReferenceListener(myReferenceListener);
myChangeManager.removeChangeListListener(myChangesListener);
if (myWidgetUninstall != null) {
myWidgetUninstall.run();
uninstallWidget();
}
private void uninstallWidget() {
final Runnable r;
synchronized (myStateLock) {
r = myWidgetUninstall;
myWidgetUninstall = null;
}
if (r != null) {
r.run();
}
}
/**
@@ -310,6 +335,7 @@ public class GitBranchConfigurations implements PersistentStateComponent<GitBran
public State getState() {
synchronized (myStateLock) {
State rc = new State();
rc.IS_WIDGET_ENABLED = myWidgetEnabled;
rc.CURRENT = myCurrentConfiguration == null ? null : myCurrentConfiguration.getName();
ArrayList<BranchConfiguration> cs = new ArrayList<BranchConfiguration>(myConfigurations.size());
for (GitBranchConfiguration ci : myConfigurations.values()) {
@@ -363,9 +389,54 @@ public class GitBranchConfigurations implements PersistentStateComponent<GitBran
}
fireCurrentConfigurationChanged();
fireConfigurationsChanged();
if (state.IS_WIDGET_ENABLED != myWidgetEnabled) {
myWidgetEnabled = state.IS_WIDGET_ENABLED;
updateWidgetState();
}
}
}
/**
* Update widget state after update
*/
private void updateWidgetState() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (isWidgetEnabled()) {
if (myVcs.isActivated() && myWidgetUninstall == null) {
installWidget();
}
}
else {
uninstallWidget();
}
}
});
}
/**
* @return true if widget is enabled
*/
public boolean isWidgetEnabled() {
synchronized (myStateLock) {
return myWidgetEnabled;
}
}
/**
* Update widget state
*
* @param value true to enable widget
*/
public void setWidgetEnabled(boolean value) {
synchronized (myStateLock) {
myWidgetEnabled = value;
updateWidgetState();
}
}
/**
* @return the candidate remote configurations
*/
@@ -632,18 +703,6 @@ public class GitBranchConfigurations implements PersistentStateComponent<GitBran
return myStateLock;
}
/**
* Check if configuration with specified name already exists
*
* @param name the name to check
* @return true if the configuration exists
*/
boolean hasConfigurationName(String name) {
synchronized (myStateLock) {
return myConfigurations.containsKey(name);
}
}
/**
* Set current configuration
*
@@ -765,6 +824,10 @@ public class GitBranchConfigurations implements PersistentStateComponent<GitBran
* The configuration state
*/
public static class State {
/**
* If true, branches widget is enabled
*/
public boolean IS_WIDGET_ENABLED = true;
/**
* The current configuration
*/
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="git4idea.config.GitVcsPanel">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
@@ -10,107 +10,150 @@
</properties>
<border type="none"/>
<children>
<component id="b1a9d" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.path.label"/>
<verifyInputWhenFocusTarget value="false"/>
</properties>
</component>
<component id="25af7" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myGitField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<vspacer id="4c83d">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="563b2" class="javax.swing.JButton" binding="myTestButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="2" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<horizontalAlignment value="0"/>
<label resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.test.label"/>
<text resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.test"/>
</properties>
</component>
<component id="5a909" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="f5de9"/>
<text resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.ssh.mode"/>
</properties>
</component>
<grid id="97c7d" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="b95e2" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<border type="etched" title="Interface Options">
<font/>
</border>
<children>
<component id="f5de9" class="javax.swing.JComboBox" binding="mySSHExecutableComboBox" default-binding="true">
<component id="26b57" class="javax.swing.JCheckBox" binding="myEnableBranchesWidgetCheckBox" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text value="Enable &amp;branches widget"/>
<toolTipText value="Enables status widget in status bar"/>
</properties>
</component>
<hspacer id="9eafb">
<hspacer id="a6134">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
<component id="a6d8e" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="7a626"/>
<text resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.convert.crlf"/>
</properties>
</component>
<grid id="a4472" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e7668" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<border type="etched" title="File Conversion"/>
<children>
<component id="a6d8e" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="7a626"/>
<text resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.convert.crlf"/>
</properties>
</component>
<hspacer id="9e883">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="8bedb">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="7a626" class="javax.swing.JComboBox" binding="myConvertTextFilesComboBox" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<toolTipText resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.convert.tooltip"/>
</properties>
</component>
<hspacer id="3c6b8">
<component id="a8818" class="javax.swing.JCheckBox" binding="myAskBeforeConversionsCheckBox" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<properties>
<selected value="true"/>
<text resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.convert.ask"/>
<toolTipText resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.convert.ask.tooltip"/>
</properties>
</component>
</children>
</grid>
<component id="a8818" class="javax.swing.JCheckBox" binding="myAskBeforeConversionsCheckBox" default-binding="true">
<grid id="c9e6b" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.convert.ask"/>
<toolTipText resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.convert.ask.tooltip"/>
</properties>
</component>
<properties/>
<border type="etched" title="Git"/>
<children>
<component id="b1a9d" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.path.label"/>
<verifyInputWhenFocusTarget value="false"/>
</properties>
</component>
<component id="25af7" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myGitField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="563b2" class="javax.swing.JButton" binding="myTestButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="2" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<horizontalAlignment value="0"/>
<label resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.test.label"/>
<text resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.test"/>
</properties>
</component>
<component id="5a909" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="f5de9"/>
<text resource-bundle="git4idea/i18n/GitBundle" key="git.vcs.config.ssh.mode"/>
</properties>
</component>
<grid id="97c7d" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<hspacer id="9eafb">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="f5de9" class="javax.swing.JComboBox" binding="mySSHExecutableComboBox" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
<vspacer id="4c83d">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>
@@ -22,6 +22,7 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.vcs.VcsException;
import git4idea.GitVcs;
import git4idea.checkout.branches.GitBranchConfigurations;
import git4idea.i18n.GitBundle;
import org.jetbrains.annotations.NotNull;
@@ -57,6 +58,10 @@ public class GitVcsPanel {
* The confirmation checkbox
*/
private JCheckBox myAskBeforeConversionsCheckBox;
/**
* The if selected, the branches widget is enabled in the status bar
*/
private JCheckBox myEnableBranchesWidgetCheckBox;
/**
* The project
*/
@@ -107,6 +112,7 @@ public class GitVcsPanel {
myConvertTextFilesComboBox.setSelectedItem(CRLF_CONVERT_TO_PROJECT);
myGitField.addBrowseFolderListener(GitBundle.getString("find.git.title"), GitBundle.getString("find.git.description"), project,
new FileChooserDescriptor(true, false, false, false, false, false));
myEnableBranchesWidgetCheckBox.setSelected(GitBranchConfigurations.getInstance(myProject).isWidgetEnabled());
}
/**
@@ -148,6 +154,7 @@ public class GitVcsPanel {
mySSHExecutableComboBox.setSelectedItem(settings.isIdeaSsh() ? IDEA_SSH : NATIVE_SSH);
myAskBeforeConversionsCheckBox.setSelected(settings.askBeforeLineSeparatorConversion());
myConvertTextFilesComboBox.setSelectedItem(crlfPolicyItem(settings));
myEnableBranchesWidgetCheckBox.setSelected(GitBranchConfigurations.getInstance(myProject).isWidgetEnabled());
}
/**
@@ -181,7 +188,8 @@ public class GitVcsPanel {
return !settings.getGitExecutable().equals(myGitField.getText()) ||
(settings.isIdeaSsh() != IDEA_SSH.equals(mySSHExecutableComboBox.getSelectedItem())) ||
!crlfPolicyItem(settings).equals(myConvertTextFilesComboBox.getSelectedItem()) ||
settings.askBeforeLineSeparatorConversion() != myAskBeforeConversionsCheckBox.isSelected();
settings.askBeforeLineSeparatorConversion() != myAskBeforeConversionsCheckBox.isSelected() ||
GitBranchConfigurations.getInstance(myProject).isWidgetEnabled() != myEnableBranchesWidgetCheckBox.isSelected();
}
/**
@@ -205,5 +213,6 @@ public class GitVcsPanel {
}
settings.setLineSeparatorsConversion(conversionPolicy);
settings.setAskBeforeLineSeparatorConversion(myAskBeforeConversionsCheckBox.isSelected());
GitBranchConfigurations.getInstance(myProject).setWidgetEnabled(myEnableBranchesWidgetCheckBox.isSelected());
}
}