~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/ImageResourceEditorDialog.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.Collections.Generic;
 
6
using System.ComponentModel;
 
7
using System.Drawing;
 
8
using System.Drawing.Design;
 
9
using System.IO;
 
10
using System.Linq;
 
11
using System.Resources;
 
12
using System.Resources.Tools;
 
13
using System.Windows.Forms;
 
14
 
 
15
using ICSharpCode.Core;
 
16
using ICSharpCode.Core.WinForms;
 
17
using ICSharpCode.FormsDesigner.Services;
 
18
using ICSharpCode.SharpDevelop;
 
19
using ICSharpCode.SharpDevelop.Dom;
 
20
using ICSharpCode.SharpDevelop.Gui;
 
21
using ICSharpCode.SharpDevelop.Project;
 
22
 
 
23
namespace ICSharpCode.FormsDesigner.Gui
 
24
{
 
25
        /// <summary>
 
26
        /// Allows the user to select a resource for an image or icon property.
 
27
        /// </summary>
 
28
        public sealed partial class ImageResourceEditorDialog : Form
 
29
        {
 
30
                readonly IProject project;
 
31
                readonly Type requiredResourceType;
 
32
                object originalImage;
 
33
                bool selectedImageIsProjectResource;
 
34
                object selectedImage;
 
35
                
 
36
                #region Constructors
 
37
                
 
38
                ImageResourceEditorDialog(IProject project, Type requiredResourceType, bool designerSupportsProjectResources)
 
39
                        : base()
 
40
                {
 
41
                        if (requiredResourceType == null)
 
42
                                throw new ArgumentNullException("requiredResourceType");
 
43
                        this.requiredResourceType = requiredResourceType;
 
44
                        this.project = project;
 
45
                        
 
46
                        //
 
47
                        // The InitializeComponent() call is required for Windows Forms designer support.
 
48
                        //
 
49
                        InitializeComponent();
 
50
                        Translate(this);
 
51
                        
 
52
                        this.projectResourcesTreeView.Nodes.Add(ResourceService.GetString("Global.PleaseWait"));
 
53
                        
 
54
                        this.importLocalResourceButton.DataBindings.Add("Enabled", this.localResourceRadioButton, "Checked");
 
55
                        this.projectResourcesTreeView.DataBindings.Add("Enabled", this.projectResourceRadioButton, "Checked");
 
56
                        
 
57
                        this.projectResourceRadioButton.Visible = designerSupportsProjectResources;
 
58
                        this.projectResourcesTreeView.Visible = designerSupportsProjectResources;
 
59
                }
 
60
                
 
61
                public ImageResourceEditorDialog(IProject project, Type requiredResourceType, ProjectResourceInfo projectResource)
 
62
                        : this(project, requiredResourceType, true)
 
63
                {
 
64
                        if (projectResource == null)
 
65
                                throw new ArgumentNullException("projectResource");
 
66
                        
 
67
                        this.projectResourceRadioButton.Checked = true;
 
68
                        this.originalImage = this.selectedImage = projectResource.OriginalValue;
 
69
                        
 
70
                        Image image = this.selectedImage as Image;
 
71
                        if (image != null) {
 
72
                                this.selectedImageIsProjectResource = true;
 
73
                                this.SetPreviewImage(image);
 
74
                        } else {
 
75
                                Icon icon = this.selectedImage as Icon;
 
76
                                if (icon != null) {
 
77
                                        this.selectedImageIsProjectResource = true;
 
78
                                        this.SetPreviewImage(icon.ToBitmap());
 
79
                                }
 
80
                        }
 
81
                        this.projectTreeScanningBackgroundWorker.RunWorkerAsync(projectResource);
 
82
                }
 
83
                
 
84
                public ImageResourceEditorDialog(IProject project, Image localResource, bool designerSupportsProjectResources)
 
85
                        : this(project, typeof(Image), designerSupportsProjectResources)
 
86
                {
 
87
                        if (localResource != null) {
 
88
                                this.localResourceRadioButton.Checked = true;
 
89
                                this.originalImage = this.selectedImage = localResource;
 
90
                                this.SetPreviewImage(localResource);
 
91
                        } else {
 
92
                                this.noResourceRadioButton.Checked = true;
 
93
                        }
 
94
                        this.projectTreeScanningBackgroundWorker.RunWorkerAsync();
 
95
                }
 
96
                
 
97
                public ImageResourceEditorDialog(IProject project, Icon localResource, bool designerSupportsProjectResources)
 
98
                        : this(project, typeof(Icon), designerSupportsProjectResources)
 
99
                {
 
100
                        if (localResource != null) {
 
101
                                this.localResourceRadioButton.Checked = true;
 
102
                                this.originalImage = this.selectedImage = localResource;
 
103
                                this.SetPreviewImage(localResource.ToBitmap());
 
104
                        } else {
 
105
                                this.noResourceRadioButton.Checked = true;
 
106
                        }
 
107
                        this.projectTreeScanningBackgroundWorker.RunWorkerAsync();
 
108
                }
 
109
                
 
110
                static void Translate(Control c)
 
111
                {
 
112
                        c.Text = StringParser.Parse(c.Text);
 
113
                        foreach (Control child in c.Controls) {
 
114
                                Translate(child);
 
115
                        }
 
116
                }
 
117
                
 
118
                #endregion
 
119
                
 
120
                #region Properties
 
121
                
 
122
                /// <summary>
 
123
                /// Gets the <see cref="ProjectResourceInfo"/> for the selected project resource,
 
124
                /// or <c>null</c> if the selected resource is not a project resource.
 
125
                /// </summary>
 
126
                public ProjectResourceInfo SelectedProjectResource {
 
127
                        get {
 
128
                                if (this.selectedImageIsProjectResource && this.projectResourceRadioButton.Checked) {
 
129
                                        
 
130
                                        TreeNode node = this.projectResourcesTreeView.SelectedNode;
 
131
                                        if (node == null) return null;
 
132
                                        
 
133
                                        return new ProjectResourceInfo(((FileProjectItem)node.Parent.Tag).FileName, node.Text);
 
134
                                        
 
135
                                } else {
 
136
                                        return null;
 
137
                                }
 
138
                        }
 
139
                }
 
140
                
 
141
                /// <summary>
 
142
                /// Gets the selected image.
 
143
                /// This can be an Image or an Icon (matching the type that was passed to the constructor) or null.
 
144
                /// </summary>
 
145
                public object SelectedResourceValue {
 
146
                        get {
 
147
                                return this.selectedImage;
 
148
                        }
 
149
                }
 
150
                
 
151
                #endregion
 
152
                
 
153
                void SetPreviewImage(Image image)
 
154
                {
 
155
                        this.previewPictureBox.Image = image;
 
156
                        if (image != null) {
 
157
                                if (image.Width > this.previewPictureBox.ClientSize.Width ||
 
158
                                    image.Height > this.previewPictureBox.ClientSize.Height) {
 
159
                                        this.previewPictureBox.SizeMode = PictureBoxSizeMode.Zoom;
 
160
                                } else {
 
161
                                        this.previewPictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
 
162
                                }
 
163
                        }
 
164
                }
 
165
                
 
166
                void DisposeImageIfNotOriginal(object image)
 
167
                {
 
168
                        if (!Object.ReferenceEquals(image, this.originalImage)) {
 
169
                                IDisposable d = image as IDisposable;
 
170
                                if (d != null) {
 
171
                                        d.Dispose();
 
172
                                }
 
173
                        }
 
174
                }
 
175
                
 
176
                void SetSelectedImage(object image, bool isProjectResource)
 
177
                {
 
178
                        if (!Object.ReferenceEquals(this.selectedImage, this.previewPictureBox.Image)) {
 
179
                                Image temp = this.previewPictureBox.Image;
 
180
                                this.previewPictureBox.Image = null;
 
181
                                this.DisposeImageIfNotOriginal(temp);
 
182
                        } else {
 
183
                                this.previewPictureBox.Image = null;
 
184
                        }
 
185
                        
 
186
                        if (!this.selectedImageIsProjectResource) {
 
187
                                this.DisposeImageIfNotOriginal(this.selectedImage);
 
188
                        }
 
189
                        
 
190
                        Image img = image as Image;
 
191
                        if (img != null) {
 
192
                                this.selectedImage = img;
 
193
                                this.selectedImageIsProjectResource = isProjectResource;
 
194
                                this.SetPreviewImage(img);
 
195
                        } else {
 
196
                                Icon icon = image as Icon;
 
197
                                if (icon != null) {
 
198
                                        this.selectedImage = icon;
 
199
                                        this.selectedImageIsProjectResource = isProjectResource;
 
200
                                        this.SetPreviewImage(icon.ToBitmap());
 
201
                                } else {
 
202
                                        this.selectedImageIsProjectResource = false;
 
203
                                        this.selectedImage = null;
 
204
                                }
 
205
                        }
 
206
                }
 
207
                
 
208
                #region Project tree filling
 
209
                
 
210
                [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
 
211
                void ProjectTreeScanningBackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
 
212
                {
 
213
                        if (this.project == null) {
 
214
                                return;
 
215
                        }
 
216
                        
 
217
                        ProjectResourceInfo selectedProjectResource = e.Argument as ProjectResourceInfo;
 
218
                        
 
219
                        IProjectContent projectContent = ParserService.GetProjectContent(this.project);
 
220
                        
 
221
                        TreeNode root = new TreeNode(this.project.Name, 0, 0);
 
222
                        TreeNode preSelection = null;
 
223
                        TreeNode lastFileNode = null;
 
224
                        int fileNodesCount = 0;
 
225
                        
 
226
                        foreach (FileProjectItem item in this.project.GetItemsOfType(ItemType.EmbeddedResource).OfType<FileProjectItem>().OrderBy(fpi => Path.GetFileName(fpi.VirtualName))) {
 
227
                                
 
228
                                if (this.projectTreeScanningBackgroundWorker.CancellationPending) {
 
229
                                        e.Cancel = true;
 
230
                                        break;
 
231
                                }
 
232
                                
 
233
                                // Skip files where the generated class name
 
234
                                // would conflict with an existing class.
 
235
                                string namespaceName = item.GetEvaluatedMetadata("CustomToolNamespace");
 
236
                                if (string.IsNullOrEmpty(namespaceName)) {
 
237
                                        namespaceName = CustomToolsService.GetDefaultNamespace(item.Project, item.FileName);
 
238
                                }
 
239
                                IClass existingClass = projectContent.GetClass(namespaceName + "." + StronglyTypedResourceBuilder.VerifyResourceName(Path.GetFileNameWithoutExtension(item.FileName), projectContent.Language.CodeDomProvider), 0);
 
240
                                if (existingClass != null) {
 
241
                                        if (!ProjectResourceService.IsGeneratedResourceClass(existingClass)) {
 
242
                                                continue;
 
243
                                        }
 
244
                                }
 
245
                                
 
246
                                bool selectedFile = (selectedProjectResource != null) && FileUtility.IsEqualFileName(selectedProjectResource.ResourceFile, item.FileName);
 
247
                                TreeNode file = null;
 
248
                                
 
249
                                try {
 
250
                                        
 
251
                                        foreach (KeyValuePair<string, object> r in this.GetResources(item.FileName).OrderBy(pair => pair.Key)) {
 
252
                                                if (this.projectTreeScanningBackgroundWorker.CancellationPending) {
 
253
                                                        e.Cancel = true;
 
254
                                                        break;
 
255
                                                }
 
256
                                                
 
257
                                                if (file == null) {
 
258
                                                        file = CreateAndAddFileNode(root, item);
 
259
                                                }
 
260
                                                
 
261
                                                TreeNode resNode = new TreeNode(r.Key, 3, 3);
 
262
                                                resNode.Tag = r.Value;
 
263
                                                file.Nodes.Add(resNode);
 
264
                                                
 
265
                                                if (selectedFile) {
 
266
                                                        if (String.Equals(r.Key, selectedProjectResource.ResourceKey, StringComparison.Ordinal)) {
 
267
                                                                preSelection = resNode;
 
268
                                                        }
 
269
                                                }
 
270
                                        }
 
271
                                        
 
272
                                        if (file != null) {
 
273
                                                lastFileNode = file;
 
274
                                                ++fileNodesCount;
 
275
                                        }
 
276
                                        
 
277
                                } catch (Exception ex) {
 
278
                                        if (file == null) {
 
279
                                                file = CreateAndAddFileNode(root, item);
 
280
                                        }
 
281
                                        TreeNode error = new TreeNode(ex.Message, 4, 4);
 
282
                                        file.Nodes.Add(error);
 
283
                                }
 
284
                        }
 
285
                        
 
286
                        if (e.Cancel) {
 
287
                                DisposeNodeImages(root);
 
288
                        } else {
 
289
                                // Preselect the file node if there is only one
 
290
                                if (preSelection == null && fileNodesCount == 1) {
 
291
                                        preSelection = lastFileNode;
 
292
                                }
 
293
                                e.Result = new TreeScanResult(root, preSelection);
 
294
                        }
 
295
                }
 
296
                
 
297
                sealed class TreeScanResult {
 
298
                        readonly TreeNode root;
 
299
                        readonly TreeNode preSelection;
 
300
                        
 
301
                        public TreeNode Root {
 
302
                                get { return root; }
 
303
                        }
 
304
                        
 
305
                        public TreeNode PreSelection {
 
306
                                get { return preSelection; }
 
307
                        }
 
308
                        
 
309
                        public TreeScanResult(TreeNode root, TreeNode preSelection)
 
310
                        {
 
311
                                this.root = root;
 
312
                                this.preSelection = preSelection;
 
313
                        }
 
314
                }
 
315
                
 
316
                static TreeNode CreateAndAddFileNode(TreeNode root, FileProjectItem item)
 
317
                {
 
318
                        string directory = Path.GetDirectoryName(item.VirtualName);
 
319
                        TreeNode dir;
 
320
                        
 
321
                        if (String.IsNullOrEmpty(directory)) {
 
322
                                dir = root;
 
323
                        } else {
 
324
                                dir = GetOrCreateDirectoryNode(root, directory);
 
325
                        }
 
326
                        
 
327
                        TreeNode file = new TreeNode(Path.GetFileName(item.VirtualName), 2, 2);
 
328
                        file.Tag = item;
 
329
                        dir.Nodes.Add(file);
 
330
                        return file;
 
331
                }
 
332
                
 
333
                static TreeNode GetOrCreateDirectoryNode(TreeNode root, string directory)
 
334
                {
 
335
                        int index = directory.IndexOfAny(new [] {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar});
 
336
                        string searchDir;
 
337
                        
 
338
                        if (index == -1) {
 
339
                                searchDir = directory;
 
340
                        } else {
 
341
                                searchDir = directory.Substring(0, index);
 
342
                        }
 
343
                        
 
344
                        TreeNode node = null;
 
345
                        foreach (TreeNode n in root.Nodes) {
 
346
                                if (n.Text == searchDir) {
 
347
                                        node = n;
 
348
                                        break;
 
349
                                }
 
350
                        }
 
351
                        
 
352
                        if (node == null) {
 
353
                                node = new TreeNode(searchDir, 1, 1);
 
354
                                int insertIndex;
 
355
                                for (insertIndex = 0; insertIndex < root.Nodes.Count; insertIndex++) {
 
356
                                        TreeNode n = root.Nodes[insertIndex];
 
357
                                        if (n.ImageIndex != 1 || StringComparer.CurrentCulture.Compare(searchDir, n.Text) < 0) {
 
358
                                                break;
 
359
                                        }
 
360
                                }
 
361
                                root.Nodes.Insert(insertIndex, node);
 
362
                        }
 
363
                        
 
364
                        if (index == -1) {
 
365
                                return node;
 
366
                        } else {
 
367
                                return GetOrCreateDirectoryNode(node, directory.Substring(index + 1));
 
368
                        }
 
369
                }
 
370
                
 
371
                Dictionary<string, object> GetResources(string fileName)
 
372
                {
 
373
                        Stream s = null;
 
374
                        WorkbenchSingleton.SafeThreadCall(
 
375
                                delegate {
 
376
                                        OpenedFile file = FileService.GetOpenedFile(fileName);
 
377
                                        if (file != null) {
 
378
                                                s = file.OpenRead();
 
379
                                        }
 
380
                                });
 
381
                        if (s == null) {
 
382
                                s = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
 
383
                        }
 
384
                        using(s) {
 
385
                                using(IResourceReader reader = ResourceStore.CreateResourceReader(s, ResourceStore.GetResourceType(fileName))) {
 
386
                                        ResXResourceReader resXReader = reader as ResXResourceReader;
 
387
                                        if (resXReader != null) {
 
388
                                                resXReader.BasePath = Path.GetDirectoryName(fileName);
 
389
                                        }
 
390
                                        
 
391
                                        var resources = new Dictionary<string, object>();
 
392
                                        foreach (System.Collections.DictionaryEntry entry in reader) {
 
393
                                                if (entry.Value == null) continue;
 
394
                                                if (this.requiredResourceType.IsAssignableFrom(entry.Value.GetType())) {
 
395
                                                        resources.Add((string)entry.Key, entry.Value);
 
396
                                                }
 
397
                                        }
 
398
                                        return resources;
 
399
                                }
 
400
                        }
 
401
                }
 
402
                
 
403
                void ProjectTreeScanningBackgroundWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 
404
                {
 
405
                        if (this.IsDisposed || this.projectResourcesTreeView.IsDisposed) {
 
406
                                // This can happen when the dialog is closed before
 
407
                                // the scan has finished
 
408
                                if (!e.Cancelled && e.Error == null) {
 
409
                                        TreeScanResult r = e.Result as TreeScanResult;
 
410
                                        if (r != null) {
 
411
                                                DisposeNodeImages(r.Root);
 
412
                                        }
 
413
                                }
 
414
                                return;
 
415
                        }
 
416
                        
 
417
                        this.projectResourcesTreeView.Nodes.Clear();
 
418
                        
 
419
                        if (e.Cancelled) {
 
420
                                return;
 
421
                        }
 
422
                        
 
423
                        if (e.Error != null) {
 
424
                                MessageService.ShowException(e.Error, "Error in project tree scanning thread");
 
425
                        }
 
426
                        
 
427
                        TreeScanResult result = e.Result as TreeScanResult;
 
428
                        if (result == null) {
 
429
                                return;
 
430
                        }
 
431
                        
 
432
                        this.projectResourcesTreeView.BeginUpdate();
 
433
                        
 
434
                        ImageList imageList = new ImageList();
 
435
                        imageList.ColorDepth = ColorDepth.Depth32Bit;
 
436
                        imageList.Images.Add(IconService.GetBitmap(IconService.GetImageForProjectType(this.project.Language)));
 
437
                        imageList.Images.Add(WinFormsResourceService.GetBitmap("ProjectBrowser.Folder.Closed"));
 
438
                        imageList.Images.Add(IconService.GetBitmap(IconService.GetImageForFile("a.resx")));
 
439
                        imageList.Images.Add(WinFormsResourceService.GetBitmap("Icons.16x16.Field"));
 
440
                        imageList.Images.Add(WinFormsResourceService.GetBitmap("Icons.16x16.Error"));
 
441
                        this.projectResourcesTreeView.ImageList = imageList;
 
442
                        
 
443
                        this.projectResourcesTreeView.Nodes.Add(result.Root);
 
444
                        
 
445
                        if (result.PreSelection != null) {
 
446
                                result.PreSelection.EnsureVisible();
 
447
                                this.projectResourcesTreeView.SelectedNode = result.PreSelection;
 
448
                                result.PreSelection.Expand();
 
449
                        } else {
 
450
                                result.Root.Expand();
 
451
                        }
 
452
                        
 
453
                        this.projectResourcesTreeView.EndUpdate();
 
454
                        
 
455
                        if (result.PreSelection != null) {
 
456
                                this.projectResourcesTreeView.Focus();
 
457
                        }
 
458
                }
 
459
                
 
460
                #endregion
 
461
                
 
462
                void NoResourceRadioButtonCheckedChanged(object sender, EventArgs e)
 
463
                {
 
464
                        if (this.noResourceRadioButton.Checked) {
 
465
                                this.SetSelectedImage(null, false);
 
466
                                this.okButton.Enabled = true;
 
467
                        }
 
468
                }
 
469
                
 
470
                void LocalResourceRadioButtonCheckedChanged(object sender, EventArgs e)
 
471
                {
 
472
                        if (this.localResourceRadioButton.Checked) {
 
473
                                this.okButton.Enabled = true;
 
474
                        }
 
475
                }
 
476
                
 
477
                void ProjectResourceRadioButtonCheckedChanged(object sender, EventArgs e)
 
478
                {
 
479
                        if (this.projectResourceRadioButton.Checked) {
 
480
                                this.UpdateOnProjectResourceSelection();
 
481
                                this.projectResourcesTreeView.Focus();
 
482
                        }
 
483
                }
 
484
                
 
485
                void ProjectResourcesTreeViewAfterSelect(object sender, TreeViewEventArgs e)
 
486
                {
 
487
                        if (this.projectResourceRadioButton.Checked) {
 
488
                                this.UpdateOnProjectResourceSelection();
 
489
                        }
 
490
                }
 
491
                
 
492
                void UpdateOnProjectResourceSelection()
 
493
                {
 
494
                        TreeNode node = this.projectResourcesTreeView.SelectedNode;
 
495
                        if (node != null && node.Tag != null && this.requiredResourceType.IsAssignableFrom(node.Tag.GetType())) {
 
496
                                this.SetSelectedImage(node.Tag, true);
 
497
                                this.okButton.Enabled = true;
 
498
                        } else {
 
499
                                this.SetSelectedImage(null, false);
 
500
                                this.okButton.Enabled = false;
 
501
                        }
 
502
                }
 
503
                
 
504
                void ImageResourceEditorDialogFormClosed(object sender, FormClosedEventArgs e)
 
505
                {
 
506
                        this.projectTreeScanningBackgroundWorker.CancelAsync();
 
507
                        if (this.projectResourcesTreeView.Nodes.Count > 0) {
 
508
                                DisposeNodeImages(this.projectResourcesTreeView.Nodes[0]);
 
509
                        }
 
510
                }
 
511
                
 
512
                static void DisposeNodeImages(TreeNode root)
 
513
                {
 
514
                        if (root.Nodes.Count == 0) {
 
515
                                IDisposable d = root.Tag as IDisposable;
 
516
                                if (d != null) {
 
517
                                        d.Dispose();
 
518
                                }
 
519
                                root.Tag = null;
 
520
                        } else {
 
521
                                foreach (TreeNode node in root.Nodes) {
 
522
                                        DisposeNodeImages(node);
 
523
                                }
 
524
                        }
 
525
                }
 
526
                
 
527
                [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
 
528
                void ImportLocalResourceButtonClick(object sender, EventArgs e)
 
529
                {
 
530
                        bool isIcon = typeof(Icon).IsAssignableFrom(this.requiredResourceType);
 
531
                        using(OpenFileDialog dialog = new OpenFileDialog()) {
 
532
                                dialog.Filter = (isIcon ? DummyIconEditor.FileFilterEntry : DummyImageEditor.FileFilterEntry);
 
533
                                dialog.RestoreDirectory = true;
 
534
                                dialog.Title = StringParser.Parse("${res:ICSharpCode.SharpDevelop.FormDesigner.Gui.ImageResourceEditor.Title}");
 
535
                                if (dialog.ShowDialog(this) == DialogResult.OK && !String.IsNullOrEmpty(dialog.FileName)) {
 
536
                                        try {
 
537
                                                
 
538
                                                if (isIcon) {
 
539
                                                        this.SetSelectedImage(new Icon(dialog.FileName), false);
 
540
                                                } else {
 
541
                                                        this.SetSelectedImage(Image.FromFile(dialog.FileName), false);
 
542
                                                }
 
543
                                                
 
544
                                        } catch (Exception ex) {
 
545
                                                MessageService.ShowError(ex.Message);
 
546
                                        }
 
547
                                }
 
548
                        }
 
549
                }
 
550
                
 
551
                #region Dummy editors for getting the file filter from the framework
 
552
                
 
553
                sealed class DummyImageEditor : ImageEditor
 
554
                {
 
555
                        DummyImageEditor()
 
556
                        {
 
557
                        }
 
558
                        
 
559
                        internal static string FileFilterEntry {
 
560
                                get { return CreateFilterEntry(new ImageEditor()); }
 
561
                        }
 
562
                }
 
563
                
 
564
                sealed class DummyIconEditor : IconEditor
 
565
                {
 
566
                        DummyIconEditor()
 
567
                        {
 
568
                        }
 
569
                        
 
570
                        internal static string FileFilterEntry {
 
571
                                get { return CreateFilterEntry(new IconEditor()); }
 
572
                        }
 
573
                }
 
574
                
 
575
                #endregion
 
576
        }
 
577
}