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)
5
using System.Windows.Forms;
6
using ICSharpCode.Core;
7
using ICSharpCode.SharpDevelop;
8
using ICSharpCode.SharpDevelop.Gui.XmlForms;
9
using ICSharpCode.SharpDevelop.Project;
11
namespace ICSharpCode.Reports.Addin.ReportWizard
13
public class AbstractOptionPanel : BaseSharpDevelopUserControl, IDialogPanel
15
bool wasActivated = false;
16
bool isFinished = true;
17
object customizationObject;
19
public Control Control {
25
public bool WasActivated {
31
public object CustomizationObject {
33
return customizationObject;
36
customizationObject = value;
37
OnCustomizationObjectChanged();
41
public virtual bool EnableFinish {
46
if (isFinished != value) {
48
OnEnableFinishChanged();
54
// public AbstractOptionPanel(string fileName) : base(fileName)
58
public AbstractOptionPanel()
63
public virtual bool ReceiveDialogMessage(DialogMessage message)
66
case DialogMessage.Activated:
72
case DialogMessage.OK:
74
return StorePanelContents();
82
public virtual void LoadPanelContents()
87
public virtual bool StorePanelContents()
92
protected string baseDirectory;
94
protected void ConnectBrowseButton(string browseButton, string target, string fileFilter, TextBoxEditMode textBoxEditMode)
96
if (ControlDictionary[browseButton] == null) {
98
MessageService.ShowError(browseButton + " not found!");
101
if (ControlDictionary[target] == null) {
102
MessageService.ShowError(target + " not found!");
105
ControlDictionary[browseButton].Click += new EventHandler(new BrowseButtonEvent(this, ControlDictionary[target], fileFilter, textBoxEditMode).Event);
108
protected void ConnectBrowseFolder(string browseButton, string target, TextBoxEditMode textBoxEditMode)
110
ConnectBrowseFolder(browseButton, target, "${res:Dialog.ProjectOptions.SelectFolderTitle}", textBoxEditMode);
112
protected void ConnectBrowseFolder(string browseButton, string target, string description, TextBoxEditMode textBoxEditMode)
114
if (ControlDictionary[browseButton] == null) {
115
MessageService.ShowError(browseButton + " not found!");
118
if (ControlDictionary[target] == null) {
119
MessageService.ShowError(target + " not found!");
123
ControlDictionary[browseButton].Click += new EventHandler(new BrowseFolderEvent(this, target, description, textBoxEditMode).Event);
125
protected void BrowseForFile(Control target, string filter, TextBoxEditMode textBoxEditMode)
127
if (target == null) {
128
throw new ArgumentNullException("target");
130
new BrowseButtonEvent(this, target, filter, textBoxEditMode).Event(null, null);
133
sealed class BrowseButtonEvent
135
AbstractOptionPanel panel;
138
TextBoxEditMode textBoxEditMode;
140
public BrowseButtonEvent(AbstractOptionPanel panel, Control target, string filter, TextBoxEditMode textBoxEditMode)
143
this.filter = filter;
144
this.target = target;
145
this.textBoxEditMode = textBoxEditMode;
148
public void Event(object sender, EventArgs e)
150
using (OpenFileDialog fdiag = new OpenFileDialog()) {
151
fdiag.Filter = StringParser.Parse(filter);
152
fdiag.Multiselect = false;
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;
159
if(fdiag.ShowDialog() == DialogResult.OK) {
160
string file = fdiag.FileName;
161
if (panel.baseDirectory != null) {
162
file = FileUtility.GetRelativePath(panel.baseDirectory, file);
164
if (textBoxEditMode == TextBoxEditMode.EditEvaluatedProperty) {
167
target.Text = MSBuildInternals.Escape(file);
174
sealed class BrowseFolderEvent
176
AbstractOptionPanel panel;
179
TextBoxEditMode textBoxEditMode;
181
internal BrowseFolderEvent(AbstractOptionPanel panel, string target, string description, TextBoxEditMode textBoxEditMode)
184
this.description = description;
185
this.target = target;
186
this.textBoxEditMode = textBoxEditMode;
189
public void Event(object sender, EventArgs e)
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);
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);
205
if (!path.EndsWith("\\") && !path.EndsWith("/"))
207
if (textBoxEditMode == TextBoxEditMode.EditEvaluatedProperty) {
208
panel.ControlDictionary[target].Text = path;
210
panel.ControlDictionary[target].Text = MSBuildInternals.Escape(path);
218
protected virtual void OnEnableFinishChanged()
220
if (EnableFinishChanged != null) {
221
EnableFinishChanged(this, null);
224
protected virtual void OnCustomizationObjectChanged()
226
if (CustomizationObjectChanged != null) {
227
CustomizationObjectChanged(this, null);
231
public event EventHandler CustomizationObjectChanged;
232
public event EventHandler EnableFinishChanged;