Implemented more commands, made some stuff more cross-platform and implemented languages

This commit is contained in:
Michael Becker 2014-06-24 15:43:45 -04:00
parent 1fb2b05b4e
commit e71c0f0e3c
10 changed files with 297 additions and 141 deletions

View File

@ -269,7 +269,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Controls
ToolStripMenuItem tsmi = (sender as ToolStripMenuItem);
ProjectTypeItemShortcut its = (tsmi.Tag as ProjectTypeItemShortcut);
WindowsFormsEngine.LastWindow.NewFile();
Engine.CurrentEngine.Commands["FileNewDocument"].Execute();
}
private void mnuContextAddNewProject_Click(object sender, EventArgs e)

View File

@ -46,7 +46,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
this.Close();
WindowsFormsEngine.SessionLoading = true;
WindowsFormsEngine.CloseAllWindows();
Engine.CurrentEngine.CloseAllWindows();
SessionManager.Session session = (lv.SelectedItems[0].Data as SessionManager.Session);
@ -62,7 +62,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
filenames.Add(wnd, window.FileNames.ToArray());
wnd.Show();
WindowsFormsEngine.Windows.Add(wnd);
Engine.CurrentEngine.Windows.Add(wnd);
}
foreach (KeyValuePair<MainWindow, string[]> fkvp in filenames)
@ -78,7 +78,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
SessionManager.Session session = new SessionManager.Session();
session.Title = txtSessionName.Text;
foreach (MainWindow wnd in WindowsFormsEngine.Windows)
foreach (MainWindow wnd in Engine.CurrentEngine.Windows)
{
SessionManager.Window window = new SessionManager.Window();
window.Left = wnd.Left;
@ -123,8 +123,8 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
if (MessageBox.Show("Would you like to close all active windows and start a new session at this time?", "Close Session", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
WindowsFormsEngine.SessionLoading = true;
WindowsFormsEngine.CloseAllWindows();
WindowsFormsEngine.OpenWindow();
Engine.CurrentEngine.CloseAllWindows();
Engine.CurrentEngine.OpenWindow();
WindowsFormsEngine.SessionLoading = false;
}
}

View File

@ -383,47 +383,6 @@ namespace UniversalEditor.UserInterface.WindowsForms
this.mnuFileSaveAll.Text = "A&ll Files and Projects";
this.mnuFileSaveAll.Click += new System.EventHandler(this.FileSaveAll_Click);
//
// mnuFileClose
//
this.mnuFileClose.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuFileCloseFile,
this.mnuFileCloseProject,
this.toolStripMenuItem11,
this.mnuFileCloseWindow});
this.mnuFileClose.Name = "mnuFileClose";
this.mnuFileClose.Size = new System.Drawing.Size(156, 22);
this.mnuFileClose.Text = "&Close";
//
// mnuFileCloseFile
//
this.mnuFileCloseFile.Name = "mnuFileCloseFile";
this.mnuFileCloseFile.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.W)));
this.mnuFileCloseFile.Size = new System.Drawing.Size(237, 22);
this.mnuFileCloseFile.Text = "&File";
this.mnuFileCloseFile.Click += new System.EventHandler(this.FileCloseFile_Click);
//
// mnuFileCloseProject
//
this.mnuFileCloseProject.Name = "mnuFileCloseProject";
this.mnuFileCloseProject.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift)
| System.Windows.Forms.Keys.W)));
this.mnuFileCloseProject.Size = new System.Drawing.Size(237, 22);
this.mnuFileCloseProject.Text = "&Project/Solution";
this.mnuFileCloseProject.Click += new System.EventHandler(this.FileCloseProject_Click);
//
// toolStripMenuItem11
//
this.toolStripMenuItem11.Name = "toolStripMenuItem11";
this.toolStripMenuItem11.Size = new System.Drawing.Size(234, 6);
//
// mnuFileCloseWindow
//
this.mnuFileCloseWindow.Name = "mnuFileCloseWindow";
this.mnuFileCloseWindow.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4)));
this.mnuFileCloseWindow.Size = new System.Drawing.Size(237, 22);
this.mnuFileCloseWindow.Text = "&Window";
this.mnuFileCloseWindow.Click += new System.EventHandler(this.mnuFileCloseWindow_Click);
//
// mnuFileSep1
//
this.mnuFileSep1.Name = "mnuFileSep1";

