From f4a46d304fdf6953c11a4075d50aae87524f9990 Mon Sep 17 00:00:00 2001 From: meanmail Date: Fri, 14 Apr 2017 23:12:48 +0700 Subject: [PATCH] Merged location and name. Added description. (New Project dialog) --- .../ui/EduCreateNewProjectDialog.java | 23 +++++----- .../ui/EduCreateNewProjectPanel.form | 43 +++++++++---------- .../ui/EduCreateNewProjectPanel.java | 38 ++++++++++------ 3 files changed, 59 insertions(+), 45 deletions(-) diff --git a/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectDialog.java b/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectDialog.java index 97e6937dae2a..9d7c42ca66fe 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectDialog.java +++ b/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectDialog.java @@ -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)() -> - 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()) { diff --git a/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectPanel.form b/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectPanel.form index 087a3863e63e..9cc641b0f21a 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectPanel.form +++ b/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectPanel.form @@ -3,28 +3,11 @@ - + - - - - - - - - - - - - - - - - - @@ -53,8 +36,8 @@ - - + + @@ -63,12 +46,28 @@ - - + + + + + + + + + + + + + + + + + + diff --git a/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectPanel.java b/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectPanel.java index be758ac5dd39..d9e71daa53d3 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectPanel.java +++ b/python/educational-core/src/com/jetbrains/edu/learning/newproject/ui/EduCreateNewProjectPanel.java @@ -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); + } }