From d63784eeca1bbc038482e80ed41e432ca4a94c75 Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Tue, 3 May 2016 02:44:04 +0300 Subject: [PATCH] vcs: Added "Show Unversioned Files" toggle button to commit dialog Removed previously used "Show/Hide unversioned files" link. --- .../vcs/changes/ui/ChangesBrowserBase.java | 3 +- .../changes/ui/CommitChangeListDialog.java | 57 ++++--------------- .../changes/ui/MultipleChangeListBrowser.java | 48 ++++++++++++---- 3 files changed, 48 insertions(+), 60 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserBase.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserBase.java index 25c50de9e7f0..8c83a3fac421 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserBase.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowserBase.java @@ -342,7 +342,8 @@ public abstract class ChangesBrowserBase extends JPanel implements TypeSafeDa myViewer.setAlwaysExpandList(value); } - private JComponent createToolbar() { + @NotNull + protected JComponent createToolbar() { DefaultActionGroup toolbarGroups = new DefaultActionGroup(); myToolBarGroup = new DefaultActionGroup(); toolbarGroups.add(myToolBarGroup); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java index 194380b30449..9c6d0ac667a8 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java @@ -19,7 +19,9 @@ import com.intellij.diff.util.DiffPlaces; import com.intellij.diff.util.DiffUserDataKeysEx; import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.Disposable; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.DataKey; +import com.intellij.openapi.actionSystem.DataSink; +import com.intellij.openapi.actionSystem.TypeSafeDataProvider; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.extensions.Extensions; @@ -49,13 +51,14 @@ import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.JBColor; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.SplitterWithSecondHideable; -import com.intellij.ui.components.labels.ActionLink; import com.intellij.util.Alarm; import com.intellij.util.ObjectUtils; import com.intellij.util.OnOffListener; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.ui.*; -import com.intellij.util.ui.components.BorderLayoutPanel; +import com.intellij.util.ui.AbstractLayoutManager; +import com.intellij.util.ui.ButtonlessScrollBarUI; +import com.intellij.util.ui.GridBag; +import com.intellij.util.ui.JBUI; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -292,8 +295,7 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj myBrowser = new AlienChangeListBrowser(project, changeLists, changes, initialSelection, true, true, singleVcs); } else { //noinspection unchecked - boolean showUnversioned = - myShowVcsCommit && myVcsConfiguration.SHOW_UNVERSIONED_FILES_WHILE_COMMIT && Registry.is("vcs.unversioned.files.in.commit"); + boolean unversionedFilesEnabled = myShowVcsCommit && Registry.is("vcs.unversioned.files.in.commit"); MultipleChangeListBrowser browser = new MultipleChangeListBrowser(project, changeLists, (List)changes, initialSelection, true, true, new Runnable() { @Override @@ -308,7 +310,7 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj handler.includedChangesChanged(); } } - }, showUnversioned) { + }, unversionedFilesEnabled) { @Override protected void afterDiffRefresh() { myBrowser.rebuildList(); @@ -1009,11 +1011,7 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj myChangesInfoCalculator = new ChangeInfoCalculator(); myLegend = new CommitLegendPanel(myChangesInfoCalculator); - BorderLayoutPanel bottomPanel = JBUI.Panels.simplePanel().addToRight(myLegend.getComponent()); - if (myShowVcsCommit && !myIsAlien && Registry.is("vcs.unversioned.files.in.commit")) { - bottomPanel.addToLeft(createShowUnversionedFilesLabel()); - } - myBrowser.getBottomPanel().add(bottomPanel, BorderLayout.SOUTH); + myBrowser.getBottomPanel().add(JBUI.Panels.simplePanel().addToRight(myLegend.getComponent()), BorderLayout.SOUTH); JPanel mainPanel; if (myAdditionalOptionsPanel != null) { @@ -1110,20 +1108,6 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj return myDetailsSplitter.getComponent(); } - @NotNull - private JComponent createShowUnversionedFilesLabel() { - ShowHideUnversionedFilesAction action = new ShowHideUnversionedFilesAction(); - ActionLink link = new ActionLink(action.getText(myVcsConfiguration.SHOW_UNVERSIONED_FILES_WHILE_COMMIT), null, action); - - JLabel label = new JLabel(" unversioned files"); - label.setEnabled(false); - - JPanel panel = SwingHelper.newHorizontalPanel(Component.CENTER_ALIGNMENT, link, label); - panel.setFont(JBUI.Fonts.smallFont()); - - return panel; - } - private void initMainSplitter() { mySplitter.setProportion(PropertiesComponent.getInstance().getFloat(SPLITTER_PROPORTION_OPTION, SPLITTER_PROPORTION_OPTION_DEFAULT)); } @@ -1401,25 +1385,4 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj myOptions.setBounds(new Rectangle(bounds.width - optionsWidth, 0, optionsWidth, bounds.height)); } } - - private class ShowHideUnversionedFilesAction extends ToggleAction { - - @Override - public boolean isSelected(@NotNull AnActionEvent e) { - return myVcsConfiguration.SHOW_UNVERSIONED_FILES_WHILE_COMMIT; - } - - @Override - public void setSelected(@NotNull AnActionEvent e, boolean state) { - myVcsConfiguration.SHOW_UNVERSIONED_FILES_WHILE_COMMIT = state; - ((MultipleChangeListBrowser)myBrowser).setShowUnversioned(state); - myBrowser.rebuildList(); - ((JLabel)e.getInputEvent().getSource()).setText(getText(state)); - } - - @NotNull - public String getText(boolean showUnversionedState) { - return showUnversionedState ? "Hide" : "Show"; - } - } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/MultipleChangeListBrowser.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/MultipleChangeListBrowser.java index 4322039608b8..c8f85ae59ac6 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/MultipleChangeListBrowser.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/MultipleChangeListBrowser.java @@ -24,10 +24,10 @@ import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBox; import com.intellij.openapi.util.Condition; -import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.VcsBundle; +import com.intellij.openapi.vcs.VcsConfiguration; import com.intellij.openapi.vcs.VcsDataKeys; import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.changes.actions.MoveChangesToAnotherListAction; @@ -57,7 +57,8 @@ public class MultipleChangeListBrowser extends ChangesBrowserBase { @NotNull private final EventDispatcher myDispatcher = EventDispatcher.create(SelectedListChangeListener.class); @Nullable private final Runnable myRebuildListListener; - private boolean myShowUnversioned; + @NotNull private final VcsConfiguration myVcsConfiguration; + private final boolean myUnversionedFilesEnabled; private Collection myAllChanges; private boolean myInRebuildList; private AnAction myMoveActionWithCustomShortcut; @@ -71,14 +72,18 @@ public class MultipleChangeListBrowser extends ChangesBrowserBase { boolean highlightProblems, @Nullable Runnable rebuildListListener, @Nullable Runnable inclusionListener, - boolean showUnversioned) { + boolean unversionedFilesEnabled) { super(project, changeLists, changes, initialListSelection, capableOfExcludingChanges, highlightProblems, inclusionListener, ChangesBrowser.MyUseCase.LOCAL_CHANGES, null, Object.class); myRebuildListListener = rebuildListListener; - myShowUnversioned = showUnversioned; + myVcsConfiguration = ObjectUtils.assertNotNull(VcsConfiguration.getInstance(myProject)); + myUnversionedFilesEnabled = unversionedFilesEnabled; myChangeListChooser = new ChangeListChooser(); myChangeListChooser.updateLists(changeLists); + // rebuild toolbar to ensure "myUnversionedFilesEnabled" is considered + myHeaderPanel.removeAll(); + myHeaderPanel.add(createToolbar(), BorderLayout.CENTER); myHeaderPanel.add(myChangeListChooser, BorderLayout.EAST); ChangeListManager.getInstance(myProject).addChangeListListener(myChangeListListener); @@ -104,8 +109,8 @@ public class MultipleChangeListBrowser extends ChangesBrowserBase { }, this); } - public void setShowUnversioned(boolean showUnversioned) { - myShowUnversioned = showUnversioned; + private boolean isShowUnversioned() { + return myUnversionedFilesEnabled && myVcsConfiguration.SHOW_UNVERSIONED_FILES_WHILE_COMMIT; } @Override @@ -190,7 +195,7 @@ public class MultipleChangeListBrowser extends ChangesBrowserBase { TreeModelBuilder builder = new TreeModelBuilder(myProject, showFlatten); builder.setChanges(findChanges(objects), changeNodeDecorator); - if (myShowUnversioned) { + if (isShowUnversioned()) { builder.setUnversioned(ChangesViewManager.getUnversionedFilesInfo(manager)); } @@ -203,7 +208,7 @@ public class MultipleChangeListBrowser extends ChangesBrowserBase { List result = ContainerUtil.newArrayList(); result.addAll(node.getAllChangesUnder()); - if (myShowUnversioned && isUnderUnversioned(node)) { + if (isShowUnversioned() && isUnderUnversioned(node)) { result.addAll(node.getAllFilesUnder()); } @@ -216,7 +221,7 @@ public class MultipleChangeListBrowser extends ChangesBrowserBase { Object result = null; Object userObject = node.getUserObject(); - if (userObject instanceof Change || myShowUnversioned && isUnderUnversioned(node) && userObject instanceof VirtualFile) { + if (userObject instanceof Change || isShowUnversioned() && isUnderUnversioned(node) && userObject instanceof VirtualFile) { result = userObject; } @@ -233,7 +238,7 @@ public class MultipleChangeListBrowser extends ChangesBrowserBase { @NotNull @Override public List getIncludedUnversionedFiles() { - return myShowUnversioned + return isShowUnversioned() ? ContainerUtil.findAll(myViewer.getIncludedChanges(), VirtualFile.class) : Collections.emptyList(); } @@ -242,7 +247,7 @@ public class MultipleChangeListBrowser extends ChangesBrowserBase { public int getUnversionedFilesCount() { int result = 0; - if (myShowUnversioned) { + if (isShowUnversioned()) { ChangesBrowserNode node = findUnversionedFilesNode(); if (node != null) { @@ -311,7 +316,8 @@ public class MultipleChangeListBrowser extends ChangesBrowserBase { rebuildList(); } }); - if (Registry.is("vcs.unversioned.files.in.commit")) { + if (myUnversionedFilesEnabled) { + toolBarGroup.add(new ShowHideUnversionedFilesAction()); toolBarGroup.add(UnversionedViewDialog.getUnversionedActionGroup()); } else { @@ -423,6 +429,24 @@ public class MultipleChangeListBrowser extends ChangesBrowserBase { } } + private class ShowHideUnversionedFilesAction extends ToggleAction { + + private ShowHideUnversionedFilesAction() { + super("Show Unversioned Files", null, AllIcons.Debugger.Disable_value_calculation); + } + + @Override + public boolean isSelected(@NotNull AnActionEvent e) { + return myVcsConfiguration.SHOW_UNVERSIONED_FILES_WHILE_COMMIT; + } + + @Override + public void setSelected(@NotNull AnActionEvent e, boolean state) { + myVcsConfiguration.SHOW_UNVERSIONED_FILES_WHILE_COMMIT = state; + rebuildList(); + } + } + private class MoveAction extends MoveChangesToAnotherListAction { @Override protected boolean isEnabled(@NotNull AnActionEvent e) {