From a0b4a09742be9b86a528ce89372144df3d171e43 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sun, 21 Jul 2019 14:27:32 -0400 Subject: [PATCH] Implement Toolbar --- .../Configuration/CommandBars.uexml | 8 ++-- .../Configuration/Commands.uexml | 46 +++++++++---------- .../UniversalEditor.UserInterface/Command.cs | 12 +++-- .../UniversalEditor.UserInterface/Engine.cs | 17 +++++++ .../MainWindow.cs | 39 ++++++++++++++++ .../Panels/ErrorListPanel.cs | 13 ++++-- 6 files changed, 102 insertions(+), 33 deletions(-) diff --git a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Configuration/CommandBars.uexml b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Configuration/CommandBars.uexml index e6324db7..cc1377f3 100644 --- a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Configuration/CommandBars.uexml +++ b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Configuration/CommandBars.uexml @@ -2,9 +2,9 @@ - - - + + + @@ -19,4 +19,4 @@ - \ No newline at end of file + diff --git a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Configuration/Commands.uexml b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Configuration/Commands.uexml index 39486203..fc33a5a4 100644 --- a/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Configuration/Commands.uexml +++ b/CSharp/Content/UniversalEditor.Content.PlatformIndependent/Configuration/Commands.uexml @@ -18,7 +18,7 @@ - + @@ -44,19 +44,19 @@ - + - + - + @@ -67,7 +67,7 @@ - + @@ -76,7 +76,7 @@ - + @@ -84,7 +84,7 @@ - + @@ -93,7 +93,7 @@ - + @@ -107,7 +107,7 @@ - + @@ -129,34 +129,34 @@ - + - + - + - + - + - + - + - + - + - + @@ -331,7 +331,7 @@ - + @@ -343,10 +343,10 @@ - + - \ No newline at end of file + diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/Command.cs b/CSharp/Libraries/UniversalEditor.UserInterface/Command.cs index 61564eae..d3873c4d 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/Command.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/Command.cs @@ -1,4 +1,5 @@ using System; +using UniversalWidgetToolkit; namespace UniversalEditor.UserInterface { @@ -47,11 +48,11 @@ namespace UniversalEditor.UserInterface private CommandShortcutKey mvarShortcutKey = new CommandShortcutKey(); public CommandShortcutKey ShortcutKey { get { return mvarShortcutKey; } set { mvarShortcutKey = value; } } - private StockCommandType mvarStockCommandType = StockCommandType.None; + private StockType mvarStockType = StockType.None; /// - /// A that represents a predefined, platform-themed command. + /// A that represents a predefined, platform-themed command. /// - public StockCommandType StockCommandType { get { return mvarStockCommandType; } set { mvarStockCommandType = value; } } + public StockType StockType { get; set; } private string mvarImageFileName = String.Empty; /// @@ -85,6 +86,11 @@ namespace UniversalEditor.UserInterface { if (Executed != null) Executed(this, EventArgs.Empty); } + + public override string ToString() + { + return this.ID; + } } } diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs b/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs index 5810c8f2..c5758e1b 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/Engine.cs @@ -756,6 +756,23 @@ namespace UniversalEditor.UserInterface cmd.DefaultCommandID = attDefaultCommandID.Value; } + MarkupAttribute attCommandStockType = tagCommand.Attributes["StockType"]; + if (attCommandStockType != null) + { + StockType stockType = StockType.None; + string[] names = Enum.GetNames(typeof(StockType)); + int[] values = (int[]) Enum.GetValues(typeof(StockType)); + for (int i = 0; i < names.Length; i++) + { + if (names[i].Equals(attCommandStockType.Value)) + { + stockType = (StockType)values[i]; + break; + } + } + cmd.StockType = stockType; + } + MarkupAttribute attTitle = tagCommand.Attributes["Title"]; if (attTitle != null) { diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs b/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs index 5aca1276..2c93246a 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs @@ -31,6 +31,38 @@ namespace UniversalEditor.UserInterface private ErrorListPanel pnlErrorList = new ErrorListPanel(); private SolutionExplorerPanel pnlSolutionExplorer = new SolutionExplorerPanel(); + private Toolbar LoadCommandBar(CommandBar cb) + { + Toolbar tb = new Toolbar(); + foreach (CommandItem ci in cb.Items) + { + if (ci is SeparatorCommandItem) + { + tb.Items.Add(new ToolbarItemSeparator()); + } + else if (ci is CommandReferenceCommandItem) + { + CommandReferenceCommandItem crci = (ci as CommandReferenceCommandItem); + Command cmd = Engine.CurrentEngine.Commands[crci.CommandID]; + if (cmd == null) continue; + + ToolbarItemButton tsb = new ToolbarItemButton(cmd.ID, (StockType)cmd.StockType); + tsb.SetExtraData("crci", crci); + tsb.Click += tsbCommand_Click; + tb.Items.Add(tsb); + } + } + return tb; + } + + private void tsbCommand_Click(object sender, EventArgs e) + { + ToolbarItemButton tsb = (sender as ToolbarItemButton); + CommandReferenceCommandItem crci = tsb.GetExtraData("crci"); + Command cmd = Engine.CurrentEngine.Commands[crci.CommandID]; + cmd.Execute(); + } + public MainWindow() { UniversalWidgetToolkit.Layouts.BoxLayout layout = new UniversalWidgetToolkit.Layouts.BoxLayout(Orientation.Vertical); @@ -49,6 +81,13 @@ namespace UniversalEditor.UserInterface } this.MenuBar.Items.Add(mi); } + foreach (CommandBar cb in Engine.CurrentEngine.CommandBars) + { + Toolbar tb = LoadCommandBar(cb); + if (tb == null) continue; + + Controls.Add(tb); + } dckContainer = new DockingContainer(); tbsDocumentTabs = new TabContainer(); diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/Panels/ErrorListPanel.cs b/CSharp/Libraries/UniversalEditor.UserInterface/Panels/ErrorListPanel.cs index 251e2201..78b00281 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/Panels/ErrorListPanel.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/Panels/ErrorListPanel.cs @@ -36,9 +36,16 @@ namespace UniversalEditor.UserInterface.Panels { this.Layout = new BoxLayout(Orientation.Vertical); - tbErrorList.Items.Add(new ToolbarItemButton("tsbErrors", "Errors")); - tbErrorList.Items.Add(new ToolbarItemButton("tsbWarnings", "Warnings")); - tbErrorList.Items.Add(new ToolbarItemButton("tsbMessages", "Messages")); + ToolbarItemButton tsbErrors = new ToolbarItemButton("tsbErrors", "Errors"); + tsbErrors.CheckOnClick = true; + ToolbarItemButton tsbWarnings = new ToolbarItemButton("tsbWarnings", "Warnings"); + tsbWarnings.CheckOnClick = true; + ToolbarItemButton tsbMessages = new ToolbarItemButton("tsbMessages", "Messages"); + tsbMessages.CheckOnClick = true; + + tbErrorList.Items.Add(tsbErrors); + tbErrorList.Items.Add(tsbWarnings); + tbErrorList.Items.Add(tsbMessages); this.Controls.Add(tbErrorList);