From: glenlow Date: Wed, 19 Mar 2008 04:15:06 +0000 (+0000) Subject: basic viewer app for Windows X-Git-Tag: LAST_LIBGRAPH~32^2~4488 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=813ba77be2e94843aa406a7ac4b8f7f44feb04c9;p=graphviz basic viewer app for Windows --- diff --git a/windows/Program.cs b/windows/Program.cs new file mode 100755 index 000000000..2589a9ebc --- /dev/null +++ b/windows/Program.cs @@ -0,0 +1,136 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2008 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Windows.Forms; + +using Microsoft.VisualBasic.ApplicationServices; + +namespace Graphviz +{ + public class Program : WindowsFormsApplicationBase + { + protected override bool OnStartup(StartupEventArgs eventArgs) + { + /* if no files opened from the Explorer, pose the open file dialog to get them, then open the lot */ + ICollection filesToOpen = eventArgs.CommandLine.Count == 0 ? + (ICollection)FilesToOpen() : + (ICollection)eventArgs.CommandLine; + if (filesToOpen != null) { + OpenFiles(filesToOpen); + return base.OnStartup(eventArgs); + } + else + return false; + } + + protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs) + { + /* if some files opened from the Explorer, open them */ + if (eventArgs.CommandLine.Count > 0) + OpenFiles(eventArgs.CommandLine); + base.OnStartupNextInstance(eventArgs); + } + + private string[] FilesToOpen() + { + /* lazily initialize open file dialog... sometimes we are created only to pass args to the main instance */ + if (_openFileDialog == null) + { + _openFileDialog = new OpenFileDialog(); + _openFileDialog.Filter = "Graphviz graphs (*.dot)|*.dot|All files (*.*)|*.*"; + _openFileDialog.Multiselect = true; + } + + /* if user said OK, return the files he selected */ + return _openFileDialog.ShowDialog() == DialogResult.OK ? _openFileDialog.FileNames : null; + } + + private void OpenFiles(ICollection filenames) + { + Form foundForm = null; + foreach (string filename in filenames) { + string canonicalFilename = Path.GetFullPath(filename).ToLower(); + if (_documentForms.ContainsKey(canonicalFilename)) + foundForm = _documentForms[canonicalFilename]; + else { + GraphForm newForm = new GraphForm(filename); + _documentForms[canonicalFilename] = foundForm = newForm; + + /* when the form closes, remove it from document form list */ + newForm.FormClosed += delegate(object sender, FormClosedEventArgs eventArgs) + { + _documentForms.Remove(canonicalFilename); + }; + + /* clicking the Open menu item calls our Open method */ + newForm.OpenMenuItem.Click += delegate(object sender, EventArgs eventArgs) + { + string[] filesToOpen = FilesToOpen(); + if (filesToOpen != null) + OpenFiles(filesToOpen); + }; + + /* compose the Window menu out of all the open form titles */ + newForm.WindowMenuItem.DropDownOpening += delegate(object sender, EventArgs eventArgs) + { + ToolStripMenuItem windowMenuItem = sender as ToolStripMenuItem; + if (windowMenuItem != null) { + windowMenuItem.DropDownItems.Clear(); + int i = 0; + foreach (Form form in OpenForms) { + Form innerForm = form; + ToolStripMenuItem formMenuItem = new ToolStripMenuItem(string.Format("{0} {1}", ++i, form.Text)); + formMenuItem.Checked = Form.ActiveForm == innerForm; + formMenuItem.Click += delegate(object innerSender, EventArgs innerEventArgs) + { + innerForm.Activate(); + }; + windowMenuItem.DropDownItems.Add(formMenuItem); + } + } + }; + foundForm.Show(); + } + } + + MainForm = foundForm; + + } + + private Program() + { + EnableVisualStyles = true; + IsSingleInstance = true; + ShutdownStyle = ShutdownMode.AfterAllFormsClose; + + _openFileDialog = null; + _documentForms = new Dictionary(); + } + + [STAThread] + static void Main(string[] commandLine) + { + new Program().Run(commandLine); + } + + private OpenFileDialog _openFileDialog; + private readonly IDictionary _documentForms; + } +} \ No newline at end of file diff --git a/windows/Properties/AssemblyInfo.cs.in b/windows/Properties/AssemblyInfo.cs.in new file mode 100755 index 000000000..7683e18ba --- /dev/null +++ b/windows/Properties/AssemblyInfo.cs.in @@ -0,0 +1,49 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2008 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Graphviz")] +[assembly: AssemblyDescription("Graph Visualization Software")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("AT&T")] +[assembly: AssemblyProduct("Graphviz")] +[assembly: AssemblyCopyright("Copyright © AT&T 1994-2008")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("78c9ce95-59fc-4513-af71-80c41d2424cc")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("@VERSION@")] +[assembly: AssemblyFileVersion("@VERSION@")] diff --git a/windows/Properties/Resources.Designer.cs b/windows/Properties/Resources.Designer.cs new file mode 100755 index 000000000..e51c356d8 --- /dev/null +++ b/windows/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.832 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Graphviz.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Graphviz.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/windows/Properties/Resources.resx b/windows/Properties/Resources.resx new file mode 100755 index 000000000..c40a448a3 --- /dev/null +++ b/windows/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file