Browse Source

SD2-438. Form designer now creating, loading and saving resources.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@481 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 21 years ago
parent
commit
5e9b5901f2
  1. 28
      src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/DesignerGenerator/CodeDOMGenerator.cs
  2. 13
      src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/FormDesignerViewContent.cs
  3. 56
      src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/Services/DesignerResourceService.cs

28
src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/DesignerGenerator/CodeDOMGenerator.cs

@ -94,9 +94,16 @@ namespace ICSharpCode.FormDesigner
// ICSharpCode.NRefactory.Parser.CodeDOMVerboseOutputGenerator outputGenerator = new ICSharpCode.NRefactory.Parser.CodeDOMVerboseOutputGenerator(); // ICSharpCode.NRefactory.Parser.CodeDOMVerboseOutputGenerator outputGenerator = new ICSharpCode.NRefactory.Parser.CodeDOMVerboseOutputGenerator();
foreach (CodeStatement statement in statements) { foreach (CodeStatement statement in statements) {
if ((statement is CodeVariableDeclarationStatement)) { CodeVariableDeclarationStatement variableDecl = statement as CodeVariableDeclarationStatement;
addedVariables.Add(((CodeVariableDeclarationStatement)statement).Name); if (variableDecl != null) {
if (variableDecl.Name == "resources") {
FixResourcesVariableDeclarationStatement(variableDecl);
} else { } else {
addedVariables.Add(((CodeVariableDeclarationStatement)statement).Name);
continue;
}
}
// indentation isn't generated when calling GenerateCodeFromStatement // indentation isn't generated when calling GenerateCodeFromStatement
writer.Write(options.IndentString); writer.Write(options.IndentString);
try { try {
@ -109,7 +116,6 @@ namespace ICSharpCode.FormDesigner
} }
} }
} }
}
bool IsComponentAdded(IComponent component) bool IsComponentAdded(IComponent component)
{ {
@ -118,5 +124,21 @@ namespace ICSharpCode.FormDesigner
} }
return false; return false;
} }
/// <summary>
/// HACK - Fix the resources variable declaration. The CodeDomSerializer
/// creates an incorrect code expression object.
/// </summary>
void FixResourcesVariableDeclarationStatement(CodeVariableDeclarationStatement variableDecl)
{
CodeObjectCreateExpression exp = variableDecl.InitExpression as CodeObjectCreateExpression;
if (exp != null) {
CodeTypeReference typeRef = new CodeTypeReference(host.RootComponent.Site.Name);
CodeTypeOfExpression typeofExpression = new CodeTypeOfExpression(typeRef);
exp.Parameters.Clear();
exp.Parameters.Add(typeofExpression);
}
}
} }
} }

13
src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/FormDesignerViewContent.cs

