diff --git a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectDialog.java b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectDialog.java index de207040bee1..75a99502c69e 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectDialog.java +++ b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/AbstractNewProjectDialog.java @@ -68,7 +68,7 @@ public abstract class AbstractNewProjectDialog extends DialogWrapper { DefaultActionGroup root = createRootStep(); Disposer.register(getDisposable(), () -> root.removeAll()); - Pair> pair = FlatWelcomeFrame.createActionGroupPanel(root, getRootPane(), null, getDisposable()); + Pair> pair = FlatWelcomeFrame.createActionGroupPanel(root, null, getDisposable()); JPanel component = pair.first; DumbAwareAction.create(e -> close(CANCEL_EXIT_CODE)) .registerCustomShortcutSet(KeyEvent.VK_ESCAPE, 0, component); diff --git a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/ProjectSettingsStepBase.java b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/ProjectSettingsStepBase.java index 6a7df8f3a6c0..aca6317fcdbb 100644 --- a/platform/lang-impl/src/com/intellij/ide/util/projectWizard/ProjectSettingsStepBase.java +++ b/platform/lang-impl/src/com/intellij/ide/util/projectWizard/ProjectSettingsStepBase.java @@ -79,6 +79,12 @@ public class ProjectSettingsStepBase extends AbstractActionWithPanel implemen checkWebProjectValid(); } + @NotNull + @Override + public JButton getActionButton() { + return myCreateButton; + } + @NotNull protected NotNullLazyValue> createLazyPeer() { return myProjectGenerator.createLazyPeer(); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/AbstractActionWithPanel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/AbstractActionWithPanel.java index 090501fb0cd1..60a1ee5b0483 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/AbstractActionWithPanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/AbstractActionWithPanel.java @@ -15,14 +15,18 @@ */ package com.intellij.openapi.wm.impl.welcomeScreen; +import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.project.DumbAware; +import org.jetbrains.annotations.NotNull; import javax.swing.*; -public abstract class AbstractActionWithPanel extends AnAction implements DumbAware { - +public abstract class AbstractActionWithPanel extends AnAction implements DumbAware, Disposable { public abstract JPanel createPanel(); public void onPanelSelected() {} + + @NotNull + public abstract JButton getActionButton(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java index d17e0a09a9a2..bdd5cfa1ffbe 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/welcomeScreen/FlatWelcomeFrame.java @@ -34,7 +34,6 @@ import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ProjectManagerListener; -import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.ListItemDescriptorAdapter; import com.intellij.openapi.util.*; @@ -476,7 +475,7 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac private AnAction wrapGroups(AnAction action) { if (action instanceof ActionGroup && ((ActionGroup)action).isPopup()) { - final Pair> panel = createActionGroupPanel((ActionGroup)action, mySlidingPanel, () -> goBack(), this); + final Pair> panel = createActionGroupPanel((ActionGroup)action, () -> goBack(), this); final Runnable onDone = () -> { setTitle("New Project"); final JBList list = panel.second; @@ -787,7 +786,6 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac } public static Pair> createActionGroupPanel(final ActionGroup action, - final JComponent parent, final Runnable backAction, @NotNull Disposable parentDisposable) { JPanel actionsListPanel = new JPanel(new BorderLayout()); @@ -872,11 +870,9 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac final JPanel main = new JPanel(new BorderLayout()); main.add(actionsListPanel, BorderLayout.WEST); - final JComponent back = createBackLabel(backAction, singleProjectGenerator); - - if (back != null && !singleProjectGenerator) { - actionsListPanel.add(back, BorderLayout.SOUTH); - } + JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + bottomPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, new JBColor(Gray._217, Gray._81))); + main.add(bottomPanel, BorderLayout.SOUTH); final HashMap panelsMap = ContainerUtil.newHashMap(); ListSelectionListener selectionListener = e -> { @@ -897,19 +893,7 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac selected.set(panel); main.add(selected.get()); - if (singleProjectGenerator && back != null) { - JPanel first = UIUtil.uiTraverser(panel).traverse().filter(JPanel.class).filter((it) -> BOTTOM_PANEL.equals(it.getName())).first(); - if (first != null) { - first.add(back, BorderLayout.WEST); - } - } - - for (JButton button : UIUtil.findComponentsOfType(main, JButton.class)) { - if (button.getClientProperty(DialogWrapper.DEFAULT_ACTION) == Boolean.TRUE) { - parent.getRootPane().setDefaultButton(button); - break; - } - } + updateBottomPanel(panel, (AbstractActionWithPanel)value, bottomPanel, backAction); main.revalidate(); main.repaint(); @@ -929,29 +913,50 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac if (singleProjectGenerator) { actionsListPanel.setPreferredSize(new Dimension(0, 0)); } - + return Pair.create(main, list); } - @Nullable - private static JComponent createBackLabel(@Nullable Runnable backAction, boolean singleProjectGenerator) { - if (backAction == null) return null; - if (singleProjectGenerator) { - JButton button = new JButton("Back"); - button.addActionListener(e -> backAction.run()); - return button; + private static void updateBottomPanel(@NotNull JPanel currentPanel, + @NotNull AbstractActionWithPanel actionWithPanel, + @NotNull JPanel bottomPanel, + @Nullable Runnable backAction) { + bottomPanel.removeAll(); + bottomPanel.setPreferredSize(JBUI.size(-1, UIUtil.isUnderDarcula() ? 44 : 40)); + + if (SystemInfoRt.isUnix) { + addCancelButton(bottomPanel, backAction); + addActionButton(bottomPanel, actionWithPanel, currentPanel); } - JLabel back = new JLabel(AllIcons.Actions.Back); - back.setBorder(JBUI.Borders.empty(3, 7, 3, 7)); - back.setHorizontalAlignment(SwingConstants.LEFT); - new ClickListener() { - @Override - public boolean onClick(@NotNull MouseEvent event, int clickCount) { - backAction.run(); - return true; - } - }.installOn(back); - return back; + else { + addActionButton(bottomPanel, actionWithPanel, currentPanel); + addCancelButton(bottomPanel, backAction); + } + } + + private static void addCancelButton(@NotNull JPanel bottomPanel, @Nullable Runnable backAction) { + JComponent cancelButton = createCancelButton(backAction); + if (cancelButton != null) { + bottomPanel.add(cancelButton); + } + } + + private static void addActionButton(@NotNull JPanel bottomPanel, + @NotNull AbstractActionWithPanel actionWithPanel, + @NotNull JPanel currentPanel) { + JButton actionButton = actionWithPanel.getActionButton(); + bottomPanel.add(actionButton); + currentPanel.getRootPane().setDefaultButton(actionButton); + } + + @Nullable + private static JComponent createCancelButton(@Nullable Runnable backAction) { + if (backAction == null) return null; + + JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(e -> backAction.run()); + + return cancelButton; } public static void installQuickSearch(JBList list) {