View File

@ -17,6 +17,8 @@ namespace UniversalEditor.UserInterface.WindowsForms
{
public partial class MainWindow : AwesomeControls.Window, IHostApplicationWindow
{
public event EventHandler WindowClosed;
#region Docking Windows
private Controls.ErrorList pnlErrorList = new Controls.ErrorList();
private DockingWindow dwErrorList = null;
@ -103,7 +105,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
ToolStripMenuItem tsmi = new ToolStripMenuItem();
tsmi.Click += tsmiCommand_Click;
tsmi.Tag = cmd;
tsmi.Text = cmd.Title;
tsmi.Text = cmd.Title.Replace("_", "&");
foreach (CommandItem item1 in cmd.Items)
{
LoadCommandBarItem(item1, tsmi);
@ -1413,9 +1415,9 @@ namespace UniversalEditor.UserInterface.WindowsForms
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
if (WindowsFormsEngine.Windows.Contains(this)) WindowsFormsEngine.Windows.Remove(this);
if (WindowClosed != null) WindowClosed(this, e);
if (!WindowsFormsEngine.SessionLoading && WindowsFormsEngine.Windows.Count == 0)
if (!WindowsFormsEngine.SessionLoading && Engine.CurrentEngine.Windows.Count == 0)
{
Application.Exit();
}
@ -1703,12 +1705,20 @@ namespace UniversalEditor.UserInterface.WindowsForms
cbc.ShowCustomizeDialog();
}
private OptionsDialog dlgOptions = null;
private void ToolsOptions_Click(object sender, EventArgs e)
{
}
private OptionsDialog dlgOptions = null;
public bool ShowOptionsDialog()
{
if (dlgOptions == null) dlgOptions = new OptionsDialog();
if (dlgOptions.IsDisposed) dlgOptions = new OptionsDialog();
dlgOptions.ShowDialog();
if (dlgOptions.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
return true;
}
return false;
}
protected override void OnShown(EventArgs e)
@ -1723,7 +1733,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
WindowsFormsEngine.LastWindow = this;
Engine.CurrentEngine.LastWindow = this;
HostApplication.CurrentWindow = this;
}
@ -1793,7 +1803,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
private void mnuWindowNewWindow_Click(object sender, EventArgs e)
{
WindowsFormsEngine.OpenWindow();
Engine.CurrentEngine.OpenWindow();
}
private void cboAddress_KeyDown(object sender, KeyEventArgs e)

View File

@ -63,7 +63,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Pages
}
return;
}
WindowsFormsEngine.OpenFile(lvRecent.SelectedItems[0].TooltipText);
Engine.CurrentEngine.OpenFile(lvRecent.SelectedItems[0].TooltipText);
}
}
}

View File

