~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/WixBinding/Project/Src/Gui/WixDialogDesignerGenerator.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
5
using System.CodeDom;
 
6
using System.CodeDom.Compiler;
 
7
using System.Collections;
 
8
using System.Collections.Generic;
 
9
using System.ComponentModel;
 
10
using System.IO;
 
11
using System.Reflection;
 
12
using System.Xml;
 
13
 
 
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;
 
20
 
 
21
namespace ICSharpCode.WixBinding
 
22
{
 
23
        /// <summary>
 
24
        /// Simplified designer generator interface that the WixDesignerLoader calls
 
25
        /// when flushing the changes.
 
26
        /// </summary>
 
27
        public interface IWixDialogDesignerGenerator
 
28
        {
 
29
                /// <summary>
 
30
                /// Passes the updated dialog element and its original id to the generator
 
31
                /// so the wix document can be updated.
 
32
                /// </summary>
 
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);
 
36
        }
 
37
        
 
38
        public class WixDialogDesignerGenerator : IDesignerGenerator, IWixDialogDesignerGenerator
 
39
        {
 
40
                FormsDesignerViewContent view;
 
41
                ITextEditor textEditor;
 
42
                
 
43
                public CodeDomProvider CodeDomProvider {
 
44
                        get { return new CSharpCodeProvider(); }
 
45
                }
 
46
                
 
47
                public FormsDesignerViewContent ViewContent {
 
48
                        get { return view; }
 
49
                }
 
50
                
 
51
                public IEnumerable<OpenedFile> GetSourceFiles(out OpenedFile designerCodeFile)
 
52
                {
 
53
                        designerCodeFile = view.PrimaryFile;
 
54
                        return new [] {designerCodeFile};
 
55
                }
 
56
                
 
57
                public void Attach(FormsDesignerViewContent view)
 
58
                {
 
59
                        this.view = view;
 
60
                        textEditor = ((ITextEditorProvider)view.PrimaryViewContent).TextEditor;
 
61
                }
 
62
                
 
63
                public void Detach()
 
64
                {
 
65
                        view = null;
 
66
                }
 
67
                
 
68
                /// <summary>
 
69
                /// Merges the changes made to the wix document by overwriting the dialog element.
 
70
                /// </summary>
 
71
                void IWixDialogDesignerGenerator.MergeFormChanges(string dialogId, XmlElement dialogElement)
 
72
                {
 
73
                        DomRegion region = GetTextEditorRegionForDialogElement(dialogId);
 
74
                        if (region.IsEmpty) {
 
75
                                ThrowDialogElementCouldNotBeFoundError(dialogId);
 
76
                        }
 
77
                        
 
78
                        WixTextWriter writer = new WixTextWriter(textEditor.Options);
 
79
                        WixDialogElement wixDialogElement = (WixDialogElement)dialogElement;
 
80
                        string newDialogXml = wixDialogElement.GetXml(writer);
 
81
                        
 
82
                        WixDocumentEditor editor = new WixDocumentEditor(textEditor);
 
83
                        editor.Replace(region, newDialogXml);
 
84
                }
 
85
                
 
86
                DomRegion GetTextEditorRegionForDialogElement(string dialogId)
 
87
                {
 
88
                        IDocument document = view.DesignerCodeFileDocument;
 
89
                        WixDocumentReader wixReader = new WixDocumentReader(document.Text);
 
90
                        return wixReader.GetElementRegion("Dialog", dialogId);
 
91
                }
 
92
                
 
93
                void ThrowDialogElementCouldNotBeFoundError(string dialogId)
 
94
                {
 
95
                        string messageFormat = StringParser.Parse("${res:ICSharpCode.WixBinding.DialogDesignerGenerator.DialogIdNotFoundMessage}");
 
96
                        string message = String.Format(messageFormat, dialogId);
 
97
                        throw new FormsDesignerLoadException(message);
 
98
                }
 
99
                
 
100
                public void MergeFormChanges(CodeCompileUnit unit)
 
101
                {
 
102
                }
 
103
                
 
104
                public void NotifyComponentRenamed(object component, string newName, string oldName)
 
105
                {
 
106
                }
 
107
                
 
108
                public bool InsertComponentEvent(IComponent component, EventDescriptor edesc, string eventMethodName, string body, out string file, out int position)
 
109
                {
 
110
                        file = null;
 
111
                        position = 0;
 
112
                        return false;
 
113
                }
 
114
                
 
115
                public ICollection GetCompatibleMethods(EventDescriptor edesc)
 
116
                {
 
117
                        return new ArrayList();
 
118
                }
 
119
                
 
120
                public ICollection GetCompatibleMethods(EventInfo edesc)
 
121
                {
 
122
                        return new ArrayList();
 
123
                }
 
124
        }
 
125
}