mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merged location and name. Added description. (New Project dialog)
This commit is contained in:
+12
-11
@@ -68,6 +68,8 @@ public class EduCreateNewProjectDialog extends DialogWrapper {
|
||||
|
||||
public void setCourse(@Nullable Course course) {
|
||||
myCourse = course;
|
||||
String description = course != null ? course.getDescription() : "";
|
||||
myPanel.setDescription(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,25 +105,23 @@ public class EduCreateNewProjectDialog extends DialogWrapper {
|
||||
super.doOKAction();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param projectGenerator
|
||||
* @return error message if didn't create project else return null
|
||||
*/
|
||||
@Nullable
|
||||
private String createProject(@NotNull final EduCourseProjectGenerator projectGenerator) {
|
||||
String name = myPanel.getName();
|
||||
String path = FileUtil.join(FileUtil.toSystemDependentName(myPanel.getLocationPath()), name);
|
||||
String location = FileUtil.toSystemDependentName(myPanel.getLocationPath());
|
||||
|
||||
ValidationResult result = projectGenerator.validate();
|
||||
if (!result.isOk()) {
|
||||
return result.getErrorMessage();
|
||||
}
|
||||
|
||||
final File location = new File(path);
|
||||
if (!location.exists() && !location.mkdirs()) {
|
||||
final File directory = new File(location);
|
||||
if (!FileUtil.createDirectory(directory)) {
|
||||
String message = "Can't create a project directory";
|
||||
LOG.error(message + ": " + path);
|
||||
LOG.error(message + ": " + location);
|
||||
return message;
|
||||
}
|
||||
|
||||
@@ -129,18 +129,19 @@ public class EduCreateNewProjectDialog extends DialogWrapper {
|
||||
|
||||
final VirtualFile baseDir = ApplicationManager.getApplication()
|
||||
.runWriteAction((Computable<VirtualFile>)() ->
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(location)
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(directory)
|
||||
);
|
||||
|
||||
if (baseDir == null) {
|
||||
LOG.error("Couldn't find '" + location + "' in VFS");
|
||||
LOG.error("Couldn't find '" + directory + "' in VFS");
|
||||
return "Couldn't find in VFS";
|
||||
}
|
||||
VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);
|
||||
|
||||
if (baseDir.getChildren().length > 0) {
|
||||
String message =
|
||||
String.format("Directory '%s' is not empty.\nFiles and directories will remove.\nDo you want continue?", location.getAbsolutePath());
|
||||
String.format("Directory '%s' is not empty.\nFiles and directories will remove.\nDo you want continue?",
|
||||
directory.getAbsolutePath());
|
||||
int rc = Messages.showYesNoDialog((Project)null, message, "New Project", Messages.getQuestionIcon());
|
||||
if (rc != Messages.YES) {
|
||||
myPanel.resetError();
|
||||
@@ -153,11 +154,11 @@ public class EduCreateNewProjectDialog extends DialogWrapper {
|
||||
String generatorName = ConvertUsagesUtil.ensureProperKey(generator.getName());
|
||||
UsageTrigger.trigger("AbstractNewProjectStep." + generatorName);
|
||||
|
||||
RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getParent());
|
||||
RecentProjectsManager.getInstance().setLastProjectCreationLocation(directory.getParent());
|
||||
|
||||
ProjectOpenedCallback callback = null;
|
||||
if(generator instanceof TemplateProjectDirectoryGenerator){
|
||||
((TemplateProjectDirectoryGenerator)generator).generateProject(baseDir.getName(), path);
|
||||
((TemplateProjectDirectoryGenerator)generator).generateProject(baseDir.getName(), location);
|
||||
} else {
|
||||
callback = (project, module) -> {
|
||||
if (projectGenerator.beforeProjectGenerated()) {
|
||||
|
||||
+21
-22
@@ -3,28 +3,11 @@
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="372" height="88"/>
|
||||
<xy x="20" y="20" width="507" height="325"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="786af" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="160bb"/>
|
||||
<text value="Name:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="160bb" class="javax.swing.JTextField" binding="myNameField">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="300" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<grid id="29be7" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
@@ -53,8 +36,8 @@
|
||||
</grid>
|
||||
<component id="628ab" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="58" height="10"/>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="58" height="67"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
@@ -63,12 +46,28 @@
|
||||
</component>
|
||||
<component id="aab8" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myLocationField">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="171" height="10"/>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="400" height="-1"/>
|
||||
<preferred-size width="400" height="67"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<scrollpane id="69178" class="com.intellij.ui.components.JBScrollPane">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="150"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="bdfa2" class="javax.swing.JTextPane" binding="myDescription">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
+26
-12
@@ -16,11 +16,11 @@
|
||||
package com.jetbrains.edu.learning.newproject.ui;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.RecentProjectsManager;
|
||||
import com.intellij.ide.util.projectWizard.ProjectWizardUtil;
|
||||
import com.intellij.ide.impl.ProjectUtil;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapperPeer;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -33,22 +33,31 @@ import java.io.File;
|
||||
|
||||
public class EduCreateNewProjectPanel extends JPanel {
|
||||
private JPanel myPanel;
|
||||
private JTextField myNameField;
|
||||
private TextFieldWithBrowseButton myLocationField;
|
||||
private JLabel myErrorIcon;
|
||||
private JLabel myErrorLabel;
|
||||
private JTextPane myDescription;
|
||||
|
||||
public EduCreateNewProjectPanel(@NotNull final Project project, @NotNull EduCreateNewProjectDialog dialog) {
|
||||
setLayout(new BorderLayout());
|
||||
add(myPanel, BorderLayout.CENTER);
|
||||
myErrorIcon.setIcon(AllIcons.Actions.Lightning);
|
||||
resetError();
|
||||
String location = RecentProjectsManager.getInstance().getLastProjectCreationLocation();
|
||||
String location = findSequentNonExistingUntitled().toString();
|
||||
myLocationField.setText(location);
|
||||
String name = ProjectWizardUtil.findNonExistingFileName(location, "course", "");
|
||||
myNameField.setText(name);
|
||||
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
|
||||
myLocationField.addBrowseFolderListener("Choose Location Folder", null, project, descriptor);
|
||||
final int index = location.lastIndexOf(File.separator);
|
||||
if (index > 0) {
|
||||
JTextField textField = myLocationField.getTextField();
|
||||
textField.select(index + 1, location.length());
|
||||
textField.putClientProperty(DialogWrapperPeer.HAVE_INITIAL_SELECTION, true);
|
||||
}
|
||||
|
||||
final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
|
||||
myLocationField.addBrowseFolderListener("Select Base Directory",
|
||||
"Select base directory for the project",
|
||||
project,
|
||||
descriptor);
|
||||
|
||||
myLocationField.addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
@@ -65,6 +74,11 @@ public class EduCreateNewProjectPanel extends JPanel {
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected File findSequentNonExistingUntitled() {
|
||||
return FileUtil.findSequentNonexistentFile(new File(ProjectUtil.getBaseDir()), "course", "");
|
||||
}
|
||||
|
||||
private void setState(boolean isVisible) {
|
||||
myErrorIcon.setVisible(isVisible);
|
||||
myErrorLabel.setVisible(isVisible);
|
||||
@@ -75,10 +89,6 @@ public class EduCreateNewProjectPanel extends JPanel {
|
||||
setState(true);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myNameField.getText();
|
||||
}
|
||||
|
||||
public String getLocationPath() {
|
||||
return myLocationField.getText();
|
||||
}
|
||||
@@ -86,4 +96,8 @@ public class EduCreateNewProjectPanel extends JPanel {
|
||||
public void resetError() {
|
||||
setState(false);
|
||||
}
|
||||
|
||||
public void setDescription(@NotNull String description) {
|
||||
myDescription.setText(description);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user