Browse Source

Hide NewFileDialog behind IUIService.

pull/32/merge
Daniel Grunwald 12 years ago
parent
commit
ca88046297
  1. 1
      src/Main/Base/Project/Configuration/AssemblyInfo.cs
  2. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  3. 20
      src/Main/Base/Project/Services/IUIService.cs
  4. 4
      src/Main/Base/Project/Src/Commands/FileCommands.cs
  5. 24
      src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs
  6. 28
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs
  7. 16
      src/Main/Base/Project/Templates/FileTemplate.cs
  8. 41
      src/Main/Base/Project/Templates/FileTemplateResult.cs
  9. 6
      src/Main/Base/Project/Templates/ITemplateService.cs
  10. 29
      src/Main/SharpDevelop/Services/UIService.cs

1
src/Main/Base/Project/Configuration/AssemblyInfo.cs

@ -25,3 +25,4 @@ using System.Windows.Markup; @@ -25,3 +25,4 @@ using System.Windows.Markup;
[assembly: AssemblyCulture("")]
[assembly: InternalsVisibleTo("SharpDevelop,PublicKey=002400000480000094000000060200000024000052534131000400000100010063d5db5957250f41969c79e88cbd8806165ca7d96d468a9d60f11704a8b0698684b5acc16fc82e6cede459e1d6ed7384b044c47a67d68bae1e08182473168e2ad92c6fabe32b9217ea59d05bb9a101318aeec9f767991d2ae8d987b60c591b6020d2816c395db7f3045a1c77c2b074c508c2b4f25dcd969688da94ebc83f5f9b")]
[assembly: InternalsVisibleTo("ICSharpCode.SharpDevelop.Tests,PublicKey=002400000480000094000000060200000024000052534131000400000100010063d5db5957250f41969c79e88cbd8806165ca7d96d468a9d60f11704a8b0698684b5acc16fc82e6cede459e1d6ed7384b044c47a67d68bae1e08182473168e2ad92c6fabe32b9217ea59d05bb9a101318aeec9f767991d2ae8d987b60c591b6020d2816c395db7f3045a1c77c2b074c508c2b4f25dcd969688da94ebc83f5f9b")]

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -237,6 +237,7 @@ @@ -237,6 +237,7 @@
<Compile Include="Src\Project\MSBuildConfigurationOrPlatformNameCollection.cs" />
<Compile Include="Templates\FileTemplate.cs" />
<Compile Include="Templates\FileTemplateOptions.cs" />
<Compile Include="Templates\FileTemplateResult.cs" />
<Compile Include="Templates\ITemplateService.cs" />
<Compile Include="Templates\TemplateLoadException.cs" />
<Compile Include="Util\AtomicBoolean.cs" />

20
src/Main/Base/Project/Services/IUIService.cs

@ -2,7 +2,10 @@ @@ -2,7 +2,10 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Templates;
namespace ICSharpCode.SharpDevelop
{
@ -13,6 +16,23 @@ namespace ICSharpCode.SharpDevelop @@ -13,6 +16,23 @@ namespace ICSharpCode.SharpDevelop
/// </summary>
public interface IUIService
{
/// <summary>
/// Shows the 'Edit Solution Configurations' dialog.
/// </summary>
void ShowSolutionConfigurationEditorDialog(ISolution solution);
/// <summary>
/// Shows the 'New File' dialog.
/// </summary>
/// <param name="project">The parent project to which the new file should be added.
/// May be <c>null</c> to create files outside of a project.</param>
/// <param name="directory">The target directory to which the new file should be saved.
/// May be <c>null</c> to create an untitled file.</param>
/// <param name="templates">The list of templates that are available in the dialog.
/// Pass <c>null</c> to use the default list (<see cref="ITemplateService.FileTemplates"/>)</param>
/// <returns>
/// Returns the FileTemplateResult; or null if no file was created.
/// </returns>
FileTemplateResult ShowNewFileDialog(IProject project, DirectoryName directory, IEnumerable<FileTemplate> templates = null);
}
}

4
src/Main/Base/Project/Src/Commands/FileCommands.cs

@ -41,9 +41,7 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -41,9 +41,7 @@ namespace ICSharpCode.SharpDevelop.Commands
}
}
using (NewFileDialog nfd = new NewFileDialog(null)) {
nfd.ShowDialog(SD.WinForms.MainWin32Window);
}
SD.UIService.ShowNewFileDialog(null, null);
}
}

24
src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs

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

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