@ -18,11 +18,6 @@ namespace UniversalEditor.UserInterface.WindowsForms
internal class WindowsFormsEngine : Engine
{
internal static MainWindow LastWindow = null;
private static List<MainWindow> mvarWindows = new List<MainWindow>();
public static List<MainWindow> Windows { get { return mvarWindows; } }
private static SplashScreenWindow splasher = null;
public static bool SessionLoading = false;
@ -31,49 +26,6 @@ namespace UniversalEditor.UserInterface.WindowsForms
{
base.AfterInitialization();
#region File
Commands["FileNewDocument"].Executed += delegate(object sender, EventArgs e)
{
LastWindow.NewFile();
};
Commands["FileNewProject"].Executed += delegate(object sender, EventArgs e)
{
LastWindow.NewProject();
};
Commands["FileOpenDocument"].Executed += delegate(object sender, EventArgs e)
{
LastWindow.OpenFile();
};
Commands["FileOpenProject"].Executed += delegate(object sender, EventArgs e)
{
LastWindow.OpenProject();
};
Commands["FileSaveDocument"].Executed += delegate(object sender, EventArgs e)
{
LastWindow.SaveFile();
};
Commands["FileSaveDocumentAs"].Executed += delegate(object sender, EventArgs e)
{
LastWindow.SaveFileAs();
};
Commands["FileSaveProject"].Executed += delegate(object sender, EventArgs e)
{
LastWindow.SaveProject();
};
Commands["FileSaveProjectAs"].Executed += delegate(object sender, EventArgs e)
{
LastWindow.SaveProjectAs();
};
Commands["FileSaveAll"].Executed += delegate(object sender, EventArgs e)
{
LastWindow.SaveAll();
};
Commands["FileCloseDocument"].Executed += delegate(object sender, EventArgs e)
{
LastWindow.CloseFile();
};
#endregion
Commands["HelpLicensingAndActivation"].Executed += delegate(object sender, EventArgs e)
{
MessageBox.Show("This product has already been activated.", "Licensing and Activation", MessageBoxButtons.OK, MessageBoxIcon.Information);
@ -426,11 +378,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
}
}
public static void OpenFile(params string[] FileNames)
{
LastWindow.OpenFile(FileNames);
}
public static void OpenWindow(params string[] FileNames)
public override void OpenWindow(params string[] FileNames)
{
MainWindow mw = new MainWindow();
@ -440,10 +388,10 @@ namespace UniversalEditor.UserInterface.WindowsForms
}
mw.Show();
mvarWindows.Add(mw);
Windows.Add(mw);
}
public static void ExitApplication()
public override void ExitApplication()
{
if (LocalConfiguration.ConfirmExit)
{
@ -454,18 +402,5 @@ namespace UniversalEditor.UserInterface.WindowsForms
}
Application.Exit();
}
public static void CloseAllWindows()
{
List<MainWindow> windowsToClose = new List<MainWindow>();
foreach (MainWindow window in mvarWindows)
{
windowsToClose.Add(window);
}
foreach (MainWindow window in windowsToClose)
{
window.Close();
}
}
}
}

View File

