~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/WizardPanels/Wizard/AbstractOptionPanel.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.Windows.Forms;
 
6
using ICSharpCode.Core;
 
7
using ICSharpCode.SharpDevelop;
 
8
using ICSharpCode.SharpDevelop.Gui.XmlForms;
 
9
using ICSharpCode.SharpDevelop.Project;
 
10
 
 
11
namespace ICSharpCode.Reports.Addin.ReportWizard
 
12
{
 
13
        public class AbstractOptionPanel : BaseSharpDevelopUserControl, IDialogPanel
 
14
        {
 
15
                bool   wasActivated = false;
 
16
                bool   isFinished   = true;
 
17
                object customizationObject;
 
18
                
 
19
                public Control Control {
 
20
                        get {
 
21
                                return this;
 
22
                        }
 
23
                }
 
24
                
 
25
                public bool WasActivated {
 
26
                        get {
 
27
                                return wasActivated;
 
28
                        }
 
29
                }
 
30
                
 
31
                public object CustomizationObject {
 
32
                        get {
 
33
                                return customizationObject;
 
34
                        }
 
35
                        set {
 
36
                                customizationObject = value;
 
37
                                OnCustomizationObjectChanged();
 
38
                        }
 
39
                }
 
40
                
 
41
                public virtual bool EnableFinish {
 
42
                        get {
 
43
                                return isFinished;
 
44
                        }
 
45
                        set {
 
46
                                if (isFinished != value) {
 
47
                                        isFinished = value;
 
48
                                        OnEnableFinishChanged();
 
49
                                }
 
50
                        }
 
51
                }
 
52
                
 
53
                
 
54
//              public AbstractOptionPanel(string fileName) : base(fileName)
 
55
//              {
 
56
//              }
 
57
                
 
58
                public AbstractOptionPanel()
 
59
                {
 
60
                }
 
61
                
 
62
                
 
63
                public virtual bool ReceiveDialogMessage(DialogMessage message)
 
64
                {
 
65
                        switch (message) {
 
66
                                case DialogMessage.Activated:
 
67
                                        if (!wasActivated) {
 
68
                                                LoadPanelContents();
 
69
                                                wasActivated = true;
 
70
                                        }
 
71
                                        break;
 
72
                                case DialogMessage.OK:
 
73
                                        if (wasActivated) {
 
74
                                                return StorePanelContents();
 
75
                                        }
 
76
                                        break;
 
77
                        }
 
78
                        
 
79
                        return true;
 
80
                }
 
81
                
 
82
                public virtual void LoadPanelContents()
 
83
                {
 
84
                        
 
85
                }
 
86
                
 
87
                public virtual bool StorePanelContents()
 
88
                {
 
89
                        return true;
 
90
                }
 
91
                
 
92
                protected string baseDirectory;
 
93
                
 
94
                protected void ConnectBrowseButton(string browseButton, string target, string fileFilter, TextBoxEditMode textBoxEditMode)
 
95
                {
 
96
                        if (ControlDictionary[browseButton] == null) {
 
97
                                
 
98
                                MessageService.ShowError(browseButton + " not found!");
 
99
                                return;
 
100
                        }
 
101
                        if (ControlDictionary[target] == null) {
 
102
                                MessageService.ShowError(target + " not found!");
 
103
                                return;
 
104
                        }
 
105
                        ControlDictionary[browseButton].Click += new EventHandler(new BrowseButtonEvent(this, ControlDictionary[target], fileFilter, textBoxEditMode).Event);
 
106
                }
 
107
                
 
108
                protected void ConnectBrowseFolder(string browseButton, string target, TextBoxEditMode textBoxEditMode)
 
109
                {
 
110
                        ConnectBrowseFolder(browseButton, target, "${res:Dialog.ProjectOptions.SelectFolderTitle}", textBoxEditMode);
 
111
                }
 
112
                protected void ConnectBrowseFolder(string browseButton, string target, string description, TextBoxEditMode textBoxEditMode)
 
113
                {
 
114
                        if (ControlDictionary[browseButton] == null) {
 
115
                                MessageService.ShowError(browseButton + " not found!");
 
116
                                return;
 
117
                        }
 
118
                        if (ControlDictionary[target] == null) {
 
119
                                MessageService.ShowError(target + " not found!");
 
120
                                return;
 
121
                        }
 
122
                        
 
123
                        ControlDictionary[browseButton].Click += new EventHandler(new BrowseFolderEvent(this, target, description, textBoxEditMode).Event);
 
124
                }
 
125
                protected void BrowseForFile(Control target, string filter, TextBoxEditMode textBoxEditMode)
 
126
                {
 
127
                        if (target == null) {
 
128
                                throw new ArgumentNullException("target");
 
129
                        }
 
130
                        new BrowseButtonEvent(this, target, filter, textBoxEditMode).Event(null, null);
 
131
                }
 
132
                
 
133
                sealed class BrowseButtonEvent
 
134
                {
 
135
                        AbstractOptionPanel panel;
 
136
                        Control target;
 
137
                        string filter;
 
138
                        TextBoxEditMode textBoxEditMode;
 
139
                        
 
140
                        public BrowseButtonEvent(AbstractOptionPanel panel, Control target, string filter, TextBoxEditMode textBoxEditMode)
 
141
                        {
 
142
                                this.panel  = panel;
 
143
                                this.filter = filter;
 
144
                                this.target = target;
 
145
                                this.textBoxEditMode = textBoxEditMode;
 
146
                        }
 
147
                        
 
148
                        public void Event(object sender, EventArgs e)
 
149
                        {
 
150
                                using (OpenFileDialog fdiag = new OpenFileDialog()) {
 
151
                                        fdiag.Filter      = StringParser.Parse(filter);
 
152
                                        fdiag.Multiselect = false;
 
153
                                        try {
 
154
                                                string initialDir = System.IO.Path.GetDirectoryName(System.IO.Path.Combine(panel.baseDirectory, target.Text));
 
155
                                                if (FileUtility.IsValidPath(initialDir) && System.IO.Directory.Exists(initialDir)) {
 
156
                                                        fdiag.InitialDirectory = initialDir;
 
157
                                                }
 
158
                                        } catch {}
 
159
                                        if(fdiag.ShowDialog() == DialogResult.OK) {
 
160
                                                string file = fdiag.FileName;
 
161
                                                if (panel.baseDirectory != null) {
 
162
                                                        file = FileUtility.GetRelativePath(panel.baseDirectory, file);
 
163
                                                }
 
164
                                                if (textBoxEditMode == TextBoxEditMode.EditEvaluatedProperty) {
 
165
                                                        target.Text = file;
 
166
                                                } else {
 
167
                                                        target.Text = MSBuildInternals.Escape(file);
 
168
                                                }
 
169
                                        }
 
170
                                }
 
171
                        }
 
172
                }
 
173
                
 
174
                sealed class BrowseFolderEvent
 
175
                {
 
176
                        AbstractOptionPanel panel;
 
177
                        string target;
 
178
                        string description;
 
179
                        TextBoxEditMode textBoxEditMode;
 
180
                        
 
181
                        internal BrowseFolderEvent(AbstractOptionPanel panel, string target, string description, TextBoxEditMode textBoxEditMode)
 
182
                        {
 
183
                                this.panel  = panel;
 
184
                                this.description = description;
 
185
                                this.target = target;
 
186
                                this.textBoxEditMode = textBoxEditMode;
 
187
                        }
 
188
                        
 
189
                        public void Event(object sender, EventArgs e)
 
190
                        {
 
191
                                string startLocation = panel.baseDirectory;
 
192
                                if (startLocation != null) {
 
193
                                        string text = panel.ControlDictionary[target].Text;
 
194
                                        if (textBoxEditMode == TextBoxEditMode.EditRawProperty)
 
195
                                                text = MSBuildInternals.Unescape(text);
 
196
                                        startLocation = FileUtility.GetAbsolutePath(startLocation, text);
 
197
                                }
 
198
                                
 
199
                                using (FolderBrowserDialog fdiag = FileService.CreateFolderBrowserDialog(description, startLocation)) {
 
200
                                        if (fdiag.ShowDialog() == DialogResult.OK) {
 
201
                                                string path = fdiag.SelectedPath;
 
202
                                                if (panel.baseDirectory != null) {
 
203
                                                        path = FileUtility.GetRelativePath(panel.baseDirectory, path);
 
204
                                                }
 
205
                                                if (!path.EndsWith("\\") && !path.EndsWith("/"))
 
206
                                                        path += "\\";
 
207
                                                if (textBoxEditMode == TextBoxEditMode.EditEvaluatedProperty) {
 
208
                                                        panel.ControlDictionary[target].Text = path;
 
209
                                                } else {
 
210
                                                        panel.ControlDictionary[target].Text = MSBuildInternals.Escape(path);
 
211
                                                }
 
212
                                        }
 
213
                                }
 
214
                        }
 
215
                }
 
216
                
 
217
                
 
218
                protected virtual void OnEnableFinishChanged()
 
219
                {
 
220
                        if (EnableFinishChanged != null) {
 
221
                                EnableFinishChanged(this, null);
 
222
                        }
 
223
                }
 
224
                protected virtual void OnCustomizationObjectChanged()
 
225
                {
 
226
                        if (CustomizationObjectChanged != null) {
 
227
                                CustomizationObjectChanged(this, null);
 
228
                        }
 
229
                }
 
230
                
 
231
                public event EventHandler CustomizationObjectChanged;
 
232
                public event EventHandler EnableFinishChanged;
 
233
        }
 
234
}