Browse Source

AddExitingProjectToSolution, AddNewProjectToSolution, AddExistingItemsToProject: set initial directory based on the node that was clicked.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2477 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
f44ff1e015
  1. 9
      src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs
  2. 2
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs
  3. 30
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/SolutionNodeCommands.cs
  4. 26
      src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs

9
src/Main/Base/Project/Src/Gui/Dialogs/NewProjectDialog.cs

@ -34,6 +34,15 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs @@ -34,6 +34,15 @@ namespace ICSharpCode.SharpDevelop.Project.Dialogs
protected bool createNewSolution;
public string InitialProjectLocationDirectory {
get {
return ((TextBox)ControlDictionary["locationTextBox"]).Text;
}
set {
((TextBox)ControlDictionary["locationTextBox"]).Text = value;
}
}
public NewProjectDialog(bool createNewSolution)
{
StandardHeader.SetHeaders();

2
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs

@ -177,6 +177,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -177,6 +177,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
fdiag.AddExtension = true;
string[] fileFilters = (string[])(AddInTree.GetTreeNode("/SharpDevelop/Workbench/FileFilter").BuildChildItems(this)).ToArray(typeof(string));
fdiag.InitialDirectory = node.Directory;
fdiag.FilterIndex = GetFileFilterIndex(node.Project, fileFilters);
fdiag.Filter = String.Join("|", fileFilters);
fdiag.Multiselect = true;
@ -230,6 +231,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -230,6 +231,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
if (res == 2) {
return;
}
// only continue for res==0 (Copy)
}
bool replaceAll = false;
foreach (KeyValuePair<string, string> pair in fileNames) {

30
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/SolutionNodeCommands.cs

@ -22,6 +22,9 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -22,6 +22,9 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
ISolutionFolderNode solutionFolderNode = node as ISolutionFolderNode;
if (node != null) {
using (NewProjectDialog npdlg = new NewProjectDialog(false)) {
npdlg.InitialProjectLocationDirectory = GetInitialDirectorySuggestion(solutionFolderNode);
// show the dialog to request project type and name
if (npdlg.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK) {
if (npdlg.NewProjectLocation.Length == 0) {
MessageService.ShowError("No project has been created, there is nothing to add.");
@ -33,6 +36,32 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -33,6 +36,32 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
}
}
}
internal static string GetInitialDirectorySuggestion(ISolutionFolderNode solutionFolderNode)
{
// Detect the correct folder to place the new project in:
int projectCount = 0;
string initialDirectory = null;
foreach (ISolutionFolder folderEntry in solutionFolderNode.Container.Folders) {
IProject project = folderEntry as IProject;
if (project != null) {
if (projectCount == 0)
initialDirectory = project.Directory;
else
initialDirectory = FileUtility.GetCommonBaseDirectory(initialDirectory, project.Directory);
projectCount++;
}
}
if (initialDirectory != null) {
if (projectCount == 1) {
return FileUtility.GetAbsolutePath(initialDirectory, "..");
} else {
return initialDirectory;
}
} else {
return solutionFolderNode.Solution.Directory;
}
}
}
public class AddExitingProjectToSolution : AbstractMenuCommand
@ -62,6 +91,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -62,6 +91,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
fdiag.Filter = ProjectService.GetAllProjectsFilter(this);
fdiag.Multiselect = true;
fdiag.CheckFileExists = true;
fdiag.InitialDirectory = AddNewProjectToSolution.GetInitialDirectorySuggestion(solutionFolderNode);
if (fdiag.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK) {
foreach (string fileName in fdiag.FileNames) {
AddProject(solutionFolderNode, fileName);

26
src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs

@ -108,6 +108,32 @@ namespace ICSharpCode.Core @@ -108,6 +108,32 @@ namespace ICSharpCode.Core
return path.IndexOf(':') >= 2;
}
public static string GetCommonBaseDirectory(string dir1, string dir2)
{
if (dir1 == null || dir2 == null) return null;
if (IsUrl(dir1) || IsUrl(dir2)) return null;
dir1 = Path.GetFullPath(dir1);
dir2 = Path.GetFullPath(dir2);
string[] aPath = dir1.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
string[] bPath = dir2.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
StringBuilder result = new StringBuilder();
int indx = 0;
for(; indx < Math.Min(bPath.Length, aPath.Length); ++indx) {
if (bPath[indx].Equals(aPath[indx], StringComparison.OrdinalIgnoreCase)) {
if (result.Length > 0) result.Append(Path.DirectorySeparatorChar);
result.Append(aPath[indx]);
} else {
break;
}
}
if (indx == 0)
return null;
else
return result.ToString();
}
/// <summary>
/// Converts a given absolute path and a given base path to a path that leads
/// from the base path to the absoulte path. (as a relative path)

Loading…
Cancel
Save