mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-57435 Use specified project name instead of directory name in case of directory-based project
This commit is contained in:
@@ -30,8 +30,6 @@ import com.intellij.projectImport.ProjectFormatPanel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
@@ -75,17 +73,6 @@ public class ProjectNameStep extends ModuleWizardStep {
|
||||
|
||||
myNamePathComponent.setVisible(myWizardContext.getProject() == null);
|
||||
myFormatPanel.setVisible(myWizardContext.getProject() == null);
|
||||
|
||||
final Object selectedProjectFormat = myFormatPanel.getStorageFormatComboBox().getSelectedItem();
|
||||
myNamePathComponent.syncNameToPath(ProjectFormatPanel.DIR_BASED.equals(selectedProjectFormat));
|
||||
|
||||
myFormatPanel.getStorageFormatComboBox().addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final Object o = myFormatPanel.getStorageFormatComboBox().getSelectedItem();
|
||||
myNamePathComponent.syncNameToPath(ProjectFormatPanel.DIR_BASED.equals(o));
|
||||
}
|
||||
});
|
||||
|
||||
myAdditionalContentPanel = new JPanel(new GridBagLayout());
|
||||
myPanel.add(myAdditionalContentPanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
|
||||
}
|
||||
|
||||
@@ -19,11 +19,13 @@ package com.intellij.openapi.roots.ui.configuration;
|
||||
import com.intellij.compiler.ModuleCompilerUtil;
|
||||
import com.intellij.ide.util.BrowseFilesListener;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.StorageScheme;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.fileChooser.FileChooserFactory;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.project.ex.ProjectEx;
|
||||
import com.intellij.openapi.roots.CompilerProjectExtension;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
@@ -71,6 +73,8 @@ public class ProjectConfigurable extends NamedConfigurable<Project> implements D
|
||||
|
||||
private FieldPanel myProjectCompilerOutput;
|
||||
|
||||
private JTextField myProjectName;
|
||||
|
||||
private MyJPanel myPanel;
|
||||
|
||||
private final Alarm myUpdateWarningAlarm = new Alarm(Alarm.ThreadToUse.SHARED_THREAD);
|
||||
@@ -107,6 +111,30 @@ public class ProjectConfigurable extends NamedConfigurable<Project> implements D
|
||||
myPanel = new MyJPanel();
|
||||
myPanel.setPreferredSize(new Dimension(700, 500));
|
||||
|
||||
if (((ProjectEx)myProject).getStateStore().getStorageScheme().equals(StorageScheme.DIRECTORY_BASED)) {
|
||||
final JPanel namePanel = new JPanel(new BorderLayout());
|
||||
final JLabel label =
|
||||
new JLabel("<html><body><b>Project name:</b></body></html>", SwingConstants.LEFT);
|
||||
label.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
|
||||
namePanel.add(label, BorderLayout.NORTH);
|
||||
|
||||
myProjectName = new JTextField();
|
||||
myProjectName.setColumns(40);
|
||||
|
||||
final JPanel nameFieldPanel = new JPanel();
|
||||
nameFieldPanel.setLayout(new BoxLayout(nameFieldPanel, BoxLayout.X_AXIS));
|
||||
nameFieldPanel.add(Box.createHorizontalStrut(10));
|
||||
nameFieldPanel.add(myProjectName);
|
||||
|
||||
namePanel.add(nameFieldPanel, BorderLayout.CENTER);
|
||||
final JPanel wrapper = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
wrapper.add(namePanel);
|
||||
wrapper.setAlignmentX(0);
|
||||
myPanel.add(wrapper, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0,
|
||||
GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(4, 0, 10, 0), 0, 0));
|
||||
}
|
||||
|
||||
myProjectJdkConfigurable = new ProjectJdkConfigurable(myProject, model);
|
||||
myPanel.add(myProjectJdkConfigurable.createComponent(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0,
|
||||
GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
|
||||
@@ -144,6 +172,10 @@ public class ProjectConfigurable extends NamedConfigurable<Project> implements D
|
||||
}
|
||||
myLanguageLevelCombo.reset(myProject);
|
||||
updateCircularDependencyWarning();
|
||||
|
||||
if (myProjectName != null) {
|
||||
myProjectName.setText(myProject.getName());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
myFreeze = false;
|
||||
@@ -193,6 +225,10 @@ public class ProjectConfigurable extends NamedConfigurable<Project> implements D
|
||||
public void apply() throws ConfigurationException {
|
||||
final CompilerProjectExtension compilerProjectExtension = CompilerProjectExtension.getInstance(myProject);
|
||||
|
||||
if (myProjectName != null && myProjectName.getText().trim().length() == 0) {
|
||||
throw new ConfigurationException("Please, specify project name!");
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
// set the output path first so that handlers of RootsChanged event sent after JDK is set
|
||||
@@ -216,6 +252,10 @@ public class ProjectConfigurable extends NamedConfigurable<Project> implements D
|
||||
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(newLevel);
|
||||
try {
|
||||
myProjectJdkConfigurable.apply();
|
||||
|
||||
if (myProjectName != null) {
|
||||
((ProjectEx)myProject).setProjectName(myProjectName.getText().trim());
|
||||
}
|
||||
}
|
||||
catch (ConfigurationException e) {
|
||||
//cant't be
|
||||
@@ -262,6 +302,10 @@ public class ProjectConfigurable extends NamedConfigurable<Project> implements D
|
||||
if (!Comparing.strEqual(FileUtil.toSystemIndependentName(VfsUtil.urlToPath(compilerOutput)),
|
||||
FileUtil.toSystemIndependentName(myProjectCompilerOutput.getText()))) return true;
|
||||
if (myProjectJdkConfigurable.isModified()) return true;
|
||||
if (myProjectName != null) {
|
||||
if (!myProjectName.getText().trim().equals(myProject.getName())) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -223,7 +223,44 @@ public abstract class RecentProjectsManagerBase implements PersistentStateCompon
|
||||
|
||||
public ReopenProjectAction(String projectPath) {
|
||||
myProjectPath = projectPath;
|
||||
getTemplatePresentation().setText(projectPath, false);
|
||||
|
||||
String _text = projectPath;
|
||||
final String projectName = getProjectName(projectPath);
|
||||
if (projectName != null) {
|
||||
_text = String.format("%s (%s)", projectPath, projectName);
|
||||
}
|
||||
|
||||
getTemplatePresentation().setText(_text, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getProjectName(String path) {
|
||||
if (new File(path).isDirectory()) {
|
||||
final File nameFile = new File(new File(path, Project.DIRECTORY_STORE_FOLDER), ".name");
|
||||
if (nameFile.exists()) {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
in = new BufferedReader(new InputStreamReader(new FileInputStream(nameFile)));
|
||||
final String name = in.readLine();
|
||||
if (name != null && name.length() > 0) return name.trim();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
|
||||
+29
-4
@@ -47,10 +47,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -272,6 +269,34 @@ class ProjectStoreImpl extends BaseFileConfigurableStoreImpl implements IProject
|
||||
if (myScheme == StorageScheme.DIRECTORY_BASED) {
|
||||
final VirtualFile baseDir = getProjectBaseDir();
|
||||
assert baseDir != null : "project file: " + (getProjectFile() == null ? "[NULL]" : getProjectFile().getPath());
|
||||
|
||||
final VirtualFile ideaDir = baseDir.findChild(".idea");
|
||||
if (ideaDir != null && ideaDir.isValid()) {
|
||||
final VirtualFile nameFile = ideaDir.findChild(".name");
|
||||
if (nameFile != null && nameFile.isValid()) {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
in = new BufferedReader(new InputStreamReader(nameFile.getInputStream()));
|
||||
final String name = in.readLine();
|
||||
if (name != null && name.length() > 0) return name.trim();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return baseDir.getName().replace(":", "");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,4 +36,6 @@ public interface ProjectEx extends Project {
|
||||
void setOptimiseTestLoadSpeed(boolean optimiseTestLoadSpeed);
|
||||
|
||||
void checkUnknownMacros(final boolean showDialog);
|
||||
|
||||
void setProjectName(String name);
|
||||
}
|
||||
|
||||
@@ -46,8 +46,11 @@ import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.ex.MessagesEx;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.openapi.wm.impl.FrameTitleBuilder;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -56,6 +59,7 @@ import org.picocontainer.defaults.CachingComponentAdapter;
|
||||
import org.picocontainer.defaults.ConstructorInjectionComponentAdapter;
|
||||
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -87,7 +91,9 @@ public class ProjectImpl extends ComponentManagerImpl implements ProjectEx {
|
||||
return isDisposed();
|
||||
}
|
||||
};
|
||||
private final String myName;
|
||||
|
||||
private String myName;
|
||||
private String myOldName;
|
||||
|
||||
public static Key<Long> CREATION_TIME = Key.create("ProjectImpl.CREATION_TIME");
|
||||
|
||||
@@ -103,6 +109,15 @@ public class ProjectImpl extends ComponentManagerImpl implements ProjectEx {
|
||||
|
||||
myManager = manager;
|
||||
myName = isDefault() ? TEMPLATE_PROJECT_NAME : projectName == null ? getStateStore().getProjectName() : projectName;
|
||||
if (!isDefault() && projectName != null && getStateStore().getStorageScheme().equals(StorageScheme.DIRECTORY_BASED)) myOldName = ""; // new project
|
||||
}
|
||||
|
||||
public void setProjectName(final String projectName) {
|
||||
if (!projectName.equals(myName)) {
|
||||
myOldName = myName;
|
||||
myName = projectName;
|
||||
WindowManager.getInstance().getFrame(this).setTitle(FrameTitleBuilder.getInstance().getProjectTitle(this));
|
||||
}
|
||||
}
|
||||
|
||||
protected void boostrapPicoContainer() {
|
||||
@@ -248,6 +263,28 @@ public class ProjectImpl extends ComponentManagerImpl implements ProjectEx {
|
||||
|
||||
if (mySavingInProgress.compareAndSet(false, true)) {
|
||||
try {
|
||||
if (!isDefault()) {
|
||||
final IProjectStore stateStore = getStateStore();
|
||||
if (stateStore.getStorageScheme().equals(StorageScheme.DIRECTORY_BASED)) {
|
||||
final VirtualFile baseDir = stateStore.getProjectBaseDir();
|
||||
if (baseDir != null && baseDir.isValid()) {
|
||||
if (myOldName != null && !myOldName.equals(getName())) {
|
||||
final VirtualFile ideaDir = baseDir.findChild(DIRECTORY_STORE_FOLDER);
|
||||
if (ideaDir != null && ideaDir.isValid() && ideaDir.isDirectory()) {
|
||||
final File nameFile = new File(ideaDir.getPath(), ".name");
|
||||
try {
|
||||
FileUtil.writeToFile(nameFile, new String(getName()).getBytes(), false);
|
||||
myOldName = null;
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.info("Unable to store project name to: " + nameFile.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
doSave();
|
||||
}
|
||||
catch (IComponentStore.SaveCancelledException e) {
|
||||
|
||||
@@ -37,6 +37,10 @@ public class MockProject extends MockComponentManager implements ProjectEx {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProjectName(String name) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkUnknownMacros(final boolean showDialog) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user