IDEA-101042 lst: allow to hide markers in gutter
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Mon, 27 Jul 2015 09:37:19 +0000 (12:37 +0300)
committerAleksey Pivovarov <AMPivovarov@gmail.com>
Mon, 3 Aug 2015 11:45:39 +0000 (14:45 +0300)
platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.form
platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.java
platform/vcs-api/src/com/intellij/openapi/vcs/VcsApplicationSettings.java
platform/vcs-impl/src/com/intellij/openapi/vcs/actions/ShowChangeMarkerAction.java
platform/vcs-impl/src/com/intellij/openapi/vcs/ex/BaseLineStatusRangeAction.java
platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTracker.java
platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RangesBuilder.java
platform/vcs-impl/src/com/intellij/openapi/vcs/ex/RollbackLineStatusAction.java
platform/vcs-impl/src/com/intellij/openapi/vcs/impl/LineStatusTrackerManager.java

index 506cf2ab5f6fe2d5d513978a8bfa4b927646f671..b8f1906cdb28369d3e3ed8660f5a4a2553ce269e 100644 (file)
                   </component>
                 </children>
               </grid>
-              <grid id="7f3f5" layout-manager="GridLayoutManager" row-count="6" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+              <grid id="7f3f5" layout-manager="GridLayoutManager" row-count="7" 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="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"/>
                   </component>
                   <vspacer id="612dd">
                     <constraints>
-                      <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+                      <grid row="6" 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="d83cc" class="com.intellij.ui.components.JBLabel" binding="myStripTrailingSpacesExplanationLabel">
                       <text value="explanation"/>
                     </properties>
                   </component>
-                  <component id="95944" class="javax.swing.JCheckBox" binding="myShowWhitespacesModificationsInLSTGutterCheckBox">
+                  <component id="95944" class="javax.swing.JCheckBox" binding="myShowLSTInGutterCheckBox">
                     <constraints>
                       <grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
                     </constraints>
                     <properties>
-                      <text value="Highlight lines with whitespace-only modifications in gutter"/>
+                      <text value="Highlight modified lines in gutter"/>
+                    </properties>
+                  </component>
+                  <component id="76ce4" class="javax.swing.JCheckBox" binding="myShowWhitespacesModificationsInLSTGutterCheckBox">
+                    <constraints>
+                      <grid row="5" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="2" use-parent-layout="false"/>
+                    </constraints>
+                    <properties>
+                      <text value="Different color for lines with whitespace-only modifications"/>
                     </properties>
                   </component>
                 </children>
