From 6b411756ea5c86d8ed8f615424701a8923df9dcf Mon Sep 17 00:00:00 2001 From: Alexander Kirillin Date: Thu, 1 Sep 2011 19:04:41 +0400 Subject: [PATCH] Better support for groups --- .../src/com/intellij/openapi/ui/Messages.java | 101 +++++++++++++++--- .../src/com/intellij/openapi/vfs/VfsUtil.java | 23 ++++ .../com/intellij/ui/mac/MacMessagesImpl.java | 4 +- 3 files changed, 109 insertions(+), 19 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/Messages.java b/platform/platform-api/src/com/intellij/openapi/ui/Messages.java index ae964c70a058..c07c502f9670 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/Messages.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/Messages.java @@ -20,6 +20,7 @@ import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.registry.Registry; @@ -33,10 +34,7 @@ import com.intellij.ui.components.JBScrollPane; import com.intellij.ui.mac.MacMessages; import com.intellij.util.PairFunction; import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.TestOnly; +import org.jetbrains.annotations.*; import javax.swing.*; import javax.swing.event.DocumentEvent; @@ -638,6 +636,25 @@ public class Messages { return dialog.getInputString(); } + @NotNull + public static Pair showInputDialogWithCheckBox(String message, + String title, + String checkboxText, + boolean checked, + boolean checkboxEnabled, + @Nullable Icon icon, + @NonNls String initialValue, + @Nullable InputValidator validator) { + if (isApplicationInUnitTestOrHeadless()) { + return new Pair(ourTestInputImplementation.show(message), checked); + } + else { + InputDialogWithCheckbox dialog = new InputDialogWithCheckbox(message, title, checkboxText, checked, checkboxEnabled, icon, initialValue, validator); + dialog.show(); + return new Pair(dialog.getInputString(), dialog.isChecked()); + } + } + @Nullable public static String showEditableChooseDialog(String message, String title, @@ -1076,7 +1093,7 @@ public class Messages { } protected static class InputDialog extends MessageDialog { - private JTextComponent myField; + protected JTextComponent myField; private InputValidator myValidator; public InputDialog(Project project, String message, String title, @Nullable Icon icon, String initialValue, @@ -1155,26 +1172,37 @@ public class Messages { panel.add(container, BorderLayout.WEST); } + JPanel messagePanel = createMessagePanel(); + panel.add(messagePanel, BorderLayout.CENTER); + + return panel; + } + + protected JPanel createMessagePanel() { JPanel messagePanel = new JPanel(new BorderLayout()); if (myMessage != null) { - JComponent textComponent; - if (BasicHTML.isHTMLString(myMessage)) { - textComponent = createMessageComponent(myMessage); - } - else { - JLabel textLabel = new JLabel(myMessage); - textLabel.setUI(new MultiLineLabelUI()); - textComponent = textLabel; - } - textComponent.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); + JComponent textComponent = createTextComponent(); messagePanel.add(textComponent, BorderLayout.NORTH); } myField = createTextFieldComponent(); messagePanel.add(myField, BorderLayout.SOUTH); - panel.add(messagePanel, BorderLayout.CENTER); - return panel; + return messagePanel; + } + + protected JComponent createTextComponent() { + JComponent textComponent; + if (BasicHTML.isHTMLString(myMessage)) { + textComponent = createMessageComponent(myMessage); + } + else { + JLabel textLabel = new JLabel(myMessage); + textLabel.setUI(new MultiLineLabelUI()); + textComponent = textLabel; + } + textComponent.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); + return textComponent; } public JTextComponent getTextField() { @@ -1216,6 +1244,45 @@ public class Messages { return new JTextArea(7, 50); } } + + protected static class InputDialogWithCheckbox extends InputDialog { + private JCheckBox myCheckBox; + + public InputDialogWithCheckbox(String message, + String title, + String checkboxText, + boolean checked, + boolean checkboxEnabled, + @Nullable Icon icon, + String initialValue, + @Nullable InputValidator validator) { + super(message, title, icon, initialValue, validator); + myCheckBox.setText(checkboxText); + myCheckBox.setSelected(checked); + myCheckBox.setEnabled(checkboxEnabled); + } + + @Override + protected JPanel createMessagePanel() { + JPanel messagePanel = new JPanel(new BorderLayout()); + if (myMessage != null) { + JComponent textComponent = createTextComponent(); + messagePanel.add(textComponent, BorderLayout.NORTH); + } + + myField = createTextFieldComponent(); + messagePanel.add(myField, BorderLayout.CENTER); + + myCheckBox = new JCheckBox(); + messagePanel.add(myCheckBox, BorderLayout.SOUTH); + + return messagePanel; + } + + public Boolean isChecked() { + return myCheckBox.isSelected(); + } + } protected static class ChooseDialog extends MessageDialog { private ComboBox myComboBox; diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java index ccaff0b181aa..d1ff5d7f8393 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java @@ -208,6 +208,29 @@ public class VfsUtil { } } + /** + * Makes a copy of the file in the toDir folder and returns it. + * Handles both files and directories. + * + * @param requestor any object to control who called this method. Note that + * it is considered to be an external change if requestor is null. + * See {@link VirtualFileEvent#getRequestor} + * @param file file or directory to make a copy of + * @param toDir directory to make a copy in + * @return a copy of the file + * @throws IOException if file failed to be copied + */ + public static VirtualFile copy(Object requestor, @NotNull VirtualFile file, @NotNull VirtualFile toDir) throws IOException { + if (file.isDirectory()) { + VirtualFile newDir = toDir.createChildDirectory(requestor, file.getName()); + copyDirectory(requestor, file, newDir, null); + return newDir; + } + else { + return copyFile(requestor, file, toDir); + } + } + /** * Gets the array of common ancestors for passed files. * diff --git a/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java b/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java index a662225f10d8..02e611f92085 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/MacMessagesImpl.java @@ -216,7 +216,7 @@ public class MacMessagesImpl extends MacMessages { return showAlertDialog(title, defaultButton, alternateButton, otherButton, message, window, false, doNotAskOption); } - public int showMessageDialog(final String title, final String message, final String moreInfo, final String[] buttons, final boolean errorStyle, + public int showMessageDialog(final String title, final String message, @Nullable final String moreInfo, final String[] buttons, final boolean errorStyle, @Nullable Window window, @Nullable final DialogWrapper.DoNotAskOption doNotAskDialogOption) { return doForWindowAndTitle(new PairFunction, JRootPane, Integer>() { @Override @@ -245,7 +245,7 @@ public class MacMessagesImpl extends MacMessages { ID paramsArray = invoke("NSArray", "arrayWithObjects:", cfString(title), // replace % -> %% to avoid formatted parameters (causes SIGTERM) cfString(StringUtil.stripHtml(message, true).replace("%", "%%")), - cfString(StringUtil.stripHtml(moreInfo, true).replace("%", "%%")), + cfString(StringUtil.stripHtml(moreInfo == null ? "" : moreInfo, true).replace("%", "%%")), focusedWindow, cfString(fakeTitle), cfString(errorStyle ? "error" : "-1"), cfString(doNotAskDialogOption == null || !doNotAskDialogOption.canBeHidden() // TODO: state=!doNotAsk.shouldBeShown()