diff --git a/CSharp/Applications/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/SessionManager.cs b/CSharp/Applications/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/SessionManager.cs index 2e7260b9..7538c3a2 100644 --- a/CSharp/Applications/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/SessionManager.cs +++ b/CSharp/Applications/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/SessionManager.cs @@ -10,77 +10,77 @@ using UniversalEditor; internal static class SessionManager { - public class Window - { - public class WindowCollection - : System.Collections.ObjectModel.Collection - { - } + public class Window + { + public class WindowCollection + : System.Collections.ObjectModel.Collection + { + } - private int mvarLeft = 0; - public int Left { get { return mvarLeft; } set { mvarLeft = value; } } + private int mvarLeft = 0; + public int Left { get { return mvarLeft; } set { mvarLeft = value; } } - private int mvarTop = 0; - public int Top { get { return mvarTop; } set { mvarTop = value; } } + private int mvarTop = 0; + public int Top { get { return mvarTop; } set { mvarTop = value; } } - private int mvarWidth = 0; - public int Width { get { return mvarWidth; } set { mvarWidth = value; } } + private int mvarWidth = 0; + public int Width { get { return mvarWidth; } set { mvarWidth = value; } } - private int mvarHeight = 0; - public int Height { get { return mvarHeight; } set { mvarHeight = value; } } + private int mvarHeight = 0; + public int Height { get { return mvarHeight; } set { mvarHeight = value; } } - private System.Windows.Forms.FormWindowState mvarWindowState = System.Windows.Forms.FormWindowState.Normal; - public System.Windows.Forms.FormWindowState WindowState { get { return mvarWindowState; } set { mvarWindowState = value; } } + private System.Windows.Forms.FormWindowState mvarWindowState = System.Windows.Forms.FormWindowState.Normal; + public System.Windows.Forms.FormWindowState WindowState { get { return mvarWindowState; } set { mvarWindowState = value; } } - private List mvarFileNames = new List(); - public List FileNames { get { return mvarFileNames; } } + private List mvarFileNames = new List(); + public List FileNames { get { return mvarFileNames; } } - } - public class Session - { - public class SessionCollection - : System.Collections.ObjectModel.Collection - { - } + } + public class Session + { + public class SessionCollection + : System.Collections.ObjectModel.Collection + { + } - private string mvarTitle = String.Empty; - public string Title { get { return mvarTitle; } set { mvarTitle = value; } } + private string mvarTitle = String.Empty; + public string Title { get { return mvarTitle; } set { mvarTitle = value; } } - private Window.WindowCollection mvarWindows = new Window.WindowCollection(); - public Window.WindowCollection Windows { get { return mvarWindows; } } - } + private Window.WindowCollection mvarWindows = new Window.WindowCollection(); + public Window.WindowCollection Windows { get { return mvarWindows; } } + } - private static string mvarDataFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] - { - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "Mike Becker's Software", - "Universal Editor", - "Sessions.xml" - }); - public static string DataFileName { get { return mvarDataFileName; } set { mvarDataFileName = value; } } + private static string mvarDataFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] + { + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "Mike Becker's Software", + "Universal Editor", + "Sessions.xml" + }); + public static string DataFileName { get { return mvarDataFileName; } set { mvarDataFileName = value; } } - private static Session.SessionCollection mvarSessions = new Session.SessionCollection(); - public static Session.SessionCollection Sessions { get { return mvarSessions; } } + private static Session.SessionCollection mvarSessions = new Session.SessionCollection(); + public static Session.SessionCollection Sessions { get { return mvarSessions; } } - private static Version mvarFormatVersion = new Version(1, 0); + private static Version mvarFormatVersion = new Version(1, 0); - public static void Load() - { - MarkupObjectModel mom = new MarkupObjectModel(); - XMLDataFormat xml = new XMLDataFormat(); + public static void Load() + { + MarkupObjectModel mom = new MarkupObjectModel(); + XMLDataFormat xml = new XMLDataFormat(); - if (!System.IO.File.Exists(mvarDataFileName)) return; + if (!System.IO.File.Exists(mvarDataFileName)) return; - Document.Load(mom, xml, new FileAccessor(mvarDataFileName), true); + Document.Load(mom, xml, new FileAccessor(mvarDataFileName), true); - MarkupTagElement tagSessions = (mom.Elements["Sessions"] as MarkupTagElement); - if (tagSessions == null) return; + MarkupTagElement tagSessions = (mom.Elements["Sessions"] as MarkupTagElement); + if (tagSessions == null) return; - MarkupAttribute attVersion = tagSessions.Attributes["Version"]; - if (attVersion != null) - { - mvarFormatVersion = new Version(attVersion.Value); - } + MarkupAttribute attVersion = tagSessions.Attributes["Version"]; + if (attVersion != null) + { + mvarFormatVersion = new Version(attVersion.Value); + } foreach (MarkupElement elSession in tagSessions.Elements) { @@ -88,123 +88,123 @@ internal static class SessionManager if (tagSession == null) continue; if (tagSession.FullName != "Session") continue; - MarkupAttribute attTitle = tagSession.Attributes["Title"]; - if (attTitle == null) continue; + MarkupAttribute attTitle = tagSession.Attributes["Title"]; + if (attTitle == null) continue; - Session session = new Session(); - session.Title = attTitle.Value; + Session session = new Session(); + session.Title = attTitle.Value; - MarkupTagElement tagWindows = (tagSession.Elements["Windows"] as MarkupTagElement); - foreach (MarkupElement elWindow in tagWindows.Elements) - { - MarkupTagElement tagWindow = (elWindow as MarkupTagElement); - if (tagWindow == null) continue; - if (tagWindow.FullName != "Window") continue; + MarkupTagElement tagWindows = (tagSession.Elements["Windows"] as MarkupTagElement); + foreach (MarkupElement elWindow in tagWindows.Elements) + { + MarkupTagElement tagWindow = (elWindow as MarkupTagElement); + if (tagWindow == null) continue; + if (tagWindow.FullName != "Window") continue; - Window window = new Window(); + Window window = new Window(); - int left = 0, top = 0, width = 600, height = 400; + int left = 0, top = 0, width = 600, height = 400; - MarkupAttribute attLeft = tagWindow.Attributes["Left"]; - if (attLeft != null) Int32.TryParse(attLeft.Value, out left); - MarkupAttribute attTop = tagWindow.Attributes["Top"]; - if (attTop != null) Int32.TryParse(attTop.Value, out top); - MarkupAttribute attWidth = tagWindow.Attributes["Width"]; - if (attWidth != null) Int32.TryParse(attWidth.Value, out width); - MarkupAttribute attHeight = tagWindow.Attributes["Height"]; - if (attHeight != null) Int32.TryParse(attHeight.Value, out height); + MarkupAttribute attLeft = tagWindow.Attributes["Left"]; + if (attLeft != null) Int32.TryParse(attLeft.Value, out left); + MarkupAttribute attTop = tagWindow.Attributes["Top"]; + if (attTop != null) Int32.TryParse(attTop.Value, out top); + MarkupAttribute attWidth = tagWindow.Attributes["Width"]; + if (attWidth != null) Int32.TryParse(attWidth.Value, out width); + MarkupAttribute attHeight = tagWindow.Attributes["Height"]; + if (attHeight != null) Int32.TryParse(attHeight.Value, out height); - window.Left = left; - window.Top = top; - window.Width = width; - window.Height = height; + window.Left = left; + window.Top = top; + window.Width = width; + window.Height = height; - MarkupTagElement tagDocuments = (tagWindow.Elements["Documents"] as MarkupTagElement); - if (tagDocuments != null) - { - foreach (MarkupElement elDocument in tagDocuments.Elements) - { - MarkupTagElement tagDocument = (elDocument as MarkupTagElement); - if (tagDocument == null) continue; - if (tagDocument.FullName != "Document") continue; + MarkupTagElement tagDocuments = (tagWindow.Elements["Documents"] as MarkupTagElement); + if (tagDocuments != null) + { + foreach (MarkupElement elDocument in tagDocuments.Elements) + { + MarkupTagElement tagDocument = (elDocument as MarkupTagElement); + if (tagDocument == null) continue; + if (tagDocument.FullName != "Document") continue; - MarkupAttribute attFileName = tagDocument.Attributes["FileName"]; - if (attFileName == null) continue; + MarkupAttribute attFileName = tagDocument.Attributes["FileName"]; + if (attFileName == null) continue; - window.FileNames.Add(attFileName.Value); - } - } + window.FileNames.Add(attFileName.Value); + } + } - session.Windows.Add(window); - } + session.Windows.Add(window); + } - mvarSessions.Add(session); + mvarSessions.Add(session); } - } - public static void Save() - { - MarkupObjectModel mom = new MarkupObjectModel(); - UniversalEditor.ObjectModel om = mom; + } + public static void Save() + { + MarkupObjectModel mom = new MarkupObjectModel(); + UniversalEditor.ObjectModel om = mom; - XMLDataFormat xml = new XMLDataFormat(); + XMLDataFormat xml = new XMLDataFormat(); - MarkupPreprocessorElement xmlp = new MarkupPreprocessorElement(); - xmlp.FullName = "xml"; - xmlp.Value = "version=\"1.0\" encoding=\"UTF-8\""; - mom.Elements.Add(xmlp); + MarkupPreprocessorElement xmlp = new MarkupPreprocessorElement(); + xmlp.FullName = "xml"; + xmlp.Value = "version=\"1.0\" encoding=\"UTF-8\""; + mom.Elements.Add(xmlp); - MarkupTagElement tagSessions = new MarkupTagElement(); - tagSessions.FullName = "Sessions"; - tagSessions.Attributes.Add("Version", mvarFormatVersion.ToString()); + MarkupTagElement tagSessions = new MarkupTagElement(); + tagSessions.FullName = "Sessions"; + tagSessions.Attributes.Add("Version", mvarFormatVersion.ToString()); - mom.Elements.Add(tagSessions); + mom.Elements.Add(tagSessions); - if (mvarSessions.Count > 0) - { - foreach (Session session in mvarSessions) - { - if (session.Windows.Count < 1) continue; + if (mvarSessions.Count > 0) + { + foreach (Session session in mvarSessions) + { + if (session.Windows.Count < 1) continue; - MarkupTagElement tagSession = new MarkupTagElement(); - tagSession.FullName = "Session"; + MarkupTagElement tagSession = new MarkupTagElement(); + tagSession.FullName = "Session"; - tagSession.Attributes.Add("Title", session.Title); + tagSession.Attributes.Add("Title", session.Title); - MarkupTagElement tagWindows = new MarkupTagElement(); - tagWindows.FullName = "Windows"; + MarkupTagElement tagWindows = new MarkupTagElement(); + tagWindows.FullName = "Windows"; - foreach (Window window in session.Windows) - { - MarkupTagElement tagWindow = new MarkupTagElement(); - tagWindow.FullName = "Window"; - - tagWindow.Attributes.Add("Left", window.Left.ToString()); - tagWindow.Attributes.Add("Top", window.Top.ToString()); - tagWindow.Attributes.Add("Width", window.Width.ToString()); - tagWindow.Attributes.Add("Height", window.Height.ToString()); + foreach (Window window in session.Windows) + { + MarkupTagElement tagWindow = new MarkupTagElement(); + tagWindow.FullName = "Window"; + + tagWindow.Attributes.Add("Left", window.Left.ToString()); + tagWindow.Attributes.Add("Top", window.Top.ToString()); + tagWindow.Attributes.Add("Width", window.Width.ToString()); + tagWindow.Attributes.Add("Height", window.Height.ToString()); - if (window.FileNames.Count > 0) - { - MarkupTagElement tagDocuments = new MarkupTagElement(); - tagDocuments.FullName = "Documents"; - foreach (string fileName in window.FileNames) - { - MarkupTagElement tagDocument = new MarkupTagElement(); - tagDocument.FullName = "Document"; - tagDocument.Attributes.Add("FileName", fileName); - tagDocuments.Elements.Add(tagDocument); - } - tagWindow.Elements.Add(tagDocuments); - } + if (window.FileNames.Count > 0) + { + MarkupTagElement tagDocuments = new MarkupTagElement(); + tagDocuments.FullName = "Documents"; + foreach (string fileName in window.FileNames) + { + MarkupTagElement tagDocument = new MarkupTagElement(); + tagDocument.FullName = "Document"; + tagDocument.Attributes.Add("FileName", fileName); + tagDocuments.Elements.Add(tagDocument); + } + tagWindow.Elements.Add(tagDocuments); + } - tagWindows.Elements.Add(tagWindow); - } - tagSession.Elements.Add(tagWindows); + tagWindows.Elements.Add(tagWindow); + } + tagSession.Elements.Add(tagWindows); - tagSessions.Elements.Add(tagSession); - } - } + tagSessions.Elements.Add(tagSession); + } + } Document.Save(om, xml, new FileAccessor(mvarDataFileName, true, true), true); - } + } }