From 7a069d912734cac3d27812bf44bc389f32e3ca32 Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Fri, 7 Jun 2019 21:09:04 +0300 Subject: [PATCH] vcs: Add splitter between changes tree and commit panel in "Local Changes" (IDEA-212227) GitOrigin-RevId: bc9b3a020b11648f5a7e43767c2da636633c4e98 --- .../changes/ChangesViewCommitPanelSplitter.kt | 34 +++++++++++++++++++ .../vcs/changes/ChangesViewManager.java | 11 +++--- .../vcs/commit/ChangesViewCommitPanel.kt | 2 +- 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewCommitPanelSplitter.kt diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewCommitPanelSplitter.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewCommitPanelSplitter.kt new file mode 100644 index 000000000000..512b8a48b349 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewCommitPanelSplitter.kt @@ -0,0 +1,34 @@ +// 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.openapi.vcs.changes + +import com.intellij.ide.util.PropertiesComponent +import com.intellij.ui.OnePixelSplitter +import com.intellij.util.ui.update.UiNotifyConnector +import javax.swing.JComponent + +private const val CHANGES_VIEW_COMMIT_SPLITTER_PROPORTION = "ChangesViewManager.COMMIT_SPLITTER_PROPORTION" + +private class ChangesViewCommitPanelSplitter : OnePixelSplitter(true, CHANGES_VIEW_COMMIT_SPLITTER_PROPORTION, 1.0f) { + private var isDefaultProportionSet = false + + override fun setSecondComponent(component: JComponent?) { + if (component != null && !isDefaultProportionSet) { + UiNotifyConnector.doWhenFirstShown(this) { + isDefaultProportionSet = true + proportion = 1.0f - (component.preferredSize.getHeight().toFloat() / height).coerceIn(0.05f, 0.95f) + } + } + super.setSecondComponent(component) + } + + override fun loadProportion() { + val key = splitterProportionKey + isDefaultProportionSet = key != null && PropertiesComponent.getInstance().isValueSet(key) + + if (isDefaultProportionSet) super.loadProportion() + } + + override fun saveProportion() { + if (isDefaultProportionSet) super.saveProportion() + } +} 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 514600fdfa50..c92848af065d 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 @@ -92,6 +92,7 @@ public class ChangesViewManager implements ChangesViewI, ProjectComponent, Persi @NotNull private final ChangesListView myView; private ChangesViewCommitPanel myCommitPanel; private BorderLayoutPanel myContentPanel; + private ChangesViewCommitPanelSplitter myCommitPanelSplitter; private SimpleToolWindowPanel myToolWindowPanel; private ChangesViewCommitWorkflowHandler myCommitWorkflowHandler; private final VcsConfiguration myVcsConfiguration; @@ -202,14 +203,12 @@ public class ChangesViewManager implements ChangesViewI, ProjectComponent, Persi myCommitWorkflowHandler = new ChangesViewCommitWorkflowHandler(new ChangesViewCommitWorkflow(myProject), myCommitPanel); Disposer.register(myContent, myCommitPanel); - myContentPanel.addToBottom(myCommitPanel); - myContentPanel.validate(); + myCommitPanelSplitter.setSecondComponent(myCommitPanel); myCommitPanel.setupShortcuts(myToolWindowPanel); } } else if (myCommitPanel != null) { - myContentPanel.remove(myCommitPanel); - myContentPanel.validate(); + myCommitPanelSplitter.setSecondComponent(null); Disposer.dispose(myCommitPanel); myCommitPanel = null; @@ -223,13 +222,15 @@ public class ChangesViewManager implements ChangesViewI, ProjectComponent, Persi addBorder(changesToolbar.getComponent(), createBorder(JBColor.border(), SideBorder.RIGHT)); BorderLayoutPanel changesPanel = simplePanel(createScrollPane(myView)).addToLeft(changesToolbar.getComponent()); + myCommitPanelSplitter = new ChangesViewCommitPanelSplitter(); + myCommitPanelSplitter.setFirstComponent(changesPanel); myContentPanel = new BorderLayoutPanel() { @Override public Dimension getMinimumSize() { return isMinimumSizeSet() ? super.getMinimumSize() : changesToolbar.getComponent().getPreferredSize(); } }; - myContentPanel.addToCenter(changesPanel); + myContentPanel.addToCenter(myCommitPanelSplitter); MyChangeProcessor changeProcessor = new MyChangeProcessor(myProject); mySplitterComponent = new PreviewDiffSplitterComponent(myContentPanel, changeProcessor, CHANGES_VIEW_PREVIEW_SPLITTER_PROPORTION, 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 3a158262bcdc..80f9ed7cb683 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/commit/ChangesViewCommitPanel.kt @@ -126,7 +126,7 @@ class ChangesViewCommitPanel(private val changesView: ChangesListView) : BorderL }.withBackground(BACKGROUND_COLOR) val centerPanel = simplePanel(commitMessage).addToBottom(buttonPanel) - addToCenter(centerPanel).addToLeft(toolbar.component).withBorder(createBorder(JBColor.border(), SideBorder.TOP)) + addToCenter(centerPanel).addToLeft(toolbar.component) withPreferredHeight(85) }