mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-100140 (one place to split them all)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -194,7 +194,7 @@ public class ParametersList implements Cloneable {
|
||||
for (ListIterator<String> iterator = myParameters.listIterator(); iterator.hasNext(); ) {
|
||||
final String param = iterator.next();
|
||||
if (param.startsWith(parameterPrefix)) {
|
||||
if ("".equals(replacement)) {
|
||||
if (replacement != null && replacement.isEmpty()) {
|
||||
iterator.remove();
|
||||
}
|
||||
else {
|
||||
@@ -203,7 +203,7 @@ public class ParametersList implements Cloneable {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!"".equals(replacement)) {
|
||||
if (replacement != null && !replacement.isEmpty()) {
|
||||
myParameters.add(position, replacement);
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,7 @@ public class ParametersList implements Cloneable {
|
||||
public void replaceOrPrepend(final @NonNls String parameter, final @NonNls String replacement) {
|
||||
replaceOrAdd(parameter, replacement, 0);
|
||||
}
|
||||
|
||||
|
||||
public void set(int ind, final @NonNls String value) {
|
||||
myParameters.set(ind, value);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.intellij.ui.mac.MacMessages;
|
||||
import com.intellij.util.PairFunction;
|
||||
import com.intellij.util.execution.ParametersListUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
@@ -96,14 +97,14 @@ public class Messages {
|
||||
}
|
||||
|
||||
/**
|
||||
* Please, use {@link #showOkCancelDialog} or {@link #showYesNoCancelDialog} if possible (these dialogs implements native OS behavior)!
|
||||
* Please, use {@link #showOkCancelDialog} or {@link #showYesNoCancelDialog} if possible (these dialogs implements native OS behavior)!
|
||||
*/
|
||||
public static int showDialog(@Nullable Project project, String message, String title, String[] options, int defaultOptionIndex, @Nullable Icon icon) {
|
||||
return showDialog(project, message, title, options, defaultOptionIndex, icon, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Please, use {@link #showOkCancelDialog} or {@link #showYesNoCancelDialog} if possible (these dialogs implements native OS behavior)!
|
||||
* Please, use {@link #showOkCancelDialog} or {@link #showYesNoCancelDialog} if possible (these dialogs implements native OS behavior)!
|
||||
*/
|
||||
public static int showDialog(@Nullable Project project, String message, String title, String[] options, int defaultOptionIndex, @Nullable Icon icon,
|
||||
@Nullable DialogWrapper.DoNotAskOption doNotAskOption) {
|
||||
@@ -162,7 +163,7 @@ public class Messages {
|
||||
return MacMessages.getInstance()
|
||||
.showMessageDialog(title, message, options, false, SwingUtilities.getWindowAncestor(parent), defaultOptionIndex, defaultOptionIndex, null);
|
||||
}
|
||||
|
||||
|
||||
MessageDialog dialog = new MessageDialog(parent, message, title, options, defaultOptionIndex, defaultOptionIndex, icon, false);
|
||||
dialog.show();
|
||||
return dialog.getExitCode();
|
||||
@@ -183,7 +184,7 @@ public class Messages {
|
||||
if (canShowMacSheetPanel()) {
|
||||
return MacMessages.getInstance().showMessageDialog(title, message, options, false, null, defaultOptionIndex, focusedOptionIndex, doNotAskOption);
|
||||
}
|
||||
|
||||
|
||||
//what's it? if (application.isUnitTestMode()) throw new RuntimeException(message);
|
||||
MessageDialog dialog = new MessageDialog(message, title, options, defaultOptionIndex, focusedOptionIndex, icon, doNotAskOption);
|
||||
dialog.show();
|
||||
@@ -219,7 +220,7 @@ public class Messages {
|
||||
MacMessages.getInstance().showOkMessageDialog(title, message, OK_BUTTON, WindowManager.getInstance().suggestParentWindow(project));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
showDialog(project, message, title, new String[]{OK_BUTTON}, 0, icon);
|
||||
}
|
||||
|
||||
@@ -228,7 +229,7 @@ public class Messages {
|
||||
MacMessages.getInstance().showOkMessageDialog(title, message, OK_BUTTON, SwingUtilities.getWindowAncestor(parent));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
showDialog(parent, message, title, new String[]{OK_BUTTON}, 0, icon);
|
||||
}
|
||||
|
||||
@@ -243,7 +244,7 @@ public class Messages {
|
||||
MacMessages.getInstance().showOkMessageDialog(title, message, OK_BUTTON);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
showDialog(message, title, new String[]{OK_BUTTON}, 0, icon);
|
||||
}
|
||||
|
||||
@@ -254,7 +255,7 @@ public class Messages {
|
||||
if (canShowMacSheetPanel()) {
|
||||
return MacMessages.getInstance().showYesNoDialog(title, message, yesText, noText, WindowManager.getInstance().suggestParentWindow(project));
|
||||
}
|
||||
|
||||
|
||||
return showDialog(project, message, title, new String[]{yesText, noText}, 0, icon);
|
||||
}
|
||||
|
||||
@@ -265,7 +266,7 @@ public class Messages {
|
||||
if (canShowMacSheetPanel()) {
|
||||
return MacMessages.getInstance().showYesNoDialog(title, message, YES_BUTTON, NO_BUTTON, WindowManager.getInstance().suggestParentWindow(project));
|
||||
}
|
||||
|
||||
|
||||
return showYesNoDialog(project, message, title, YES_BUTTON, NO_BUTTON, icon);
|
||||
}
|
||||
|
||||
@@ -276,7 +277,7 @@ public class Messages {
|
||||
if (canShowMacSheetPanel()) {
|
||||
return MacMessages.getInstance().showYesNoDialog(title, message, YES_BUTTON, NO_BUTTON, SwingUtilities.getWindowAncestor(parent));
|
||||
}
|
||||
|
||||
|
||||
return showDialog(parent, message, title, new String[]{YES_BUTTON, NO_BUTTON}, 0, icon);
|
||||
}
|
||||
|
||||
@@ -292,10 +293,10 @@ public class Messages {
|
||||
if (canShowMacSheetPanel()) {
|
||||
return MacMessages.getInstance().showYesNoDialog(title, message, yesText, noText, null, doNotAskOption);
|
||||
}
|
||||
|
||||
|
||||
return showDialog(message, title, new String[]{yesText, noText}, 0, icon, doNotAskOption);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use this method only if you do not know project or component
|
||||
*
|
||||
@@ -306,7 +307,7 @@ public class Messages {
|
||||
public static int showYesNoDialog(String message, String title, String yesText, String noText, @Nullable Icon icon) {
|
||||
return showYesNoDialog(message, title, yesText, noText, icon, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use this method only if you do not know project or component
|
||||
*
|
||||
@@ -328,7 +329,7 @@ public class Messages {
|
||||
return MacMessages.getInstance().showYesNoDialog(title, message, okText, cancelText, WindowManager.getInstance().suggestParentWindow(project),
|
||||
doNotAskOption);
|
||||
}
|
||||
|
||||
|
||||
return showDialog(project, message, title, new String[]{okText, cancelText}, 0, icon, doNotAskOption);
|
||||
}
|
||||
|
||||
@@ -336,7 +337,7 @@ public class Messages {
|
||||
if (canShowMacSheetPanel()) {
|
||||
return MacMessages.getInstance().showYesNoDialog(title, message, okText, cancelText, WindowManager.getInstance().suggestParentWindow(project));
|
||||
}
|
||||
|
||||
|
||||
return showDialog(project, message, title, new String[]{okText, cancelText}, 0, icon);
|
||||
}
|
||||
|
||||
@@ -387,7 +388,7 @@ public class Messages {
|
||||
if (canShowMacSheetPanel()) {
|
||||
return MacMessages.getInstance().showYesNoDialog(title, message, okText, cancelText, null, doNotAskOption);
|
||||
}
|
||||
|
||||
|
||||
return showDialog(message, title, new String[]{okText, cancelText}, 0, icon, doNotAskOption);
|
||||
}
|
||||
|
||||
@@ -445,7 +446,7 @@ public class Messages {
|
||||
MacMessages.getInstance().showErrorDialog(CommonBundle.getErrorTitle(), message, OK_BUTTON, SwingUtilities.getWindowAncestor(component));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
showDialog(component, message, CommonBundle.getErrorTitle(), new String[]{OK_BUTTON}, 0, getErrorIcon());
|
||||
}
|
||||
|
||||
@@ -469,7 +470,7 @@ public class Messages {
|
||||
MacMessages.getInstance().showErrorDialog(CommonBundle.getWarningTitle(), message, OK_BUTTON, WindowManager.getInstance().suggestParentWindow(project));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
showDialog(project, message, title, new String[]{OK_BUTTON}, 0, getWarningIcon());
|
||||
}
|
||||
|
||||
@@ -493,7 +494,7 @@ public class Messages {
|
||||
MacMessages.getInstance().showErrorDialog(CommonBundle.getWarningTitle(), message, OK_BUTTON, null);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
showDialog(message, title, new String[]{OK_BUTTON}, 0, getWarningIcon());
|
||||
}
|
||||
|
||||
@@ -536,7 +537,7 @@ public class Messages {
|
||||
if (canShowMacSheetPanel()) {
|
||||
return MacMessages.getInstance().showYesNoCancelDialog(title, message, yes, no, cancel, null, doNotAskOption);
|
||||
}
|
||||
|
||||
|
||||
return showDialog(message, title, new String[]{yes, no, cancel}, 0, icon, doNotAskOption);
|
||||
}
|
||||
|
||||
@@ -549,7 +550,7 @@ public class Messages {
|
||||
public static int showYesNoCancelDialog(String message, String title, String yes, String no, String cancel, Icon icon) {
|
||||
return showYesNoCancelDialog(message, title, yes, no, cancel, icon, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use this method only if you do not know project or component
|
||||
*
|
||||
@@ -809,7 +810,7 @@ public class Messages {
|
||||
MacMessages.getInstance().showOkMessageDialog(title, message, OK_BUTTON, SwingUtilities.getWindowAncestor(component));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
showMessageDialog(component, message, title, getInformationIcon());
|
||||
}
|
||||
|
||||
@@ -843,7 +844,7 @@ public class Messages {
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows dialog with text area to edit long strings that don't fit in text field
|
||||
* Shows dialog with text area to edit long strings that don't fit in text field.
|
||||
*/
|
||||
public static void showTextAreaDialog(final JTextField textField, final String title, @NonNls final String dimensionServiceKey) {
|
||||
if (isApplicationInUnitTestOrHeadless()) {
|
||||
@@ -853,8 +854,7 @@ public class Messages {
|
||||
final JTextArea textArea = new JTextArea(10, 50);
|
||||
textArea.setWrapStyleWord(true);
|
||||
textArea.setLineWrap(true);
|
||||
String s = textField.getText().replaceAll("[ ]*=[ ]*", "=").replaceAll("=\\-", "=\\ \\-");
|
||||
List<String> lines = StringUtil.splitHonorQuotes(s, ' ');
|
||||
List<String> lines = ParametersListUtil.parse(textField.getText(), true);
|
||||
textArea.setText(StringUtil.join(lines, "\n"));
|
||||
InsertPathAction.copyFromTo(textField, textArea);
|
||||
final DialogBuilder builder = new DialogBuilder(textField);
|
||||
@@ -946,7 +946,7 @@ public class Messages {
|
||||
public MessageDialog(Component parent, String message, String title, String[] options, int defaultOptionIndex, @Nullable Icon icon) {
|
||||
this(parent, message, title, options, defaultOptionIndex, icon, false);
|
||||
}
|
||||
|
||||
|
||||
public MessageDialog(Component parent, String message, String title, String[] options, int defaultOptionIndex, @Nullable Icon icon, boolean canBeParent) {
|
||||
this(parent, message, title, options, defaultOptionIndex, -1, icon, canBeParent);
|
||||
}
|
||||
@@ -960,7 +960,7 @@ public class Messages {
|
||||
public MessageDialog(String message, String title, String[] options, int defaultOptionIndex, @Nullable Icon icon) {
|
||||
this(message, title, options, defaultOptionIndex, icon, false);
|
||||
}
|
||||
|
||||
|
||||
public MessageDialog(String message, String title, String[] options, int defaultOptionIndex, @Nullable Icon icon, boolean canBeParent) {
|
||||
super(canBeParent);
|
||||
_init(title, message, options, defaultOptionIndex, -1, icon, null);
|
||||
|
||||
+12
-5
@@ -17,8 +17,12 @@ package com.intellij.openapi.execution;
|
||||
|
||||
import com.intellij.execution.configurations.ParametersList;
|
||||
import com.intellij.execution.configurations.ParamsGroup;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.execution.ParametersListUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -171,12 +175,12 @@ public class ParametersListTest {
|
||||
"C:\\phing.bat");
|
||||
checkTokenizer("-Dp.1=\"some text\" -Dp.2=\\\"value\\\"",
|
||||
"-Dp.1=some text", "-Dp.2=\"value\"");
|
||||
checkTokenizer("-Dp.1=value\n\"-Dp.2=-\"\n-Dp.3=value",
|
||||
"-Dp.1=value", "-Dp.2=-", "-Dp.3=value");
|
||||
checkTokenizer("-Dp.1=- -dump-config",
|
||||
"-Dp.1=-", "-dump-config");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joiningParams() throws Exception {
|
||||
public void joiningParams() {
|
||||
String[] parameters = {"simpleParam", "param with spaces", "withQuote=\"", "param=\"complex quoted\""};
|
||||
ParametersList parametersList = new ParametersList();
|
||||
parametersList.addAll(parameters);
|
||||
@@ -186,16 +190,19 @@ public class ParametersListTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void properties() throws Exception {
|
||||
public void properties() {
|
||||
ParametersList params = new ParametersList();
|
||||
params.addProperty("foo.foo", "\"bar bar\" bar");
|
||||
assertEquals(1, params.getProperties().size());
|
||||
assertEquals("\"bar bar\" bar", params.getProperties().get("foo.foo"));
|
||||
}
|
||||
|
||||
private static void checkTokenizer(final String paramString, final String... expected) {
|
||||
private static void checkTokenizer(String paramString, String... expected) {
|
||||
ParametersList params = new ParametersList();
|
||||
params.addParametersString(paramString);
|
||||
assertEquals(asList(expected), params.getList());
|
||||
|
||||
List<String> lines = ParametersListUtil.parse(paramString, true);
|
||||
assertEquals(paramString, StringUtil.join(lines, " "));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,7 +70,7 @@ public class ParametersListUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Converts single parameter string (as created by {@link #join(java.util.List)}) into list of parameters.</p>
|
||||
* <p>Splits single parameter string (as created by {@link #join(List)}) into list of parameters.</p>
|
||||
* <p/>
|
||||
* <p>
|
||||
* <strong>Conversion rules:</strong>
|
||||
@@ -90,11 +90,16 @@ public class ParametersListUtil {
|
||||
* <code>'"a \"1 2\"" b' => ['a="1 2"', 'b']</code>
|
||||
* </p>
|
||||
*
|
||||
* @param string parameter string to split.
|
||||
* @param parameterString parameter string to split.
|
||||
* @return array of parameters.
|
||||
*/
|
||||
@NotNull
|
||||
public static List<String> parse(@NotNull String parameterString) {
|
||||
return parse(parameterString, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> parse(@NotNull String parameterString, boolean keepQuotes) {
|
||||
parameterString = parameterString.trim();
|
||||
|
||||
final ArrayList<String> params = ContainerUtilRt.newArrayList();
|
||||
@@ -110,7 +115,9 @@ public class ParametersListUtil {
|
||||
if (!escapedQuote) {
|
||||
inQuotes = !inQuotes;
|
||||
nonEmpty = true;
|
||||
continue;
|
||||
if (!keepQuotes) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
escapedQuote = false;
|
||||
}
|
||||
@@ -127,7 +134,9 @@ public class ParametersListUtil {
|
||||
else if (ch == '\\') {
|
||||
if (i < parameterString.length() - 1 && parameterString.charAt(i + 1) == '"') {
|
||||
escapedQuote = true;
|
||||
continue;
|
||||
if (!keepQuotes) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user