@ -59,6 +59,7 @@ namespace ICSharpCode.FormDesigner
IDesignerLoaderProvider loader; IDesignerLoaderProvider loader;
IDesignerGenerator generator; IDesignerGenerator generator;
DesignerResourceService designerResourceService;
public override Control Control { public override Control Control {
get { get {
@ -117,7 +118,7 @@ namespace ICSharpCode.FormDesigner
serviceContainer.AddService(typeof(System.ComponentModel.Design.IMenuCommandService), new ICSharpCode.FormDesigner.Services.MenuCommandService(p, serviceContainer)); serviceContainer.AddService(typeof(System.ComponentModel.Design.IMenuCommandService), new ICSharpCode.FormDesigner.Services.MenuCommandService(p, serviceContainer));
serviceContainer.AddService(typeof(IHelpService), new HelpService()); serviceContainer.AddService(typeof(IHelpService), new HelpService());
serviceContainer.AddService(typeof(System.Drawing.Design.IPropertyValueUIService), new PropertyValueUIService()); serviceContainer.AddService(typeof(System.Drawing.Design.IPropertyValueUIService), new PropertyValueUIService());
DesignerResourceService designerResourceService = new DesignerResourceService(this.resources); designerResourceService = new DesignerResourceService(this.resources);
serviceContainer.AddService(typeof(System.ComponentModel.Design.IResourceService), designerResourceService); serviceContainer.AddService(typeof(System.ComponentModel.Design.IResourceService), designerResourceService);
AmbientProperties ambientProperties = new AmbientProperties(); AmbientProperties ambientProperties = new AmbientProperties();
serviceContainer.AddService(typeof(AmbientProperties), ambientProperties); serviceContainer.AddService(typeof(AmbientProperties), ambientProperties);
@ -135,6 +136,7 @@ namespace ICSharpCode.FormDesigner
designSurface = new DesignSurface(serviceContainer); designSurface = new DesignSurface(serviceContainer);
eventBindingService.ServiceProvider = designSurface; eventBindingService.ServiceProvider = designSurface;
designerResourceService.Host = Host; designerResourceService.Host = Host;
designerResourceService.FileName = viewContent.FileName;
serviceContainer.AddService(typeof(IDesignerHost), Host); serviceContainer.AddService(typeof(IDesignerHost), Host);
DesignerLoader designerLoader = loader.CreateLoader(); DesignerLoader designerLoader = loader.CreateLoader();
@ -295,6 +297,15 @@ namespace ICSharpCode.FormDesigner
MergeFormChanges(); MergeFormChanges();
} }
public override void NotifyAfterSave(bool successful)
{
if (successful) {
if (designerResourceService != null) {
designerResourceService.Save();
}
}
}
protected void UpdateSelectableObjects() protected void UpdateSelectableObjects()
{ {
propertyContainer.SelectableObjects = Host.Container.Components; propertyContainer.SelectableObjects = Host.Container.Components;

56
src/AddIns/DisplayBindings/FormDesigner/Project/Src/FormDesigner/Services/DesignerResourceService.cs

@ -17,6 +17,7 @@ using System.ComponentModel.Design;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Project.Commands;
namespace ICSharpCode.FormDesigner.Services namespace ICSharpCode.FormDesigner.Services
{ {
@ -30,7 +31,6 @@ namespace ICSharpCode.FormDesigner.Services
protected IProject project; protected IProject project;
protected Hashtable Readers = new Hashtable();
protected Hashtable Writers = new Hashtable(); protected Hashtable Writers = new Hashtable();
#region ResourceStorage #region ResourceStorage
@ -62,15 +62,6 @@ namespace ICSharpCode.FormDesigner.Services
using (BinaryWriter binWriter = new BinaryWriter(System.IO.File.OpenWrite(fileName))) { using (BinaryWriter binWriter = new BinaryWriter(System.IO.File.OpenWrite(fileName))) {
binWriter.Write(this.storage); binWriter.Write(this.storage);
} }
// Add this resource file to the project
if (project != null && !project.IsFileInProject(fileName)) {
// ProjectFile fileInformation = ProjectService.AddFileToProject(project, fileName, BuildAction.EmbedAsResource);
// TODO: Project system...
// ICSharpCode.SharpDevelop.Gui.ProjectBrowser.ProjectBrowserView pbv = (ICSharpCode.SharpDevelop.Gui.ProjectBrowser.ProjectBrowserView)WorkbenchSingleton.Workbench.GetPad(typeof(ICSharpCode.SharpDevelop.Gui.ProjectBrowser.ProjectBrowserView));
// pbv.UpdateCombineTree();
// projectService.SaveCombine();
}
} }
} }
#endregion #endregion
@ -115,14 +106,12 @@ namespace ICSharpCode.FormDesigner.Services
try { try {
IResourceWriter resourceWriter = (IResourceWriter)Writers[info]; IResourceWriter resourceWriter = (IResourceWriter)Writers[info];
string fileName = CalcResourceFileName(info); string fileName = CalcResourceFileName(info);
if (resourceWriter == null) { if (resourceWriter == null) {
ResourceStorage resourceStorage = new ResourceStorage(new MemoryStream()); ResourceStorage resourceStorage = new ResourceStorage(new MemoryStream());
resources[fileName] = resourceStorage; resources[fileName] = resourceStorage;
resourceWriter = new ResourceWriter(resourceStorage.stream); resourceWriter = new ResourceWriter(resourceStorage.stream);
Writers[info] = resourceWriter; Writers[info] = resourceWriter;
resourceStorage.project = project; resourceStorage.project = project;
} }
return resourceWriter; return resourceWriter;
} catch (Exception e) { } catch (Exception e) {
@ -135,19 +124,14 @@ namespace ICSharpCode.FormDesigner.Services
{ {
try { try {
string fileName = CalcResourceFileName(info); string fileName = CalcResourceFileName(info);
IResourceReader resourceReader = (IResourceReader)Readers[info]; IResourceReader resourceReader = null;
if (resourceReader == null) {
if (resources != null && resources[fileName] != null) { if (resources != null && resources[fileName] != null) {
MemoryStream stream = (MemoryStream) ((ResourceStorage)resources[fileName]).stream; MemoryStream stream = new MemoryStream(((ResourceStorage)resources[fileName]).storage);
stream.Seek( 0, System.IO.SeekOrigin.Begin );
resourceReader = new ResourceReader(stream); resourceReader = new ResourceReader(stream);
} else if (File.Exists(fileName)) { } else if (File.Exists(fileName)) {
resourceReader = new ResourceReader(fileName); resourceReader = new ResourceReader(fileName);
} }
if (resourceReader != null) {
Readers[info] = resourceReader;
}
}
return resourceReader; return resourceReader;
} catch (Exception e) { } catch (Exception e) {
MessageService.ShowError(e); MessageService.ShowError(e);
@ -160,8 +144,21 @@ namespace ICSharpCode.FormDesigner.Services
{ {
if (resources != null) { if (resources != null) {
foreach (DictionaryEntry entry in resources) { foreach (DictionaryEntry entry in resources) {
string resourceFileName = (string)entry.Key;
FileUtility.ObservedSave(new NamedFileOperationDelegate(((ResourceStorage)entry.Value).Save), resourceFileName, FileErrorPolicy.Inform);
FileUtility.ObservedSave(new NamedFileOperationDelegate(((ResourceStorage)entry.Value).Save), (string) entry.Key, FileErrorPolicy.Inform); // Add this resource file to the project
if (project != null && !project.IsFileInProject(resourceFileName)) {
PadDescriptor pd = WorkbenchSingleton.Workbench.GetPad(typeof(ProjectBrowserPad));
FileNode formFileNode = ((ProjectBrowserPad)pd.PadContent).ProjectBrowserControl.FindFileNode(FileName);
if (formFileNode != null) {
FileNode fileNode = new FileNode(resourceFileName, FileNodeStatus.InProject);
fileNode.AddTo(formFileNode.Parent);
fileNode.EnsureVisible();
IncludeFileInProject.IncludeFileNode(fileNode);
ProjectService.SaveSolution();
}
}
} }
} }
} }
@ -178,13 +175,14 @@ namespace ICSharpCode.FormDesigner.Services
resourceFileName = new StringBuilder(Path.GetTempPath()); resourceFileName = new StringBuilder(Path.GetTempPath());
} }
resourceFileName.Append(Path.DirectorySeparatorChar); resourceFileName.Append(Path.DirectorySeparatorChar);
resourceFileName.Append(host.RootComponentClassName); resourceFileName.Append(host.RootComponent.Site.Name);
if (info != null && info.Name.Length > 0) { if (info != null && info.Name.Length > 0) {
resourceFileName.Append('.'); resourceFileName.Append('.');
resourceFileName.Append(info.Name); resourceFileName.Append(info.Name);
} }
resourceFileName.Append(".resources"); resourceFileName.Append(".resources");
return resourceFileName.ToString(); return resourceFileName.ToString();
} }
@ -210,12 +208,6 @@ namespace ICSharpCode.FormDesigner.Services
public void SerializationEnded(bool serialize) public void SerializationEnded(bool serialize)
{ {
if (serialize == true && resources != null) {
foreach (ResourceStorage storage in Resources.Values) {
storage.storage = storage.stream.ToArray();
}
}
foreach (IResourceWriter resourceWriter in Writers.Values) { foreach (IResourceWriter resourceWriter in Writers.Values) {
if (resourceWriter != null) { if (resourceWriter != null) {
resourceWriter.Close(); resourceWriter.Close();
@ -224,13 +216,11 @@ namespace ICSharpCode.FormDesigner.Services
} }
Writers.Clear(); Writers.Clear();
foreach (IResourceReader resourceReader in Readers.Values) { if (serialize == true && resources != null) {
if (resourceReader != null) { foreach (ResourceStorage storage in Resources.Values) {
resourceReader.Close(); storage.storage = storage.stream.ToArray();
resourceReader.Dispose();
} }
} }
Readers.Clear();
} }
public void Dispose() public void Dispose()

Loading…
Cancel
Save