|
|
|
@ -25,14 +25,16 @@ namespace ICSharpCode.SharpDevelop.Gui |
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// This class is for creating a new "empty" file
|
|
|
|
/// This class is for creating a new "empty" file
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class NewFileDialog : BaseSharpDevelopForm |
|
|
|
internal class NewFileDialog : BaseSharpDevelopForm |
|
|
|
{ |
|
|
|
{ |
|
|
|
ArrayList alltemplates = new ArrayList(); |
|
|
|
ArrayList alltemplates = new ArrayList(); |
|
|
|
ArrayList categories = new ArrayList(); |
|
|
|
ArrayList categories = new ArrayList(); |
|
|
|
Hashtable icons = new Hashtable(); |
|
|
|
Hashtable icons = new Hashtable(); |
|
|
|
bool allowUntitledFiles; |
|
|
|
bool allowUntitledFiles; |
|
|
|
string basePath; |
|
|
|
IProject project; |
|
|
|
|
|
|
|
DirectoryName basePath; |
|
|
|
List<KeyValuePair<string, FileDescriptionTemplate>> createdFiles = new List<KeyValuePair<string, FileDescriptionTemplate>>(); |
|
|
|
List<KeyValuePair<string, FileDescriptionTemplate>> createdFiles = new List<KeyValuePair<string, FileDescriptionTemplate>>(); |
|
|
|
|
|
|
|
internal FileTemplateOptions options; |
|
|
|
|
|
|
|
|
|
|
|
public List<KeyValuePair<string, FileDescriptionTemplate>> CreatedFiles { |
|
|
|
public List<KeyValuePair<string, FileDescriptionTemplate>> CreatedFiles { |
|
|
|
get { |
|
|
|
get { |
|
|
|
@ -40,9 +42,10 @@ namespace ICSharpCode.SharpDevelop.Gui |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public NewFileDialog(string basePath) |
|
|
|
public NewFileDialog(IProject project, DirectoryName basePath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
StandardHeader.SetHeaders(); |
|
|
|
StandardHeader.SetHeaders(); |
|
|
|
|
|
|
|
this.project = project; |
|
|
|
this.basePath = basePath; |
|
|
|
this.basePath = basePath; |
|
|
|
this.allowUntitledFiles = basePath == null; |
|
|
|
this.allowUntitledFiles = basePath == null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -469,13 +472,12 @@ namespace ICSharpCode.SharpDevelop.Gui |
|
|
|
} |
|
|
|
} |
|
|
|
fileName = Path.Combine(basePath, fileName); |
|
|
|
fileName = Path.Combine(basePath, fileName); |
|
|
|
fileName = FileUtility.NormalizePath(fileName); |
|
|
|
fileName = FileUtility.NormalizePath(fileName); |
|
|
|
IProject project = ProjectService.CurrentProject; |
|
|
|
|
|
|
|
if (project != null) { |
|
|
|
if (project != null) { |
|
|
|
StringParserPropertyContainer.FileCreation["StandardNamespace"] = CustomToolsService.GetDefaultNamespace(project, fileName); |
|
|
|
StringParserPropertyContainer.FileCreation["StandardNamespace"] = CustomToolsService.GetDefaultNamespace(project, fileName); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
FileTemplateOptions options = new FileTemplateOptions(); |
|
|
|
options = new FileTemplateOptions(); |
|
|
|
options.ClassName = GenerateValidClassOrNamespaceName(Path.GetFileNameWithoutExtension(fileName), false); |
|
|
|
options.ClassName = GenerateValidClassOrNamespaceName(Path.GetFileNameWithoutExtension(fileName), false); |
|
|
|
options.FileName = FileName.Create(fileName); |
|
|
|
options.FileName = FileName.Create(fileName); |
|
|
|
options.IsUntitled = allowUntitledFiles; |
|
|
|
options.IsUntitled = allowUntitledFiles; |
|
|
|
@ -490,20 +492,20 @@ namespace ICSharpCode.SharpDevelop.Gui |
|
|
|
StringParserPropertyContainer.FileCreation["ClassName"] = options.ClassName; |
|
|
|
StringParserPropertyContainer.FileCreation["ClassName"] = options.ClassName; |
|
|
|
|
|
|
|
|
|
|
|
// when adding a file to a project (but not when creating a standalone file while a project is open):
|
|
|
|
// when adding a file to a project (but not when creating a standalone file while a project is open):
|
|
|
|
if (ProjectService.CurrentProject != null && !this.allowUntitledFiles) { |
|
|
|
if (project != null && !this.allowUntitledFiles) { |
|
|
|
options.Project = ProjectService.CurrentProject; |
|
|
|
options.Project = project; |
|
|
|
// add required assembly references to the project
|
|
|
|
// add required assembly references to the project
|
|
|
|
bool changes = false; |
|
|
|
bool changes = false; |
|
|
|
foreach (ReferenceProjectItem reference in item.Template.RequiredAssemblyReferences) { |
|
|
|
foreach (ReferenceProjectItem reference in item.Template.RequiredAssemblyReferences) { |
|
|
|
IEnumerable<ProjectItem> refs = ProjectService.CurrentProject.GetItemsOfType(ItemType.Reference); |
|
|
|
IEnumerable<ProjectItem> refs = project.GetItemsOfType(ItemType.Reference); |
|
|
|
if (!refs.Any(projItem => string.Equals(projItem.Include, reference.Include, StringComparison.OrdinalIgnoreCase))) { |
|
|
|
if (!refs.Any(projItem => string.Equals(projItem.Include, reference.Include, StringComparison.OrdinalIgnoreCase))) { |
|
|
|
ReferenceProjectItem projItem = (ReferenceProjectItem)reference.CloneFor(ProjectService.CurrentProject); |
|
|
|
ReferenceProjectItem projItem = (ReferenceProjectItem)reference.CloneFor(project); |
|
|
|
ProjectService.AddProjectItem(ProjectService.CurrentProject, projItem); |
|
|
|
ProjectService.AddProjectItem(project, projItem); |
|
|
|
changes = true; |
|
|
|
changes = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (changes) { |
|
|
|
if (changes) { |
|
|
|
ProjectService.CurrentProject.Save(); |
|
|
|
project.Save(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|