Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

2007-09-26 Ivan N. Zlatev <contact@i-nz.net>

        * DesignTime/CodeProviderDesignerLoader.cs: SetUIDirty to 
        clear the errors.
        * UI/ErrorListTabPage.cs, UI/ErrorList.cs: new TabPage.
        * UI/MainView.cs: refactor to use the ErrorListTabPage.
        * Project/Document.cs, UI/MainView.cs: Handle failed to 
        load documents.
        * Project/Document.cs: add disposing behavior.
        * Project/Document.cs, Project/Workspace.cs, UI/MainView.cs:
        Move document load/close logic to the workspace.
        * Project/Workspace.cs, UI/MainView.cs: documents now can be
        associated with a key object.
        * UI/PropertyGrid.cs: NRE fixes.

2007-09-19  Ivan N. Zlatev <contact@i-nz.net>

        * UI/MainView.cs: Show the Errors tab.

2007-09-18  Ivan N. Zlatev <contact@i-nz.net>

        * DesignTime/CodeProviderDesignerLoader.cs: Make use of
        * IUIService
        to report errors.
        * UI/ErrorList.cs: Add.


svn path=/trunk/mwf-designer/; revision=86374
  • Loading branch information...
commit 298b3ce6da4af6bce44505a34dc1511bdaa299bc 1 parent fda32c5
Ivan Zlatev ivanz authored
25 ChangeLog
... ... @@ -1,3 +1,28 @@
  1 +2007-09-26 Ivan N. Zlatev <contact@i-nz.net>
  2 +
  3 + * DesignTime/CodeProviderDesignerLoader.cs: SetUIDirty to
  4 + clear the errors.
  5 + * UI/ErrorListTabPage.cs, UI/ErrorList.cs: new TabPage.
  6 + * UI/MainView.cs: refactor to use the ErrorListTabPage.
  7 + * Project/Document.cs, UI/MainView.cs: Handle failed to
  8 + load documents.
  9 + * Project/Document.cs: add disposing behavior.
  10 + * Project/Document.cs, Project/Workspace.cs, UI/MainView.cs:
  11 + Move document load/close logic to the workspace.
  12 + * Project/Workspace.cs, UI/MainView.cs: documents now can be
  13 + associated with a key object.
  14 + * UI/PropertyGrid.cs: NRE fixes.
  15 +
  16 +2007-09-19 Ivan N. Zlatev <contact@i-nz.net>
  17 +
  18 + * UI/MainView.cs: Show the Errors tab.
  19 +
  20 +2007-09-18 Ivan N. Zlatev <contact@i-nz.net>
  21 +
  22 + * DesignTime/CodeProviderDesignerLoader.cs: Make use of IUIService
  23 + to report errors.
  24 + * UI/ErrorList.cs: Add.
  25 +
1 26 2007-09-13 Ivan N. Zlatev <contact@i-nz.net>
2 27
3 28 * UI/ReferencesDialog.cs: Allow referencing executables.
31 src/DesignTime/CodeProviderDesignerLoader.cs
@@ -26,12 +26,15 @@
26 26 //
27 27
28 28 using System;
  29 +using System.Collections;
29 30 using System.CodeDom;
30 31 using System.CodeDom.Compiler;
31 32 using System.ComponentModel;
32 33 using System.ComponentModel.Design;
33 34 using System.ComponentModel.Design.Serialization;
34 35 using System.IO;
  36 +using System.Windows.Forms.Design;
  37 +
35 38
36 39 #if WITH_MONO_DESIGN
37 40 using Mono.Design;
@@ -57,7 +60,7 @@ public CodeProviderDesignerLoader (CodeProvider provider)
57 60 }
58 61
59 62 protected override ITypeResolutionService TypeResolutionService {
60   - get { return base.LoaderHost.GetService (typeof (ITypeResolutionService)) as ITypeResolutionService; }
  63 + get { return base.GetService (typeof (ITypeResolutionService)) as ITypeResolutionService; }
61 64 }
62 65
63 66 protected override CodeCompileUnit Parse ()
@@ -69,5 +72,31 @@ protected override void Write (CodeCompileUnit unit)
69 72 {
70 73 _provider.Write (unit);
71 74 }
  75 +
  76 + protected override void OnEndLoad (bool successful, ICollection errors)
  77 + {
  78 + base.OnEndLoad (successful, errors);
  79 + ReportErrors (errors);
  80 + }
  81 +
  82 + protected override void ReportFlushErrors (ICollection errors)
  83 + {
  84 + base.ReportFlushErrors (errors);
  85 + ReportErrors (errors);
  86 + }
  87 +
  88 + private void ReportErrors (ICollection errors)
  89 + {
  90 + IUIService service = base.GetService (typeof (IUIService)) as IUIService;
  91 + if (service != null) {
  92 + service.SetUIDirty (); // clears the error list
  93 + foreach (object error in errors) {
  94 + if (error is Exception)
  95 + service.ShowError ((Exception) error);
  96 + else if (error is string)
  97 + service.ShowError ((string) error);
  98 + }
  99 + }
  100 + }