@ -61,12 +61,98 @@ namespace UniversalEditor.UserInterface
return m_AvailableEngines;
}
protected virtual void BeforeInitialization()
{
}
protected virtual void AfterInitialization()
{
}
public bool AttachCommandEventHandler(string commandID, EventHandler handler)
{
Command cmd = Commands[commandID];
if (cmd != null)
{
cmd.Executed += handler;
return true;
}
Console.WriteLine("attempted to attach handler for unknown command '" + commandID + "'");
return false;
}
protected virtual void BeforeInitialization()
{
}
protected virtual void AfterInitialization()
{
// Initialize all the commands that are common to UniversalEditor
#region File
AttachCommandEventHandler("FileNewDocument", delegate(object sender, EventArgs e)
{
LastWindow.NewFile();
});
AttachCommandEventHandler("FileNewProject", delegate(object sender, EventArgs e)
{
LastWindow.NewProject();
});
AttachCommandEventHandler("FileOpenDocument", delegate(object sender, EventArgs e)
{
LastWindow.OpenFile();
});
AttachCommandEventHandler("FileOpenProject", delegate(object sender, EventArgs e)
{
LastWindow.OpenProject();
});
AttachCommandEventHandler("FileSaveDocument", delegate(object sender, EventArgs e)
{
LastWindow.SaveFile();
});
AttachCommandEventHandler("FileSaveDocumentAs", delegate(object sender, EventArgs e)
{
LastWindow.SaveFileAs();
});
AttachCommandEventHandler("FileSaveProject", delegate(object sender, EventArgs e)
{
LastWindow.SaveProject();
});
AttachCommandEventHandler("FileSaveProjectAs", delegate(object sender, EventArgs e)
{
LastWindow.SaveProjectAs();
});
AttachCommandEventHandler("FileSaveAll", delegate(object sender, EventArgs e)
{
LastWindow.SaveAll();
});
AttachCommandEventHandler("FileCloseDocument", delegate(object sender, EventArgs e)
{
LastWindow.CloseFile();
});
AttachCommandEventHandler("FileExit", delegate(object sender, EventArgs e)
{
ExitApplication();
});
#endregion
#region Tools
// ToolsOptions should actually be under the Edit menu as "Preferences" on Linux systems
AttachCommandEventHandler("ToolsOptions", delegate(object sender, EventArgs e)
{
LastWindow.ShowOptionsDialog();
});
#endregion
}
public virtual void ExitApplication()
{
}
private IHostApplicationWindowCollection mvarWindows = new IHostApplicationWindowCollection();
public IHostApplicationWindowCollection Windows { get { return mvarWindows; } }
public void CloseAllWindows()
{
List<IHostApplicationWindow> windowsToClose = new List<IHostApplicationWindow>();
foreach (IHostApplicationWindow window in mvarWindows)
{
windowsToClose.Add(window);
}
foreach (IHostApplicationWindow window in windowsToClose)
{
window.CloseWindow();
}
}
public static bool Execute()
{
@ -93,6 +179,18 @@ namespace UniversalEditor.UserInterface
/// The commands defined for this application.
/// </summary>
public Command.CommandCollection Commands { get { return mvarCommands; } }
private Language mvarDefaultLanguage = null;
/// <summary>
/// The default <see cref="Language"/> used to display translatable text in this application.
/// </summary>
public Language DefaultLanguage { get { return mvarDefaultLanguage; } set { mvarDefaultLanguage = value; } }
private Language.LanguageCollection mvarLanguages = new Language.LanguageCollection();
/// <summary>
/// The languages defined for this application. Translations can be added through XML files in the ~/Languages folder.
/// </summary>
public Language.LanguageCollection Languages { get { return mvarLanguages; } }
private EngineMainMenu mvarMainMenu = new EngineMainMenu();
/// <summary>
@ -135,6 +233,19 @@ namespace UniversalEditor.UserInterface
private IHostApplicationWindow mvarLastWindow = null;
public IHostApplicationWindow LastWindow { get { return mvarLastWindow; } set { mvarLastWindow = value; } }
public void OpenFile(params string[] FileNames)
{
LastWindow.OpenFile(FileNames);
}
/// <summary>
/// Opens a new window, optionally loading the specified documents.
/// </summary>
/// <param name="FileNames">The file name(s) of the document(s) to load.</param>
public virtual void OpenWindow(params string[] FileNames)
{
}
// UniversalDataStorage.Editor.WindowsForms.Program
private void SingleInstanceManager_Callback(object sender, SingleInstanceManager.InstanceCallbackEventArgs e)
{
@ -189,14 +300,14 @@ namespace UniversalEditor.UserInterface
cmd.ID = attID.Value;
MarkupAttribute attTitle = tagCommand.Attributes["Title"];
if (attTitle != null)
{
cmd.Title = attTitle.Value;
}
else
{
cmd.Title = cmd.ID;
}
if (attTitle != null)
{
cmd.Title = attTitle.Value;
}
else
{
cmd.Title = cmd.ID;
}
MarkupTagElement tagItems = (tagCommand.Elements["Items"] as MarkupTagElement);
if (tagItems != null)
@ -221,8 +332,80 @@ namespace UniversalEditor.UserInterface
if (tagItem == null) continue;
InitializeMainMenuItem(tagItem, null);
}
MarkupTagElement tagLanguages = (mvarRawMarkup.FindElement("UniversalEditor", "Application", "Languages") as MarkupTagElement);
foreach (MarkupElement elLanguage in tagLanguages.Elements)
{
MarkupTagElement tagLanguage = (elLanguage as MarkupTagElement);
if (tagLanguage == null) continue;
if (tagLanguage.FullName != "Language") continue;
InitializeLanguage(tagLanguage);
}
MarkupAttribute attDefaultLanguageID = tagLanguages.Attributes["DefaultLanguageID"];
if (attDefaultLanguageID != null)
{
mvarDefaultLanguage = mvarLanguages[attDefaultLanguageID.Value];
}
#endregion
if (mvarDefaultLanguage != null)
{
foreach (Command cmd in mvarCommands)
{
cmd.Title = mvarDefaultLanguage.GetCommandTitle(cmd.ID, cmd.ID);
}
}
}
private void InitializeLanguage(MarkupTagElement tag)
{
Language lang = new Language();
MarkupAttribute attID = tag.Attributes["ID"];
if (attID != null)
{
lang.ID = attID.Value;
}
MarkupTagElement tagStringTable = (tag.Elements["StringTable"] as MarkupTagElement);
if (tagStringTable != null)
{
foreach (MarkupElement elStringTableEntry in tagStringTable.Elements)
{
MarkupTagElement tagStringTableEntry = (elStringTableEntry as MarkupTagElement);
if (tagStringTableEntry == null) continue;
if (tagStringTableEntry.FullName != "StringTableEntry") continue;
MarkupAttribute attStringTableEntryID = tagStringTableEntry.Attributes["ID"];
if (attStringTableEntryID == null) continue;
MarkupAttribute attStringTableEntryValue = tagStringTableEntry.Attributes["Value"];
if (attStringTableEntryValue == null) continue;
lang.SetStringTableEntry(attStringTableEntryID.Value, attStringTableEntryValue.Value);
}
}
MarkupTagElement tagCommands = (tag.Elements["Commands"] as MarkupTagElement);
if (tagCommands != null)
{
foreach (MarkupElement elCommand in tagCommands.Elements)
{
MarkupTagElement tagCommand = (elCommand as MarkupTagElement);
if (tagCommand == null) continue;
if (tagCommand.FullName != "Command") continue;
MarkupAttribute attCommandID = tagCommand.Attributes["ID"];
if (attCommandID == null) continue;
MarkupAttribute attCommandTitle = tagCommand.Attributes["Title"];
if (attCommandTitle == null) continue;
lang.SetCommandTitle(attCommandID.Value, attCommandTitle.Value);
}
}
mvarLanguages.Add(lang);
}
private void InitializeMainMenuItem(MarkupTagElement tag, Command parent)
@ -295,7 +478,7 @@ namespace UniversalEditor.UserInterface
// overridden with a switch (/basepath:...) ?
mvarBasePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
BeforeInitialization();
BeforeInitialization();
// Initialize the XML files
InitializeXMLConfiguration();
@ -323,7 +506,7 @@ namespace UniversalEditor.UserInterface
}
if (!SingleInstanceManager.CreateSingleInstance(INSTANCEID, new EventHandler<SingleInstanceManager.InstanceCallbackEventArgs>(SingleInstanceManager_Callback))) return;
AfterInitialization();
AfterInitialization();
MainLoop();
}

