AbstractNewProjectDialog refactoring:

All implementations use `AbstractNewProjectStep` and any other action wouldn't really work.

We deprecate old method and force users to use new (the one that returns `AbstractNewProjectStep`).

Some methods are finalized because overwriting them might break the contract


Merge-request: IJ-MR-142822
Merged-by: Ilya Kazakevich <ilya.kazakevich@jetbrains.com>

GitOrigin-RevId: aafa6fb336f78391077773ac6d202d35c15a8c8d
This commit is contained in:
Ilya Kazakevich
2024-08-19 17:11:21 +00:00
committed by intellij-monorepo-bot
parent d75afcb4b9
commit bc2d1d84f4
3 changed files with 34 additions and 14 deletions

View File

@@ -18436,14 +18436,15 @@ a:com.intellij.ide.util.gotoByName.SimpleChooseByNameModel
a:com.intellij.ide.util.projectWizard.AbstractNewProjectDialog
- com.intellij.openapi.ui.DialogWrapper
- <init>():V
- p:createActions():javax.swing.Action[]
- p:createCenterPanel():javax.swing.JComponent
- pa:createRootStep():com.intellij.openapi.actionSystem.DefaultActionGroup
- pf:createActions():javax.swing.Action[]
- pf:createCenterPanel():javax.swing.JComponent
- p:createNewProjectStep():com.intellij.ide.util.projectWizard.AbstractNewProjectStep
- p:createRootStep():com.intellij.openapi.actionSystem.DefaultActionGroup
- p:createSouthPanel():javax.swing.JComponent
- p:getHelpId():java.lang.String
- getPreferredFocusedComponent():javax.swing.JComponent
- p:getStyle():com.intellij.openapi.ui.DialogWrapper$DialogStyle
- p:init():V
- pf:init():V
a:com.intellij.ide.util.projectWizard.AbstractNewProjectStep
- com.intellij.openapi.actionSystem.DefaultActionGroup
- com.intellij.openapi.project.DumbAware

View File

@@ -1,6 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.util.projectWizard;
import com.intellij.diagnostic.PluginException;
import com.intellij.ide.wizard.Step;
import com.intellij.ide.wizard.StepAdapter;
import com.intellij.openapi.Disposable;
@@ -44,7 +45,7 @@ public abstract class AbstractNewProjectDialog extends DialogWrapper {
}
@Override
protected void init() {
protected final void init() {
super.init();
DialogWrapperPeer peer = getPeer();
JRootPane pane = peer.getRootPane();
@@ -56,16 +57,14 @@ public abstract class AbstractNewProjectDialog extends DialogWrapper {
}
@Override
protected @Nullable JComponent createCenterPanel() {
protected final @Nullable JComponent createCenterPanel() {
setTitle(AbstractNewProjectStep.EP_NAME.hasAnyExtensions() ? ProjectBundle.message("dialog.title.new.project")
: ProjectBundle.message("dialog.title.create.project"));
DefaultActionGroup root = createRootStep();
: ProjectBundle.message("dialog.title.create.project"));
var root = createNewProjectStep();
Disposer.register(getDisposable(), () -> root.removeAll());
Pair<JPanel, JBList<AnAction>> pair = ActionGroupPanelWrapper.createActionGroupPanel(root, null, getDisposable());
if (root instanceof AbstractNewProjectStep<?> projectStep) {
projectStep.setWizardContext(createWizardContext(pair, getDisposable()));
}
root.setWizardContext(createWizardContext(pair, getDisposable()));
JPanel component = pair.first;
myPair = pair;
UiNotifyConnector.doWhenFirstShown(myPair.second, () -> ScrollingUtil.ensureSelectionExists(myPair.second));
@@ -113,7 +112,24 @@ public abstract class AbstractNewProjectDialog extends DialogWrapper {
return DialogStyle.COMPACT;
}
protected abstract DefaultActionGroup createRootStep();
/**
* @deprecated use {@link #createNewProjectStep()}
*/
@Deprecated
@Nullable
protected DefaultActionGroup createRootStep() {
return null;
}
@NotNull
protected AbstractNewProjectStep<?> createNewProjectStep() {
var step = createRootStep();
if (step instanceof AbstractNewProjectStep<?> abstractNewProjectStep) {
return abstractNewProjectStep;
}
throw PluginException.createByClass(new AssertionError("override 'createNewProjectStep' instead of deprecated 'createRootStep'"), getClass());
}
@Override
protected String getHelpId() {
@@ -121,12 +137,13 @@ public abstract class AbstractNewProjectDialog extends DialogWrapper {
}
@Override
protected Action @NotNull [] createActions() {
protected final Action @NotNull [] createActions() {
return new Action[0];
}
static class ProjectStepPeerHolder extends StepAdapter {
private final ProjectGeneratorPeer<?> myPeer;
ProjectStepPeerHolder(ProjectGeneratorPeer<?> peer) {
myPeer = peer;
}

View File

@@ -2,11 +2,13 @@
package com.intellij.pycharm.community.ide.impl.newProject;
import com.intellij.ide.util.projectWizard.AbstractNewProjectDialog;
import com.intellij.ide.util.projectWizard.AbstractNewProjectStep;
import com.intellij.pycharm.community.ide.impl.newProject.steps.PyCharmNewProjectStep;
import org.jetbrains.annotations.NotNull;
public class PyCharmNewProjectDialog extends AbstractNewProjectDialog {
@Override
protected PyCharmNewProjectStep createRootStep() {
protected @NotNull AbstractNewProjectStep<?> createNewProjectStep() {
return new PyCharmNewProjectStep();
}