Permalink
Browse files

2008-01-07 Ivan N. Zlatev <contact@i-nz.net>

        * UI/ToolBoxList/ToolBoxList.cs: 
         - Drop Docking of the categories for using custom layouting in
           order
         to show the categories in the order they were added.
         - Implement RemoveToolboxItem.
         - Drop NotImplementedExceptions in order to make it work on
           MSNET.
        * DesignTime/ToolboxFiller.cs, Project/Workspace.cs,
        * UI/MainView.cs:
         Move the Toolbox filling code out of the Workspace and create a 
         Mediator(?) between References and Toolbox.
        * Project/References.cs: Provide add/remove notication.
        * DesignTime/CodeProvider.cs,
        * DesignTime/CodeProviderDesignerLoader.cs:
         NRefactory doesn't recognize between field and property
reference, so
         we need to tell it in oder to get proper CodeExpressions
generated.
        * UndoRedoEngine.cs: Implemented.
        * deps/ICSharpCode.NRefactory.dll: Update to 2.2.1.
        * Makefile: fixes for building without Mono.Design.


svn path=/trunk/mwf-designer/; revision=92371
  • Loading branch information...
ivanz committed Jan 6, 2008
1 parent 06028ed commit bcbb6b937765ee6c4c7ce70ccd7d2c2c900792f9
View
@@ -1,3 +1,21 @@
+2008-01-07 Ivan N. Zlatev <contact@i-nz.net>
+
+ * UI/ToolBoxList/ToolBoxList.cs:
+ - Drop Docking of the categories for using custom layouting in order
+ to show the categories in the order they were added.
+ - Implement RemoveToolboxItem.
+ - Drop NotImplementedExceptions in order to make it work on MSNET.
+ * DesignTime/ToolboxFiller.cs, Project/Workspace.cs, UI/MainView.cs:
+ Move the Toolbox filling code out of the Workspace and create a
+ Mediator(?) between References and Toolbox.
+ * Project/References.cs: Provide add/remove notication.
+ * DesignTime/CodeProvider.cs, DesignTime/CodeProviderDesignerLoader.cs:
+ NRefactory doesn't recognize between field and property reference, so
+ we need to tell it in oder to get proper CodeExpressions generated.
+ * UndoRedoEngine.cs: Implemented.
+ * deps/ICSharpCode.NRefactory.dll: Update to 2.2.1.
+ * Makefile: fixes for building without Mono.Design.
+
2007-10-24 Ivan N. Zlatev <contact@i-nz.net>
* Program.cs: More exception handling.
View
@@ -3,22 +3,22 @@ BUILD_DIR=build
MD_BUILD_DIR=../build
DEPS_DIR = deps
DEPS = ${DEPS_DIR}/*
-DIST_DIR = ${BUILD_DIR}/mwf-designer
+DIST_DIR = ${BUILD_DIR}/mwf-designer-dist
MD_DIST_DIR = ${MD_BUILD_DIR}/mwf-designer
ASSEMBLY=mwf-designer.exe
-REFERENCES=System.Design,System.Windows.Forms,System.Drawing,System.Data,${BUILD_DIR}/ICSharpCode.NRefactory.dll
+REFERENCES=System.Design,System.Windows.Forms,System.Drawing,System.Data,${DEPS_DIR}/ICSharpCode.NRefactory.dll
MD_REFERENCES=System.Design,System.Windows.Forms,System.Drawing,System.Data,${MD_BUILD_DIR}/ICSharpCode.NRefactory.dll
all:
- mkdir -p ${BUILD_DIR}
- cp ${DEPS_DIR}/ICSharpCode.NRefactory.dll ${BUILD_DIR}
- gmcs -debug -r:${REFERENCES} -out:${BUILD_DIR}/${ASSEMBLY} ${SOURCES}
+ mkdir -p ${MD_BUILD_DIR}
+ cp ${DEPS_DIR}/ICSharpCode.NRefactory.dll ${MD_BUILD_DIR}
+ export MCS_COLORS=disable;gmcs -debug -r:${REFERENCES} -out:${MD_BUILD_DIR}/${ASSEMBLY} ${SOURCES}
run:
- cd ${BUILD_DIR};mono --debug mwf-designer.exe
+ cd ${MD_BUILD_DIR};mono --debug mwf-designer.exe
msnet:
- csc -debug -d:NET_2_0 -t:library -r:System.Design.dll,System.Windows.Forms.dll,System.Drawing.dll,System.Data.dll,..\build\Mono.Design.dll,..\build\ICSharpCode.NRefactory.dll -out:build\mwf-designer.exe src\*.cs src\*\*.cs
+ csc -debug -d:NET_2_0 -t:library -r:System.Design.dll,System.Windows.Forms.dll,System.Drawing.dll,System.Data.dll,..\build\Mono.Design.dll,..\build\ICSharpCode.NRefactory.dll -out:build\mwf-designer.exe src\\*.cs src\\*\\*.cs
dist:
mkdir -p ${DIST_DIR}
@@ -30,7 +30,7 @@ dist:
mono-design:
mkdir -p ${MD_BUILD_DIR}
cp ${DEPS} ${MD_BUILD_DIR}
- gmcs -d:WITH_MONO_DESIGN -debug -r:${MD_REFERENCES} -r:${MD_BUILD_DIR}/Mono.Design.dll -out:${MD_BUILD_DIR}/${ASSEMBLY} ${SOURCES}
+ export MCS_COLORS=disable;gmcs -d:WITH_MONO_DESIGN -debug -r:${MD_REFERENCES} -r:${MD_BUILD_DIR}/Mono.Design.dll -out:${MD_BUILD_DIR}/${ASSEMBLY} ${SOURCES}
mono-design-run:
cd ${MD_BUILD_DIR};mono --debug mwf-designer.exe
Binary file not shown.
@@ -2,7 +2,7 @@
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
-// (C) 2007 Ivan N. Zlatev
+// (C) 2007-2008 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
@@ -30,6 +30,7 @@
using System.CodeDom;
using System.CodeDom.Compiler;
using System.ComponentModel;
+using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.IO;
using System.Reflection;
@@ -46,13 +47,34 @@ namespace mwf_designer
{
internal class CodeProvider
{
+ private class EnvironmentInformationProvider : ICSharpCode.NRefactory.IEnvironmentInformationProvider
+ {
+ private ITypeResolutionService _resolution;
+
+ public EnvironmentInformationProvider (ITypeResolutionService resolution)
+ {
+ _resolution = resolution;
+ }
+
+ public bool HasField (string fullTypeName, string fieldName)
+ {
+ if (_resolution != null) {
+ Type type = _resolution.GetType (fullTypeName);
+ if (type != null)
+ return type.GetField (fieldName) != null;
+ }
+ return false;
+ }
+ }
+
private string _codeBehindFileName;
private string _fileName;
private CodeDomProvider _provider;
+ private EnvironmentInformationProvider _informationProvider;
// TODO: parse both and try to find the basetype of the partial codebehind
//
- public CodeProvider (string fileName)
+ public CodeProvider (string fileName, ITypeResolutionService resolutionSvc)
{
if (fileName == null)
throw new ArgumentNullException ("fileName");
@@ -63,14 +85,15 @@ public CodeProvider (string fileName)
_fileName = fileName;
_provider = GetCodeProvider (fileName);
+ _informationProvider = new EnvironmentInformationProvider (resolutionSvc);
}
internal static string GetCodeBehindFileName (string file)
{
return Path.Combine (Path.GetDirectoryName (file),
- Path.GetFileNameWithoutExtension (file) + ".Designer" +
- Path.GetExtension (file));
+ Path.GetFileNameWithoutExtension (file) + ".Designer" +
+ Path.GetExtension (file));
}
public static bool IsValid (string file)
@@ -105,6 +128,13 @@ private CodeCompileUnit MergeParse (string fileName, string codeBehindFileName)
// get the first valid typedeclaration name
CodeDomVisitor visitor = new CodeDomVisitor ();
+
+ // NRefactory can't decide on its own whether to generate CodePropertyReference or
+ // CodeFieldReference. This will be done by the supplied by us IEnvironmentInformationProvider.
+ // Our EnvironmentInformationProvider makes use of the ITypeResolutionService to get the type
+ // (from the name) and check if a field is available.
+ //
+ visitor.EnvironmentInformationProvider = _informationProvider;
visitor.VisitCompilationUnit (codeBehindParser.CompilationUnit, null);
mergedUnit = visitor.codeCompileUnit;
@@ -2,7 +2,7 @@
// Authors:
// Ivan N. Zlatev (contact i-nZ.net)
//
-// (C) 2007 Ivan N. Zlatev
+// (C) 2007-2008 Ivan N. Zlatev
//
// Permission is hereby granted, free of charge, to any person obtaining
@@ -75,26 +75,27 @@ protected override void Write (CodeCompileUnit unit)
protected override void OnEndLoad (bool successful, ICollection errors)
{
+ if (!successful)
+ ReportErrors (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);
+ else
+ service.ShowError (error.ToString ());
}
}
}
@@ -0,0 +1,190 @@
+//
+// Authors:
+// Ivan N. Zlatev (contact i-nZ.net)
+//
+// (C) 2008 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.Generic;
+using System.ComponentModel;
+using System.ComponentModel.Design;
+using System.Reflection;
+using System.Drawing.Design;
+
+#if WITH_MONO_DESIGN
+using Mono.Design;
+#endif
+
+namespace mwf_designer
+{
+ internal class ToolboxFiller
+ {
+ private ToolBoxList _toolbox;
+ private References _references;
+
+ public ToolboxFiller (References references, ToolBoxList toolbox)
+ {
+ if (toolbox == null)
+ throw new ArgumentNullException ("toolbox");
+ if (references == null)
+ throw new ArgumentNullException ("references");
+
+ _references = references;
+ _references.ReferenceAdded += OnReferenceAdded;
+ _references.ReferenceRemoved += OnReferenceRemoved;
+ _toolbox = toolbox;
+ LoadToolboxItems (toolbox, references);
+ }
+
+ private void LoadToolboxItems (ToolBoxList toolbox, References references)
+ {
+ toolbox.SuspendLayout ();
+ foreach (Type type in containers) {
+ ToolboxItem tool = new ToolboxItem (type);
+ toolbox.AddToolboxItem (tool, "Containers");
+ }
+ foreach (Type type in commonControls) {
+ ToolboxItem tool = new ToolboxItem (type);
+ toolbox.AddToolboxItem (tool, "Common Controls");
+ }
+ foreach (Type type in menusToolbars) {
+ ToolboxItem tool = new ToolboxItem (type);
+ toolbox.AddToolboxItem (tool, "Menus and Toolbars");
+ }
+ foreach (Type type in commonComponents) {
+ ToolboxItem tool = new ToolboxItem (type);
+ toolbox.AddToolboxItem (tool, "Common Components");
+ }
+ foreach (Assembly assembly in references.Assemblies)
+ LoadAssemblyToolboxItems (toolbox, assembly);
+ toolbox.ResumeLayout ();
+ }
+
+ private void LoadAssemblyToolboxItems (ToolBoxList toolbox, Assembly assembly)
+ {
+ _toolbox.SuspendLayout ();
+ foreach (Type type in assembly.GetTypes()) {
+ if (IsValidToolType (type) && HasEmptyPublicCtor (type)) {
+ ToolboxItem tool = new ToolboxItem (type);
+ // If the assembly is not in the GAC assume
+ // an assembly with custom controls
+ //
+ if (assembly.GlobalAssemblyCache)
+ toolbox.AddToolboxItem (tool, "All");
+ else
+ toolbox.AddToolboxItem (tool, "Custom Components");
+ }
+ }
+ _toolbox.ResumeLayout ();
+ }
+
+ private void OnReferenceAdded (object sender, ReferenceAddedEventArgs args)
+ {
+ LoadAssemblyToolboxItems (_toolbox, args.Assembly);
+ }
+
+ private void OnReferenceRemoved (object sender, ReferenceRemovedEventArgs args)
+ {
+ _toolbox.Clear ();
+ LoadToolboxItems (_toolbox, _references);
+ }
+
+ private bool HasEmptyPublicCtor (Type type)
+ {
+ bool result = false;
+ ConstructorInfo[] ctors = type.GetConstructors ();
+ if (ctors.Length > 0) {
+ foreach (ConstructorInfo ctor in ctors)
+ if (ctor.GetParameters().Length == 0)
+ result = true;
+ }
+ return result;
+ }
+
+ private bool IsValidToolType (Type type)
+ {
+ ToolboxItemAttribute toolboxAttribute = TypeDescriptor.GetAttributes (type)[typeof (ToolboxItemAttribute)] as ToolboxItemAttribute;
+ if (toolboxAttribute.ToolboxItemTypeName != ToolboxItemAttribute.None.ToolboxItemTypeName &&
+ !type.IsAbstract && !type.IsInterface &&
+ ((type.Attributes & TypeAttributes.Public) == TypeAttributes.Public) &&
+ ((type.Attributes & TypeAttributes.NestedFamily) != TypeAttributes.NestedFamily) &&
+ ((type.Attributes & TypeAttributes.NestedFamORAssem) != TypeAttributes.NestedFamORAssem) &&
+ typeof (System.Windows.Forms.Control).IsAssignableFrom (type))
+ return true;
+ return false;
+ }
+
+
+ private static readonly Type[] containers = new Type[] {
+ typeof (System.Windows.Forms.FlowLayoutPanel),
+ typeof (System.Windows.Forms.GroupBox),
+ typeof (System.Windows.Forms.Panel),
+ typeof (System.Windows.Forms.SplitContainer),
+ typeof (System.Windows.Forms.TabControl),
+ typeof (System.Windows.Forms.TableLayoutPanel),
+ };
+
+ private static readonly Type[] menusToolbars = new Type[] {
+ typeof (System.Windows.Forms.ContextMenuStrip),
+ typeof (System.Windows.Forms.MenuStrip),
+ typeof (System.Windows.Forms.StatusStrip),
+ typeof (System.Windows.Forms.ToolStrip),
+ typeof (System.Windows.Forms.ToolStripContainer),
+ };
+
+ private static readonly Type[] commonControls = new Type[] {
+ typeof (System.Windows.Forms.Button),
+ typeof (System.Windows.Forms.CheckBox),
+ typeof (System.Windows.Forms.CheckedListBox),
+ typeof (System.Windows.Forms.ComboBox),
+ typeof (System.Windows.Forms.DateTimePicker),
+ typeof (System.Windows.Forms.Label),
+ typeof (System.Windows.Forms.LinkLabel),
+ typeof (System.Windows.Forms.ListBox),
+ typeof (System.Windows.Forms.ListView),
+ typeof (System.Windows.Forms.MaskedTextBox),
+ typeof (System.Windows.Forms.MonthCalendar),
+ typeof (System.Windows.Forms.NotifyIcon),
+ typeof (System.Windows.Forms.NumericUpDown),
+ typeof (System.Windows.Forms.PictureBox),
+ typeof (System.Windows.Forms.ProgressBar),
+ typeof (System.Windows.Forms.RadioButton),
+ typeof (System.Windows.Forms.RichTextBox),
+ typeof (System.Windows.Forms.TextBox),
+ typeof (System.Windows.Forms.ToolTip),
+ typeof (System.Windows.Forms.TreeView),
+ typeof (System.Windows.Forms.WebBrowser),
+ };
+
+ private static readonly Type[] commonComponents = new Type[] {
+ typeof (System.ComponentModel.BackgroundWorker),
+ typeof (System.IO.FileSystemWatcher),
+ typeof (System.Diagnostics.Process),
+ typeof (System.Windows.Forms.ImageList),
+ typeof (System.Windows.Forms.HelpProvider),
+ typeof (System.IO.Ports.SerialPort),
+ typeof (System.Windows.Forms.Timer),
+ };
+ }
+}
@@ -116,9 +116,6 @@ public Type GetType (string name, bool throwOnError, bool ignoreCase)
if (result == null)
result = Assembly.GetExecutingAssembly ().GetType (name, false, ignoreCase);
- if (result == null)
- throw new InvalidOperationException ("Cannot find the Type of: " + name);
-
return result;
}
Oops, something went wrong.

0 comments on commit bcbb6b9

Please sign in to comment.