From 476bccdd715e94ef7b51b2a8090b5b8f52f96550 Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Fri, 7 Jun 2019 08:15:29 +0300 Subject: [PATCH] vcs: Allow switching between modal/non-modal commit without restart GitOrigin-RevId: e16f23d602f4a7a2c321615b92d4dd13cae07348 --- .../util/resources/misc/registry.properties | 1 - .../actions/AbstractCommonCheckinAction.kt | 7 +-- .../vcs/changes/ChangesViewManager.java | 61 +++++++++++++------ .../vcs/changes/ui/CurrentBranchComponent.kt | 12 +++- .../vcs/commit/ChangesViewCommitPanel.kt | 4 +- .../vcs/commit/ChangesViewCommitWorkflow.kt | 14 ++--- .../src/com/intellij/vcsUtil/VcsImplUtil.java | 7 +-- 7 files changed, 64 insertions(+), 42 deletions(-) diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 0e918cb5e037..061cad2b562d 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -515,7 +515,6 @@ vcs.skip.single.default.changelist.description=Don't show changelist node in Loc vcs.non.modal.commit=false vcs.non.modal.commit.description=Allow to commit directly from Local Changes -vcs.non.modal.commit.restartRequired=true vcs.unversioned.files.max.intree=1000 vcs.unversioned.files.max.intree.description=Maximum number of unversioned and ignored files displayed in the Local Changes file tree. \ diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.kt index e67c4bee73c0..446cb01fc4f5 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractCommonCheckinAction.kt @@ -14,7 +14,6 @@ import com.intellij.openapi.vcs.changes.* import com.intellij.openapi.vcs.changes.ui.CommitChangeListDialog import com.intellij.util.containers.ContainerUtil.concat import com.intellij.util.ui.UIUtil.removeMnemonic -import com.intellij.vcsUtil.VcsImplUtil.isNonModalCommit private val LOG = logger() @@ -97,9 +96,9 @@ abstract class AbstractCommonCheckinAction : AbstractVcsAction(), UpdateInBackgr } val executor = getExecutor(project) - if (executor == null && isNonModalCommit()) { - val workflowHandler = (ChangesViewManager.getInstance(project) as? ChangesViewManager)?.commitWorkflowHandler - workflowHandler?.run { + val workflowHandler = (ChangesViewManager.getInstance(project) as? ChangesViewManager)?.commitWorkflowHandler + if (executor == null && workflowHandler != null) { + workflowHandler.run { setCommitState(included, isForceUpdateNotEmptyCommitState()) activate() } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java index 9e3de6f9c759..7071eabf2f4c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java @@ -23,6 +23,8 @@ import com.intellij.openapi.ui.SimpleToolWindowPanel; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Factory; import com.intellij.openapi.util.registry.Registry; +import com.intellij.openapi.util.registry.RegistryValue; +import com.intellij.openapi.util.registry.RegistryValueListener; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsBundle; @@ -77,7 +79,6 @@ import static com.intellij.ui.ScrollPaneFactory.createScrollPane; import static com.intellij.util.containers.ContainerUtil.set; import static com.intellij.util.ui.JBUI.Panels.simplePanel; import static com.intellij.util.ui.UIUtil.addBorder; -import static com.intellij.vcsUtil.VcsImplUtil.isNonModalCommit; import static java.util.stream.Collectors.toList; @State( @@ -91,6 +92,8 @@ public class ChangesViewManager implements ChangesViewI, ProjectComponent, Persi @NotNull private final ChangesListView myView; private ChangesViewCommitPanel myCommitPanel; + private BorderLayoutPanel myContentPanel; + private SimpleToolWindowPanel myToolWindowPanel; private ChangesViewCommitWorkflowHandler myCommitWorkflowHandler; private final VcsConfiguration myVcsConfiguration; private JPanel myProgressLabel; @@ -114,6 +117,8 @@ public class ChangesViewManager implements ChangesViewI, ProjectComponent, Persi private boolean myModelUpdateInProgress; private final MyTreeExpander myTreeExpander; + @NotNull private final RegistryValue myIsNonModalCommit = Registry.get("vcs.non.modal.commit"); + @NotNull public static ChangesViewI getInstance(@NotNull Project project) { return project.getComponent(ChangesViewI.class); @@ -157,12 +162,19 @@ public class ChangesViewManager implements ChangesViewI, ProjectComponent, Persi ChangeListManager.getInstance(myProject).addChangeListListener(new MyChangeListListener(), myProject); if (ApplicationManager.getApplication().isHeadlessEnvironment()) return; - JComponent panel = createChangeViewComponent(); - myContent = new MyChangeViewContent(panel, ChangesViewContentManager.LOCAL_CHANGES, false); + myToolWindowPanel = createChangeViewComponent(); + myContent = new MyChangeViewContent(myToolWindowPanel, ChangesViewContentManager.LOCAL_CHANGES, false); myContent.setHelpId(ChangesListView.HELP_ID); myContent.setCloseable(false); myContentManager.addContent(myContent); - if (myCommitPanel != null) Disposer.register(myContent, myCommitPanel); + + myIsNonModalCommit.addListener(new RegistryValueListener.Adapter() { + @Override + public void afterValueChanged(@NotNull RegistryValue value) { + updateCommitWorkflow(value.asBoolean()); + } + }, myProject); + updateCommitWorkflow(myIsNonModalCommit.asBoolean()); scheduleRefresh(); myProject.getMessageBus().connect().subscribe(RemoteRevisionsCache.REMOTE_VERSION_CHANGED, () -> scheduleRefresh()); @@ -192,27 +204,44 @@ public class ChangesViewManager implements ChangesViewI, ProjectComponent, Persi return myCommitWorkflowHandler; } - private JComponent createChangeViewComponent() { + private void updateCommitWorkflow(boolean isNonModal) { + if (isNonModal) { + if (myCommitPanel == null) { + myCommitPanel = new ChangesViewCommitPanel(myView); + myCommitWorkflowHandler = new ChangesViewCommitWorkflowHandler(new ChangesViewCommitWorkflow(myProject), myCommitPanel); + Disposer.register(myContent, myCommitPanel); + + myContentPanel.addToBottom(myCommitPanel); + myContentPanel.validate(); + myCommitPanel.setupShortcuts(myToolWindowPanel); + } + } + else if (myCommitPanel != null) { + myContentPanel.remove(myCommitPanel); + myContentPanel.validate(); + Disposer.dispose(myCommitPanel); + + myCommitPanel = null; + myCommitWorkflowHandler = null; + } + } + + @NotNull + private SimpleToolWindowPanel createChangeViewComponent() { ActionToolbar changesToolbar = createChangesToolbar(); addBorder(changesToolbar.getComponent(), createBorder(JBColor.border(), SideBorder.RIGHT)); BorderLayoutPanel changesPanel = simplePanel(createScrollPane(myView)).addToLeft(changesToolbar.getComponent()); - BorderLayoutPanel contentPanel = new BorderLayoutPanel() { + myContentPanel = new BorderLayoutPanel() { @Override public Dimension getMinimumSize() { return isMinimumSizeSet() ? super.getMinimumSize() : changesToolbar.getComponent().getPreferredSize(); } }; - contentPanel.addToCenter(changesPanel); - if (isNonModalCommit()) { - myCommitPanel = new ChangesViewCommitPanel(myView); - contentPanel.addToBottom(myCommitPanel); - - myCommitWorkflowHandler = new ChangesViewCommitWorkflowHandler(new ChangesViewCommitWorkflow(myProject), myCommitPanel); - } + myContentPanel.addToCenter(changesPanel); MyChangeProcessor changeProcessor = new MyChangeProcessor(myProject); - mySplitterComponent = new PreviewDiffSplitterComponent(contentPanel, changeProcessor, CHANGES_VIEW_PREVIEW_SPLITTER_PROPORTION, + mySplitterComponent = new PreviewDiffSplitterComponent(myContentPanel, changeProcessor, CHANGES_VIEW_PREVIEW_SPLITTER_PROPORTION, myVcsConfiguration.LOCAL_CHANGES_DETAILS_PREVIEW_SHOWN); myView.installPopupHandler((DefaultActionGroup)ActionManager.getInstance().getAction("ChangesViewPopupMenu")); @@ -243,13 +272,11 @@ public class ChangesViewManager implements ChangesViewI, ProjectComponent, Persi return panel; } - private void registerShortcuts(@NotNull JComponent component) { + private static void registerShortcuts(@NotNull JComponent component) { registerWithShortcutSet("ChangesView.Refresh", CommonShortcuts.getRerun(), component); registerWithShortcutSet("ChangesView.NewChangeList", CommonShortcuts.getNew(), component); registerWithShortcutSet("ChangesView.RemoveChangeList", CommonShortcuts.getDelete(), component); registerWithShortcutSet(IdeActions.MOVE_TO_ANOTHER_CHANGE_LIST, CommonShortcuts.getMove(), component); - - if (myCommitPanel != null) myCommitPanel.setupShortcuts(component); } @NotNull diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CurrentBranchComponent.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CurrentBranchComponent.kt index 15b728e5c57f..a76f0a0851da 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CurrentBranchComponent.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CurrentBranchComponent.kt @@ -2,10 +2,11 @@ package com.intellij.openapi.vcs.changes.ui import com.intellij.icons.AllIcons +import com.intellij.openapi.Disposable import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Disposer import com.intellij.openapi.vcs.changes.Change import com.intellij.openapi.vcs.changes.ChangesUtil.getFilePath -import com.intellij.vcs.commit.CommitWorkflowUi import com.intellij.openapi.vcs.changes.ui.ChangesGroupingSupport.Companion.REPOSITORY_GROUPING import com.intellij.openapi.vfs.VirtualFile import com.intellij.ui.ColorUtil @@ -17,9 +18,11 @@ import com.intellij.util.ui.UIUtil.rightArrow import com.intellij.vcs.branch.BranchData import com.intellij.vcs.branch.BranchStateProvider import com.intellij.vcs.branch.LinkedBranchData +import com.intellij.vcs.commit.CommitWorkflowUi import com.intellij.vcsUtil.VcsUtil.getFilePath import java.awt.Color import java.awt.Dimension +import java.beans.PropertyChangeListener import javax.swing.JTree.TREE_MODEL_PROPERTY import javax.swing.UIManager @@ -38,14 +41,19 @@ class CurrentBranchComponent( } init { + isVisible = false icon = AllIcons.Vcs.Branch foreground = TEXT_COLOR - tree.addPropertyChangeListener { e -> + val treeChangeListener = PropertyChangeListener { e -> if (e.propertyName == TREE_MODEL_PROPERTY) { refresh() } } + tree.addPropertyChangeListener(treeChangeListener) + Disposer.register(commitWorkflowUi, Disposable { tree.removePropertyChangeListener(treeChangeListener) }) + + refresh() } override fun getPreferredSize(): Dimension? = if (isVisible) super.getPreferredSize() else emptySize() diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt index 1b9c02ced66d..3a158262bcdc 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt @@ -144,10 +144,10 @@ class ChangesViewCommitPanel(private val changesView: ChangesListView) : BorderL private fun fireDefaultExecutorCalled() = executorEventDispatcher.multicaster.executorCalled(null) fun setupShortcuts(component: JComponent) { - DefaultCommitAction().registerCustomShortcutSet(DEFAULT_COMMIT_ACTION_SHORTCUT, component) + DefaultCommitAction().registerCustomShortcutSet(DEFAULT_COMMIT_ACTION_SHORTCUT, component, this) DumbAwareAction.create { if (commitButton.isEnabled) commitButton.showPopup() - }.registerCustomShortcutSet(getDefaultShowPopupShortcut(), component) + }.registerCustomShortcutSet(getDefaultShowPopupShortcut(), component, this) } override val commitMessageUi: CommitMessageUi get() = commitMessage diff --git a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflow.kt b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflow.kt index 348c7510c44c..c849e46de70a 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflow.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitWorkflow.kt @@ -4,20 +4,19 @@ package com.intellij.vcs.commit import com.intellij.openapi.application.runInEdt import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project -import com.intellij.openapi.util.Disposer import com.intellij.openapi.vcs.ProjectLevelVcsManager -import com.intellij.openapi.vcs.ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED -import com.intellij.openapi.vcs.VcsListener import com.intellij.openapi.vcs.changes.* import com.intellij.openapi.vcs.checkin.CheckinHandler import com.intellij.openapi.vcs.impl.PartialChangesUtil +import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl +import com.intellij.openapi.vcs.impl.VcsInitObject private val LOG = logger() internal class CommitState(val changes: List, val commitMessage: String) class ChangesViewCommitWorkflow(project: Project) : AbstractCommitWorkflow(project) { - private val vcsManager = ProjectLevelVcsManager.getInstance(project) + private val vcsManager = ProjectLevelVcsManager.getInstance(project) as ProjectLevelVcsManagerImpl private val changeListManager = ChangeListManager.getInstance(project) override val isDefaultCommitEnabled: Boolean get() = true @@ -26,12 +25,7 @@ class ChangesViewCommitWorkflow(project: Project) : AbstractCommitWorkflow(proje internal lateinit var commitState: CommitState init { - val connection = project.messageBus.connect() - connection.subscribe(VCS_CONFIGURATION_CHANGED, VcsListener { - Disposer.dispose(connection) - - runInEdt { updateVcses(vcsManager.allActiveVcss.toSet()) } - }) + vcsManager.addInitializationRequest(VcsInitObject.AFTER_COMMON) { runInEdt { updateVcses(vcsManager.allActiveVcss.toSet()) } } } internal fun getAffectedChangeList(changes: Collection): LocalChangeList = diff --git a/platform/vcs-impl/src/com/intellij/vcsUtil/VcsImplUtil.java b/platform/vcs-impl/src/com/intellij/vcsUtil/VcsImplUtil.java index 49fb55c756ec..6b5537646532 100644 --- a/platform/vcs-impl/src/com/intellij/vcsUtil/VcsImplUtil.java +++ b/platform/vcs-impl/src/com/intellij/vcsUtil/VcsImplUtil.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.vcsUtil; import com.intellij.openapi.application.ReadAction; @@ -6,7 +6,6 @@ import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.FileStatus; import com.intellij.openapi.vcs.changes.ChangeListManager; @@ -62,10 +61,6 @@ public class VcsImplUtil { return repositoryPath.isEmpty() ? root.getName() : repositoryPath; } - public static boolean isNonModalCommit() { - return Registry.is("vcs.non.modal.commit"); - } - @Nullable public static IgnoredFileContentProvider findIgnoredFileContentProvider(@NotNull Project project, @NotNull AbstractVcs vcs) {