Skip to content
Browse files

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...
1 parent fda32c5 commit 298b3ce6da4af6bce44505a34dc1511bdaa299bc @ivanz ivanz committed Sep 25, 2007
View
25 ChangeLog
@@ -1,3 +1,28 @@
+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.
+
2007-09-13 Ivan N. Zlatev <contact@i-nz.net>
* UI/ReferencesDialog.cs: Allow referencing executables.
View
31 src/DesignTime/CodeProviderDesignerLoader.cs
@@ -26,12 +26,15 @@
//
using System;
+using System.Collections;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.IO;
+using System.Windows.Forms.Design;
+
#if WITH_MONO_DESIGN
using Mono.Design;
@@ -57,7 +60,7 @@ public CodeProviderDesignerLoader (CodeProvider provider)
}
protected override ITypeResolutionService TypeResolutionService {
- get { return base.LoaderHost.GetService (typeof (ITypeResolutionService)) as ITypeResolutionService; }
+ get { return base.GetService (typeof (ITypeResolutionService)) as ITypeResolutionService; }
}
protected override CodeCompileUnit Parse ()
@@ -69,5 +72,31 @@ protected override void Write (CodeCompileUnit unit)
{
_provider.Write (unit);
}
+
+ protected override void OnEndLoad (bool successful, ICollection errors)
+ {
+ base.OnEndLoad (successful, errors);
+ ReportErrors (errors);
+ }
+
+ protected override void ReportFlushErrors (ICollection errors)
+ {
+ base.ReportFlushErrors (errors);
+ ReportErrors (errors);
+ }
+
+ private void ReportErrors (ICollection errors)
+ {
+ IUIService service = base.GetService (typeof (IUIService)) as IUIService;
+ if (service != null) {
+ service.SetUIDirty (); // clears the error list
+ foreach (object error in errors) {
+ if (error is Exception)
+ service.ShowError ((Exception) error);
+ else if (error is string)
+ service.ShowError ((string) error);
+ }
+ }
+ }
}
}
View
9 src/Program.cs
@@ -14,7 +14,14 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new MainView());
+ try {
+ Application.Run(new MainView());
+ } catch (Exception e) {
+ MessageBox.Show ("A fatal error occured. Please file a bug report with the following details (Ctrl-C to copy to clipboard):" +
+ System.Environment.NewLine + System.Environment.NewLine +
+ e.ToString (), "Fatal Error");
+ System.Windows.Forms.Application.Exit ();
+ }
}
}
}
View
42 src/Project/Document.cs
@@ -40,6 +40,7 @@ namespace mwf_designer
{
internal class Document : IDisposable
{
+ private bool _loaded;
private CodeProvider _codeProvider;
private Workspace _workspace;
@@ -56,10 +57,14 @@ public Document (string fileName, Workspace workspace)
throw new ArgumentNullException ("fileName");
_fileName = fileName;
_workspace = workspace;
+ _loaded = false;
}
- public void Load ()
+ public bool Load ()
{
+ if (_loaded)
+ return true;
+ _loaded = false;
_modified = false;
// Initialize code provider, loader and surface
@@ -74,22 +79,34 @@ public void Load ()
container.AddService (typeof (IEventBindingService), new CodeProviderEventBindingService (_codeProvider,
(IServiceProvider) container));
_surface.BeginLoad (_loader);
+ if (_surface.IsLoaded) {
+ _loaded = true;
+ // Mark as Modified on ComponentChanged
+ //
+ IComponentChangeService changeService = (IComponentChangeService)_surface.GetService (typeof (IComponentChangeService));
+ changeService.ComponentChanged += delegate {
+ _modified = true;
+ if (Modified != null)
+ Modified (this, EventArgs.Empty);
+ };
+ if (Loaded != null)
+ Loaded (this, EventArgs.Empty);
+ } else {
+ _surface.Dispose ();
+ _loader.Dispose ();
+ }
- // Mark as Modified on ComponentChanged
- //
- IComponentChangeService changeService = (IComponentChangeService)_surface.GetService (typeof (IComponentChangeService));
- changeService.ComponentChanged += delegate {
- _modified = true;
- if (Modified != null)
- Modified (this, EventArgs.Empty);
- };
- if (Loaded != null)
- Loaded (this, EventArgs.Empty);
+ return _loaded;
+ }
+
+ public bool LoadSuccessful {
+ get { return _loaded; }
+ set { _loaded = value; }
}
public void Save ()
{
- if (_modified) {
+ if (_loaded && _modified) {
_surface.Flush ();
_modified = false;
}
@@ -123,6 +140,7 @@ public void Save ()
public void Dispose ()
{
_surface.Dispose ();
+ _codeProvider = null;
}
public event EventHandler Loaded;
View
6 src/Project/References.cs
@@ -43,6 +43,12 @@ public References ()
_assemblies = new List<Assembly> ();
}
+ public void Dispose ()
+ {
+ _assemblies.Clear ();
+ _assemblies = null;
+ }
+
public void AddReference (Assembly assembly)
{
if (assembly == null)
View
57 src/Project/Workspace.cs
@@ -41,14 +41,14 @@ namespace mwf_designer
internal class Workspace
{
- private List<Document> _documents;
+ private Dictionary<object, Document> _documents;
private Document _activeDocument;
private References _references;
private ServiceContainer _serviceContainer;
public Workspace ()
{
- _documents = new List<Document>();
+ _documents = new Dictionary<object, Document>();
_activeDocument = null;
_references = new References ();
_serviceContainer = new ServiceContainer ();
@@ -60,6 +60,16 @@ public void Load ()
LoadDefaultServices (_serviceContainer);
}
+ public void Dispose ()
+ {
+ _activeDocument = null;
+ _documents = null;
+ _references.Dispose ();
+ _references = null;
+ _serviceContainer.Dispose ();
+ _serviceContainer = null;
+ }
+
private void LoadDefaultServices (IServiceContainer container)
{
container.AddService (typeof (ITypeResolutionService), new TypeResolutionService (this.References));
@@ -76,14 +86,45 @@ private void LoadDefaultReferences (References references)
get { return _references; }
}
- public void AddDocument (Document doc)
+ public Document LoadDocument (string file)
{
- _documents.Add (doc);
+ return LoadDocument (file, file);
}
- public void RemoveDocument (Document doc)
+ public Document LoadDocument (string file, object identifierKey)
{
- _documents.Remove (doc);
+ Document doc = new Document (file, this);
+ _documents[identifierKey] = doc;
+ doc.Load ();
+ return doc;
+ }
+
+ public Document GetDocument (object identifierKey)
+ {
+ return _documents[identifierKey];
+ }
+
+ public void CloseDocument (Document doc)
+ {
+ object key = null;
+ foreach (KeyValuePair<object, Document> kvp in _documents)
+ if (doc == kvp.Value)
+ key = kvp.Key;
+ if (key != null)
+ CloseDocument (key);
+ }
+
+ public void CloseDocument (object identifierKey)
+ {
+ Document doc = _documents[identifierKey];
+ if (doc != null) {
+ if (doc.IsModified && doc.LoadSuccessful)
+ doc.Save ();
+ _documents[identifierKey] = null;
+ doc.Dispose ();
+ }
+
+ // TODO: Handle active document change here if closed doc is active
}
public ServiceContainer Services {
@@ -99,7 +140,6 @@ public void RemoveDocument (Document doc)
}
}
-
private static readonly Type[] containers = new Type[] {
typeof (System.Windows.Forms.FlowLayoutPanel),
typeof (System.Windows.Forms.GroupBox),
@@ -235,9 +275,6 @@ internal class ActiveDocumentChangedEventArgs : EventArgs
public ActiveDocumentChangedEventArgs (Document newDocument, Document oldDocument)
{
- if (newDocument == null)
- throw new ArgumentNullException ("newDocument");
-
_newDocument = newDocument;
_oldDocument = oldDocument;
}
View
142 src/UI/ErrorList.Designer.cs
@@ -0,0 +1,142 @@
+namespace mwf_designer
+{
+ partial class ErrorList
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose (bool disposing)
+ {
+ if (disposing && (components != null)) {
+ components.Dispose ();
+ }
+ base.Dispose (disposing);
+ }
+
+ #region Component Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent ()
+ {
+ this.splitContainer1 = new System.Windows.Forms.SplitContainer();
+ this._errorsList = new System.Windows.Forms.ListBox();
+ this.splitContainer2 = new System.Windows.Forms.SplitContainer();
+ this._detailedText = new System.Windows.Forms.TextBox();
+ this.saveButton = new System.Windows.Forms.Button();
+ this.splitContainer1.Panel1.SuspendLayout();
+ this.splitContainer1.Panel2.SuspendLayout();
+ this.splitContainer1.SuspendLayout();
+ this.splitContainer2.Panel1.SuspendLayout();
+ this.splitContainer2.Panel2.SuspendLayout();
+ this.splitContainer2.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // splitContainer1
+ //
+ this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
+ this.splitContainer1.Location = new System.Drawing.Point(0, 0);
+ this.splitContainer1.Name = "splitContainer1";
+ this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
+ //
+ // splitContainer1.Panel1
+ //
+ this.splitContainer1.Panel1.Controls.Add(this._errorsList);
+ //
+ // splitContainer1.Panel2
+ //
+ this.splitContainer1.Panel2.Controls.Add(this.splitContainer2);
+ this.splitContainer1.Size = new System.Drawing.Size(737, 492);
+ this.splitContainer1.SplitterDistance = 160;
+ this.splitContainer1.TabIndex = 0;
+ //
+ // _errorsList
+ //
+ this._errorsList.Dock = System.Windows.Forms.DockStyle.Fill;
+ this._errorsList.FormattingEnabled = true;
+ this._errorsList.IntegralHeight = false;
+ this._errorsList.Location = new System.Drawing.Point(0, 0);
+ this._errorsList.Name = "_errorsList";
+ this._errorsList.Size = new System.Drawing.Size(737, 121);
+ this._errorsList.TabIndex = 3;
+ this._errorsList.HorizontalScrollbar = true;
+ this._errorsList.SelectedIndexChanged += new System.EventHandler(this.errorsList_SelectedIndexChanged);
+ //
+ // splitContainer2
+ //
+ this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.splitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
+ this.splitContainer2.IsSplitterFixed = true;
+ this.splitContainer2.Location = new System.Drawing.Point(0, 0);
+ this.splitContainer2.Name = "splitContainer2";
+ this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
+ //
+ // splitContainer2.Panel1
+ //
+ this.splitContainer2.Panel1.Controls.Add(this._detailedText);
+ //
+ // splitContainer2.Panel2
+ //
+ this.splitContainer2.Panel2.Controls.Add(this.saveButton);
+ this.splitContainer2.Size = new System.Drawing.Size(737, 367);
+ this.splitContainer2.SplitterDistance = 335;
+ this.splitContainer2.TabIndex = 0;
+ //
+ // _detailedText
+ //
+ this._detailedText.Dock = System.Windows.Forms.DockStyle.Fill;
+ this._detailedText.Location = new System.Drawing.Point(0, 0);
+ this._detailedText.Multiline = true;
+ this._detailedText.Name = "_detailedText";
+ this._detailedText.ReadOnly = true;
+ this._detailedText.Size = new System.Drawing.Size(737, 335);
+ this._detailedText.TabIndex = 2;
+ //
+ // saveButton
+ //
+ this.saveButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.saveButton.Location = new System.Drawing.Point(640, 2);
+ this.saveButton.Name = "saveButton";
+ this.saveButton.Size = new System.Drawing.Size(94, 23);
+ this.saveButton.TabIndex = 0;
+ this.saveButton.Text = "Save log to file";
+ this.saveButton.UseVisualStyleBackColor = true;
+ this.saveButton.Click += new System.EventHandler(this.saveButton_Click);
+ //
+ // ErrorList
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.splitContainer1);
+ this.Name = "ErrorList";
+ this.Size = new System.Drawing.Size(737, 492);
+ this.splitContainer1.Panel1.ResumeLayout(false);
+ this.splitContainer1.Panel2.ResumeLayout(false);
+ this.splitContainer1.ResumeLayout(false);
+ this.splitContainer2.Panel1.ResumeLayout(false);
+ this.splitContainer2.Panel1.PerformLayout();
+ this.splitContainer2.Panel2.ResumeLayout(false);
+ this.splitContainer2.ResumeLayout(false);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.SplitContainer splitContainer1;
+ private System.Windows.Forms.SplitContainer splitContainer2;
+ private System.Windows.Forms.TextBox _detailedText;
+ private System.Windows.Forms.Button saveButton;
+ private System.Windows.Forms.ListBox _errorsList;
+ }
+}
View
124 src/UI/ErrorList.cs
@@ -0,0 +1,124 @@
+//
+// Authors:
+// Ivan N. Zlatev (contact i-nZ.net)
+//
+// (C) 2007 Ivan N. Zlatev
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Text;
+using System.Windows.Forms;
+using System.IO;
+
+namespace mwf_designer
+{
+ internal partial class ErrorList : UserControl
+ {
+
+ private class Error
+ {
+ private string _details;
+ private string _message;
+
+ public Error (string message, string details)
+ {
+ if (message == null)
+ throw new ArgumentNullException ("message");
+ _details = details;
+ _message = message;
+ }
+
+ public string Details {
+ get { return _details; }
+ set { _details = value; }
+ }
+
+ public string Message {
+ get { return _message; }
+ set { _message = value; }
+ }
+
+ public override string ToString ()
+ {
+ return _message;
+ }
+ }
+
+ public ErrorList ()
+ {
+ InitializeComponent ();
+ }
+
+ private void saveButton_Click (object sender, EventArgs e)
+ {
+ SaveFileDialog dialog = new SaveFileDialog();
+ dialog.OverwritePrompt = true;
+ if (dialog.ShowDialog() == DialogResult.OK)
+ WriteErrorsToFile (dialog.FileName);
+ }
+
+ private void errorsList_SelectedIndexChanged (object sender, EventArgs e)
+ {
+ if (_errorsList.SelectedIndex != -1) {
+ Error error = (Error) _errorsList.Items[_errorsList.SelectedIndex];
+ _detailedText.Text = error.Details;
+ }
+ }
+
+ public void AddError (string message, string details)
+ {
+ _errorsList.Items.Add (new Error (message, details));
+ }
+
+ private void WriteErrorsToFile (string fileName)
+ {
+ StringBuilder sb = new StringBuilder ();
+ foreach (Error error in _errorsList.Items) {
+ sb.AppendLine ("==== " + error.Message + " ====");
+ sb.Append (Environment.NewLine);
+ sb.Append (error.Details);
+ sb.Append (Environment.NewLine);
+ sb.Append (Environment.NewLine);
+ }
+
+ FileStream stream = File.OpenWrite (fileName);
+ byte [] bytes = Encoding.Default.GetBytes (sb.ToString ());
+ stream.Write (bytes, 0, bytes.Length);
+ stream.Close ();
+ stream.Dispose ();
+ }
+
+ public void Clear ()
+ {
+ _errorsList.SuspendLayout ();
+ _errorsList.Items.Clear ();
+ _errorsList.ResumeLayout ();
+ _detailedText.Text = "";
+ }
+ }
+}
View
144 src/UI/ErrorListTabPage.cs
@@ -0,0 +1,144 @@
+//
+// Authors:
+// Ivan N. Zlatev (contact i-nZ.net)
+//
+// (C) 2007 Ivan N. Zlatev
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Windows.Forms;
+using System.Windows.Forms.Design;
+
+namespace mwf_designer
+{
+ internal class ErrorListTabPage : TabPage, IUIService
+ {
+ private ErrorList _errorList;
+ private readonly string ERRORS_TAB_KEY = @"!?\/#__Errors__!?\/#";
+ private readonly string ERRORS_TAB_TEXT = "Errors";
+
+ public ErrorListTabPage ()
+ {
+ InitializeComponent ();
+ }
+
+ private void InitializeComponent ()
+ {
+ _errorList = new ErrorList ();
+ _errorList.Dock = DockStyle.Fill;
+
+ this.Name = ERRORS_TAB_KEY;
+ this.Text = ERRORS_TAB_TEXT;
+ this.Controls.Add (_errorList);
+ }
+
+#region IUIService
+
+ private IDictionary _styles;
+
+ void IUIService.SetUIDirty ()
+ {
+ _errorList.Clear ();
+ }
+
+ void IUIService.ShowError (Exception exception)
+ {
+ string details = exception.StackTrace;
+
+ if (exception.Data["Details"] != null)
+ details = (string)exception.Data["Details"] + System.Environment.NewLine + System.Environment.NewLine + details;
+
+ _errorList.AddError (exception.Message, details);
+ }
+
+ void IUIService.ShowError (string message)
+ {
+ _errorList.AddError (message, Environment.StackTrace);
+ }
+
+ void IUIService.ShowError (Exception exception, string message)
+ {
+ _errorList.AddError (message, exception.ToString ());
+ }
+
+ void IUIService.ShowMessage (string message)
+ {
+ _errorList.AddError (message, Environment.StackTrace);
+ }
+
+ void IUIService.ShowMessage (string message, string caption)
+ {
+ _errorList.AddError (caption, message);
+ }
+
+ DialogResult IUIService.ShowMessage (string message, string caption, MessageBoxButtons buttons)
+ {
+ throw new NotImplementedException ();
+ }
+
+ IDictionary IUIService.Styles {
+ get {
+ if (_styles == null)
+ _styles = new Hashtable ();
+ return _styles;
+ }
+ }
+
+ IWin32Window IUIService.GetDialogOwnerWindow ()
+ {
+ Control parent = this.Parent;
+
+ while (parent != null) {
+ if (parent is Form)
+ return (Form)parent;
+ parent = parent.Parent;
+ }
+
+ return null;
+ }
+
+ bool IUIService.CanShowComponentEditor (object component)
+ {
+ throw new NotImplementedException ();
+ }
+
+ bool IUIService.ShowComponentEditor (object component, IWin32Window parent)
+ {
+ throw new NotImplementedException ();
+ }
+
+ DialogResult IUIService.ShowDialog (Form form)
+ {
+ throw new NotImplementedException ();
+ }
+
+ bool IUIService.ShowToolWindow (Guid toolWindow)
+ {
+ throw new NotImplementedException ();
+ }
+#endregion
+
+ }
+}
View
102 src/UI/MainView.cs
@@ -48,6 +48,7 @@ namespace mwf_designer
public partial class MainView : Form
{
Workspace _workspace;
+ private readonly string MODIFIED_MARKER = " *";
public MainView ()
{
@@ -56,18 +57,6 @@ public MainView ()
LoadWorkspace ();
}
- private IComponent GetPrimarySelection (Document document)
- {
- if (document == null)
- throw new ArgumentNullException ("document");
-
- ISelectionService service = document.DesignSurface.GetService (typeof (ISelectionService)) as ISelectionService;
- if (service != null)
- return (IComponent) service.PrimarySelection;
- else
- return null;
- }
-
private void openToolStripMenuItem_Click (object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog ();
@@ -99,16 +88,37 @@ private void OnToolbox_ToolPicked (object sender, EventArgs args)
private void LoadWorkspace ()
{
_workspace = new Workspace ();
- _workspace.ActiveDocumentChanged += delegate (object sender, ActiveDocumentChangedEventArgs args) {
- propertyGrid.ActiveComponents = new object[] { GetPrimarySelection (args.NewDocument) };
+ surfaceTabs.SelectedIndexChanged += delegate {
+ UpdateWorkspaceActiveDocument ();
};
+ _workspace.ActiveDocumentChanged += OnActiveDocumentChanged;
_workspace.References.ReferencesChanged += delegate {
PopulateToolbox (toolbox, _workspace.References);
};
_workspace.Services.AddService (typeof (IToolboxService), (IToolboxService) toolbox);
+ AddErrorsTab ();
_workspace.Load ();
}
+ private IComponent GetPrimarySelection (Document document)
+ {
+ if (document == null)
+ throw new ArgumentNullException ("document");
+
+ ISelectionService service = document.DesignSurface.GetService (typeof (ISelectionService)) as ISelectionService;
+ if (service != null)
+ return (IComponent) service.PrimarySelection;
+ else
+ return null;
+ }
+
+ private void AddErrorsTab ()
+ {
+ ErrorListTabPage errors = new ErrorListTabPage ();
+ surfaceTabs.TabPages.Add (errors);
+ _workspace.Services.AddService (typeof (IUIService), (IUIService) errors);
+ }
+
// Currently populates with all MWF Controls that have a public ctor with no params
//
private void PopulateToolbox (ToolBoxList toolbox, References references)
@@ -127,20 +137,42 @@ private void PopulateToolbox (ToolBoxList toolbox, References references)
private void LoadDocument (string file, Workspace workspace)
{
- Document doc = new Document (file, workspace);
- doc.Load ();
- doc.Modified += delegate {
- if (!surfaceTabs.TabPages[file].Text.EndsWith (" *"))
- surfaceTabs.TabPages[file].Text += " *";
- };
- workspace.AddDocument (doc);
- workspace.ActiveDocument = doc;
- surfaceTabs.TabPages.Add (file, Path.GetFileNameWithoutExtension (file));
- surfaceTabs.TabPages[file].Controls.Add ((Control)doc.DesignSurface.View);
- surfaceTabs.SelectedTab = surfaceTabs.TabPages[file];
+ TabPage tab = new TabPage (Path.GetFileNameWithoutExtension (file));
+ tab.Name = file; // the key
+
+ // loads and associates the tab page with the document
+ Document doc = workspace.LoadDocument (file, tab);
+ if (doc.LoadSuccessful) {
+ doc.Modified += OnDocumentModified;
+ workspace.ActiveDocument = doc;
+ tab.Controls.Add ((Control)doc.DesignSurface.View);
+ surfaceTabs.TabPages.Add (tab);
+ surfaceTabs.SelectedTab = surfaceTabs.TabPages[file];
+ } else {
+ workspace.CloseDocument (doc);
+ tab.Dispose ();
+ }
+ }
+
+ private void OnDocumentModified (object sender, EventArgs args)
+ {
+ if (!surfaceTabs.SelectedTab.Text.EndsWith (MODIFIED_MARKER))
+ surfaceTabs.SelectedTab.Text += MODIFIED_MARKER;
+ }
+
+ private void OnActiveDocumentChanged (object sender, ActiveDocumentChangedEventArgs args)
+ {
+ object primarySelection = args.NewDocument != null ? GetPrimarySelection (args.NewDocument) : null;
+ propertyGrid.ActiveComponents = primarySelection != null ? new object[] { primarySelection } : new object[0];
+ }
+
+ private void CloseDocument (Document doc)
+ {
+ doc.Modified -= OnDocumentModified;
+ _workspace.CloseDocument (doc);
+ surfaceTabs.TabPages.Remove (surfaceTabs.SelectedTab);
}
-
private void newToolStripMenuItem_Click (object sender, EventArgs e)
{
NewFileDialog dialog = new NewFileDialog (TemplateManager.AvailableTemplates);
@@ -151,6 +183,15 @@ private void newToolStripMenuItem_Click (object sender, EventArgs e)
}
}
+ private void UpdateWorkspaceActiveDocument ()
+ {
+ if (!(surfaceTabs.SelectedTab is ErrorListTabPage))
+ _workspace.ActiveDocument = _workspace.GetDocument (surfaceTabs.SelectedTab);
+ else
+ _workspace.ActiveDocument = null;
+ }
+
+
private void exitToolStripMenuItem_Click (object sender, EventArgs e)
{
this.Close ();
@@ -166,12 +207,9 @@ private void saveToolStripMenuItem_Click (object sender, EventArgs e)
private void closeToolStripMenuItem_Click (object sender, EventArgs e)
{
- if (_workspace.ActiveDocument != null) {
- if (_workspace.ActiveDocument.IsModified)
- _workspace.ActiveDocument.Save ();
- _workspace.ActiveDocument.Dispose ();
- surfaceTabs.TabPages.Remove (surfaceTabs.SelectedTab);
- }
+ if (!(surfaceTabs.SelectedTab is ErrorListTabPage))
+ if (_workspace.ActiveDocument != null)
+ CloseDocument (_workspace.ActiveDocument);
}
private void referencesToolStripMenuItem_Click (object sender, EventArgs e)
View
25 src/UI/PropertyGrid.cs
@@ -74,10 +74,13 @@ private void OnComponentsCombo_SelectedIndexChanged (object sender, EventArgs ar
private IComponent PrimarySelection {
get {
- if (this.ActiveComponents.Length > 0) {
- ISelectionService selectionService = ((IComponent)ActiveComponents[0]).Site.GetService (typeof (ISelectionService)) as ISelectionService;
- if (selectionService != null)
- return (IComponent) selectionService.PrimarySelection;
+ if (this.ActiveComponents != null && ActiveComponents.Length > 0) {
+ IComponent component = ActiveComponents[0] as IComponent;
+ if (component != null && component.Site != null) {
+ ISelectionService selectionService = component.Site.GetService (typeof (ISelectionService)) as ISelectionService;
+ if (selectionService != null)
+ return selectionService.PrimarySelection as IComponent;
+ }
}
return null;
}
@@ -94,6 +97,9 @@ private void SetActiveComponents (object[] components)
_componentsCombo.SelectedIndex = _componentsCombo.Items.IndexOf (component.Site.Name);
_propertyGrid.SelectedObject = component;
EnableNotification (component);
+ } else if (components.Length == 0) {
+ _propertyGrid.SelectedObjects = components;
+ _componentsCombo.Items.Clear ();
} else {
_propertyGrid.SelectedObjects = components;
_componentsCombo.SelectedIndex = -1;
@@ -145,7 +151,16 @@ private void OnComponentAdded (object sender, ComponentEventArgs args)
private void OnComponentRemoving (object sender, ComponentEventArgs args)
{
- _componentsCombo.Items.Remove (args.Component.Site.Name);
+ int index = -1;
+ for (int i=0; i < _componentsCombo.Items.Count; i++) {
+ if (_componentsCombo.Items[i] == args.Component) {
+ index = i;
+ break;
+ }
+ }
+ if (index != -1)
+ _componentsCombo.Items.RemoveAt (index);
+ // MWF bug: _componentsCombo.Items.Remove (args.Component.Site.Name);
}
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.