Moving much of the WindowsFormsEngine-specific, engine-agnostic stuff to Engine proper
This commit is contained in:
parent
b900065d18
commit
3353898ae2
@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using UniversalEditor.ObjectModels.Markup;
|
||||
using UniversalEditor.DataFormats.Markup.XML;
|
||||
using System.Drawing;
|
||||
using UniversalEditor.Accessors;
|
||||
|
||||
namespace UniversalEditor.UserInterface.WindowsForms
|
||||
{
|
||||
public class LocalConfiguration
|
||||
{
|
||||
private static string mvarApplicationName = "Universal Editor";
|
||||
public static string ApplicationName { get { return mvarApplicationName; } set { mvarApplicationName = value; } }
|
||||
|
||||
private static string mvarApplicationShortName = "universal-editor"; // polymolive
|
||||
public static string ApplicationShortName { get { return mvarApplicationShortName; } set { mvarApplicationShortName = value; } }
|
||||
|
||||
private static string mvarCompanyName = "Mike Becker's Software";
|
||||
public static string CompanyName { get { return mvarCompanyName; } set { mvarCompanyName = value; } }
|
||||
|
||||
private static SplashScreenSettings mvarSplashScreen = new SplashScreenSettings();
|
||||
public static SplashScreenSettings SplashScreen { get { return mvarSplashScreen; } }
|
||||
|
||||
private static StartPageSettings mvarStartPage = new StartPageSettings();
|
||||
public static StartPageSettings StartPage { get { return mvarStartPage; } }
|
||||
|
||||
private static ColorSchemeSettings mvarColorScheme = new ColorSchemeSettings();
|
||||
public static ColorSchemeSettings ColorScheme { get { return mvarColorScheme; } }
|
||||
|
||||
private static bool mvarConfirmExit = false;
|
||||
public static bool ConfirmExit { get { return mvarConfirmExit; } set { mvarConfirmExit = value; } }
|
||||
|
||||
private static void LoadPreliminaryConfiguration(ref MarkupObjectModel mom)
|
||||
{
|
||||
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
LoadConfigurationFiles(path, ref mom);
|
||||
|
||||
MarkupTagElement tagTitle = (mom.FindElement("UniversalEditor", "Application", "Title") as MarkupTagElement);
|
||||
if (tagTitle != null)
|
||||
{
|
||||
mvarApplicationName = tagTitle.Value;
|
||||
}
|
||||
MarkupTagElement tagShortTitle = (mom.FindElement("UniversalEditor", "Application", "ShortTitle") as MarkupTagElement);
|
||||
if (tagShortTitle != null)
|
||||
{
|
||||
mvarApplicationShortName = tagShortTitle.Value;
|
||||
}
|
||||
MarkupTagElement tagCompanyName = (mom.FindElement("UniversalEditor", "Application", "CompanyName") as MarkupTagElement);
|
||||
if (tagCompanyName != null)
|
||||
{
|
||||
mvarCompanyName = tagCompanyName.Value;
|
||||
}
|
||||
}
|
||||
|
||||
static LocalConfiguration()
|
||||
{
|
||||
MarkupObjectModel mom = new MarkupObjectModel();
|
||||
|
||||
LoadPreliminaryConfiguration(ref mom);
|
||||
|
||||
List<string> paths = new List<string>();
|
||||
switch (Environment.OSVersion.Platform)
|
||||
{
|
||||
case PlatformID.MacOSX:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case PlatformID.Unix:
|
||||
{
|
||||
paths.Add(String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] { System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), mvarApplicationShortName }));
|
||||
paths.Add(String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] { System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), mvarApplicationShortName }));
|
||||
paths.Add(String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] { System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), mvarApplicationShortName }));
|
||||
break;
|
||||
}
|
||||
case PlatformID.Win32NT:
|
||||
case PlatformID.Win32S:
|
||||
case PlatformID.Win32Windows:
|
||||
case PlatformID.WinCE:
|
||||
{
|
||||
paths.Add(String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] { System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), mvarCompanyName, mvarApplicationName }));
|
||||
paths.Add(String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] { System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), mvarCompanyName, mvarApplicationName }));
|
||||
paths.Add(String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] { System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Mike Becker's Software", "PolyMo Live!" }));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string path in paths)
|
||||
{
|
||||
if (!System.IO.Directory.Exists(path)) continue;
|
||||
LoadConfigurationFiles(path, ref mom);
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadConfigurationFiles(string path, ref MarkupObjectModel mom)
|
||||
{
|
||||
string[] xmlfiles = null;
|
||||
try
|
||||
{
|
||||
xmlfiles = System.IO.Directory.GetFiles(path, "*.xml", System.IO.SearchOption.AllDirectories);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
if (xmlfiles == null) return;
|
||||
|
||||
foreach (string xmlfile in xmlfiles)
|
||||
{
|
||||
MarkupObjectModel local_mom = new MarkupObjectModel();
|
||||
|
||||
Document doc = new Document(local_mom, new XMLDataFormat(), new FileAccessor(xmlfile));
|
||||
if (local_mom.FindElement("UniversalEditor") == null) continue;
|
||||
|
||||
local_mom.CopyTo(mom);
|
||||
}
|
||||
}
|
||||
|
||||
private static System.Drawing.Icon mvarMainIcon = null;
|
||||
public static System.Drawing.Icon MainIcon { get { return mvarMainIcon; } set { mvarMainIcon = value; } }
|
||||
}
|
||||
|
||||
public class StartPageSettings
|
||||
{
|
||||
private bool mvarShowOnStartup = true;
|
||||
public bool ShowOnStartup { get { return mvarShowOnStartup; } set { mvarShowOnStartup = value; } }
|
||||
|
||||
private string mvarHeaderImageFileName = @"Images/SplashScreen/header2.png"; // null;
|
||||
public string HeaderImageFileName { get { return mvarHeaderImageFileName; } set { mvarHeaderImageFileName = value; } }
|
||||
}
|
||||
|
||||
public class ColorSchemeSettings
|
||||
{
|
||||
private Color mvarDarkColor = Color.FromArgb(30, 30, 30);
|
||||
public Color DarkColor { get { return mvarDarkColor; } set { mvarDarkColor = value; } }
|
||||
private Color mvarLightColor = Color.FromArgb(51, 51, 51);
|
||||
public Color LightColor { get { return mvarLightColor; } set { mvarLightColor = value; } }
|
||||
private Color mvarBackgroundColor = Color.FromArgb(77, 77, 77);
|
||||
public Color BackgroundColor { get { return mvarBackgroundColor; } set { mvarBackgroundColor = value; } }
|
||||
}
|
||||
}
|
||||
@ -16,6 +16,8 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
{
|
||||
public partial class MainWindow : AwesomeControls.Window, IHostApplicationWindow
|
||||
{
|
||||
internal WindowsFormsEngine engine = null;
|
||||
|
||||
#region Docking Windows
|
||||
private Controls.ErrorList pnlErrorList = new Controls.ErrorList();
|
||||
private DockingWindow dwErrorList = null;
|
||||
@ -31,6 +33,16 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
private DockingWindow dwOutput = null;
|
||||
#endregion
|
||||
|
||||
public void ActivateWindow()
|
||||
{
|
||||
// Invoke required when being called from SingleInstance_Callback
|
||||
Invoke(new Action(delegate()
|
||||
{
|
||||
Activate();
|
||||
BringToFront();
|
||||
}));
|
||||
}
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -38,8 +50,8 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
|
||||
pnlSolutionExplorer.ParentWindow = this;
|
||||
|
||||
this.Icon = Configuration.MainIcon;
|
||||
this.Text = Configuration.ApplicationName;
|
||||
this.Icon = LocalConfiguration.MainIcon;
|
||||
this.Text = LocalConfiguration.ApplicationName;
|
||||
|
||||
mnuContextDocumentTypeDataFormat.Font = new Font(SystemFonts.MenuFont, FontStyle.Bold);
|
||||
|
||||
@ -52,8 +64,8 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
HostApplication.Messages.MessageAdded += Messages_MessageAdded;
|
||||
HostApplication.Messages.MessageRemoved += Messages_MessageRemoved;
|
||||
|
||||
mnuBookmarksSep1.Visible = (BookmarksManager.FileNames.Count > 0);
|
||||
foreach (string FileName in BookmarksManager.FileNames)
|
||||
mnuBookmarksSep1.Visible = (engine.BookmarksManager.FileNames.Count > 0);
|
||||
foreach (string FileName in engine.BookmarksManager.FileNames)
|
||||
{
|
||||
ToolStripMenuItem tsmi = new ToolStripMenuItem();
|
||||
tsmi.Text = System.IO.Path.GetFileName(FileName);
|
||||
@ -1809,7 +1821,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
{
|
||||
if (doc.Accessor is FileAccessor)
|
||||
{
|
||||
if (!BookmarksManager.FileNames.Contains((doc.Accessor as FileAccessor).FileName))
|
||||
if (!engine.BookmarksManager.FileNames.Contains((doc.Accessor as FileAccessor).FileName))
|
||||
{
|
||||
ToolStripMenuItem mnu = new ToolStripMenuItem();
|
||||
mnu.Text = System.IO.Path.GetFileName((doc.Accessor as FileAccessor).FileName);
|
||||
@ -1818,7 +1830,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
mnuBookmarks.DropDownItems.Insert(mnuBookmarks.DropDownItems.Count - 2, mnu);
|
||||
mnuBookmarksSep1.Visible = true;
|
||||
|
||||
BookmarksManager.FileNames.Add((doc.Accessor as FileAccessor).FileName);
|
||||
engine.BookmarksManager.FileNames.Add((doc.Accessor as FileAccessor).FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,15 +17,15 @@ namespace UniversalEditor.UserInterface.WindowsForms.Pages
|
||||
Title = "Start Page";
|
||||
Description = "Start Page";
|
||||
|
||||
lblApplicationTitle.Text = Configuration.ApplicationName;
|
||||
lblApplicationTitle.Text = LocalConfiguration.ApplicationName;
|
||||
|
||||
pnlTop.BackColor = Configuration.ColorScheme.DarkColor;
|
||||
pnlSide.BackColor = Configuration.ColorScheme.LightColor;
|
||||
BackColor = Configuration.ColorScheme.BackgroundColor;
|
||||
pnlTop.BackColor = LocalConfiguration.ColorScheme.DarkColor;
|
||||
pnlSide.BackColor = LocalConfiguration.ColorScheme.LightColor;
|
||||
BackColor = LocalConfiguration.ColorScheme.BackgroundColor;
|
||||
|
||||
if (Configuration.MainIcon != null)
|
||||
if (LocalConfiguration.MainIcon != null)
|
||||
{
|
||||
picIcon.Image = Configuration.MainIcon.ToBitmap();
|
||||
picIcon.Image = LocalConfiguration.MainIcon.ToBitmap();
|
||||
}
|
||||
|
||||
foreach (string FileName in RecentFileManager.FileNames)
|
||||
|
||||
@ -28,17 +28,17 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
}
|
||||
*/
|
||||
|
||||
if (Configuration.SplashScreen.Image != null)
|
||||
if (LocalConfiguration.SplashScreen.Image != null)
|
||||
{
|
||||
pictureBox1.Image = Configuration.SplashScreen.Image;
|
||||
pictureBox1.Image = LocalConfiguration.SplashScreen.Image;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!String.IsNullOrEmpty(Configuration.SplashScreen.ImageFileName))
|
||||
if (!String.IsNullOrEmpty(LocalConfiguration.SplashScreen.ImageFileName))
|
||||
{
|
||||
if (System.IO.File.Exists(Configuration.SplashScreen.ImageFileName))
|
||||
if (System.IO.File.Exists(LocalConfiguration.SplashScreen.ImageFileName))
|
||||
{
|
||||
pictureBox1.Image = Image.FromFile(Configuration.SplashScreen.ImageFileName);
|
||||
pictureBox1.Image = Image.FromFile(LocalConfiguration.SplashScreen.ImageFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,16 +49,16 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
{
|
||||
base.OnShown(e);
|
||||
|
||||
if (Configuration.SplashScreen.Sound != null)
|
||||
if (LocalConfiguration.SplashScreen.Sound != null)
|
||||
{
|
||||
System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Configuration.SplashScreen.Sound);
|
||||
System.Media.SoundPlayer sp = new System.Media.SoundPlayer(LocalConfiguration.SplashScreen.Sound);
|
||||
sp.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (System.IO.File.Exists(Configuration.SplashScreen.SoundFileName))
|
||||
if (System.IO.File.Exists(LocalConfiguration.SplashScreen.SoundFileName))
|
||||
{
|
||||
System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Configuration.SplashScreen.SoundFileName);
|
||||
System.Media.SoundPlayer sp = new System.Media.SoundPlayer(LocalConfiguration.SplashScreen.SoundFileName);
|
||||
sp.Play();
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,12 +44,10 @@
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Runtime.Remoting" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BookmarksManager.cs" />
|
||||
<Compile Include="Configuration.cs" />
|
||||
<Compile Include="LocalConfiguration.cs" />
|
||||
<Compile Include="Controls\ErrorList.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
@ -181,9 +179,6 @@
|
||||
</Compile>
|
||||
<Compile Include="WindowsFormsEngine.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RecentFileManager.cs" />
|
||||
<Compile Include="SessionManager.cs" />
|
||||
<Compile Include="SingleInstanceManager.cs" />
|
||||
<Compile Include="SplashScreenWindow.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
@ -17,8 +17,6 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
|
||||
internal class WindowsFormsEngine : Engine
|
||||
{
|
||||
private static readonly string INSTANCEID = "UniversalEditor.UserInterface.WindowsForms.DesktopApplication$2d429aa3371c421fb63b42525e51a50c$92751853175891031214292357218181357901238$" + System.Reflection.Assembly.GetEntryAssembly().Location;
|
||||
|
||||
internal static MainWindow LastWindow = null;
|
||||
|
||||
private static List<MainWindow> mvarWindows = new List<MainWindow>();
|
||||
@ -28,26 +26,6 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
|
||||
public static bool SessionLoading = false;
|
||||
|
||||
// UniversalDataStorage.Editor.WindowsForms.Program
|
||||
private static void SingleInstanceManager_Callback(object sender, SingleInstanceManager.InstanceCallbackEventArgs e)
|
||||
{
|
||||
if (!e.IsFirstInstance)
|
||||
{
|
||||
if (WindowsFormsEngine.LastWindow != null)
|
||||
{
|
||||
WindowsFormsEngine.LastWindow.Invoke(new Action(delegate()
|
||||
{
|
||||
for (int i = 1; i < e.CommandLineArgs.Length; i++)
|
||||
{
|
||||
LastWindow.OpenFile(e.CommandLineArgs[i].ToString());
|
||||
}
|
||||
WindowsFormsEngine.LastWindow.Activate();
|
||||
WindowsFormsEngine.LastWindow.BringToFront();
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void InitializeBranding()
|
||||
{
|
||||
base.InitializeBranding();
|
||||
@ -64,21 +42,21 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
if (fileSplashScreenImage != null)
|
||||
{
|
||||
System.IO.MemoryStream ms = new System.IO.MemoryStream(fileSplashScreenImage.GetDataAsByteArray());
|
||||
Configuration.SplashScreen.Image = System.Drawing.Image.FromStream(ms);
|
||||
LocalConfiguration.SplashScreen.Image = System.Drawing.Image.FromStream(ms);
|
||||
}
|
||||
|
||||
UniversalEditor.ObjectModels.FileSystem.File fileSplashScreenSound = fsom.Files["SplashScreen.wav"];
|
||||
if (fileSplashScreenSound != null)
|
||||
{
|
||||
System.IO.MemoryStream ms = new System.IO.MemoryStream(fileSplashScreenSound.GetDataAsByteArray());
|
||||
Configuration.SplashScreen.Sound = ms;
|
||||
LocalConfiguration.SplashScreen.Sound = ms;
|
||||
}
|
||||
|
||||
UniversalEditor.ObjectModels.FileSystem.File fileMainIcon = fsom.Files["MainIcon.ico"];
|
||||
if (fileMainIcon != null)
|
||||
{
|
||||
System.IO.MemoryStream ms = new System.IO.MemoryStream(fileMainIcon.GetDataAsByteArray());
|
||||
Configuration.MainIcon = new System.Drawing.Icon(ms);
|
||||
LocalConfiguration.MainIcon = new System.Drawing.Icon(ms);
|
||||
}
|
||||
|
||||
UniversalEditor.ObjectModels.FileSystem.File fileConfiguration = fsom.Files["Configuration.upl"];
|
||||
@ -89,10 +67,10 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
UniversalEditor.ObjectModels.PropertyList.PropertyListObjectModel plomBranding = new ObjectModels.PropertyList.PropertyListObjectModel();
|
||||
Document.Load(plomBranding, new UniversalPropertyListDataFormat(), new StreamAccessor(ms), true);
|
||||
|
||||
Configuration.ApplicationName = plomBranding.GetValue<string>(new string[] { "Application", "Title" }, String.Empty);
|
||||
LocalConfiguration.ApplicationName = plomBranding.GetValue<string>(new string[] { "Application", "Title" }, String.Empty);
|
||||
|
||||
Configuration.ColorScheme.DarkColor = ParseColor(plomBranding.GetValue<string>(new string[] { "ColorScheme", "DarkColor" }, "#2A0068"));
|
||||
Configuration.ColorScheme.LightColor = ParseColor(plomBranding.GetValue<string>(new string[] { "ColorScheme", "LightColor" }, "#C0C0FF"));
|
||||
LocalConfiguration.ColorScheme.DarkColor = ParseColor(plomBranding.GetValue<string>(new string[] { "ColorScheme", "DarkColor" }, "#2A0068"));
|
||||
LocalConfiguration.ColorScheme.LightColor = ParseColor(plomBranding.GetValue<string>(new string[] { "ColorScheme", "LightColor" }, "#C0C0FF"));
|
||||
}
|
||||
|
||||
fa.Close();
|
||||
@ -107,7 +85,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
"Branding",
|
||||
"SplashScreen.png"
|
||||
});
|
||||
if (System.IO.File.Exists(SplashScreenImageFileName)) Configuration.SplashScreen.ImageFileName = SplashScreenImageFileName;
|
||||
if (System.IO.File.Exists(SplashScreenImageFileName)) LocalConfiguration.SplashScreen.ImageFileName = SplashScreenImageFileName;
|
||||
|
||||
string SplashScreenSoundFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[]
|
||||
{
|
||||
@ -115,7 +93,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
"Branding",
|
||||
"SplashScreen.wav"
|
||||
});
|
||||
if (System.IO.File.Exists(SplashScreenSoundFileName)) Configuration.SplashScreen.SoundFileName = SplashScreenSoundFileName;
|
||||
if (System.IO.File.Exists(SplashScreenSoundFileName)) LocalConfiguration.SplashScreen.SoundFileName = SplashScreenSoundFileName;
|
||||
|
||||
string MainIconFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[]
|
||||
{
|
||||
@ -123,7 +101,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
"Branding",
|
||||
"MainIcon.ico"
|
||||
});
|
||||
if (System.IO.File.Exists(MainIconFileName)) Configuration.MainIcon = System.Drawing.Icon.ExtractAssociatedIcon(MainIconFileName);
|
||||
if (System.IO.File.Exists(MainIconFileName)) LocalConfiguration.MainIcon = System.Drawing.Icon.ExtractAssociatedIcon(MainIconFileName);
|
||||
|
||||
string ConfigurationFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[]
|
||||
{
|
||||
@ -136,10 +114,10 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
UniversalEditor.ObjectModels.PropertyList.PropertyListObjectModel plomBranding = new ObjectModels.PropertyList.PropertyListObjectModel();
|
||||
Document.Load(plomBranding, new UniversalPropertyListDataFormat(), new FileAccessor(ConfigurationFileName), true);
|
||||
|
||||
Configuration.ApplicationName = plomBranding.GetValue<string>(new string[] { "Application", "Title" }, String.Empty);
|
||||
LocalConfiguration.ApplicationName = plomBranding.GetValue<string>(new string[] { "Application", "Title" }, String.Empty);
|
||||
|
||||
Configuration.ColorScheme.DarkColor = ParseColor(plomBranding.GetValue<string>(new string[] { "ColorScheme", "DarkColor" }, "#2A0068"));
|
||||
Configuration.ColorScheme.LightColor = ParseColor(plomBranding.GetValue<string>(new string[] { "ColorScheme", "LightColor" }, "#C0C0FF"));
|
||||
LocalConfiguration.ColorScheme.DarkColor = ParseColor(plomBranding.GetValue<string>(new string[] { "ColorScheme", "DarkColor" }, "#2A0068"));
|
||||
LocalConfiguration.ColorScheme.LightColor = ParseColor(plomBranding.GetValue<string>(new string[] { "ColorScheme", "LightColor" }, "#C0C0FF"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -157,8 +135,6 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
// AwesomeControls.Theming.BuiltinThemes.SlickTheme theme = new AwesomeControls.Theming.BuiltinThemes.SlickTheme();
|
||||
AwesomeControls.Theming.Theme.CurrentTheme = theme;
|
||||
|
||||
if (!SingleInstanceManager.CreateSingleInstance(INSTANCEID, new EventHandler<SingleInstanceManager.InstanceCallbackEventArgs>(WindowsFormsEngine.SingleInstanceManager_Callback))) return;
|
||||
|
||||
Glue.ApplicationInformation.ApplicationID = new Guid("{b359fe9a-080a-43fc-ae38-00ba7ac1703e}");
|
||||
switch (System.Environment.OSVersion.Platform)
|
||||
{
|
||||
@ -179,18 +155,10 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
}
|
||||
}
|
||||
|
||||
RecentFileManager.DataFileName = Configuration.DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "RecentItems.xml";
|
||||
BookmarksManager.DataFileName = Configuration.DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Bookmarks.xml";
|
||||
SessionManager.DataFileName = Configuration.DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Sessions.xml";
|
||||
|
||||
RecentFileManager.Load();
|
||||
BookmarksManager.Load();
|
||||
SessionManager.Load();
|
||||
|
||||
System.Threading.Thread threadLoader = new System.Threading.Thread(threadLoader_ThreadStart);
|
||||
threadLoader.Start();
|
||||
|
||||
if (Configuration.SplashScreen.Enabled)
|
||||
if (LocalConfiguration.SplashScreen.Enabled)
|
||||
{
|
||||
splasher = new SplashScreenWindow();
|
||||
splasher.ShowDialog();
|
||||
@ -389,7 +357,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
// if (Configuration.SplashScreen.Enabled) splasher.InvokeUpdateStatus("Loading data formats...");
|
||||
UniversalEditor.Common.Reflection.GetAvailableDataFormats();
|
||||
|
||||
if (Configuration.SplashScreen.Enabled)
|
||||
if (LocalConfiguration.SplashScreen.Enabled)
|
||||
{
|
||||
while (splasher == null)
|
||||
{
|
||||
@ -406,6 +374,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
public static void OpenWindow(params string[] FileNames)
|
||||
{
|
||||
MainWindow mw = new MainWindow();
|
||||
mw.Engine = this;
|
||||
|
||||
if (FileNames.Length > 0)
|
||||
{
|
||||
@ -418,9 +387,9 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
|
||||
public static void ExitApplication()
|
||||
{
|
||||
if (Configuration.ConfirmExit)
|
||||
if (LocalConfiguration.ConfirmExit)
|
||||
{
|
||||
if (MessageBox.Show("Are you sure you wish to quit " + Configuration.ApplicationName + "?", "Quit Application", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
|
||||
if (MessageBox.Show("Are you sure you wish to quit " + LocalConfiguration.ApplicationName + "?", "Quit Application", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using UniversalEditor.ObjectModels.Markup;
|
||||
using UniversalEditor.DataFormats.Markup.XML;
|
||||
using UniversalEditor.Accessors;
|
||||
using UniversalEditor;
|
||||
|
||||
namespace UniversalEditor.UserInterface
|
||||
{
|
||||
public class BookmarksManager
|
||||
{
|
||||
private System.Collections.Specialized.StringCollection mvarFileNames = new System.Collections.Specialized.StringCollection();
|
||||
public System.Collections.Specialized.StringCollection FileNames { get { return mvarFileNames; } }
|
||||
|
||||
private string mvarDataFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[]
|
||||
{
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"Mike Becker's Software",
|
||||
"Universal Editor",
|
||||
"Bookmarks.xml"
|
||||
});
|
||||
public string DataFileName { get { return mvarDataFileName; } set { mvarDataFileName = value; } }
|
||||
|
||||
private Version mvarFormatVersion = new Version(1, 0);
|
||||
|
||||
public void Load()
|
||||
{
|
||||
MarkupObjectModel mom = new MarkupObjectModel();
|
||||
XMLDataFormat xml = new XMLDataFormat();
|
||||
|
||||
if (!System.IO.File.Exists(mvarDataFileName)) return;
|
||||
|
||||
Document.Load(mom, xml, new FileAccessor(mvarDataFileName), true);
|
||||
|
||||
MarkupTagElement tagBookmarks = (mom.Elements["Bookmarks"] as MarkupTagElement);
|
||||
if (tagBookmarks == null) return;
|
||||
|
||||
MarkupAttribute attVersion = tagBookmarks.Attributes["Version"];
|
||||
if (attVersion != null)
|
||||
{
|
||||
mvarFormatVersion = new Version(attVersion.Value);
|
||||
}
|
||||
|
||||
foreach (MarkupElement elDocument in tagBookmarks.Elements)
|
||||
{
|
||||
MarkupTagElement tagBookmark = (elDocument as MarkupTagElement);
|
||||
if (tagBookmark == null) continue;
|
||||
if (tagBookmark.FullName != "Bookmark") continue;
|
||||
|
||||
MarkupAttribute attFileName = tagBookmark.Attributes["FileName"];
|
||||
if (attFileName == null) continue;
|
||||
|
||||
mvarFileNames.Add(attFileName.Value);
|
||||
}
|
||||
}
|
||||
public void Save()
|
||||
{
|
||||
MarkupObjectModel mom = new MarkupObjectModel();
|
||||
XMLDataFormat xml = new XMLDataFormat();
|
||||
|
||||
MarkupPreprocessorElement xmlp = new MarkupPreprocessorElement();
|
||||
xmlp.FullName = "xml";
|
||||
xmlp.Value = "version=\"1.0\" encoding=\"UTF-8\"";
|
||||
mom.Elements.Add(xmlp);
|
||||
|
||||
MarkupTagElement tagBookmarks = new MarkupTagElement();
|
||||
tagBookmarks.FullName = "Bookmarks";
|
||||
tagBookmarks.Attributes.Add("Version", mvarFormatVersion.ToString());
|
||||
|
||||
mom.Elements.Add(tagBookmarks);
|
||||
|
||||
if (mvarFileNames.Count > 0)
|
||||
{
|
||||
foreach (string fileName in mvarFileNames)
|
||||
{
|
||||
MarkupTagElement tagBookmark = new MarkupTagElement();
|
||||
tagBookmark.FullName = "Bookmark";
|
||||
tagBookmark.Attributes.Add("FileName", fileName);
|
||||
tagBookmarks.Elements.Add(tagBookmark);
|
||||
}
|
||||
}
|
||||
|
||||
Document.Save(mom, xml, new FileAccessor(mvarDataFileName, true, true), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using UniversalEditor.Accessors;
|
||||
using UniversalEditor.ObjectModels.FileSystem;
|
||||
using UniversalEditor.ObjectModels.PropertyList;
|
||||
|
||||
namespace UniversalEditor.UserInterface
|
||||
{
|
||||
@ -11,17 +12,68 @@ namespace UniversalEditor.UserInterface
|
||||
{
|
||||
protected abstract void MainLoop();
|
||||
|
||||
private PropertyListObjectModel mvarConfiguration = new PropertyListObjectModel();
|
||||
public PropertyListObjectModel Configuration { get { return mvarConfiguration; } }
|
||||
|
||||
private System.Collections.ObjectModel.ReadOnlyCollection<string> mvarSelectedFileNames = null;
|
||||
public System.Collections.ObjectModel.ReadOnlyCollection<string> SelectedFileNames { get { return mvarSelectedFileNames; } }
|
||||
|
||||
private string mvarBasePath = String.Empty;
|
||||
public string BasePath { get { return mvarBasePath; } }
|
||||
|
||||
private static string mvarDataPath = null;
|
||||
public static string DataPath
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mvarDataPath == null)
|
||||
{
|
||||
mvarDataPath = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[]
|
||||
{
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"Mike Becker's Software",
|
||||
"Universal Editor"
|
||||
});
|
||||
}
|
||||
return mvarDataPath;
|
||||
}
|
||||
}
|
||||
|
||||
private IHostApplicationWindow mvarLastWindow = null;
|
||||
public IHostApplicationWindow LastWindow { get { return mvarLastWindow; } set { mvarLastWindow = value; } }
|
||||
|
||||
// UniversalDataStorage.Editor.WindowsForms.Program
|
||||
private void SingleInstanceManager_Callback(object sender, SingleInstanceManager.InstanceCallbackEventArgs e)
|
||||
{
|
||||
if (!e.IsFirstInstance)
|
||||
{
|
||||
if (LastWindow != null)
|
||||
{
|
||||
string[] FileNames = new string[e.CommandLineArgs.Length - 1];
|
||||
for (int i = 1; i < e.CommandLineArgs.Length; i++)
|
||||
{
|
||||
FileNames[i - 1] = e.CommandLineArgs[i];
|
||||
}
|
||||
LastWindow.OpenFile(FileNames);
|
||||
LastWindow.ActivateWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void InitializeBranding()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private RecentFileManager mvarRecentFileManager = new RecentFileManager();
|
||||
public RecentFileManager RecentFileManager { get { return mvarRecentFileManager; } }
|
||||
|
||||
private BookmarksManager mvarBookmarksManager = new BookmarksManager();
|
||||
public BookmarksManager BookmarksManager { get { return mvarBookmarksManager; } }
|
||||
|
||||
private SessionManager mvarSessionManager = new SessionManager();
|
||||
public SessionManager SessionManager { get { return mvarSessionManager; } set { mvarSessionManager = value; } }
|
||||
|
||||
public void StartApplication()
|
||||
{
|
||||
string[] args1 = Environment.GetCommandLineArgs();
|
||||
@ -42,6 +94,26 @@ namespace UniversalEditor.UserInterface
|
||||
// Initialize the branding for the selected application
|
||||
InitializeBranding();
|
||||
|
||||
// Initialize Recent File Manager
|
||||
mvarRecentFileManager.DataFileName = DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "RecentItems.xml";
|
||||
mvarRecentFileManager.Load();
|
||||
|
||||
// Initialize Bookmarks Manager
|
||||
mvarBookmarksManager.DataFileName = DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Bookmarks.xml";
|
||||
mvarBookmarksManager.Load();
|
||||
|
||||
// Initialize Session Manager
|
||||
mvarSessionManager.DataFileName = DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Sessions.xml";
|
||||
mvarSessionManager.Load();
|
||||
|
||||
string INSTANCEID = GetType().FullName + "$2d429aa3371c421fb63b42525e51a50c$92751853175891031214292357218181357901238$";
|
||||
if (Configuration.GetValue<bool>("SingleInstanceUniquePerDirectory", true))
|
||||
{
|
||||
// The single instance should be unique per directory
|
||||
INSTANCEID += System.Reflection.Assembly.GetEntryAssembly().Location;
|
||||
}
|
||||
if (!SingleInstanceManager.CreateSingleInstance(INSTANCEID, new EventHandler<SingleInstanceManager.InstanceCallbackEventArgs>(SingleInstanceManager_Callback))) return;
|
||||
|
||||
MainLoop();
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,5 +32,7 @@ namespace UniversalEditor.UserInterface
|
||||
|
||||
void UpdateProgress(bool visible);
|
||||
void UpdateProgress(int minimum, int maximium, int value);
|
||||
|
||||
void ActivateWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using UniversalEditor.ObjectModels.Markup;
|
||||
using UniversalEditor.DataFormats.Markup.XML;
|
||||
using UniversalEditor.Accessors;
|
||||
using UniversalEditor;
|
||||
|
||||
namespace UniversalEditor.UserInterface
|
||||
{
|
||||
public class RecentFileManager
|
||||
{
|
||||
private System.Collections.Specialized.StringCollection mvarFileNames = new System.Collections.Specialized.StringCollection();
|
||||
public System.Collections.Specialized.StringCollection FileNames { get { return mvarFileNames; } }
|
||||
|
||||
private int mvarMaximumDocumentFileNames = 5;
|
||||
public int MaximumDocumentFileNames { get { return mvarMaximumDocumentFileNames; } set { mvarMaximumDocumentFileNames = value; } }
|
||||
|
||||
private string mvarDataFileName = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[]
|
||||
{
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"Mike Becker's Software",
|
||||
"Universal Editor",
|
||||
"RecentItems.xml"
|
||||
});
|
||||
public string DataFileName { get { return mvarDataFileName; } set { mvarDataFileName = value; } }
|
||||
|
||||
private Version mvarFormatVersion = new Version(1, 0);
|
||||
|
||||
public void Load()
|
||||
{
|
||||
MarkupObjectModel mom = new MarkupObjectModel();
|
||||
XMLDataFormat xml = new XMLDataFormat();
|
||||
|
||||
if (!System.IO.File.Exists(mvarDataFileName)) return;
|
||||
|
||||
Document doc = new Document(mom, xml, new FileAccessor(mvarDataFileName));
|
||||
|
||||
MarkupTagElement tagRecentItems = (mom.Elements["RecentItems"] as MarkupTagElement);
|
||||
if (tagRecentItems == null) return;
|
||||
|
||||
MarkupAttribute attVersion = tagRecentItems.Attributes["Version"];
|
||||
if (attVersion != null)
|
||||
{
|
||||
mvarFormatVersion = new Version(attVersion.Value);
|
||||
}
|
||||
|
||||
MarkupTagElement tagSolutions = (tagRecentItems.Elements["Solutions"] as MarkupTagElement);
|
||||
|
||||
MarkupTagElement tagDocuments = (tagRecentItems.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;
|
||||
|
||||
mvarFileNames.Add(attFileName.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Save()
|
||||
{
|
||||
MarkupObjectModel mom = new MarkupObjectModel();
|
||||
XMLDataFormat xml = new XMLDataFormat();
|
||||
|
||||
MarkupPreprocessorElement xmlp = new MarkupPreprocessorElement();
|
||||
xmlp.FullName = "xml";
|
||||
xmlp.Value = "version=\"1.0\" encoding=\"UTF-8\"";
|
||||
mom.Elements.Add(xmlp);
|
||||
|
||||
MarkupTagElement tagRecentItems = new MarkupTagElement();
|
||||
tagRecentItems.FullName = "RecentItems";
|
||||
tagRecentItems.Attributes.Add("Version", mvarFormatVersion.ToString());
|
||||
|
||||
mom.Elements.Add(tagRecentItems);
|
||||
|
||||
if (mvarFileNames.Count > 0)
|
||||
{
|
||||
MarkupTagElement tagDocuments = new MarkupTagElement();
|
||||
tagDocuments.FullName = "Documents";
|
||||
tagDocuments.Attributes.Add("Maximum", mvarMaximumDocumentFileNames.ToString());
|
||||
foreach (string fileName in mvarFileNames)
|
||||
{
|
||||
MarkupTagElement tagDocument = new MarkupTagElement();
|
||||
tagDocument.FullName = "Document";
|
||||
tagDocument.Attributes.Add("FileName", fileName);
|
||||
tagDocuments.Elements.Add(tagDocument);
|
||||
}
|
||||
tagRecentItems.Elements.Add(tagDocuments);
|
||||
}
|
||||
|
||||
Document.Save(mom, xml, new FileAccessor(mvarDataFileName, true, true), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
213
CSharp/Libraries/UniversalEditor.UserInterface/SessionManager.cs
Normal file
213
CSharp/Libraries/UniversalEditor.UserInterface/SessionManager.cs
Normal file
@ -0,0 +1,213 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using UniversalEditor.ObjectModels.Markup;
|
||||
using UniversalEditor.DataFormats.Markup.XML;
|
||||
using UniversalEditor.Accessors;
|
||||
using UniversalEditor;
|
||||
|
||||
namespace UniversalEditor.UserInterface
|
||||
{
|
||||
public class SessionManager
|
||||
{
|
||||
public class Window
|
||||
{
|
||||
public class WindowCollection
|
||||
: System.Collections.ObjectModel.Collection<Window>
|
||||
{
|
||||
}
|
||||
|
||||
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 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 WindowState mvarWindowState = WindowState.Normal;
|
||||
public WindowState WindowState { get { return mvarWindowState; } set { mvarWindowState = value; } }
|
||||
|
||||
private List<string> mvarFileNames = new List<string>();
|
||||
public List<string> FileNames { get { return mvarFileNames; } }
|
||||
|
||||
}
|
||||
public class Session
|
||||
{
|
||||
public class SessionCollection
|
||||
: System.Collections.ObjectModel.Collection<Session>
|
||||
{
|
||||
}
|
||||
|
||||
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 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 string DataFileName { get { return mvarDataFileName; } set { mvarDataFileName = value; } }
|
||||
|
||||
private Session.SessionCollection mvarSessions = new Session.SessionCollection();
|
||||
public Session.SessionCollection Sessions { get { return mvarSessions; } }
|
||||
|
||||
private Version mvarFormatVersion = new Version(1, 0);
|
||||
|
||||
public void Load()
|
||||
{
|
||||
MarkupObjectModel mom = new MarkupObjectModel();
|
||||
XMLDataFormat xml = new XMLDataFormat();
|
||||
|
||||
if (!System.IO.File.Exists(mvarDataFileName)) return;
|
||||
|
||||
Document.Load(mom, xml, new FileAccessor(mvarDataFileName), true);
|
||||
|
||||
MarkupTagElement tagSessions = (mom.Elements["Sessions"] as MarkupTagElement);
|
||||
if (tagSessions == null) return;
|
||||
|
||||
MarkupAttribute attVersion = tagSessions.Attributes["Version"];
|
||||
if (attVersion != null)
|
||||
{
|
||||
mvarFormatVersion = new Version(attVersion.Value);
|
||||
}
|
||||
|
||||
foreach (MarkupElement elSession in tagSessions.Elements)
|
||||
{
|
||||
MarkupTagElement tagSession = (elSession as MarkupTagElement);
|
||||
if (tagSession == null) continue;
|
||||
if (tagSession.FullName != "Session") continue;
|
||||
|
||||
MarkupAttribute attTitle = tagSession.Attributes["Title"];
|
||||
if (attTitle == null) continue;
|
||||
|
||||
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;
|
||||
|
||||
Window window = new Window();
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
MarkupAttribute attFileName = tagDocument.Attributes["FileName"];
|
||||
if (attFileName == null) continue;
|
||||
|
||||
window.FileNames.Add(attFileName.Value);
|
||||
}
|
||||
}
|
||||
|
||||
session.Windows.Add(window);
|
||||
}
|
||||
|
||||
mvarSessions.Add(session);
|
||||
}
|
||||
}
|
||||
public void Save()
|
||||
{
|
||||
MarkupObjectModel mom = new MarkupObjectModel();
|
||||
UniversalEditor.ObjectModel om = mom;
|
||||
|
||||
XMLDataFormat xml = new XMLDataFormat();
|
||||
|
||||
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());
|
||||
|
||||
mom.Elements.Add(tagSessions);
|
||||
|
||||
if (mvarSessions.Count > 0)
|
||||
{
|
||||
foreach (Session session in mvarSessions)
|
||||
{
|
||||
if (session.Windows.Count < 1) continue;
|
||||
|
||||
MarkupTagElement tagSession = new MarkupTagElement();
|
||||
tagSession.FullName = "Session";
|
||||
|
||||
tagSession.Attributes.Add("Title", session.Title);
|
||||
|
||||
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());
|
||||
|
||||
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);
|
||||
|
||||
tagSessions.Elements.Add(tagSession);
|
||||
}
|
||||
}
|
||||
|
||||
Document.Save(om, xml, new FileAccessor(mvarDataFileName, true, true), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Security.Permissions;
|
||||
using System.Threading;
|
||||
using System.Runtime.Remoting.Channels;
|
||||
using System.Runtime.Remoting;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.Remoting.Channels.Ipc;
|
||||
|
||||
internal static class SingleInstanceManager
|
||||
{
|
||||
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
|
||||
[Serializable]
|
||||
private class InstanceProxy : MarshalByRefObject
|
||||
{
|
||||
public static bool IsFirstInstance
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
public static string[] CommandLineArgs
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
public void SetCommandLineArgs(bool isFirstInstance, string[] commandLineArgs)
|
||||
{
|
||||
SingleInstanceManager.InstanceProxy.IsFirstInstance = isFirstInstance;
|
||||
SingleInstanceManager.InstanceProxy.CommandLineArgs = commandLineArgs;
|
||||
}
|
||||
}
|
||||
public class InstanceCallbackEventArgs : EventArgs
|
||||
{
|
||||
public bool IsFirstInstance
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public string[] CommandLineArgs
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal InstanceCallbackEventArgs(bool isFirstInstance, string[] commandLineArgs)
|
||||
{
|
||||
this.IsFirstInstance = isFirstInstance;
|
||||
this.CommandLineArgs = commandLineArgs;
|
||||
}
|
||||
}
|
||||
public static bool CreateSingleInstance(string name, EventHandler<SingleInstanceManager.InstanceCallbackEventArgs> callback)
|
||||
{
|
||||
bool result;
|
||||
switch (Environment.OSVersion.Platform)
|
||||
{
|
||||
case PlatformID.Unix:
|
||||
case PlatformID.Xbox:
|
||||
case PlatformID.MacOSX:
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
name = name.Replace("\\", "_");
|
||||
name = name.Replace("/", "_");
|
||||
EventWaitHandle eventWaitHandle = null;
|
||||
string name2 = string.Format("{0}-{1}", Environment.MachineName, name);
|
||||
SingleInstanceManager.InstanceProxy.IsFirstInstance = false;
|
||||
SingleInstanceManager.InstanceProxy.CommandLineArgs = Environment.GetCommandLineArgs();
|
||||
try
|
||||
{
|
||||
eventWaitHandle = EventWaitHandle.OpenExisting(name2);
|
||||
}
|
||||
catch
|
||||
{
|
||||
SingleInstanceManager.InstanceProxy.IsFirstInstance = true;
|
||||
}
|
||||
if (SingleInstanceManager.InstanceProxy.IsFirstInstance)
|
||||
{
|
||||
eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, name2);
|
||||
ThreadPool.RegisterWaitForSingleObject(eventWaitHandle, new WaitOrTimerCallback(SingleInstanceManager.WaitOrTimerCallback), callback, -1, false);
|
||||
eventWaitHandle.Close();
|
||||
SingleInstanceManager.RegisterRemoteType(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
SingleInstanceManager.UpdateRemoteObject(name);
|
||||
if (eventWaitHandle != null)
|
||||
{
|
||||
eventWaitHandle.Set();
|
||||
}
|
||||
Environment.Exit(0);
|
||||
}
|
||||
result = SingleInstanceManager.InstanceProxy.IsFirstInstance;
|
||||
return result;
|
||||
}
|
||||
private static void UpdateRemoteObject(string uri)
|
||||
{
|
||||
IpcClientChannel chnl = new IpcClientChannel();
|
||||
ChannelServices.RegisterChannel(chnl, true);
|
||||
SingleInstanceManager.InstanceProxy instanceProxy = Activator.GetObject(typeof(SingleInstanceManager.InstanceProxy), string.Format("ipc://{0}{1}/{1}", Environment.MachineName, uri)) as SingleInstanceManager.InstanceProxy;
|
||||
if (instanceProxy != null)
|
||||
{
|
||||
instanceProxy.SetCommandLineArgs(SingleInstanceManager.InstanceProxy.IsFirstInstance, SingleInstanceManager.InstanceProxy.CommandLineArgs);
|
||||
}
|
||||
ChannelServices.UnregisterChannel(chnl);
|
||||
}
|
||||
private static void RegisterRemoteType(string uri)
|
||||
{
|
||||
IpcServerChannel serverChannel = new IpcServerChannel(Environment.MachineName + uri);
|
||||
ChannelServices.RegisterChannel(serverChannel, true);
|
||||
RemotingConfiguration.RegisterWellKnownServiceType(typeof(SingleInstanceManager.InstanceProxy), uri, WellKnownObjectMode.Singleton);
|
||||
Process currentProcess = Process.GetCurrentProcess();
|
||||
currentProcess.Exited += delegate
|
||||
{
|
||||
ChannelServices.UnregisterChannel(serverChannel);
|
||||
};
|
||||
}
|
||||
private static void WaitOrTimerCallback(object state, bool timedOut)
|
||||
{
|
||||
EventHandler<SingleInstanceManager.InstanceCallbackEventArgs> eventHandler = state as EventHandler<SingleInstanceManager.InstanceCallbackEventArgs>;
|
||||
if (eventHandler != null)
|
||||
{
|
||||
eventHandler(state, new SingleInstanceManager.InstanceCallbackEventArgs(SingleInstanceManager.InstanceProxy.IsFirstInstance, SingleInstanceManager.InstanceProxy.CommandLineArgs));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,8 +50,10 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Runtime.Remoting" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BookmarksManager.cs" />
|
||||
<Compile Include="CommandDisplayStyle.cs" />
|
||||
<Compile Include="Common\Reflection.cs" />
|
||||
<Compile Include="Engine.cs" />
|
||||
@ -65,8 +67,12 @@
|
||||
<Compile Include="ObjectModelChangingEvent.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="PropertyMapping.cs" />
|
||||
<Compile Include="RecentFileManager.cs" />
|
||||
<Compile Include="SessionManager.cs" />
|
||||
<Compile Include="SingleInstanceManager.cs" />
|
||||
<Compile Include="Toolbar.cs" />
|
||||
<Compile Include="Toolbox.cs" />
|
||||
<Compile Include="WindowState.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UniversalEditor.UserInterface
|
||||
{
|
||||
public enum WindowState
|
||||
{
|
||||
Hidden = 0,
|
||||
Normal = 1,
|
||||
Minimized = 2,
|
||||
Maximized = 3
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user