diff --git a/plugins/git4idea/src/git4idea/actions/GitStash.java b/plugins/git4idea/src/git4idea/actions/GitStash.java index 7d76003e618b..01f57027c48b 100644 --- a/plugins/git4idea/src/git4idea/actions/GitStash.java +++ b/plugins/git4idea/src/git4idea/actions/GitStash.java @@ -6,7 +6,8 @@ import com.intellij.openapi.vcs.changes.ChangeListManager; import com.intellij.openapi.vfs.VirtualFile; import git4idea.i18n.GitBundle; import git4idea.stash.GitStashOperations; -import git4idea.ui.GitStashDialog; +import git4idea.stash.GitStashUtils; +import git4idea.stash.ui.GitStashDialog; import org.jetbrains.annotations.NotNull; import java.util.Collections; @@ -19,13 +20,16 @@ public class GitStash extends GitRepositoryAction { if (ChangeListManager.getInstance(project).isFreezedWithNotification(GitBundle.message("stash.error.can.not.stash.changes.now"))) { return; } - GitStashDialog d = new GitStashDialog(project, gitRoots, defaultRoot); - if (!d.showAndGet()) { - return; - } - d.logUsage(); + GitStashDialog dialog = new GitStashDialog(project, gitRoots, defaultRoot); + if (!dialog.showAndGet()) return; - GitStashOperations.runStashInBackground(project, Collections.singleton(d.getGitRoot()), root -> d.handler()); + VirtualFile selectedRoot = dialog.getSelectedRoot(); + String message = dialog.getMessage(); + boolean keepIndex = dialog.getKeepIndex(); + + GitStashOperations.runStashInBackground(project, Collections.singleton(selectedRoot), root -> { + return GitStashUtils.createStashHandler(project, root, keepIndex, message); + }); } @Override diff --git a/plugins/git4idea/src/git4idea/stash/ui/GitStashDialog.kt b/plugins/git4idea/src/git4idea/stash/ui/GitStashDialog.kt new file mode 100644 index 000000000000..0f7475dbb45a --- /dev/null +++ b/plugins/git4idea/src/git4idea/stash/ui/GitStashDialog.kt @@ -0,0 +1,53 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package git4idea.stash.ui + +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.ComboBox +import com.intellij.openapi.ui.DialogWrapper +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.ui.components.JBCheckBox +import com.intellij.ui.components.JBLabel +import com.intellij.ui.dsl.builder.Align +import com.intellij.ui.dsl.builder.panel +import git4idea.GitStashUsageCollector +import git4idea.i18n.GitBundle +import git4idea.util.GitUIUtil +import javax.swing.JComponent +import javax.swing.JTextField + +internal class GitStashDialog(project: Project, roots: List, defaultRoot: VirtualFile) : DialogWrapper(project, true) { + private val rootComboBox = ComboBox().also { it.toolTipText = GitBundle.message("common.git.root.tooltip") } + private val currentBranchLabel = JBLabel().also { it.toolTipText = GitBundle.message("common.current.branch.tooltip") } + private val stashMessageEditor = JTextField().also { it.toolTipText = GitBundle.message("stash.message.tooltip") } + private val keepIndexCheckBox = JBCheckBox(GitBundle.message("stash.keep.index")) + + val selectedRoot: VirtualFile get() = rootComboBox.item + val message: String get() = stashMessageEditor.text + val keepIndex: Boolean get() = keepIndexCheckBox.isSelected + + init { + title = GitBundle.message("stash.title") + setOKButtonText(GitBundle.message("stash.button")) + GitUIUtil.setupRootChooser(project, roots, defaultRoot, rootComboBox, currentBranchLabel) + init() + } + + override fun createCenterPanel(): JComponent { + return panel { + row(GitBundle.message("common.git.root")) { cell(rootComboBox) } + row(GitBundle.message("common.current.branch")) { cell(currentBranchLabel) } + row(GitBundle.message("stash.message")) { cell(stashMessageEditor).align(Align.FILL) } + row { cell(keepIndexCheckBox) } + } + } + + override fun doOKAction() { + super.doOKAction() + + GitStashUsageCollector.logStashPushDialog(message.isNotEmpty(), keepIndex) + } + + override fun getPreferredFocusedComponent(): JComponent = stashMessageEditor + override fun getDimensionServiceKey(): String = javaClass.name + override fun getHelpId(): String = "reference.VersionControl.Git.Stash" +} \ No newline at end of file diff --git a/plugins/git4idea/src/git4idea/ui/GitStashDialog.form b/plugins/git4idea/src/git4idea/ui/GitStashDialog.form deleted file mode 100644 index 5b105104e28e..000000000000 --- a/plugins/git4idea/src/git4idea/ui/GitStashDialog.form +++ /dev/null @@ -1,80 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/git4idea/src/git4idea/ui/GitStashDialog.java b/plugins/git4idea/src/git4idea/ui/GitStashDialog.java deleted file mode 100644 index 07fb427c28be..000000000000 --- a/plugins/git4idea/src/git4idea/ui/GitStashDialog.java +++ /dev/null @@ -1,78 +0,0 @@ -// 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. -package git4idea.ui; - -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VirtualFile; -import git4idea.GitStashUsageCollector; -import git4idea.commands.GitLineHandler; -import git4idea.i18n.GitBundle; -import git4idea.stash.GitStashUtils; -import git4idea.util.GitUIUtil; - -import javax.swing.*; -import java.util.List; - -/** - * The git stash dialog. - */ -public class GitStashDialog extends DialogWrapper { - private JComboBox myGitRootComboBox; // Git root selector - private JPanel myRootPanel; - private JLabel myCurrentBranch; - private JTextField myMessageTextField; - private JCheckBox myKeepIndexCheckBox; // --keep-index - private final Project myProject; - - /** - * A constructor - * - * @param project the project - * @param roots the list of Git roots - * @param defaultRoot the default root to select - */ - public GitStashDialog(final Project project, final List roots, final VirtualFile defaultRoot) { - super(project, true); - myProject = project; - setTitle(GitBundle.message("stash.title")); - setOKButtonText(GitBundle.message("stash.button")); - GitUIUtil.setupRootChooser(project, roots, defaultRoot, myGitRootComboBox, myCurrentBranch); - init(); - } - - public GitLineHandler handler() { - return GitStashUtils.createStashHandler(myProject, getGitRoot(), myKeepIndexCheckBox.isSelected(), myMessageTextField.getText()); - } - - public void logUsage() { - GitStashUsageCollector.logStashPushDialog(!StringUtil.isEmpty(myMessageTextField.getText()), myKeepIndexCheckBox.isSelected()); - } - - /** - * @return the selected git root - */ - public VirtualFile getGitRoot() { - return (VirtualFile)myGitRootComboBox.getSelectedItem(); - } - - @Override - protected JComponent createCenterPanel() { - return myRootPanel; - } - - @Override - protected String getDimensionServiceKey() { - return getClass().getName(); - } - - @Override - protected String getHelpId() { - return "reference.VersionControl.Git.Stash"; - } - - @Override - public JComponent getPreferredFocusedComponent() { - return myMessageTextField; - } -}