mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-21675 Default and active buttons in the open project frame confirmation
This commit is contained in:
+1
-1
@@ -176,7 +176,7 @@ public class BackendCompilerWrapper {
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (fileToDelete != null) {
|
||||
if (fileToDelete != null && myCompileContext.getMessageCount(CompilerMessageCategory.ERROR) == 0) {
|
||||
FileUtil.asyncDelete(fileToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class NewProjectUtil {
|
||||
Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
|
||||
if (openProjects.length > 0) {
|
||||
int exitCode = Messages.showDialog(IdeBundle.message("prompt.open.project.in.new.frame"), IdeBundle.message("title.new.project"),
|
||||
new String[]{IdeBundle.message("button.newframe"), IdeBundle.message("button.existingframe")}, 1,
|
||||
new String[]{IdeBundle.message("button.newframe"), IdeBundle.message("button.existingframe")}, 1, 0,
|
||||
Messages.getQuestionIcon());
|
||||
if (exitCode == 1) { // "No" option
|
||||
ProjectUtil.closeProject(projectToClose != null ? projectToClose : openProjects[openProjects.length - 1]);
|
||||
|
||||
@@ -74,6 +74,8 @@ public abstract class DialogWrapper {
|
||||
*/
|
||||
@NonNls public static final String DEFAULT_ACTION = "DefaultAction";
|
||||
|
||||
@NonNls public static final String FOCUSED_ACTION = "FocusedAction";
|
||||
|
||||
private final DialogWrapperPeer myPeer;
|
||||
private int myExitCode = CANCEL_EXIT_CODE;
|
||||
|
||||
@@ -107,6 +109,8 @@ public abstract class DialogWrapper {
|
||||
@Nullable
|
||||
private DoNotAskOption myDoNotAsk;
|
||||
|
||||
private JComponent myPreferredFocusedComponent;
|
||||
|
||||
protected String getDoNotShowMessage() {
|
||||
return CommonBundle.message("dialog.options.do.not.show");
|
||||
}
|
||||
@@ -370,6 +374,10 @@ public abstract class DialogWrapper {
|
||||
button.setMnemonic(mnemonic);
|
||||
}
|
||||
|
||||
if (action.getValue(FOCUSED_ACTION) != null) {
|
||||
myPreferredFocusedComponent = button;
|
||||
}
|
||||
|
||||
buttons.add(button);
|
||||
buttonsPanel.add(button);
|
||||
}
|
||||
@@ -706,7 +714,7 @@ public abstract class DialogWrapper {
|
||||
*/
|
||||
@Nullable
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return null;
|
||||
return SystemInfo.isMac ? myPreferredFocusedComponent : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,11 +90,15 @@ public class Messages {
|
||||
}
|
||||
|
||||
public static int showDialog(Project project, String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
return showDialog(project, message, title, options, defaultOptionIndex, -1, icon);
|
||||
}
|
||||
|
||||
public static int showDialog(Project project, String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon) {
|
||||
if (isApplicationInUnitTestOrHeadless()) {
|
||||
return ourTestImplementation.show(message);
|
||||
}
|
||||
else {
|
||||
MessageDialog dialog = new MessageDialog(project, message, title, options, defaultOptionIndex, icon);
|
||||
MessageDialog dialog = new MessageDialog(project, message, title, options, defaultOptionIndex, focusedOptionIndex, icon);
|
||||
dialog.show();
|
||||
return dialog.getExitCode();
|
||||
}
|
||||
@@ -106,11 +110,27 @@ public class Messages {
|
||||
}
|
||||
|
||||
public static int showDialog(Component parent, String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
return showDialog(parent, message, title, options, defaultOptionIndex, icon);
|
||||
}
|
||||
|
||||
public static int showDialog(Component parent, String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon) {
|
||||
if (isApplicationInUnitTestOrHeadless()) {
|
||||
return ourTestImplementation.show(message);
|
||||
}
|
||||
else {
|
||||
MessageDialog dialog = new MessageDialog(parent, message, title, options, defaultOptionIndex, icon);
|
||||
MessageDialog dialog = new MessageDialog(parent, message, title, options, defaultOptionIndex, focusedOptionIndex, icon);
|
||||
dialog.show();
|
||||
return dialog.getExitCode();
|
||||
}
|
||||
}
|
||||
|
||||
public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon, DialogWrapper.DoNotAskOption doNotAskOption) {
|
||||
if (isApplicationInUnitTestOrHeadless()) {
|
||||
return ourTestImplementation.show(message);
|
||||
}
|
||||
else {
|
||||
//what's it? if (application.isUnitTestMode()) throw new RuntimeException(message);
|
||||
MessageDialog dialog = new MessageDialog(message, title, options, defaultOptionIndex, focusedOptionIndex, icon, doNotAskOption);
|
||||
dialog.show();
|
||||
return dialog.getExitCode();
|
||||
}
|
||||
@@ -123,19 +143,15 @@ public class Messages {
|
||||
* @see #showDialog(Component, String, String, String[], int, Icon)
|
||||
*/
|
||||
public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, Icon icon, DialogWrapper.DoNotAskOption doNotAskOption) {
|
||||
if (isApplicationInUnitTestOrHeadless()) {
|
||||
return ourTestImplementation.show(message);
|
||||
}
|
||||
else {
|
||||
//what's it? if (application.isUnitTestMode()) throw new RuntimeException(message);
|
||||
MessageDialog dialog = new MessageDialog(message, title, options, defaultOptionIndex, icon, doNotAskOption);
|
||||
dialog.show();
|
||||
return dialog.getExitCode();
|
||||
}
|
||||
return showDialog(message, title, options, defaultOptionIndex, -1, icon, doNotAskOption);
|
||||
}
|
||||
|
||||
public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
return showDialog(message, title, options, defaultOptionIndex, icon, null);
|
||||
return showDialog(message, title, options, defaultOptionIndex, -1, icon);
|
||||
}
|
||||
|
||||
public static int showDialog(String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon) {
|
||||
return showDialog(message, title, options, defaultOptionIndex, focusedOptionIndex, icon, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -486,33 +502,47 @@ public class Messages {
|
||||
protected String myMessage;
|
||||
protected String[] myOptions;
|
||||
protected int myDefaultOptionIndex;
|
||||
protected int myFocusedOptionIndex;
|
||||
protected Icon myIcon;
|
||||
|
||||
public MessageDialog(Project project, String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
this(project, message, title, options, defaultOptionIndex, -1, icon);
|
||||
}
|
||||
|
||||
public MessageDialog(Project project, String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon) {
|
||||
super(project, false);
|
||||
_init(title, message, options, defaultOptionIndex, icon, null);
|
||||
_init(title, message, options, defaultOptionIndex, focusedOptionIndex, icon, null);
|
||||
}
|
||||
|
||||
public MessageDialog(Component parent, String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
this(parent, message, title, options, defaultOptionIndex, -1, icon);
|
||||
}
|
||||
|
||||
public MessageDialog(Component parent, String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon) {
|
||||
super(parent, false);
|
||||
_init(title, message, options, defaultOptionIndex, icon, null);
|
||||
_init(title, message, options, defaultOptionIndex, focusedOptionIndex, icon, null);
|
||||
}
|
||||
|
||||
public MessageDialog(String message, String title, String[] options, int defaultOptionIndex, Icon icon) {
|
||||
super(false);
|
||||
_init(title, message, options, defaultOptionIndex, icon, null);
|
||||
_init(title, message, options, defaultOptionIndex, -1, icon, null);
|
||||
}
|
||||
|
||||
public MessageDialog(String message, String title, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon, DoNotAskOption doNotAskOption) {
|
||||
super(false);
|
||||
_init(title, message, options, defaultOptionIndex, focusedOptionIndex, icon, doNotAskOption);
|
||||
}
|
||||
|
||||
public MessageDialog(String message, String title, String[] options, int defaultOptionIndex, Icon icon, DoNotAskOption doNotAskOption) {
|
||||
super(false);
|
||||
_init(title, message, options, defaultOptionIndex, icon, doNotAskOption);
|
||||
this(message, title, options, defaultOptionIndex, -1, icon, doNotAskOption);
|
||||
}
|
||||
|
||||
private void _init(String title, String message, String[] options, int defaultOptionIndex, Icon icon, DoNotAskOption doNotAskOption) {
|
||||
private void _init(String title, String message, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon, DoNotAskOption doNotAskOption) {
|
||||
setTitle(title);
|
||||
myMessage = message;
|
||||
myOptions = options;
|
||||
myDefaultOptionIndex = defaultOptionIndex;
|
||||
myFocusedOptionIndex = focusedOptionIndex;
|
||||
myIcon = icon;
|
||||
setButtonsAlignment(SwingUtilities.CENTER);
|
||||
setDoNotAskOption(doNotAskOption);
|
||||
@@ -529,9 +559,15 @@ public class Messages {
|
||||
close(exitCode, true);
|
||||
}
|
||||
};
|
||||
|
||||
if (i == myDefaultOptionIndex) {
|
||||
actions[i].putValue(DEFAULT_ACTION, Boolean.TRUE);
|
||||
}
|
||||
|
||||
if (i == myFocusedOptionIndex) {
|
||||
actions[i].putValue(FOCUSED_ACTION, Boolean.TRUE);
|
||||
}
|
||||
|
||||
assignMnemonic(option, actions[i]);
|
||||
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class ProjectUtil {
|
||||
if (settings.getConfirmOpenNewProject() < 0) {
|
||||
exitCode = Messages.showDialog(IdeBundle.message("prompt.open.project.in.new.frame"), IdeBundle.message("title.open.project"),
|
||||
new String[]{IdeBundle.message("button.newframe"), IdeBundle.message("button.existingframe"),
|
||||
CommonBundle.getCancelButtonText()}, 1, Messages.getQuestionIcon(), new DialogWrapper.DoNotAskOption() {
|
||||
CommonBundle.getCancelButtonText()}, 1, 0, Messages.getQuestionIcon(), new DialogWrapper.DoNotAskOption() {
|
||||
public boolean isToBeShown() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class PlatformProjectOpenProcessor extends ProjectOpenProcessor {
|
||||
if (!forceOpenInNewFrame && openProjects.length > 0) {
|
||||
int exitCode = Messages.showDialog(IdeBundle.message("prompt.open.project.in.new.frame"), IdeBundle.message("title.open.project"),
|
||||
new String[]{IdeBundle.message("button.newframe"), IdeBundle.message("button.existingframe"),
|
||||
CommonBundle.getCancelButtonText()}, 1, Messages.getQuestionIcon());
|
||||
CommonBundle.getCancelButtonText()}, 1, 0, Messages.getQuestionIcon());
|
||||
if (exitCode == 1) { // "No" option
|
||||
if (!ProjectUtil.closeProject(projectToClose != null ? projectToClose : openProjects[openProjects.length - 1])) return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user