1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
6
using System.CodeDom.Compiler;
7
using System.Collections;
8
using System.Collections.Generic;
9
using System.ComponentModel;
11
using System.Reflection;
14
using ICSharpCode.Core;
15
using ICSharpCode.FormsDesigner;
16
using ICSharpCode.SharpDevelop;
17
using ICSharpCode.SharpDevelop.Dom;
18
using ICSharpCode.SharpDevelop.Editor;
19
using Microsoft.CSharp;
21
namespace ICSharpCode.WixBinding
24
/// Simplified designer generator interface that the WixDesignerLoader calls
25
/// when flushing the changes.
27
public interface IWixDialogDesignerGenerator
30
/// Passes the updated dialog element and its original id to the generator
31
/// so the wix document can be updated.
33
/// <remarks>The dialog id is passed since it becomes the name of the
34
/// form and this can be changed from the designer.</remarks>
35
void MergeFormChanges(string dialogId, XmlElement dialogElement);
38
public class WixDialogDesignerGenerator : IDesignerGenerator, IWixDialogDesignerGenerator
40
FormsDesignerViewContent view;
41
ITextEditor textEditor;
43
public CodeDomProvider CodeDomProvider {
44
get { return new CSharpCodeProvider(); }
47
public FormsDesignerViewContent ViewContent {
51
public IEnumerable<OpenedFile> GetSourceFiles(out OpenedFile designerCodeFile)
53
designerCodeFile = view.PrimaryFile;
54
return new [] {designerCodeFile};
57
public void Attach(FormsDesignerViewContent view)
60
textEditor = ((ITextEditorProvider)view.PrimaryViewContent).TextEditor;
69
/// Merges the changes made to the wix document by overwriting the dialog element.
71
void IWixDialogDesignerGenerator.MergeFormChanges(string dialogId, XmlElement dialogElement)
73
DomRegion region = GetTextEditorRegionForDialogElement(dialogId);
75
ThrowDialogElementCouldNotBeFoundError(dialogId);
78
WixTextWriter writer = new WixTextWriter(textEditor.Options);
79
WixDialogElement wixDialogElement = (WixDialogElement)dialogElement;
80
string newDialogXml = wixDialogElement.GetXml(writer);
82
WixDocumentEditor editor = new WixDocumentEditor(textEditor);
83
editor.Replace(region, newDialogXml);
86
DomRegion GetTextEditorRegionForDialogElement(string dialogId)
88
IDocument document = view.DesignerCodeFileDocument;
89
WixDocumentReader wixReader = new WixDocumentReader(document.Text);
90
return wixReader.GetElementRegion("Dialog", dialogId);
93
void ThrowDialogElementCouldNotBeFoundError(string dialogId)
95
string messageFormat = StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}");
96
string message = String.Format(messageFormat, dialogId);
97
throw new FormsDesignerLoadException(message);
100
public void MergeFormChanges(CodeCompileUnit unit)
104
public void NotifyComponentRenamed(object component, string newName, string oldName)
108
public bool InsertComponentEvent(IComponent component, EventDescriptor edesc, string eventMethodName, string body, out string file, out int position)
115
public ICollection GetCompatibleMethods(EventDescriptor edesc)
117
return new ArrayList();
120
public ICollection GetCompatibleMethods(EventInfo edesc)
122
return new ArrayList();