index f8a8e8595d77fb4858d53eb7f22ed82d694e2654..d8744526bcdf74aed7f722fea5451aa7ca225723 100644 (file)
@@ -104,6 +104,7 @@ public class EditorOptionsPanel {
   private JCheckBox    myShowInlineDialogForCheckBox;
   private JBLabel      myStripTrailingSpacesExplanationLabel;
   private JCheckBox    myCbEnableRichCopyByDefault;
+  private JCheckBox    myShowLSTInGutterCheckBox;
   private JCheckBox    myShowWhitespacesModificationsInLSTGutterCheckBox;
 
   private static final String ACTIVE_COLOR_SCHEME = ApplicationBundle.message("combobox.richcopy.color.scheme.active");
@@ -155,6 +156,7 @@ public class EditorOptionsPanel {
     myConfigurable = new MyConfigurable();
     initQuickDocProcessing();
     initSoftWrapsSettingsProcessing();
+    initVcsSettingsProcessing();
   }
 
 
@@ -228,6 +230,7 @@ public class EditorOptionsPanel {
     myShowNotificationAfterReformatCodeCheckBox.setSelected(editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_REFORMAT_CODE_ACTION);
     myShowNotificationAfterOptimizeImportsCheckBox.setSelected(editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_OPTIMIZE_IMPORTS_ACTION);
 
+    myShowLSTInGutterCheckBox.setSelected(vcsSettings.SHOW_LST_GUTTER_MARKERS);
     myShowWhitespacesModificationsInLSTGutterCheckBox.setSelected(vcsSettings.SHOW_WHITESPACES_IN_LST);
 
     myErrorHighlightingPanel.reset();
@@ -345,8 +348,16 @@ public class EditorOptionsPanel {
     editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_REFORMAT_CODE_ACTION = myShowNotificationAfterReformatCodeCheckBox.isSelected();
     editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_OPTIMIZE_IMPORTS_ACTION = myShowNotificationAfterOptimizeImportsCheckBox.isSelected();
 
+    boolean updateVcsSettings = false;
     if (vcsSettings.SHOW_WHITESPACES_IN_LST != myShowWhitespacesModificationsInLSTGutterCheckBox.isSelected()) {
       vcsSettings.SHOW_WHITESPACES_IN_LST = myShowWhitespacesModificationsInLSTGutterCheckBox.isSelected();
+      updateVcsSettings = true;
+    }
+    if (vcsSettings.SHOW_LST_GUTTER_MARKERS != myShowLSTInGutterCheckBox.isSelected()) {
+      vcsSettings.SHOW_LST_GUTTER_MARKERS = myShowLSTInGutterCheckBox.isSelected();
+      updateVcsSettings = true;
+    }
+    if (updateVcsSettings) {
       Project[] projects = ProjectManager.getInstance().getOpenProjects();
       for (Project project : projects) {
         LineStatusTrackerManager.getInstance(project).updateSettings();
@@ -494,6 +505,7 @@ public class EditorOptionsPanel {
     isModified |= isModified(myShowNotificationAfterReformatCodeCheckBox, editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_REFORMAT_CODE_ACTION);
     isModified |= isModified(myShowNotificationAfterOptimizeImportsCheckBox, editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_OPTIMIZE_IMPORTS_ACTION);
 
+    isModified |= isModified(myShowLSTInGutterCheckBox, vcsSettings.SHOW_LST_GUTTER_MARKERS);
     isModified |= isModified(myShowWhitespacesModificationsInLSTGutterCheckBox, vcsSettings.SHOW_WHITESPACES_IN_LST);
 
     isModified |= myErrorHighlightingPanel.isModified();
@@ -576,6 +588,15 @@ public class EditorOptionsPanel {
     myCbShowSoftWrapsOnlyOnCaretLine.setEnabled(softWrapsEnabled);
   }
 
+  private void initVcsSettingsProcessing() {
+    myShowLSTInGutterCheckBox.addItemListener(new ItemListener() {
+      @Override
+      public void itemStateChanged(ItemEvent e) {
+        myShowWhitespacesModificationsInLSTGutterCheckBox.setEnabled(myShowLSTInGutterCheckBox.isSelected());
+      }
+    });
+  }
+
   public JComponent getComponent() {
     return myBehaviourPanel;
   }
index 04e307d24641fde95aea2197869cde1c86e721d0..ffb54448a6f02f7cfc840f1d6c4953632243a117 100644 (file)
@@ -28,6 +28,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil;
 public class VcsApplicationSettings implements PersistentStateComponent<VcsApplicationSettings> {
   public String PATCH_STORAGE_LOCATION = null;
   public boolean SHOW_WHITESPACES_IN_LST = false;
+  public boolean SHOW_LST_GUTTER_MARKERS = true;
 
   public static VcsApplicationSettings getInstance() {
     return ServiceManager.getService(VcsApplicationSettings.class);
index 39fd37dc277174fc9503b18d6f692057d0e77116..262e40549cf869c3cf832c0bf7742898f9be341e 100644 (file)
@@ -96,6 +96,12 @@ public abstract class ShowChangeMarkerAction extends AbstractVcsAction {
 
   @Override
   protected void update(VcsContext context, Presentation presentation) {
+    LineStatusTracker tracker = myChangeMarkerContext.getLineStatusTracker(context);
+    if (tracker == null || tracker.isSilentMode()) {
+      presentation.setEnabledAndVisible(false);
+      return;
+    }
+
     boolean active = isActive(context);
     presentation.setEnabled(active);
     presentation.setVisible(myChangeMarkerContext.getEditor(context) != null || ActionPlaces.isToolbarPlace(context.getPlace()));
index aaa16af64ebdb705bf4cc73a4581f758e6551ce8..d2c0b288cfef43dc76f91d83b95efba464cd3f6c 100644 (file)
@@ -35,7 +35,7 @@ public abstract class BaseLineStatusRangeAction extends AnAction implements Dumb
   }
 
   public void update(final AnActionEvent e) {
-    e.getPresentation().setEnabled(isEnabled());
+    e.getPresentation().setEnabled(!myLineStatusTracker.isSilentMode() && isEnabled());
   }
 
   public abstract boolean isEnabled();
index 625dd86a67586dd8a3c8f6ab3f6607d17ac18b0f..812e7e98a1430fa3f0cc623aa0ba968dbb836462 100644 (file)
@@ -57,7 +57,7 @@ import static com.intellij.diff.util.DiffUtil.getLineCount;
  *         author: lesya
  */
 public class LineStatusTracker {
-  public enum Mode {DEFAULT, SMART}
+  public enum Mode {DEFAULT, SMART, SILENT}
 
   public static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.ex.LineStatusTracker");
   private static final Key<CanNotCalculateDiffPanel> PANEL_KEY =
@@ -187,12 +187,14 @@ public class LineStatusTracker {
     }
   }
 
-  @NotNull
+  @Nullable
   private RangeHighlighter createHighlighter(@NotNull Range range) {
     myApplication.assertIsDispatchThread();
 
     LOG.assertTrue(!myReleased, "Already released");
 
+    if (myMode == Mode.SILENT) return null;
+
     int first =
       range.getLine1() >= getLineCount(myDocument) ? myDocument.getTextLength() : myDocument.getLineStartOffset(range.getLine1());
 
@@ -273,6 +275,15 @@ public class LineStatusTracker {
     return myVirtualFile;
   }
 
+  @NotNull
+  public Mode getMode() {
+    return myMode;
+  }
+
+  public boolean isSilentMode() {
+    return myMode == Mode.SILENT;
+  }
+
   @NotNull
   public List<Range> getRanges() {
     synchronized (myLock) {
index 18cf26ec9be13f0a04027600e8f478487a2c6057..6b795a294873679ce666ddc37e00e463dfc8f208 100644 (file)
@@ -59,6 +59,7 @@ public class RangesBuilder {
 
     switch (mode) {
       case DEFAULT:
+      case SILENT:
         processDefault(current, vcs, shift, vcsShift);
         break;
       case SMART:
index 0b21a6b6ac8bd7c78f43feb8c8c2d625162e75f5..9fb66d26e9a634bbdb3525203c88bb4ba864e45f 100644 (file)
@@ -45,7 +45,7 @@ public class RollbackLineStatusAction extends DumbAwareAction {
       return;
     }
     LineStatusTracker tracker = LineStatusTrackerManager.getInstance(project).getLineStatusTracker(editor.getDocument());
-    if (tracker == null) {
+    if (tracker == null || tracker.isSilentMode()) {
       e.getPresentation().setEnabledAndVisible(false);
       return;
     }
index 6de1143b6f8ac62019f015ef9a63023916ef9e18..d9cd4150de5af379b02474faff2a12426e25e219 100644 (file)
@@ -318,7 +318,9 @@ public class LineStatusTrackerManager implements ProjectComponent, LineStatusTra
 
   @NotNull
   private static LineStatusTracker.Mode getMode() {
-    return VcsApplicationSettings.getInstance().SHOW_WHITESPACES_IN_LST ? LineStatusTracker.Mode.SMART : LineStatusTracker.Mode.DEFAULT;
+    VcsApplicationSettings vcsApplicationSettings = VcsApplicationSettings.getInstance();
+    if (!vcsApplicationSettings.SHOW_LST_GUTTER_MARKERS) return LineStatusTracker.Mode.SILENT;
+    return vcsApplicationSettings.SHOW_WHITESPACES_IN_LST ? LineStatusTracker.Mode.SMART : LineStatusTracker.Mode.DEFAULT;
   }
 
   private void startAlarm(@NotNull final Document document, @NotNull final VirtualFile virtualFile) {