branch context notification: option to turn off the feature

This commit is contained in:
Dmitry Avdeev
2017-09-11 15:05:05 +03:00
parent d22f0ba72c
commit aaf8221d3c
4 changed files with 22 additions and 12 deletions
@@ -6,6 +6,7 @@ import com.intellij.notification.NotificationType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.vcs.BranchChangeListener;
import com.intellij.openapi.vcs.VcsConfiguration;
import org.jetbrains.annotations.NotNull;
import javax.swing.event.HyperlinkEvent;
@@ -13,7 +14,7 @@ import javax.swing.event.HyperlinkEvent;
public class BranchContextTracker implements BranchChangeListener {
public static final NotificationGroup NOTIFICATION = new NotificationGroup(
"Branch Context group", NotificationDisplayType.STICKY_BALLOON, true);
"Branch Context group", NotificationDisplayType.BALLOON, true);
private final WorkingContextManager myContextManager;
private final Project myProject;
@@ -31,19 +32,19 @@ public class BranchContextTracker implements BranchChangeListener {
@Override
public void branchHasChanged(@NotNull String branchName) {
VcsConfiguration vcsConfiguration = VcsConfiguration.getInstance(myProject);
if (!vcsConfiguration.RELOAD_CONTEXT) return;
String contextName = getContextName(branchName);
if (!myContextManager.hasContext(contextName)) return;
myContextManager.clearContext();
myContextManager.loadContext(contextName);
NOTIFICATION.createNotification(null, null, "Branch context has been loaded<br>" +
"<a href='ok'>Got it!</a><br>" +
"<a href='off'>Turn off the feature</a>", NotificationType.INFORMATION, (notification, event) -> {
if (event.getEventType() != HyperlinkEvent.EventType.ACTIVATED) return;
if ("ok".equals(event.getDescription())) {
notification.expire();
}
if ("off".equals(event.getDescription())) {
vcsConfiguration.RELOAD_CONTEXT = false;
notification.expire();
}
}).notify(myProject);
@@ -79,6 +79,7 @@ public final class VcsConfiguration implements PersistentStateComponent<VcsConfi
public boolean SHOW_UNVERSIONED_FILES_WHILE_COMMIT = true;
public boolean LOCAL_CHANGES_DETAILS_PREVIEW_SHOWN = false;
public boolean SHELVE_DETAILS_PREVIEW_SHOWN = false;
public boolean RELOAD_CONTEXT = true;
@AbstractCollection(surroundWithTag = false, elementTag = "path")
@Tag("ignored-roots")
@@ -152,7 +152,7 @@
<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>
<grid id="aa6eb" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="aa6eb" layout-manager="GridLayoutManager" row-count="7" 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>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -186,7 +186,7 @@
</component>
<grid id="da366" layout-manager="FlowLayout" hgap="5" vgap="2" flow-align="0">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="6" 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"/>
@@ -212,7 +212,7 @@
</grid>
<grid id="6c335" layout-manager="FlowLayout" hgap="5" vgap="2" flow-align="0">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="5" 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"/>
@@ -244,6 +244,14 @@
<text value="Clear &amp;initial commit message"/>
</properties>
</component>
<component id="3e34c" class="javax.swing.JCheckBox" binding="myReloadContext">
<constraints>
<grid row="4" 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>
<text value="Reload context on &amp;branch switching"/>
</properties>
</component>
</children>
</grid>
</children>
@@ -16,8 +16,6 @@
package com.intellij.openapi.vcs.configurable;
import com.intellij.ide.actions.ShowFilePathAction;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.SystemInfo;
@@ -27,8 +25,6 @@ import com.intellij.openapi.vcs.ex.ProjectLevelVcsManagerEx;
import com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -65,6 +61,7 @@ public class VcsGeneralConfigurationPanel {
private JComboBox myFailedCommitChangelistCombo;
private JComboBox myOnPatchCreation;
private JCheckBox myClearInitialCommitMessage;
private JCheckBox myReloadContext;
private ButtonGroup myEmptyChangelistRemovingGroup;
public VcsGeneralConfigurationPanel(final Project project) {
@@ -109,6 +106,7 @@ public class VcsGeneralConfigurationPanel {
settings.OFFER_MOVE_TO_ANOTHER_CHANGELIST_ON_PARTIAL_COMMIT = myCbOfferToMoveChanges.isSelected();
settings.REMOVE_EMPTY_INACTIVE_CHANGELISTS = getSelected(myEmptyChangelistRemovingGroup);
settings.MOVE_TO_FAILED_COMMIT_CHANGELIST = getFailedCommitConfirm();
settings.RELOAD_CONTEXT = myReloadContext.isSelected();
for (VcsShowOptionsSettingImpl setting : myPromptOptions.keySet()) {
setting.setValue(myPromptOptions.get(setting).isSelected());
@@ -191,6 +189,7 @@ public class VcsGeneralConfigurationPanel {
if (settings.REMOVE_EMPTY_INACTIVE_CHANGELISTS != getSelected(myEmptyChangelistRemovingGroup)){
return true;
}
if (settings.RELOAD_CONTEXT != myReloadContext.isSelected()) return true;
if (!Comparing.equal(getFailedCommitConfirm(), settings.MOVE_TO_FAILED_COMMIT_CHANGELIST)) {
return true;
@@ -216,6 +215,7 @@ public class VcsGeneralConfigurationPanel {
myForceNonEmptyComment.setSelected(settings.FORCE_NON_EMPTY_COMMENT);
myClearInitialCommitMessage.setSelected(settings.CLEAR_INITIAL_COMMIT_MESSAGE);
myCbOfferToMoveChanges.setSelected(settings.OFFER_MOVE_TO_ANOTHER_CHANGELIST_ON_PARTIAL_COMMIT);
myReloadContext.setSelected(settings.RELOAD_CONTEXT);
VcsShowConfirmationOption.Value value = settings.REMOVE_EMPTY_INACTIVE_CHANGELISTS;
UIUtil.setSelectedButton(myEmptyChangelistRemovingGroup, value == VcsShowConfirmationOption.Value.SHOW_CONFIRMATION
? 0