mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
PY-75868: NPW: Simplify API to customize new project name.
All generators share the same logic, only providing `newProjectName`. Python PyV3 generators use generator name by default. GitOrigin-RevId: ffcb56a1bd2beaad1c7693550036aa091fa05a2b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
30d167776f
commit
379719b7ea
@@ -18541,6 +18541,7 @@ c:com.intellij.ide.util.projectWizard.ProjectSettingsStepBase
|
||||
- pf:myProjectDirectory:com.intellij.openapi.util.NotNullLazyValue
|
||||
- pf:myProjectGenerator:com.intellij.platform.DirectoryProjectGenerator
|
||||
- <init>(com.intellij.platform.DirectoryProjectGenerator,com.intellij.ide.util.projectWizard.AbstractNewProjectStep$AbstractCallback):V
|
||||
- p:<init>(com.intellij.platform.DirectoryProjectGenerator,com.intellij.ide.util.projectWizard.AbstractNewProjectStep$AbstractCallback,java.lang.String):V
|
||||
- actionPerformed(com.intellij.openapi.actionSystem.AnActionEvent):V
|
||||
- checkValid():Z
|
||||
- pf:createActionButton():javax.swing.JButton
|
||||
@@ -18554,7 +18555,7 @@ c:com.intellij.ide.util.projectWizard.ProjectSettingsStepBase
|
||||
- p:createLocationComponent():com.intellij.openapi.ui.LabeledComponent
|
||||
- createPanel():javax.swing.JPanel
|
||||
- dispose():V
|
||||
- p:findSequentNonExistingUntitled():java.io.File
|
||||
- p:findSequentNonExistingUntitled():java.nio.file.Path
|
||||
- getActionButton():javax.swing.JButton
|
||||
- pf:getIcon():javax.swing.Icon
|
||||
- p:getPeer():com.intellij.platform.ProjectGeneratorPeer
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.ui.*;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.NlsSafe;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.HtmlChunk;
|
||||
@@ -42,6 +43,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -62,6 +64,8 @@ public class ProjectSettingsStepBase<T> extends AbstractActionWithPanel implemen
|
||||
protected JLabel myErrorLabel;
|
||||
protected NotNullLazyValue<ProjectGeneratorPeer<T>> myLazyGeneratorPeer;
|
||||
private AbstractNewProjectStep<T> myProjectStep;
|
||||
private static final String DEFAULT_PROJECT_NAME = "untitled";
|
||||
private final @NlsSafe @NotNull String myNewProjectName;
|
||||
/**
|
||||
* If {@link ProjectGeneratorPeer#getComponent()} is Kotlin DSL UI, we store it here and use for validation
|
||||
*/
|
||||
@@ -70,12 +74,22 @@ public class ProjectSettingsStepBase<T> extends AbstractActionWithPanel implemen
|
||||
|
||||
public ProjectSettingsStepBase(DirectoryProjectGenerator<T> projectGenerator,
|
||||
AbstractNewProjectStep.AbstractCallback<T> callback) {
|
||||
this(projectGenerator, callback, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newProjectName {@link #myLocationField} will have default value ending with this name. Null means default
|
||||
*/
|
||||
protected ProjectSettingsStepBase(DirectoryProjectGenerator<T> projectGenerator,
|
||||
AbstractNewProjectStep.AbstractCallback<T> callback,
|
||||
@NlsSafe @Nullable String newProjectName) {
|
||||
super();
|
||||
getTemplatePresentation().setIcon(projectGenerator.getLogo());
|
||||
getTemplatePresentation().setText(projectGenerator.getName());
|
||||
myProjectGenerator = projectGenerator;
|
||||
myCallback = callback;
|
||||
myProjectDirectory = NotNullLazyValue.lazy(() -> findSequentNonExistingUntitled());
|
||||
myProjectDirectory = NotNullLazyValue.lazy(() -> findSequentNonExistingUntitled().toFile());
|
||||
myNewProjectName = newProjectName != null ? newProjectName : DEFAULT_PROJECT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -367,8 +381,11 @@ public class ProjectSettingsStepBase<T> extends AbstractActionWithPanel implemen
|
||||
BorderLayout.WEST);
|
||||
}
|
||||
|
||||
protected @NotNull File findSequentNonExistingUntitled() {
|
||||
return FileUtil.findSequentNonexistentFile(new File(ProjectUtil.getBaseDir()), "untitled", "");
|
||||
/**
|
||||
* Looks for the place for a new project
|
||||
*/
|
||||
protected @NotNull Path findSequentNonExistingUntitled() {
|
||||
return FileUtil.findSequentNonexistentFile(new File(ProjectUtil.getBaseDir()), myNewProjectName, "").toPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,4 +9,4 @@ import com.jetbrains.python.newProjectWizard.PyV3ProjectBaseGenerator
|
||||
internal class PyV3ProjectSpecificStep(
|
||||
generator: PyV3ProjectBaseGenerator<*>,
|
||||
callback: AbstractNewProjectStep.AbstractCallback<PyV3BaseProjectSettings>,
|
||||
) : ProjectSettingsStepBase<PyV3BaseProjectSettings>(generator, callback)
|
||||
) : ProjectSettingsStepBase<PyV3BaseProjectSettings>(generator, callback, generator.newProjectName)
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.annotations.Nls
|
||||
import javax.swing.Icon
|
||||
|
||||
class PyV3EmptyProjectGenerator : PyV3ProjectBaseGenerator<PyV3EmptyProjectSettings>(
|
||||
PyV3EmptyProjectSettings(generateWelcomeScript = false), PyV3EmptyProjectUI) {
|
||||
PyV3EmptyProjectSettings(generateWelcomeScript = false), PyV3EmptyProjectUI, _newProjectName = "PythonProject") {
|
||||
override fun getName(): @Nls String = PyBundle.message("pure.python.project")
|
||||
|
||||
override fun getLogo(): Icon = PythonPsiApiIcons.Python
|
||||
|
||||
@@ -88,9 +88,6 @@ public abstract class PythonProjectGenerator<T extends PyNewProjectSettings> ext
|
||||
myErrorCallback = errorCallback;
|
||||
}
|
||||
|
||||
public @Nullable JComponent getSettingsPanel(File baseDir) throws ProcessCanceledException {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upper part of project generation wizard panel could be customized
|
||||
|
||||
@@ -61,7 +61,9 @@ public class ProjectSpecificSettingsStep<T extends PyNewProjectSettings> extends
|
||||
|
||||
public ProjectSpecificSettingsStep(final @NotNull DirectoryProjectGenerator<T> projectGenerator,
|
||||
final @NotNull AbstractNewProjectStep.AbstractCallback<T> callback) {
|
||||
super(projectGenerator, callback);
|
||||
super(projectGenerator, callback, (projectGenerator instanceof PythonProjectGenerator<T> pyProjectGenerator)
|
||||
? pyProjectGenerator.getNewProjectPrefix()
|
||||
: null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,19 +78,12 @@ public class ProjectSpecificSettingsStep<T extends PyNewProjectSettings> extends
|
||||
@Override
|
||||
protected @Nullable JPanel createAdvancedSettings() {
|
||||
JComponent advancedSettings = null;
|
||||
if (myProjectGenerator instanceof PythonProjectGenerator) {
|
||||
advancedSettings = ((PythonProjectGenerator<?>)myProjectGenerator).getSettingsPanel(myProjectDirectory.get());
|
||||
}
|
||||
else if (myProjectGenerator instanceof WebProjectTemplate) {
|
||||
if (myProjectGenerator instanceof WebProjectTemplate) {
|
||||
advancedSettings = getPeer().getComponent();
|
||||
}
|
||||
if (advancedSettings != null) {
|
||||
final JPanel jPanel = new JPanel(new VerticalFlowLayout());
|
||||
final HideableDecorator deco = new HideableDecorator(jPanel, PyBundle.message("python.new.project.more.settings"), false);
|
||||
if (myProjectGenerator instanceof PythonProjectGenerator) {
|
||||
final ValidationResult result = ((PythonProjectGenerator<?>)myProjectGenerator).warningValidation(getInterpreterPanelSdk());
|
||||
deco.setOn(!result.isOk());
|
||||
}
|
||||
deco.setContentComponent(advancedSettings);
|
||||
return jPanel;
|
||||
}
|
||||
@@ -361,16 +356,7 @@ public class ProjectSpecificSettingsStep<T extends PyNewProjectSettings> extends
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull File findSequentNonExistingUntitled() {
|
||||
return Optional
|
||||
.ofNullable(PyUtil.as(myProjectGenerator, PythonProjectGenerator.class))
|
||||
.map(PythonProjectGenerator::getNewProjectPrefix)
|
||||
.map(it -> FileUtil.findSequentNonexistentFile(getBaseDir(), it, ""))
|
||||
.orElseGet(() -> super.findSequentNonExistingUntitled());
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* If {@link PythonProjectGenerator} {@link PythonProjectGenerator#supportsWelcomeScript()},
|
||||
* {@link ProjectSpecificSettingsStep} and inheritors should ask use if one should be created, and return true if so.
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.jetbrains.python.newProject.PyNewProjectSettings
|
||||
import com.jetbrains.python.newProject.PythonProjectGenerator
|
||||
import com.jetbrains.python.newProject.collector.InterpreterStatisticsInfo
|
||||
import com.jetbrains.python.newProject.promotion.PromoProjectGenerator
|
||||
import com.jetbrains.python.psi.PyUtil
|
||||
import com.jetbrains.python.sdk.PyLazySdk
|
||||
import com.jetbrains.python.sdk.add.v2.PythonAddNewEnvironmentPanel
|
||||
import com.jetbrains.python.util.ShowingMessageErrorSync
|
||||
@@ -43,7 +42,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import java.io.File
|
||||
import java.nio.file.InvalidPathException
|
||||
import java.nio.file.Path
|
||||
import java.util.*
|
||||
import javax.swing.JPanel
|
||||
|
||||
|
||||
@@ -171,13 +169,6 @@ class PythonProjectSpecificSettingsStep<T : PyNewProjectSettings>(
|
||||
}
|
||||
|
||||
|
||||
override fun findSequentNonExistingUntitled(): File {
|
||||
return Optional
|
||||
.ofNullable(PyUtil.`as`(myProjectGenerator, PythonProjectGenerator::class.java))
|
||||
.map { it.newProjectPrefix }
|
||||
.map { FileUtil.findSequentNonexistentFile(getBaseDir(), it!!, "") }
|
||||
.orElseGet { super.findSequentNonExistingUntitled() }
|
||||
}
|
||||
|
||||
private fun getBaseDir(): File {
|
||||
if (PlatformUtils.isDataSpell() && Path.of(ProjectUtil.getBaseDir()).startsWith(PathManager.getConfigDir())) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.platform.DirectoryProjectGenerator
|
||||
import com.intellij.platform.ProjectGeneratorPeer
|
||||
@@ -29,15 +30,19 @@ import java.nio.file.Path
|
||||
* [typeSpecificSettings] are settings defaults.
|
||||
* [typeSpecificUI] is a UI to display these settings and bind then using Kotlin DSL UI
|
||||
* [allowedInterpreterTypes] limits a list of allowed interpreters (all interpreters are allowed by default)
|
||||
* [newProjectName] is a default name of the new project ([getName]Project is default)
|
||||
*/
|
||||
abstract class PyV3ProjectBaseGenerator<TYPE_SPECIFIC_SETTINGS : PyV3ProjectTypeSpecificSettings>(
|
||||
private val typeSpecificSettings: TYPE_SPECIFIC_SETTINGS,
|
||||
private val typeSpecificUI: PyV3ProjectTypeSpecificUI<TYPE_SPECIFIC_SETTINGS>?,
|
||||
private val allowedInterpreterTypes: Set<PythonInterpreterSelectionMode>? = null,
|
||||
private val errorSink: ErrorSink = ShowingMessageErrorSync,
|
||||
private val _newProjectName: @NlsSafe String? = null,
|
||||
) : DirectoryProjectGenerator<PyV3BaseProjectSettings> {
|
||||
private val baseSettings = PyV3BaseProjectSettings()
|
||||
private val projectPathFlow = MutableStateFlow(Path.of(SystemProperties.getUserHome()))
|
||||
val newProjectName: @NlsSafe String get() = _newProjectName ?: "${name.replace(" ", "")}Project"
|
||||
|
||||
|
||||
override fun generateProject(project: Project, baseDir: VirtualFile, settings: PyV3BaseProjectSettings, module: Module) {
|
||||
val coroutineScope = project.service<MyService>().coroutineScope
|
||||
|
||||
Reference in New Issue
Block a user