]> granicus.if.org Git - graphviz/commitdiff
Win tweak panel for graph, default node and default edge attributes
authorglenlow <devnull@localhost>
Tue, 1 Apr 2008 16:37:51 +0000 (16:37 +0000)
committerglenlow <devnull@localhost>
Tue, 1 Apr 2008 16:37:51 +0000 (16:37 +0000)
windows/GraphPropertyDescriptor.cs [new file with mode: 0755]
windows/Program.cs

diff --git a/windows/GraphPropertyDescriptor.cs b/windows/GraphPropertyDescriptor.cs
new file mode 100755 (executable)
index 0000000..ff844c2
--- /dev/null
@@ -0,0 +1,107 @@
+/* $Id$ $Revision$ */\r
+/* vim:set shiftwidth=4 ts=8: */\r
+\r
+/**********************************************************\r
+*      This software is part of the graphviz package      *\r
+*                http://www.graphviz.org/                 *\r
+*                                                         *\r
+*            Copyright (c) 1994-2008 AT&T Corp.           *\r
+*                and is licensed under the                *\r
+*            Common Public License, Version 1.0           *\r
+*                      by AT&T Corp.                      *\r
+*                                                         *\r
+*        Information and Software Systems Research        *\r
+*              AT&T Research, Florham Park NJ             *\r
+**********************************************************/\r
+\r
+using System;\r
+using System.Collections.Generic;\r
+using System.ComponentModel;\r
+\r
+namespace Graphviz\r
+{\r
+       public class GraphPropertyDescriptor : PropertyDescriptor\r
+       {\r
+               public GraphPropertyDescriptor(string graphComponent, string name, Attribute[] attrs): base(name, attrs)\r
+               {\r
+                       _graphComponent = graphComponent;\r
+               }\r
+               \r
+               public override bool CanResetValue(object component)\r
+               {\r
+                       /* can reset whenever value isn't at default */\r
+                       return !object.Equals(GetValue(component), DefaultValue);\r
+               }\r
+\r
+               public override Type ComponentType\r
+               {\r
+                       /* property defined on graph components, so we'll say object */\r
+                       get { return typeof(object); }\r
+               }\r
+\r
+               public override object GetValue(object component)\r
+               {\r
+                       /* return either the set value or the default value */\r
+                       string value;\r
+                       GetDictionary(component).TryGetValue(Name, out value);\r
+                       return value == null ? DefaultValue : value;\r
+               }\r
+\r
+               public override bool IsReadOnly\r
+               {\r
+                       get { return false; }\r
+               }\r
+\r
+               public override Type PropertyType\r
+               {\r
+                       /* property returns strings only */\r
+                       get { return typeof(string); }\r
+               }\r
+\r
+               public override void ResetValue(object component)\r
+               {\r
+                       SetValue(component, DefaultValue);\r
+               }\r
+\r
+               public override void SetValue(object component, object value)\r
+               {\r
+                       GetDictionary(component)[Name] = (string)value;\r
+               }\r
+\r
+               public override bool ShouldSerializeValue(object component)\r
+               {\r
+                       return CanResetValue(component);\r
+               }\r
+               \r
+               private object DefaultValue\r
+               {\r
+                       get\r
+                       {\r
+                               /* return default value attribute if any */\r
+                               DefaultValueAttribute defaultValueAttribute = (DefaultValueAttribute)Attributes[typeof(DefaultValueAttribute)];\r
+                               return defaultValueAttribute == null ? null : defaultValueAttribute.Value;\r
+                       }\r
+               }\r
+               \r
+               private IDictionary<string, string> GetDictionary(object component)\r
+               {\r
+                       /* if the component is a graph, return the appropriate dictionary */\r
+                       Graph graph = component as Graph;\r
+                       if (graph != null)\r
+                               switch (_graphComponent) {\r
+                                       case "graph":\r
+                                               return graph.GraphAttributes;\r
+                                       case "node":\r
+                                               return graph.DefaultNodeAttributes;\r
+                                       case "edge":\r
+                                               return graph.DefaultEdgeAttributes;\r
+                                       default:\r
+                                               return null;\r
+                               }\r
+                       else\r
+                               return null;            \r
+               }\r
+               \r
+               private readonly string _graphComponent;\r
+       }\r
+}\r
index 2589a9ebca082676297dabda6af2af54daf9b91d..30b2d2b86b7f8541be2c3edb49bd98bb6d7965ba 100755 (executable)
@@ -16,9 +16,6 @@
 \r
 using System;\r
 using System.Collections.Generic;\r
-using System.Collections.ObjectModel;\r
-using System.IO;\r
-using System.Windows.Forms;\r
 \r
 using Microsoft.VisualBasic.ApplicationServices;\r
 \r