@ -6,10 +6,10 @@ using System.Collections.Generic; @@ -6,10 +6,10 @@ using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Templates;
namespace ICSharpCode.SharpDevelop.Project.Commands
{
@ -348,27 +348,13 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -348,27 +348,13 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
node.Expand();
node.Expanding();
List<FileProjectItem> addedItems = new List<FileProjectItem>();
using (NewFileDialog nfd = new NewFileDialog(node.Directory)) {
if (nfd.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) {
bool additionalProperties = false;
foreach (KeyValuePair<string, FileDescriptionTemplate> createdFile in nfd.CreatedFiles) {
FileProjectItem item = node.AddNewFile(createdFile.Key);
addedItems.Add(item);
if (createdFile.Value.SetProjectItemProperties(item)) {
additionalProperties = true;
}
}
if (additionalProperties) {
node.Project.Save();
node.RecreateSubNodes();
}
}
FileTemplateResult result = SD.UIService.ShowNewFileDialog(node.Project, node.Directory);
if (result != null) {
node.RecreateSubNodes();
return result.NewFiles.Select(node.Project.FindFile).Where(f => f != null).ToArray();
} else {
return null;
}
return addedItems.AsReadOnly();
}
}

16
src/Main/Base/Project/Templates/FileTemplate.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Templates
{
@ -14,7 +15,15 @@ namespace ICSharpCode.SharpDevelop.Templates @@ -14,7 +15,15 @@ namespace ICSharpCode.SharpDevelop.Templates
public abstract string Description { get; }
public abstract IImage Icon { get; }
public virtual bool NewFileDialogVisible { get { return true; } }
/// <summary>
/// Gets whether this template is available for the specified project.
/// </summary>
/// <param name="project">The project to which the new file should be added.
/// Can be <c>null</c> when creating a file outside of a project.</param>
public virtual bool IsVisible(IProject project)
{
return true;
}
/// <summary>
/// Proposes a name for the new file.
@ -31,5 +40,10 @@ namespace ICSharpCode.SharpDevelop.Templates @@ -31,5 +40,10 @@ namespace ICSharpCode.SharpDevelop.Templates
{
return null;
}
/// <summary>
/// Instanciates the template, writes the new files to disk, and adds them to the project.
/// </summary>
public abstract FileTemplateResult Create(FileTemplateOptions options);
}
}

41
src/Main/Base/Project/Templates/FileTemplateResult.cs

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
namespace ICSharpCode.SharpDevelop.Templates
{
/// <summary>
/// Description of FileTemplateResult.
/// </summary>
public class FileTemplateResult
{
readonly FileTemplateOptions options;
public FileTemplateResult(FileTemplateOptions options)
{
if (options == null)
throw new ArgumentNullException("options");
this.options = options;
}
/// <summary>
/// Gets the options used to instanciate the template.
/// </summary>
public FileTemplateOptions Options {
get { return options; }
}
IList<FileName> newFiles = new List<FileName>();
/// <summary>
/// Gets the list of newly created files.
/// </summary>
public IList<FileName> NewFiles {
get { return newFiles; }
}
}
}

6
src/Main/Base/Project/Templates/ITemplateService.cs

@ -11,8 +11,14 @@ namespace ICSharpCode.SharpDevelop.Templates @@ -11,8 +11,14 @@ namespace ICSharpCode.SharpDevelop.Templates
[SDService("SD.Templates")]
public interface ITemplateService
{
/// <summary>
/// Gets the list of file templates that are available in the 'new file' dialog.
/// </summary>
IEnumerable<FileTemplate> FileTemplates { get; }
/// <summary>
/// Loads a file template (.xft file) from a stream.
/// </summary>
FileTemplate LoadFileTemplate(Stream stream);
}
}

29
src/Main/SharpDevelop/Services/UIService.cs

@ -2,7 +2,14 @@ @@ -2,7 +2,14 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Internal.Templates;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Templates;
namespace ICSharpCode.SharpDevelop
{
@ -19,5 +26,27 @@ namespace ICSharpCode.SharpDevelop @@ -19,5 +26,27 @@ namespace ICSharpCode.SharpDevelop
}
}
}
public FileTemplateResult ShowNewFileDialog(IProject project, DirectoryName directory, IEnumerable<ICSharpCode.SharpDevelop.Templates.FileTemplate> templates)
{
using (NewFileDialog nfd = new NewFileDialog(project, directory)) {
if (nfd.ShowDialog(SD.WinForms.MainWin32Window) != DialogResult.OK)
return null;
if (project != null) {
foreach (KeyValuePair<string, FileDescriptionTemplate> createdFile in nfd.CreatedFiles) {
FileName fileName = FileName.Create(createdFile.Key);
ItemType type = project.GetDefaultItemType(fileName);
FileProjectItem newItem = new FileProjectItem(project, type);
newItem.FileName = fileName;
createdFile.Value.SetProjectItemProperties(newItem);
project.Items.Add(newItem);
}
project.Save();
}
var result = new FileTemplateResult(nfd.options);
result.NewFiles.AddRange(nfd.CreatedFiles.Select(p => FileName.Create(p.Key)));
return result;
}
}
}
}

Loading…
Cancel
Save