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.
This commit is contained in:
Mikhail Golubev
2015-03-24 21:45:59 +03:00
parent c060df2435
commit d08e1a4413
@@ -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<PsiNamedElement> elements, @Nullable String destination) {
protected PyMoveModuleMembersDialog(@NotNull Project project, @NotNull final List<PsiNamedElement> 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);