72 101 }
73 102 }
9 src/Program.cs
@@ -14,7 +14,14 @@ static void Main()
14 14 {
15 15 Application.EnableVisualStyles();
16 16 Application.SetCompatibleTextRenderingDefault(false);
17   - Application.Run(new MainView());
  17 + try {
  18 + Application.Run(new MainView());
  19 + } catch (Exception e) {
  20 + MessageBox.Show ("A fatal error occured. Please file a bug report with the following details (Ctrl-C to copy to clipboard):" +
  21 + System.Environment.NewLine + System.Environment.NewLine +
  22 + e.ToString (), "Fatal Error");
  23 + System.Windows.Forms.Application.Exit ();
  24 + }
18 25 }
19 26 }
20 27 }
42 src/Project/Document.cs
@@ -40,6 +40,7 @@ namespace mwf_designer
40 40 {
41 41 internal class Document : IDisposable
42 42 {
  43 + private bool _loaded;
43 44
44 45 private CodeProvider _codeProvider;
45 46 private Workspace _workspace;
@@ -56,10 +57,14 @@ public Document (string fileName, Workspace workspace)
56 57 throw new ArgumentNullException ("fileName");
57 58 _fileName = fileName;
58 59 _workspace = workspace;
  60 + _loaded = false;
59 61 }
60 62
61   - public void Load ()
  63 + public bool Load ()
62 64 {
  65 + if (_loaded)
  66 + return true;
  67 + _loaded = false;
63 68 _modified = false;
64 69
65 70 // Initialize code provider, loader and surface
@@ -74,22 +79,34 @@ public void Load ()
74 79 container.AddService (typeof (IEventBindingService), new CodeProviderEventBindingService (_codeProvider,
75 80 (IServiceProvider) container));
76 81 _surface.BeginLoad (_loader);
  82 + if (_surface.IsLoaded) {
  83 + _loaded = true;
  84 + // Mark as Modified on ComponentChanged
  85 + //
  86 + IComponentChangeService changeService = (IComponentChangeService)_surface.GetService (typeof (IComponentChangeService));
  87 + changeService.ComponentChanged += delegate {
  88 + _modified = true;
  89 + if (Modified != null)
  90 + Modified (this, EventArgs.Empty);
  91 + };
  92 + if (Loaded != null)
  93 + Loaded (this, EventArgs.Empty);
  94 + } else {
  95 + _surface.Dispose ();
  96 + _loader.Dispose ();
  97 + }
77 98
78   - // Mark as Modified on ComponentChanged
79   - //
80   - IComponentChangeService changeService = (IComponentChangeService)_surface.GetService (typeof (IComponentChangeService));
81   - changeService.ComponentChanged += delegate {
82   - _modified = true;
83   - if (Modified != null)
84   - Modified (this, EventArgs.Empty);
85   - };
86   - if (Loaded != null)
87   - Loaded (this, EventArgs.Empty);
  99 + return _loaded;
  100 + }
  101 +
  102 + public bool LoadSuccessful {
  103 + get { return _loaded; }
  104 + set { _loaded = value; }
88 105 }
89 106
90 107 public void Save ()
91 108 {
92   - if (_modified) {
  109 + if (_loaded && _modified) {
93 110 _surface.Flush ();
94 111 _modified = false;
95 112 }
@@ -123,6 +140,7 @@ public void Save ()
123 140 public void Dispose ()
124 141 {
125 142 _surface.Dispose ();
  143 + _codeProvider = null;
126 144 }
127 145
128 146 public event EventHandler Loaded;
6 src/Project/References.cs
@@ -43,6 +43,12 @@ public References ()
43 43 _assemblies = new List<Assembly> ();
44 44 }
45 45
  46 + public void Dispose ()
  47 + {
  48 + _assemblies.Clear ();
  49 + _assemblies = null;
  50 + }
  51 +
46 52 public void AddReference (Assembly assembly)
47 53 {
48 54 if (assembly == null)
57 src/Project/Workspace.cs
@@ -41,14 +41,14 @@ namespace mwf_designer
41 41 internal class Workspace
42 42 {
43 43
44   - private List<Document> _documents;
  44 + private Dictionary<object, Document> _documents;
45 45 private Document _activeDocument;
46 46 private References _references;
47 47 private ServiceContainer _serviceContainer;
48 48
49 49 public Workspace ()
50 50 {
51   - _documents = new List<Document>();
  51 + _documents = new Dictionary<object, Document>();
52 52 _activeDocument = null;
53 53 _references = new References ();
54 54 _serviceContainer = new ServiceContainer ();
@@ -60,6 +60,16 @@ public void Load ()
60 60 LoadDefaultServices (_serviceContainer);
61 61 }
62 62
  63 + public void Dispose ()
  64 + {
  65 + _activeDocument = null;
  66 + _documents = null;
  67 + _references.Dispose ();
  68 + _references = null;
  69 + _serviceContainer.Dispose ();
  70 + _serviceContainer = null;
  71 + }
  72 +
63 73 private void LoadDefaultServices (IServiceContainer container)
64 74 {
65 75 container.AddService (typeof (ITypeResolutionService), new TypeResolutionService (this.References));
@@ -76,14 +86,45 @@ private void LoadDefaultReferences (References references)
76 86 get { return _references; }
77 87 }
78 88
79   - public void AddDocument (Document doc)
  89 + public Document LoadDocument (string file)
80 90 {
81   - _documents.Add (doc);
  91 + return LoadDocument (file, file);
82 92 }
83 93
84   - public void RemoveDocument (Document doc)
  94 + public Document LoadDocument (string file, object identifierKey)
85 95 {
86   - _documents.Remove (doc);
  96 + Document doc = new Document (file, this);
  97 + _documents[identifierKey] = doc;
  98 + doc.Load ();
  99 + return doc;
  100 + }
  101 +
  102 + public Document GetDocument (object identifierKey)
  103 + {
  104 + return _documents[identifierKey];
  105 + }
  106 +
  107 + public void CloseDocument (Document doc)
  108 + {
  109 + object key = null;
  110 + foreach (KeyValuePair<object, Document> kvp in _documents)
  111 + if (doc == kvp.Value)
  112 + key = kvp.Key;
  113 + if (key != null)
  114 + CloseDocument (key);
  115 + }
  116 +
  117 + public void CloseDocument (object identifierKey)
  118 + {
  119 + Document doc = _documents[identifierKey];
  120 + if (doc != null) {
  121 + if (doc.IsModified && doc.LoadSuccessful)
  122 + doc.Save ();
  123 + _documents[identifierKey] = null;
  124 + doc.Dispose ();
  125 + }
  126 +
  127 + // TODO: Handle active document change here if closed doc is active
87 128 }
88 129
89 130 public ServiceContainer Services {
@@ -99,7 +140,6 @@ public void RemoveDocument (Document doc)
99 140 }
100 141 }
101 142
102   -
103 143 private static readonly Type[] containers = new Type[] {
104 144 typeof (System.Windows.Forms.FlowLayoutPanel),
105 145 typeof (System.Windows.Forms.GroupBox),
@@ -235,9 +275,6 @@ internal class ActiveDocumentChangedEventArgs : EventArgs
235 275
236 276 public ActiveDocumentChangedEventArgs (Document newDocument, Document oldDocument)
237 277 {
238   - if (newDocument == null)
239   - throw new ArgumentNullException ("newDocument");
240   -
241 278 _newDocument = newDocument;
242 279 _oldDocument = oldDocument;
243 280 }
142 src/UI/ErrorList.Designer.cs
... ... @@ -0,0 +1,142 @@
  1 +namespace mwf_designer
  2 +{
  3 + partial class ErrorList
  4 + {
  5 + /// <summary>
  6 + /// Required designer variable.
  7 + /// </summary>
  8 + private System.ComponentModel.IContainer components = null;
  9 +
  10 + /// <summary>
  11 + /// Clean up any resources being used.
  12 + /// </summary>
  13 + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  14 + protected override void Dispose (bool disposing)
  15 + {
  16 + if (disposing && (components != null)) {
  17 + components.Dispose ();
  18 + }
  19 + base.Dispose (disposing);
  20 + }
  21 +
  22 + #region Component Designer generated code
  23 +
  24 + /// <summary>
  25 + /// Required method for Designer support - do not modify
  26 + /// the contents of this method with the code editor.
  27 + /// </summary>
  28 + private void InitializeComponent ()
  29 + {
  30 + this.splitContainer1 = new System.Windows.Forms.SplitContainer();
  31 + this._errorsList = new System.Windows.Forms.ListBox();
  32 + this.splitContainer2 = new System.Windows.Forms.SplitContainer();
  33 + this._detailedText = new System.Windows.Forms.TextBox();
  34 + this.saveButton = new System.Windows.Forms.Button();
  35 + this.splitContainer1.Panel1.SuspendLayout();
  36 + this.splitContainer1.Panel2.SuspendLayout();
  37 + this.splitContainer1.SuspendLayout();
  38 + this.splitContainer2.Panel1.SuspendLayout();
  39 + this.splitContainer2.Panel2.SuspendLayout();
  40 + this.splitContainer2.SuspendLayout();
  41 + this.SuspendLayout();
  42 + //
  43 + // splitContainer1
  44 + //
  45 + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
  46 + this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
  47 + this.splitContainer1.Location = new System.Drawing.Point(0, 0);
  48 + this.splitContainer1.Name = "splitContainer1";
  49 + this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
  50 + //
  51 + // splitContainer1.Panel1
  52 + //
  53 + this.splitContainer1.Panel1.Controls.Add(this._errorsList);
  54 + //
  55 + // splitContainer1.Panel2
  56 + //
  57 + this.splitContainer1.Panel2.Controls.Add(this.splitContainer2);
  58 + this.splitContainer1.Size = new System.Drawing.Size(737, 492);
  59 + this.splitContainer1.SplitterDistance = 160;
  60 + this.splitContainer1.TabIndex = 0;
  61 + //
  62 + // _errorsList
  63 + //
  64 + this._errorsList.Dock = System.Windows.Forms.DockStyle.Fill;
  65 + this._errorsList.FormattingEnabled = true;
  66 + this._errorsList.IntegralHeight = false;
  67 + this._errorsList.Location = new System.Drawing.Point(0, 0);
  68 + this._errorsList.Name = "_errorsList";
  69 + this._errorsList.Size = new System.Drawing.Size(737, 121);
  70 + this._errorsList.TabIndex = 3;
  71 + this._errorsList.HorizontalScrollbar = true;
  72 + this._errorsList.SelectedIndexChanged += new System.EventHandler(this.errorsList_SelectedIndexChanged);
  73 + //
  74 + // splitContainer2
  75 + //
  76 + this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
  77 + this.splitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
  78 + this.splitContainer2.IsSplitterFixed = true;
  79 + this.splitContainer2.Location = new System.Drawing.Point(0, 0);
  80 + this.splitContainer2.Name = "splitContainer2";
  81 + this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
  82 + //
  83 + // splitContainer2.Panel1
  84 + //
  85 + this.splitContainer2.Panel1.Controls.Add(this._detailedText);
  86 + //
  87 + // splitContainer2.Panel2
  88 + //
  89 + this.splitContainer2.Panel2.Controls.Add(this.saveButton);
  90 + this.splitContainer2.Size = new System.Drawing.Size(737, 367);
  91 + this.splitContainer2.SplitterDistance = 335;
  92 + this.splitContainer2.TabIndex = 0;
  93 + //
  94 + // _detailedText
  95 + //
  96 + this._detailedText.Dock = System.Windows.Forms.DockStyle.Fill;
  97 + this._detailedText.Location = new System.Drawing.Point(0, 0);
  98 + this._detailedText.Multiline = true;
  99 + this._detailedText.Name = "_detailedText";
  100 + this._detailedText.ReadOnly = true;
  101 + this._detailedText.Size = new System.Drawing.Size(737, 335);
  102 + this._detailedText.TabIndex = 2;
  103 + //
  104 + // saveButton
  105 + //
  106 + this.saveButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  107 + | System.Windows.Forms.AnchorStyles.Right)));
  108 + this.saveButton.Location = new System.Drawing.Point(640, 2);
  109 + this.saveButton.Name = "saveButton";
  110 + this.saveButton.Size = new System.Drawing.Size(94, 23);
  111 + this.saveButton.TabIndex = 0;
  112 + this.saveButton.Text = "Save log to file";
  113 + this.saveButton.UseVisualStyleBackColor = true;
  114 + this.saveButton.Click += new System.EventHandler(this.saveButton_Click);
  115 + //
  116 + // ErrorList
  117 + //
  118 + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  119 + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  120 + this.Controls.Add(this.splitContainer1);
  121 + this.Name = "ErrorList";
  122 + this.Size = new System.Drawing.Size(737, 492);
  123 + this.splitContainer1.Panel1.ResumeLayout(false);
  124 + this.splitContainer1.Panel2.ResumeLayout(false);
  125 + this.splitContainer1.ResumeLayout(false);
  126 + this.splitContainer2.Panel1.ResumeLayout(false);
  127 + this.splitContainer2.Panel1.PerformLayout();
  128 + this.splitContainer2.Panel2.ResumeLayout(false);
  129 + this.splitContainer2.ResumeLayout(false);
  130 + this.ResumeLayout(false);
  131 +
  132 + }
  133 +
  134 + #endregion
  135 +
  136 + private System.Windows.Forms.SplitContainer splitContainer1;
  137 + private System.Windows.Forms.SplitContainer splitContainer2;
  138 + private System.Windows.Forms.TextBox _detailedText;
  139 + private System.Windows.Forms.Button saveButton;
  140 + private System.Windows.Forms.ListBox _errorsList;
  141 + }
  142 +}
124 src/UI/ErrorList.cs
... ... @@ -0,0 +1,124 @@
  1 +//
  2 +// Authors:
  3 +// Ivan N. Zlatev (contact i-nZ.net)
  4 +//
  5 +// (C) 2007 Ivan N. Zlatev
  6 +
  7 +//
  8 +// Permission is hereby granted, free of charge, to any person obtaining
  9 +// a copy of this software and associated documentation files (the
  10 +// "Software"), to deal in the Software without restriction, including
  11 +// without limitation the rights to use, copy, modify, merge, publish,
  12 +// distribute, sublicense, and/or sell copies of the Software, and to
  13 +// permit persons to whom the Software is furnished to do so, subject to
  14 +// the following conditions:
  15 +//
  16 +// The above copyright notice and this permission notice shall be
  17 +// included in all copies or substantial portions of the Software.
  18 +//
  19 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20 +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22 +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23 +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24 +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25 +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26 +//
  27 +
  28 +using System;
  29 +using System.Collections;
  30 +using System.Collections.Generic;
  31 +using System.ComponentModel;
  32 +using System.Drawing;
  33 +using System.Data;
  34 +using System.Text;
  35 +using System.Windows.Forms;
  36 +using System.IO;
  37 +
  38 +namespace mwf_designer
  39 +{
  40 + internal partial class ErrorList : UserControl
  41 + {
  42 +
  43 + private class Error
  44 + {
  45 + private string _details;
  46 + private string _message;
  47 +
  48 + public Error (string message, string details)
  49 + {
  50 + if (message == null)
  51 + throw new ArgumentNullException ("message");
  52 + _details = details;
  53 + _message = message;
  54 + }
  55 +
  56 + public string Details {
  57 + get { return _details; }
  58 + set { _details = value; }
  59 + }
  60 +
  61 + public string Message {
  62 + get { return _message; }
  63 + set { _message = value; }
  64 + }
  65 +
  66 + public override string ToString ()
  67 + {
  68 + return _message;
  69 + }
  70 + }
  71 +
  72 + public ErrorList ()
  73 + {
  74 + InitializeComponent ();
  75 + }
  76 +
  77 + private void saveButton_Click (object sender, EventArgs e)
  78 + {
  79 + SaveFileDialog dialog = new SaveFileDialog();
  80 + dialog.OverwritePrompt = true;
  81 + if (dialog.ShowDialog() == DialogResult.OK)
  82 + WriteErrorsToFile (dialog.FileName);
  83 + }
  84 +
  85 + private void errorsList_SelectedIndexChanged (object sender, EventArgs e)
  86 + {
  87 + if (_errorsList.SelectedIndex != -1) {
  88 + Error error = (Error) _errorsList.Items[_errorsList.SelectedIndex];
  89 + _detailedText.Text = error.Details;
  90 + }
  91 + }
  92 +
  93 + public void AddError (string message, string details)
  94 + {
  95 + _errorsList.Items.Add (new Error (message, details));
  96 + }
  97 +
  98 + private void WriteErrorsToFile (string fileName)
  99 + {
  100 + StringBuilder sb = new StringBuilder ();
  101 + foreach (Error error in _errorsList.Items) {
  102 + sb.AppendLine ("==== " + error.Message + " ====");
  103 + sb.Append (Environment.NewLine);
  104 + sb.Append (error.Details);
  105 + sb.Append (Environment.NewLine);
  106 + sb.Append (Environment.NewLine);
  107 + }
  108 +
  109 + FileStream stream = File.OpenWrite (fileName);
  110 + byte [] bytes = Encoding.Default.GetBytes (sb.ToString ());
  111 + stream.Write (bytes, 0, bytes.Length);
  112 + stream.Close ();
  113 + stream.Dispose ();
  114 + }
  115 +
  116 + public void Clear ()
  117 + {
  118 + _errorsList.SuspendLayout ();
  119 + _errorsList.Items.Clear ();
  120 + _errorsList.ResumeLayout ();
  121 + _detailedText.Text = "";
  122 + }
  123 + }
  124 +}
144 src/UI/ErrorListTabPage.cs
... ... @@ -0,0 +1,144 @@
  1 +//
  2 +// Authors:
  3 +// Ivan N. Zlatev (contact i-nZ.net)
  4 +//
  5 +// (C) 2007 Ivan N. Zlatev
  6 +
  7 +//
  8 +// Permission is hereby granted, free of charge, to any person obtaining
  9 +// a copy of this software and associated documentation files (the
  10 +// "Software"), to deal in the Software without restriction, including
  11 +// without limitation the rights to use, copy, modify, merge, publish,
  12 +// distribute, sublicense, and/or sell copies of the Software, and to
  13 +// permit persons to whom the Software is furnished to do so, subject to
  14 +// the following conditions:
  15 +//
  16 +// The above copyright notice and this permission notice shall be
  17 +// included in all copies or substantial portions of the Software.
  18 +//
  19 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  20 +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  22 +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  23 +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  24 +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  25 +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26 +//
  27 +
  28 +using System;
  29 +using System.Collections;
  30 +using System.Collections.Generic;
  31 +using System.Windows.Forms;
  32 +using System.Windows.Forms.Design;
  33 +
  34 +namespace mwf_designer
  35 +{
  36 + internal class ErrorListTabPage : TabPage, IUIService
  37 + {
  38 + private ErrorList _errorList;
  39 + private readonly string ERRORS_TAB_KEY = @"!?\/#__Errors__!?\/#";
  40 + private readonly string ERRORS_TAB_TEXT = "Errors";
  41 +
  42 + public ErrorListTabPage ()
  43 + {
  44 + InitializeComponent ();
  45 + }
  46 +
  47 + private void InitializeComponent ()
  48 + {
  49 + _errorList = new ErrorList ();
  50 + _errorList.Dock = DockStyle.Fill;
  51 +
  52 + this.Name = ERRORS_TAB_KEY;
  53 + this.Text = ERRORS_TAB_TEXT;
  54 + this.Controls.Add (_errorList);
  55 + }
  56 +
  57 +#region IUIService
  58 +
  59 + private IDictionary _styles;
  60 +
  61 + void IUIService.SetUIDirty ()
  62 + {
  63 + _errorList.Clear ();
  64 + }
  65 +
  66 + void IUIService.ShowError (Exception exception)
  67 + {
  68 + string details = exception.StackTrace;
  69 +
  70 + if (exception.Data["Details"] != null)
  71 + details = (string)exception.Data["Details"] + System.Environment.NewLine + System.Environment.NewLine + details;
  72 +
  73 + _errorList.AddError (exception.Message, details);
  74 + }
  75 +
  76 + void IUIService.ShowError (string message)
  77 + {
  78 + _errorList.AddError (message, Environment.StackTrace);
  79 + }
  80 +
  81 + void IUIService.ShowError (Exception exception, string message)
  82 + {
  83 + _errorList.AddError (message, exception.ToString ());
  84 + }
  85 +
  86 + void IUIService.ShowMessage (string message)
  87 + {
  88 + _errorList.AddError (message, Environment.StackTrace);
  89 + }
  90 +
  91 + void IUIService.ShowMessage (string message, string caption)
  92 + {
  93 + _errorList.AddError (caption, message);
  94 + }
  95 +
  96 + DialogResult IUIService.ShowMessage (string message, string caption, MessageBoxButtons buttons)
  97 + {
  98 + throw new NotImplementedException ();
  99 + }
  100 +
  101 + IDictionary IUIService.Styles {
  102 + get {
  103 + if (_styles == null)
  104 + _styles = new Hashtable ();
  105 + return _styles;
  106 + }
  107 + }
  108 +
  109 + IWin32Window IUIService.GetDialogOwnerWindow ()
  110 + {
  111 + Control parent = this.Parent;
  112 +
  113 + while (parent != null) {
  114 + if (parent is Form)
  115 + return (Form)parent;
  116 + parent = parent.Parent;
  117 + }
  118 +
  119 + return null;
  120 + }
  121 +
  122 + bool IUIService.CanShowComponentEditor (object component)
  123 + {
  124 + throw new NotImplementedException ();
  125 + }
  126 +
  127 + bool IUIService.ShowComponentEditor (object component, IWin32Window parent)
  128 + {
  129 + throw new NotImplementedException ();
  130 + }
  131 +
  132 + DialogResult IUIService.ShowDialog (Form form)
  133 + {
  134 + throw new NotImplementedException ();
  135 + }
  136 +
  137 + bool IUIService.ShowToolWindow (Guid toolWindow)
  138 + {
  139 + throw new NotImplementedException ();
  140 + }
  141 +#endregion
  142 +
  143 + }
  144 +}
102 src/UI/MainView.cs
@@ -48,6 +48,7 @@ namespace mwf_designer
48 48 public partial class MainView : Form
49 49 {
50 50 Workspace _workspace;
  51 + private readonly string MODIFIED_MARKER = " *";
51 52
52 53 public MainView ()
53 54 {
@@ -56,18 +57,6 @@ public MainView ()
56 57 LoadWorkspace ();
57 58 }
58 59
59   - private IComponent GetPrimarySelection (Document document)
60   - {
61   - if (document == null)
62   - throw new ArgumentNullException ("document");
63   -
64   - ISelectionService service = document.DesignSurface.GetService (typeof (ISelectionService)) as ISelectionService;
65   - if (service != null)
66   - return (IComponent) service.PrimarySelection;
67   - else
68   - return null;
69   - }
70   -
71 60 private void openToolStripMenuItem_Click (object sender, EventArgs e)
72 61 {
73 62 OpenFileDialog dialog = new OpenFileDialog ();
@@ -99,16 +88,37 @@ private void OnToolbox_ToolPicked (object sender, EventArgs args)
99 88 private void LoadWorkspace ()
100 89 {
101 90 _workspace = new Workspace ();
102   - _workspace.ActiveDocumentChanged += delegate (object sender, ActiveDocumentChangedEventArgs args) {
103   - propertyGrid.ActiveComponents = new object[] { GetPrimarySelection (args.NewDocument) };
  91 + surfaceTabs.SelectedIndexChanged += delegate {
  92 + UpdateWorkspaceActiveDocument ();
104 93 };
  94 + _workspace.ActiveDocumentChanged += OnActiveDocumentChanged;
105 95 _workspace.References.ReferencesChanged += delegate {
106 96 PopulateToolbox (toolbox, _workspace.References);
107 97 };
108 98 _workspace.Services.AddService (typeof (IToolboxService), (IToolboxService) toolbox);
  99 + AddErrorsTab ();
109 100 _workspace.Load ();
110 101 }
111 102
  103 + private IComponent GetPrimarySelection (Document document)
  104 + {
  105 + if (document == null)
  106 + throw new ArgumentNullException ("document");
  107 +
  108 + ISelectionService service = document.DesignSurface.GetService (typeof (ISelectionService)) as ISelectionService;
  109 + if (service != null)
  110 + return (IComponent) service.PrimarySelection;
  111 + else
  112 + return null;
  113 + }
  114 +
  115 + private void AddErrorsTab ()
  116 + {
  117 + ErrorListTabPage errors = new ErrorListTabPage ();
  118 + surfaceTabs.TabPages.Add (errors);
  119 + _workspace.Services.AddService (typeof (IUIService), (IUIService) errors);
  120 + }
  121 +
112 122 // Currently populates with all MWF Controls that have a public ctor with no params
113 123 //
114 124 private void PopulateToolbox (ToolBoxList toolbox, References references)
@@ -127,20 +137,42 @@ private void PopulateToolbox (ToolBoxList toolbox, References references)
127 137
128 138 private void LoadDocument (string file, Workspace workspace)
129 139 {
130   - Document doc = new Document (file, workspace);
131   - doc.Load ();
132   - doc.Modified += delegate {
133   - if (!surfaceTabs.TabPages[file].Text.EndsWith (" *"))
134   - surfaceTabs.TabPages[file].Text += " *";
135   - };
136   - workspace.AddDocument (doc);
137   - workspace.ActiveDocument = doc;
138   - surfaceTabs.TabPages.Add (file, Path.GetFileNameWithoutExtension (file));
139   - surfaceTabs.TabPages[file].Controls.Add ((Control)doc.DesignSurface.View);
140   - surfaceTabs.SelectedTab = surfaceTabs.TabPages[file];
  140 + TabPage tab = new TabPage (Path.GetFileNameWithoutExtension (file));
  141 + tab.Name = file; // the key
  142 +
  143 + // loads and associates the tab page with the document
  144 + Document doc = workspace.LoadDocument (file, tab);
  145 + if (doc.LoadSuccessful) {
  146 + doc.Modified += OnDocumentModified;
  147 + workspace.ActiveDocument = doc;
  148 + tab.Controls.Add ((Control)doc.DesignSurface.View);
  149 + surfaceTabs.TabPages.Add (tab);
  150 + surfaceTabs.SelectedTab = surfaceTabs.TabPages[file];
  151 + } else {
  152 + workspace.CloseDocument (doc);
  153 + tab.Dispose ();
  154 + }
  155 + }
  156 +
  157 + private void OnDocumentModified (object sender, EventArgs args)
  158 + {
  159 + if (!surfaceTabs.SelectedTab.Text.EndsWith (MODIFIED_MARKER))
  160 + surfaceTabs.SelectedTab.Text += MODIFIED_MARKER;
  161 + }
  162 +
  163 + private void OnActiveDocumentChanged (object sender, ActiveDocumentChangedEventArgs args)
  164 + {
  165 + object primarySelection = args.NewDocument != null ? GetPrimarySelection (args.NewDocument) : null;
  166 + propertyGrid.ActiveComponents = primarySelection != null ? new object[] { primarySelection } : new object[0];
  167 + }
  168 +
  169 + private void CloseDocument (Document doc)
  170 + {
  171 + doc.Modified -= OnDocumentModified;
  172 + _workspace.CloseDocument (doc);
  173 + surfaceTabs.TabPages.Remove (surfaceTabs.SelectedTab);
141 174 }
142 175
143   -
144 176 private void newToolStripMenuItem_Click (object sender, EventArgs e)
145 177 {
146 178 NewFileDialog dialog = new NewFileDialog (TemplateManager.AvailableTemplates);
@@ -151,6 +183,15 @@ private void newToolStripMenuItem_Click (object sender, EventArgs e)
151 183 }
152 184 }
153 185
  186 + private void UpdateWorkspaceActiveDocument ()
  187 + {
  188 + if (!(surfaceTabs.SelectedTab is ErrorListTabPage))
  189 + _workspace.ActiveDocument = _workspace.GetDocument (surfaceTabs.SelectedTab);
  190 + else
  191 + _workspace.ActiveDocument = null;
  192 + }
  193 +
  194 +
154 195 private void exitToolStripMenuItem_Click (object sender, EventArgs e)
155 196 {
156 197 this.Close ();
@@ -166,12 +207,9 @@ private void saveToolStripMenuItem_Click (object sender, EventArgs e)
166 207
167 208 private void closeToolStripMenuItem_Click (object sender, EventArgs e)
168 209 {
169   - if (_workspace.ActiveDocument != null) {
170   - if (_workspace.ActiveDocument.IsModified)
171   - _workspace.ActiveDocument.Save ();
172   - _workspace.ActiveDocument.Dispose ();
173   - surfaceTabs.TabPages.Remove (surfaceTabs.SelectedTab);
174   - }
  210 + if (!(surfaceTabs.SelectedTab is ErrorListTabPage))
  211 + if (_workspace.ActiveDocument != null)
  212 + CloseDocument (_workspace.ActiveDocument);
175 213 }
176 214
177 215 private void referencesToolStripMenuItem_Click (object sender, EventArgs e)
25 src/UI/PropertyGrid.cs
@@ -74,10 +74,13 @@ private void OnComponentsCombo_SelectedIndexChanged (object sender, EventArgs ar
74 74
75 75 private IComponent PrimarySelection {
76 76 get {
77   - if (this.ActiveComponents.Length > 0) {
78   - ISelectionService selectionService = ((IComponent)ActiveComponents[0]).Site.GetService (typeof (ISelectionService)) as ISelectionService;
79   - if (selectionService != null)
80   - return (IComponent) selectionService.PrimarySelection;
  77 + if (this.ActiveComponents != null && ActiveComponents.Length > 0) {
  78 + IComponent component = ActiveComponents[0] as IComponent;
  79 + if (component != null && component.Site != null) {
  80 + ISelectionService selectionService = component.Site.GetService (typeof (ISelectionService)) as ISelectionService;
  81 + if (selectionService != null)
  82 + return selectionService.PrimarySelection as IComponent;
  83 + }
81 84 }
82 85 return null;
83 86 }
@@ -94,6 +97,9 @@ private void SetActiveComponents (object[] components)
94 97 _componentsCombo.SelectedIndex = _componentsCombo.Items.IndexOf (component.Site.Name);
95 98 _propertyGrid.SelectedObject = component;
96 99 EnableNotification (component);
  100 + } else if (components.Length == 0) {
  101 + _propertyGrid.SelectedObjects = components;
  102 + _componentsCombo.Items.Clear ();
97 103 } else {
98 104 _propertyGrid.SelectedObjects = components;
99 105 _componentsCombo.SelectedIndex = -1;
@@ -145,7 +151,16 @@ private void OnComponentAdded (object sender, ComponentEventArgs args)
145 151
146 152 private void OnComponentRemoving (object sender, ComponentEventArgs args)
147 153 {
148   - _componentsCombo.Items.Remove (args.Component.Site.Name);
  154 + int index = -1;
  155 + for (int i=0; i < _componentsCombo.Items.Count; i++) {
  156 + if (_componentsCombo.Items[i] == args.Component) {
  157 + index = i;
  158 + break;
  159 + }
  160 + }
  161 + if (index != -1)
  162 + _componentsCombo.Items.RemoveAt (index);
  163 + // MWF bug: _componentsCombo.Items.Remove (args.Component.Site.Name);
149 164 }
150 165
151 166 private void OnComponentRename (object sender, ComponentRenameEventArgs args)

0 comments on commit 298b3ce

Please sign in to comment.
Something went wrong with that request. Please try again.