Better support for groups

This commit is contained in:
Alexander Kirillin
2011-09-01 19:06:20 +04:00
parent 66b886fa91
commit 6b411756ea
3 changed files with 109 additions and 19 deletions
@@ -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<String, Boolean> 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<String, Boolean>(ourTestInputImplementation.show(message), checked);
}
else {
InputDialogWithCheckbox dialog = new InputDialogWithCheckbox(message, title, checkboxText, checked, checkboxEnabled, icon, initialValue, validator);
dialog.show();
return new Pair<String, Boolean>(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;
@@ -208,6 +208,29 @@ public class VfsUtil {
}
}
/**
* Makes a copy of the <code>file</code> in the <code>toDir</code> 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 <code>requestor</code> is <code>null</code>.
* 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.
*
@@ -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<Pair<Window, String>, 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()