View File

@ -7,6 +7,8 @@ namespace UniversalEditor.UserInterface
{
public interface IHostApplicationWindow
{
event EventHandler WindowClosed;
void NewFile();
void NewProject(bool combineObjects = false);
@ -24,6 +26,16 @@ namespace UniversalEditor.UserInterface
void SaveProjectAs(string FileName, DataFormat df);
void SaveAll();
void CloseFile();
void CloseWindow();
/// <summary>
/// Displays the "Options" dialog (on Windows, under the "Tools" menu; on Linux, under the "Edit"
/// menu, labeled as "Preferences").
/// </summary>
/// <returns>True if the user accepted the dialog; false otherwise.</returns>
bool ShowOptionsDialog();
void ToggleMenuItemEnabled(string menuItemName, bool enabled);
void RefreshCommand(object nativeCommandObject);
@ -35,4 +47,9 @@ namespace UniversalEditor.UserInterface
void ActivateWindow();
}
public class IHostApplicationWindowCollection
: System.Collections.ObjectModel.Collection<IHostApplicationWindow>
{
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UniversalEditor.UserInterface
{
public class Language
{
public class LanguageCollection
: System.Collections.ObjectModel.Collection<Language>
{
public Language this[string ID]
{
get
{
foreach (Language language in this)
{
if (language.ID == ID) return language;
}
return null;
}
}
}
private string mvarID = String.Empty;
public string ID { get { return mvarID; } set { mvarID = value; } }
private Dictionary<string, string> mvarCommandTitles = new Dictionary<string, string>();
private Dictionary<string, string> mvarStringTableEntries = new Dictionary<string, string>();
public string GetCommandTitle(string id, string defaultValue = null)
{
if (mvarCommandTitles.ContainsKey(id)) return mvarCommandTitles[id];
return defaultValue;
}
public void SetCommandTitle(string id, string value)
{
mvarCommandTitles[id] = value;
}
public string GetStringTableEntry(string id, string defaultValue = null)
{
if (mvarStringTableEntries.ContainsKey(id)) return mvarStringTableEntries[id];
return defaultValue;
}
public void SetStringTableEntry(string id, string value)
{
mvarStringTableEntries[id] = value;
}
}
}

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -63,6 +63,7 @@
<Compile Include="IEditorImplementation.cs" />
<Compile Include="IHostApplicationWindow.cs" />
<Compile Include="IOptionPanelImplementation.cs" />
<Compile Include="Language.cs" />
<Compile Include="MenuBar.cs" />
<Compile Include="ObjectModelChangingEvent.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />