diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java index 3e41738c0d3e..ce39f72ccdea 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java @@ -176,7 +176,7 @@ public class BackendCompilerWrapper { } } finally { - if (fileToDelete != null) { + if (fileToDelete != null && myCompileContext.getMessageCount(CompilerMessageCategory.ERROR) == 0) { FileUtil.asyncDelete(fileToDelete); } } diff --git a/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java b/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java index 175e0865360f..3a55f74021bd 100644 --- a/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java +++ b/java/idea-ui/src/com/intellij/ide/impl/NewProjectUtil.java @@ -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]); diff --git a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java index bf1149306301..259fd4249c13 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java @@ -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; } /** 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 249abf64d253..35909e5e5c26 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/Messages.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/Messages.java @@ -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]); } diff --git a/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java b/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java index d164f33a7464..c7c32794d651 100644 --- a/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.java @@ -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; } diff --git a/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java b/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java index 1834a3813a0b..e8aa291a72ff 100644 --- a/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java +++ b/platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.java @@ -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; }