@@ -30,13 +27,14 @@ namespace Graphviz
                {\r
                        /* if no files opened from the Explorer, pose the open file dialog to get them, then open the lot */\r
                        ICollection<string> filesToOpen = eventArgs.CommandLine.Count == 0 ?\r
-                               (ICollection<string>)FilesToOpen() :\r
+                               (ICollection<string>)FormController.Instance.FilesToOpen() :\r
                                (ICollection<string>)eventArgs.CommandLine;\r
                        if (filesToOpen != null) {\r
-                               OpenFiles(filesToOpen);\r
+                               MainForm = FormController.Instance.OpenFiles(filesToOpen);\r
                                return base.OnStartup(eventArgs);\r
                        }\r
                        else\r
+                               /* user cancelled open dialog, so just quit */\r
                                return false;\r
                }\r
                \r
@@ -44,84 +42,15 @@ namespace Graphviz
                {\r
                        /* if some files opened from the Explorer, open them */\r
                        if (eventArgs.CommandLine.Count > 0)\r
-                               OpenFiles(eventArgs.CommandLine);\r
+                               MainForm = FormController.Instance.OpenFiles(eventArgs.CommandLine);\r
                        base.OnStartupNextInstance(eventArgs);\r
                }\r
                \r
-               private string[] FilesToOpen()\r
-               {\r
-                       /* lazily initialize open file dialog... sometimes we are created only to pass args to the main instance */\r
-                       if (_openFileDialog == null)\r
-                       {\r
-                               _openFileDialog = new OpenFileDialog();\r
-                               _openFileDialog.Filter = "Graphviz graphs (*.dot)|*.dot|All files (*.*)|*.*";\r
-                               _openFileDialog.Multiselect = true;\r
-                       }\r
-                       \r
-                       /* if user said OK, return the files he selected */\r
-                       return _openFileDialog.ShowDialog() == DialogResult.OK ? _openFileDialog.FileNames : null;\r
-               }\r
-               \r
-               private void OpenFiles(ICollection<string> filenames)\r
-               {\r
-                       Form foundForm = null;\r
-                       foreach (string filename in filenames) {\r
-                               string canonicalFilename = Path.GetFullPath(filename).ToLower();\r
-                               if (_documentForms.ContainsKey(canonicalFilename))\r
-                                       foundForm = _documentForms[canonicalFilename];\r
-                               else {\r
-                                       GraphForm newForm = new GraphForm(filename);\r
-                                       _documentForms[canonicalFilename] = foundForm = newForm;\r
-\r
-                                       /* when the form closes, remove it from document form list */\r
-                                       newForm.FormClosed += delegate(object sender, FormClosedEventArgs eventArgs)\r
-                                       {\r
-                                               _documentForms.Remove(canonicalFilename);\r
-                                       };\r
-                                       \r
-                                       /* clicking the Open menu item calls our Open method */\r
-                                       newForm.OpenMenuItem.Click += delegate(object sender, EventArgs eventArgs)\r
-                                       {\r
-                                               string[] filesToOpen = FilesToOpen();\r
-                                               if (filesToOpen != null)\r
-                                                       OpenFiles(filesToOpen);\r
-                                       };\r
-\r
-                                       /* compose the Window menu out of all the open form titles */\r
-                                       newForm.WindowMenuItem.DropDownOpening += delegate(object sender, EventArgs eventArgs)\r
-                                       {\r
-                                               ToolStripMenuItem windowMenuItem = sender as ToolStripMenuItem;\r
-                                               if (windowMenuItem != null) {\r
-                                                       windowMenuItem.DropDownItems.Clear();\r
-                                                       int i = 0;\r
-                                                       foreach (Form form in OpenForms) {\r
-                                                               Form innerForm = form;\r
-                                                               ToolStripMenuItem formMenuItem = new ToolStripMenuItem(string.Format("{0} {1}", ++i, form.Text));\r
-                                                               formMenuItem.Checked = Form.ActiveForm == innerForm;\r
-                                                               formMenuItem.Click += delegate(object innerSender, EventArgs innerEventArgs)\r
-                                                               {\r
-                                                                       innerForm.Activate();\r
-                                                               };\r
-                                                               windowMenuItem.DropDownItems.Add(formMenuItem);\r
-                                                       }\r
-                                               }\r
-                                       };\r
-                                       foundForm.Show();\r
-                               }\r
-                       }\r
-                       \r
-                       MainForm = foundForm;\r
-               \r
-               }\r
-               \r
                private Program()\r
                {\r
                        EnableVisualStyles = true;\r
                        IsSingleInstance = true;\r
                        ShutdownStyle = ShutdownMode.AfterAllFormsClose;\r
-                       \r
-                       _openFileDialog = null;\r
-                       _documentForms = new Dictionary<string, Form>();\r
                }\r
                \r
                [STAThread]\r
@@ -129,8 +58,5 @@ namespace Graphviz
                {\r
                        new Program().Run(commandLine);\r
                }\r
-               \r
-               private OpenFileDialog _openFileDialog;\r
-               private readonly IDictionary<string, Form> _documentForms;\r
        }\r
-}
\ No newline at end of file
+}