diff --git a/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/MainWindow.cs b/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/MainWindow.cs index 2122ce85..b66a5f27 100644 --- a/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/MainWindow.cs +++ b/CSharp/Environments/WindowsForms/Engines/UniversalEditor.UserInterface.WindowsForms.DesktopApplication/MainWindow.cs @@ -84,11 +84,144 @@ namespace UniversalEditor.UserInterface.WindowsForms mbMenuBar.Items.Clear(); foreach (CommandItem item in Engine.CurrentEngine.MainMenu.Items) { - LoadCommandBarItem(item, null); + LoadCommandBarMenuItem(item, null); + } + + foreach (CommandBar bar in Engine.CurrentEngine.CommandBars) + { + LoadCommandBar(bar); } } - private void LoadCommandBarItem(CommandItem item, ToolStripMenuItem parent) + private void LoadCommandBar(CommandBar bar) + { + AwesomeControls.CommandBars.CBToolBar tb = new AwesomeControls.CommandBars.CBToolBar(); + tb.Text = bar.Title; + foreach (CommandItem item in bar.Items) + { + LoadCommandBarItem(item, tb); + } + cbc.TopToolStripPanel.Controls.Add(tb); + } + + private ToolStripItem InitializeCommandBarItem(CommandItem item, bool isOnDropDown = false) + { + if (item is SeparatorCommandItem) + { + return new ToolStripSeparator(); + } + else if (item is CommandReferenceCommandItem) + { + CommandReferenceCommandItem crci = (item as CommandReferenceCommandItem); + Command cmd = Engine.CurrentEngine.Commands[crci.CommandID]; + if (cmd == null) + { + Console.WriteLine("could not find command '" + crci.CommandID + "'"); + return null; + } + + if (cmd.Items.Count > 0) + { + ToolStripDropDownItem tsi = null; + if (!isOnDropDown) + { + if (!String.IsNullOrEmpty(cmd.DefaultCommandID)) + { + ToolStripSplitButton tsb = new ToolStripSplitButton(); + tsb.ButtonClick += tsbCommandBarButton_Click; + tsi = tsb; + } + else + { + ToolStripDropDownButton tsb = new ToolStripDropDownButton(); + tsi = tsb; + } + } + else + { + ToolStripMenuItem tsmi = new ToolStripMenuItem(); + tsi = tsmi; + } + + if (tsi == null) + { + Console.WriteLine("ToolStripDropDownItem was not loaded!"); + return null; + } + + tsi.Tag = cmd; + tsi.Text = cmd.Title.Replace("_", "&"); + foreach (CommandItem item1 in cmd.Items) + { + LoadCommandBarItem(item1, tsi); + } + return tsi; + } + else + { + ToolStripItem tsi = null; + if (!isOnDropDown) + { + tsi = new ToolStripButton(); + } + else + { + tsi = new ToolStripMenuItem(); + } + tsi.Tag = cmd; + tsi.Text = cmd.Title.Replace("_", "&"); + tsi.Click += tsbCommandBarButton_Click; + return tsi; + } + } + return null; + } + + private void LoadCommandBarItem(CommandItem item, ToolStripDropDownItem parent) + { + ToolStripItem tsi = InitializeCommandBarItem(item, true); + if (tsi == null) return; + + parent.DropDownItems.Add(tsi); + } + private void LoadCommandBarItem(CommandItem item, AwesomeControls.CommandBars.CBToolBar parent) + { + ToolStripItem tsi = InitializeCommandBarItem(item); + if (tsi == null) return; + + parent.Items.Add(tsi); + } + + private void tsbCommandBarButton_Click(object sender, EventArgs e) + { + if (sender is ToolStripDropDownItem) + { + ToolStripDropDownItem tsi = (sender as ToolStripDropDownItem); + Command cmd = (tsi.Tag as Command); + if (tsi.DropDownItems.Count > 0) + { + Command cmd1 = Engine.CurrentEngine.Commands[cmd.DefaultCommandID]; + if (cmd1 == null) + { + Console.WriteLine("could not find command '" + cmd.DefaultCommandID + "'"); + return; + } + cmd1.Execute(); + } + else + { + cmd.Execute(); + } + } + else if (sender is ToolStripItem) + { + ToolStripItem tsi = (sender as ToolStripItem); + Command cmd = (tsi.Tag as Command); + cmd.Execute(); + } + } + + private void LoadCommandBarMenuItem(CommandItem item, ToolStripMenuItem parent) { ToolStripItem tsi = null; @@ -108,7 +241,7 @@ namespace UniversalEditor.UserInterface.WindowsForms tsmi.Text = cmd.Title.Replace("_", "&"); foreach (CommandItem item1 in cmd.Items) { - LoadCommandBarItem(item1, tsmi); + LoadCommandBarMenuItem(item1, tsmi); } tsi = tsmi; } diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/CommandBar.cs b/CSharp/Libraries/UniversalEditor.UserInterface/CommandBar.cs new file mode 100644 index 00000000..8dad56ee --- /dev/null +++ b/CSharp/Libraries/UniversalEditor.UserInterface/CommandBar.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace UniversalEditor.UserInterface +{ + public class CommandBar + { + public class CommandBarCollection + : System.Collections.ObjectModel.Collection + { + + } + + private string mvarID = String.Empty; + public string ID { get { return mvarID; } set { mvarID = value; } } + + private string mvarTitle = String.Empty; + public string Title { get { return mvarTitle; } set { mvarTitle = value; } } + + private CommandItem.CommandItemCollection mvarItems = new CommandItem.CommandItemCollection(); + public CommandItem.CommandItemCollection Items { get { return mvarItems; } } + } +} diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs b/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs index 1e87d732..67d569f3 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs @@ -218,9 +218,15 @@ namespace UniversalEditor.UserInterface private EngineMainMenu mvarMainMenu = new EngineMainMenu(); /// - /// The main menu of this application, which can hold multiple s. + /// The main menu of this application, which can hold multiple s. /// public EngineMainMenu MainMenu { get { return mvarMainMenu; } } + + private CommandBar.CommandBarCollection mvarCommandBars = new CommandBar.CommandBarCollection(); + /// + /// The command bars loaded in this application, which can each hold multiple s. + /// + public CommandBar.CommandBarCollection CommandBars { get { return mvarCommandBars; } } /// /// The aggregated raw markup of all the various XML files loaded in the current search path. @@ -310,6 +316,8 @@ namespace UniversalEditor.UserInterface { #region Load the XML files string[] xmlfiles = System.IO.Directory.GetFiles(mvarBasePath, "*.xml", System.IO.SearchOption.AllDirectories); + + UpdateSplashScreenStatus("Loading XML configuration files", 0, 0, xmlfiles.Length); XMLDataFormat xdf = new XMLDataFormat(); foreach (string xmlfile in xmlfiles) @@ -321,11 +329,16 @@ namespace UniversalEditor.UserInterface doc.Accessor.Open (); doc.Load (); doc.Close (); - - markup.CopyTo (mvarRawMarkup); + + markup.CopyTo(mvarRawMarkup); + + UpdateSplashScreenStatus("Loading XML configuration files", Array.IndexOf(xmlfiles, xmlfile) + 1); } + + UpdateSplashScreenStatus("Loading available commands"); #endregion + #region Initialize the configuration with the loaded data MarkupTagElement tagCommands = (mvarRawMarkup.FindElement ("UniversalEditor", "Application", "Commands") as MarkupTagElement); @@ -342,6 +355,12 @@ namespace UniversalEditor.UserInterface Command cmd = new Command(); cmd.ID = attID.Value; + + MarkupAttribute attDefaultCommandID = tagCommand.Attributes["DefaultCommandID"]; + if (attDefaultCommandID != null) + { + cmd.DefaultCommandID = attDefaultCommandID.Value; + } MarkupAttribute attTitle = tagCommand.Attributes["Title"]; if (attTitle != null) @@ -368,6 +387,8 @@ namespace UniversalEditor.UserInterface mvarCommands.Add (cmd); } } + + UpdateSplashScreenStatus("Loading main menu items"); MarkupTagElement tagMainMenuItems = (mvarRawMarkup.FindElement ("UniversalEditor", "Application", "MainMenu", "Items") as MarkupTagElement); foreach (MarkupElement elItem in tagMainMenuItems.Elements) @@ -377,6 +398,19 @@ namespace UniversalEditor.UserInterface InitializeMainMenuItem(tagItem, null); } + UpdateSplashScreenStatus("Loading command bars"); + + MarkupTagElement tagCommandBars = (mvarRawMarkup.FindElement("UniversalEditor", "Application", "CommandBars") as MarkupTagElement); + foreach (MarkupElement elCommandBar in tagCommandBars.Elements) + { + MarkupTagElement tagCommandBar = (elCommandBar as MarkupTagElement); + if (tagCommandBar == null) continue; + if (tagCommandBar.FullName != "CommandBar") continue; + InitializeCommandBar(tagCommandBar); + } + + UpdateSplashScreenStatus("Loading languages and translations"); + MarkupTagElement tagLanguages = (mvarRawMarkup.FindElement("UniversalEditor", "Application", "Languages") as MarkupTagElement); foreach (MarkupElement elLanguage in tagLanguages.Elements) { @@ -393,6 +427,8 @@ namespace UniversalEditor.UserInterface } #endregion + UpdateSplashScreenStatus("Setting language"); + if (mvarDefaultLanguage != null) { foreach (Command cmd in mvarCommands) @@ -400,6 +436,9 @@ namespace UniversalEditor.UserInterface cmd.Title = mvarDefaultLanguage.GetCommandTitle(cmd.ID, cmd.ID); } } + + UpdateSplashScreenStatus("Finalizing configuration"); + } private void InitializeLanguage(MarkupTagElement tag) @@ -461,6 +500,80 @@ namespace UniversalEditor.UserInterface mvarLanguages.Add(lang); } + private void InitializeCommandBar(MarkupTagElement tag) + { + MarkupAttribute attID = tag.Attributes["ID"]; + if (attID == null) return; + + CommandBar cb = new CommandBar(); + cb.ID = attID.Value; + + MarkupAttribute attTitle = tag.Attributes["Title"]; + if (attTitle != null) + { + cb.Title = attTitle.Value; + } + else + { + cb.Title = cb.ID; + } + + MarkupTagElement tagItems = tag.Elements["Items"] as MarkupTagElement; + if (tagItems != null) + { + foreach (MarkupElement elItem in tagItems.Elements) + { + MarkupTagElement tagItem = (elItem as MarkupTagElement); + if (tagItem == null) continue; + switch (tagItem.FullName) + { + case "CommandReference": + { + MarkupAttribute attCommandID = tagItem.Attributes["CommandID"]; + if (attCommandID != null) + { + cb.Items.Add(new CommandReferenceCommandItem(attCommandID.Value)); + } + break; + } + case "Separator": + { + cb.Items.Add(new SeparatorCommandItem()); + break; + } + } + } + } + + mvarCommandBars.Add(cb); + } + + private void InitializeCommandBarItem(MarkupTagElement tag, CommandBar parent) + { + CommandItem item = null; + switch (tag.FullName) + { + case "CommandReference": + { + MarkupAttribute attCommandID = tag.Attributes["CommandID"]; + if (attCommandID != null) + { + item = new CommandReferenceCommandItem(attCommandID.Value); + } + break; + } + case "Separator": + { + item = new SeparatorCommandItem(); + break; + } + } + + if (item != null) + { + parent.Items.Add(item); + } + } private void InitializeMainMenuItem(MarkupTagElement tag, Command parent) { CommandItem item = null; @@ -525,6 +638,7 @@ namespace UniversalEditor.UserInterface private void Initialize() { System.Threading.Thread threadLoader = new System.Threading.Thread(threadLoader_ThreadStart); + threadLoader.Name = "Initialization Thread"; threadLoader.Start(); ShowSplashScreen(); diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj b/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj index 105334c8..0b7812cc 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj +++ b/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj @@ -54,6 +54,7 @@ +