From d08e1a4413c15f1f5d834831ee0c3d57a172eb3c Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Tue, 24 Mar 2015 20:30:39 +0300 Subject: [PATCH] PY-15383 Automatically expand "Bulk move" group if several elements were selected in the editor Because size of the dialog is remembered in PropertiesComponent, this feature required special handling of the case when the dialog is not high enough to show entire table, because last time this group was collapsed and smaller dimensions were saved in settings. --- .../move/PyMoveModuleMembersDialog.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/python/src/com/jetbrains/python/refactoring/move/PyMoveModuleMembersDialog.java b/python/src/com/jetbrains/python/refactoring/move/PyMoveModuleMembersDialog.java index dcbac0236d76..58f3f77f2607 100644 --- a/python/src/com/jetbrains/python/refactoring/move/PyMoveModuleMembersDialog.java +++ b/python/src/com/jetbrains/python/refactoring/move/PyMoveModuleMembersDialog.java @@ -5,6 +5,7 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.ui.DialogWrapperPeer; import com.intellij.openapi.ui.TextComponentAccessor; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.util.io.FileUtil; @@ -55,6 +56,7 @@ public class PyMoveModuleMembersDialog extends RefactoringDialog { private final TopLevelSymbolsSelectionTable myMemberSelectionTable; private final PyModuleMemberInfoModel myModuleMemberModel; + private final boolean mySeveralElementsSelected; private JPanel myCenterPanel; private JPanel myTablePanel; private TextFieldWithBrowseButton myBrowseFieldWithButton; @@ -91,7 +93,7 @@ public class PyMoveModuleMembersDialog extends RefactoringDialog { * @param elements elements to move * @param destination destination where elements have to be moved */ - protected PyMoveModuleMembersDialog(@NotNull Project project, @NotNull List elements, @Nullable String destination) { + protected PyMoveModuleMembersDialog(@NotNull Project project, @NotNull final List elements, @Nullable String destination) { super(project, true); assert !elements.isEmpty(); @@ -130,8 +132,8 @@ public class PyMoveModuleMembersDialog extends RefactoringDialog { validateButtons(); } }); - // MoveMemberDialog for Java uses SeparatorFactory.createSeparator instead of custom border - final boolean tableIsVisible = PropertiesComponent.getInstance().getBoolean(BULK_MOVE_TABLE_VISIBLE, false); + mySeveralElementsSelected = elements.size() > 1; + final boolean tableIsVisible = mySeveralElementsSelected || PropertiesComponent.getInstance().getBoolean(BULK_MOVE_TABLE_VISIBLE, false); final String description; if (!tableIsVisible && elements.size() == 1) { if (firstElement instanceof PyFunction) { @@ -174,12 +176,24 @@ public class PyMoveModuleMembersDialog extends RefactoringDialog { UiNotifyConnector.doWhenFirstShown(myCenterPanel, new Runnable() { @Override public void run() { + enlargeDialogHeightIfNecessary(); preselectLastPathComponent(myBrowseFieldWithButton.getTextField()); } }); init(); } + private void enlargeDialogHeightIfNecessary() { + if (mySeveralElementsSelected && !PropertiesComponent.getInstance(getProject()).getBoolean(BULK_MOVE_TABLE_VISIBLE, false)) { + final DialogWrapperPeer peer = getPeer(); + final Dimension realSize = peer.getSize(); + final double preferredHeight = peer.getPreferredSize().getHeight(); + if (realSize.getHeight() < preferredHeight) { + peer.setSize((int)realSize.getWidth(), (int)preferredHeight); + } + } + } + private static void preselectLastPathComponent(@NotNull JTextField field) { final String text = field.getText(); final int start = text.lastIndexOf(File.separatorChar);