From b16d63279e173bd5f5668f2a28486dcefd8e8592 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Wed, 11 Aug 2021 22:26:12 -0400 Subject: [PATCH] preliminary implementation of Panel references - XML and Editor Panels to come soon --- .../EditorApplication.cs | 48 +++++++ .../EditorPropertiesPanel.cs | 2 +- .../MainWindow.cs | 123 ++++++++++-------- .../UniversalEditor.UserInterface/Panel.cs | 4 +- .../PanelReference.cs | 49 +++++++ .../Panels/DocumentExplorerPanel.cs | 8 ++ .../Panels/ErrorListPanel.cs | 2 + .../Panels/PropertyListPanel.cs | 19 +++ .../Panels/SolutionExplorerPanel.cs | 2 + .../Panels/ToolboxPanel.cs | 88 +++++++++++++ .../UniversalEditor.UserInterface.csproj | 2 + 11 files changed, 290 insertions(+), 57 deletions(-) create mode 100644 Libraries/UniversalEditor.UserInterface/PanelReference.cs create mode 100644 Libraries/UniversalEditor.UserInterface/Panels/ToolboxPanel.cs diff --git a/Libraries/UniversalEditor.UserInterface/EditorApplication.cs b/Libraries/UniversalEditor.UserInterface/EditorApplication.cs index 756c4c5d..c5bf4116 100644 --- a/Libraries/UniversalEditor.UserInterface/EditorApplication.cs +++ b/Libraries/UniversalEditor.UserInterface/EditorApplication.cs @@ -28,11 +28,59 @@ namespace UniversalEditor.UserInterface ShortName = "universal-editor"; } + protected override void InitializeInternal() + { + base.InitializeInternal(); + + InitializePanels(); + } + + /// + /// Initializes the panels. This can only be called after the application has been created. If this + /// function is called before the application has been created (i.e. in a constructor), the application + /// will crash. + /// + private void InitializePanels() + { + // FIXME: this should all be done in XML + PanelReference prPropertyList = new PanelReference(PropertyListPanel.ID); + prPropertyList.Title = "Property List"; + prPropertyList.Control = new PropertyListPanel(); + prPropertyList.Placement = DockingItemPlacement.Right; + Panels.Add(prPropertyList); + + PanelReference prToolbox = new PanelReference(ToolboxPanel.ID); + prToolbox.Title = "Toolbox"; + prToolbox.Control = new ToolboxPanel(); + prToolbox.Placement = DockingItemPlacement.Left; + Panels.Add(prToolbox); + + PanelReference prSolutionExplorer = new PanelReference(SolutionExplorerPanel.ID); + prSolutionExplorer.Title = "Solution Explorer"; + prSolutionExplorer.Control = new SolutionExplorerPanel(); + prSolutionExplorer.Placement = DockingItemPlacement.Left; + Panels.Add(prSolutionExplorer); + + PanelReference prDocumentExplorer = new PanelReference(DocumentExplorerPanel.ID); + prDocumentExplorer.Title = "Document Explorer"; + prDocumentExplorer.Control = new DocumentExplorerPanel(); + prDocumentExplorer.Placement = DockingItemPlacement.Left; + Panels.Add(prDocumentExplorer); + + PanelReference prErrorList = new PanelReference(ErrorListPanel.ID); + prErrorList.Title = "Error List"; + prErrorList.Control = new ErrorListPanel(); + prErrorList.Placement = DockingItemPlacement.Bottom; + Panels.Add(prErrorList); + } + public ConfigurationManager ConfigurationManager { get; } = new ConfigurationManager(); public RecentFileManager RecentFileManager { get; } = new RecentFileManager(); public BookmarksManager BookmarksManager { get; } = new BookmarksManager(); public SessionManager SessionManager { get; } = new SessionManager(); + public PanelReference.PanelReferenceCollection Panels { get; } = new PanelReference.PanelReferenceCollection(); + protected override void OnStartup(EventArgs e) { base.OnStartup(e); diff --git a/Libraries/UniversalEditor.UserInterface/EditorPropertiesPanel.cs b/Libraries/UniversalEditor.UserInterface/EditorPropertiesPanel.cs index 48918e34..7fe1273e 100644 --- a/Libraries/UniversalEditor.UserInterface/EditorPropertiesPanel.cs +++ b/Libraries/UniversalEditor.UserInterface/EditorPropertiesPanel.cs @@ -43,7 +43,7 @@ namespace UniversalEditor.UserInterface if (Parent?.ParentWindow is MainWindow) { - (Parent.ParentWindow as MainWindow).pnlPropertyList.SelectedObject = value; + ((PropertyListPanel)(Parent.ParentWindow as MainWindow).FindPanel(PropertyListPanel.ID)).SelectedObject = value; } } } diff --git a/Libraries/UniversalEditor.UserInterface/MainWindow.cs b/Libraries/UniversalEditor.UserInterface/MainWindow.cs index b032fa1a..4446bfd7 100644 --- a/Libraries/UniversalEditor.UserInterface/MainWindow.cs +++ b/Libraries/UniversalEditor.UserInterface/MainWindow.cs @@ -40,12 +40,6 @@ namespace UniversalEditor.UserInterface { private DockingContainerControl dckContainer = null; - private ErrorListPanel pnlErrorList = new ErrorListPanel(); - private SolutionExplorerPanel pnlSolutionExplorer = new SolutionExplorerPanel(); - internal PropertyListPanel pnlPropertyList = new PropertyListPanel(); - private DocumentExplorerPanel pnlDocumentExplorer = new DocumentExplorerPanel(); - public DocumentExplorerPanel DocumentExplorerPanel { get { return pnlDocumentExplorer; } } - private RibbonTab LoadRibbonBar(CommandBar cb) { RibbonTab tab = new RibbonTab (); @@ -101,6 +95,18 @@ namespace UniversalEditor.UserInterface return tab; } + public void RegisterPanel(PanelReference panelReference, Panel panel) + { + _MyPanels[panelReference] = panel; + _MyPanels_ID[panelReference.ID] = panel; + } + public Panel FindPanel(Guid guid) + { + if (_MyPanels_ID.ContainsKey(guid)) + return _MyPanels_ID[guid]; + return null; + } + protected override void OnLostFocus(EventArgs e) { base.OnLostFocus(e); @@ -190,8 +196,6 @@ namespace UniversalEditor.UserInterface ((UIApplication)Application.Instance).ExecuteCommand(cmd.ID); } - private DefaultTreeModel tmToolbox = new DefaultTreeModel(new Type[] { typeof(string) }); - public MainWindow() { Layout = new BoxLayout(Orientation.Vertical); @@ -213,20 +217,7 @@ namespace UniversalEditor.UserInterface InitStartPage(); - ListViewControl lvToolbox = new ListViewControl(); - lvToolbox.RowActivated += LvToolbox_RowActivated; - lvToolbox.Model = tmToolbox; - lvToolbox.Columns.Add(new ListViewColumn("Item", new CellRenderer[] { new CellRendererText(tmToolbox.Columns[0]) })); - lvToolbox.HeaderStyle = ColumnHeaderStyle.None; - AddPanel("Toolbox", DockingItemPlacement.Left, lvToolbox); - - AddPanel("Document Explorer", DockingItemPlacement.Bottom, pnlDocumentExplorer); - - DockingContainer dcExplorerProperties = null; // AddPanelContainer(DockingItemPlacement.Right, null); - AddPanel("Solution Explorer", DockingItemPlacement.Left, pnlSolutionExplorer, dcExplorerProperties); - AddPanel("Properties", DockingItemPlacement.Bottom, pnlPropertyList, dcExplorerProperties); - - AddPanel("Error List", DockingItemPlacement.Bottom, pnlErrorList); + InitializePanels(); Container pnlButtons = new Container(); pnlButtons.Layout = new BoxLayout(Orientation.Horizontal); @@ -247,16 +238,32 @@ namespace UniversalEditor.UserInterface UpdateSuperDuperButtonBar(); } - void LvToolbox_RowActivated(object sender, ListViewRowActivatedEventArgs e) + public DocumentExplorerPanel DocumentExplorerPanel { get { return (DocumentExplorerPanel)FindPanel(Panels.DocumentExplorerPanel.ID); } } + + private void InitializePanels() { - Editor ed = GetCurrentEditor(); - if (ed != null) + foreach (PanelReference panel in ((EditorApplication)Application.Instance).Panels) { - ed.ActivateToolboxItem(e.Row.GetExtraData("item")); + Panel p = null; + if (panel.Control != null) + { + p = panel.Control; + } + else if (panel.ControlTypeName != null) + { + p = MBS.Framework.Reflection.CreateType(panel.ControlTypeName); + } + else + { + Console.Error.WriteLine("ue: MainWindow.InitializePanels() - could not create panel '{0}'; neither Control nor ControlTypeName were specified", panel.Title); + continue; + } + + RegisterPanel(panel, p); + AddPanel(panel.Title, panel.Placement, p); } } - void Application_ContextChanged(object sender, ContextChangedEventArgs e) { UpdateSuperDuperButtonBar(); @@ -384,29 +391,50 @@ namespace UniversalEditor.UserInterface return true; } + + private void InvokeMethod(object obj, string methodName, object[] args) + { + System.Type typ = obj.GetType(); + + System.Type[] typs = new Type[args.Length]; + System.Reflection.ParameterModifier[] mods = new System.Reflection.ParameterModifier[args.Length]; + + for (int i = 0; i < args.Length; i++) + { + if (args[i] == null) + { + typs[i] = null; + } + else + { + typs[i] = args[i].GetType(); + } + } + + System.Reflection.MethodInfo mi = typ.GetMethod(methodName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, typs, mods); + mi.Invoke(obj, args); + } + + private Dictionary _MyPanels = new Dictionary(); + private Dictionary _MyPanels_ID = new Dictionary(); private void _OnEditorChanged(EditorChangedEventArgs e) { + foreach (PanelReference panel in ((EditorApplication)Application.Instance).Panels) + { + InvokeMethod(_MyPanels[panel], "OnEditorChanged", new object[] { e }); + } + if (e.CurrentEditor != null) { // initialize toolbox items - EditorReference er = e.CurrentEditor.MakeReference(); - for (int i = 0; i < er.Toolbox.Items.Count; i++) - { - TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[] { new TreeModelRowColumn(tmToolbox.Columns[0], er.Toolbox.Items[i].Name) }); - row.SetExtraData("item", er.Toolbox.Items[i]); - tmToolbox.Rows.Add(row); - } DocumentFileName = dckContainer.CurrentItem.Name; } else { DocumentFileName = null; - tmToolbox.Rows.Clear(); } - pnlDocumentExplorer.CurrentEditor = e.CurrentEditor; UpdateMenuItems(); - UpdatePropertyPanel(); // forward to window event handler OnEditorChanged(e); @@ -415,21 +443,6 @@ namespace UniversalEditor.UserInterface ((EditorApplication)Application.Instance).OnEditorChanged(e); } - private void UpdatePropertyPanel() - { - pnlPropertyList.Objects.Clear(); - - Editor editor = GetCurrentEditor(); - if (editor == null) return; - - foreach (PropertyPanelObject obj in editor.PropertiesPanel.Objects) - { - pnlPropertyList.Objects.Add(obj); - } - - pnlPropertyList.cboObject.Visible = editor.PropertiesPanel.ShowObjectSelector; - } - private void dckContainer_SelectionChanged(object sender, EventArgs e) { Editor editor = null; @@ -1781,18 +1794,18 @@ namespace UniversalEditor.UserInterface if (value == null || changed) _CurrentSolutionDocument = null; - pnlSolutionExplorer.Solution = value; + ((SolutionExplorerPanel)FindPanel(SolutionExplorerPanel.ID)).Solution = value; } } public ProjectObjectModel CurrentProject { get { - return pnlSolutionExplorer.Project; + return ((SolutionExplorerPanel)FindPanel(SolutionExplorerPanel.ID)).Project; } set { - pnlSolutionExplorer.Project = value; + ((SolutionExplorerPanel)FindPanel(SolutionExplorerPanel.ID)).Project = value; UpdateMenuItems(); } } diff --git a/Libraries/UniversalEditor.UserInterface/Panel.cs b/Libraries/UniversalEditor.UserInterface/Panel.cs index 1c4a3125..cac22286 100644 --- a/Libraries/UniversalEditor.UserInterface/Panel.cs +++ b/Libraries/UniversalEditor.UserInterface/Panel.cs @@ -25,6 +25,8 @@ namespace UniversalEditor.UserInterface { public class Panel : Container { - + protected virtual void OnEditorChanged(EditorChangedEventArgs e) + { + } } } diff --git a/Libraries/UniversalEditor.UserInterface/PanelReference.cs b/Libraries/UniversalEditor.UserInterface/PanelReference.cs new file mode 100644 index 00000000..cb17eadb --- /dev/null +++ b/Libraries/UniversalEditor.UserInterface/PanelReference.cs @@ -0,0 +1,49 @@ +// +// PanelReference.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2021 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Controls.Docking; + +namespace UniversalEditor.UserInterface +{ + public class PanelReference + { + public class PanelReferenceCollection + : System.Collections.ObjectModel.Collection + { + + } + + public Guid ID { get; set; } = Guid.Empty; + public string Title { get; set; } = null; + public DockingItemPlacement Placement { get; set; } = DockingItemPlacement.Left; + + public string ControlTypeName { get; set; } = null; + public Panel Control { get; set; } = null; + + public string LayoutFileName { get; set; } = null; + + public PanelReference(Guid id) + { + ID = id; + } + } +} diff --git a/Libraries/UniversalEditor.UserInterface/Panels/DocumentExplorerPanel.cs b/Libraries/UniversalEditor.UserInterface/Panels/DocumentExplorerPanel.cs index ef594bc6..a445be52 100644 --- a/Libraries/UniversalEditor.UserInterface/Panels/DocumentExplorerPanel.cs +++ b/Libraries/UniversalEditor.UserInterface/Panels/DocumentExplorerPanel.cs @@ -8,6 +8,8 @@ namespace UniversalEditor.UserInterface.Panels { public class DocumentExplorerPanel : Panel { + public static readonly Guid ID = new Guid("{5410f224-d594-4b6c-b31d-ac70e09b6a00}"); + private ListViewControl lv = null; public ListViewControl ListView { get { return lv; } } @@ -28,6 +30,12 @@ namespace UniversalEditor.UserInterface.Panels Controls.Add(lv, new BoxLayout.Constraints(true, true)); } + protected override void OnEditorChanged(EditorChangedEventArgs e) + { + base.OnEditorChanged(e); + CurrentEditor = e.CurrentEditor; + } + private void lv_BeforeContextMenu(object sender, EventArgs e) { if (lv.SelectedRows.Count == 0) diff --git a/Libraries/UniversalEditor.UserInterface/Panels/ErrorListPanel.cs b/Libraries/UniversalEditor.UserInterface/Panels/ErrorListPanel.cs index 8b969c14..180c1469 100644 --- a/Libraries/UniversalEditor.UserInterface/Panels/ErrorListPanel.cs +++ b/Libraries/UniversalEditor.UserInterface/Panels/ErrorListPanel.cs @@ -34,6 +34,8 @@ namespace UniversalEditor.UserInterface.Panels private DefaultTreeModel tm = new DefaultTreeModel(new Type[] { typeof(int), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string) }); + public static readonly Guid ID = new Guid("{7b420eba-c64f-48d7-b093-c016ce23f44f}"); + public ErrorListPanel() { this.Layout = new BoxLayout(Orientation.Vertical); diff --git a/Libraries/UniversalEditor.UserInterface/Panels/PropertyListPanel.cs b/Libraries/UniversalEditor.UserInterface/Panels/PropertyListPanel.cs index e73df74c..0130a5ff 100644 --- a/Libraries/UniversalEditor.UserInterface/Panels/PropertyListPanel.cs +++ b/Libraries/UniversalEditor.UserInterface/Panels/PropertyListPanel.cs @@ -147,6 +147,25 @@ namespace UniversalEditor.UserInterface.Panels public PropertyPanelObject.PropertyPanelObjectCollection Objects { get; private set; } = null; + public static readonly Guid ID = new Guid("{c935e3af-e5c6-4b3e-a3a4-e16ba229a91d}"); + + protected override void OnEditorChanged(EditorChangedEventArgs e) + { + base.OnEditorChanged(e); + + Objects.Clear(); + + Editor editor = ((MainWindow)ParentWindow).GetCurrentEditor(); + if (editor == null) return; + + foreach (PropertyPanelObject obj in editor.PropertiesPanel.Objects) + { + Objects.Add(obj); + } + + cboObject.Visible = editor.PropertiesPanel.ShowObjectSelector; + } + public PropertyListPanel() { Objects = new PropertyPanelObject.PropertyPanelObjectCollection(this); diff --git a/Libraries/UniversalEditor.UserInterface/Panels/SolutionExplorerPanel.cs b/Libraries/UniversalEditor.UserInterface/Panels/SolutionExplorerPanel.cs index 799e918e..df7f6fdc 100644 --- a/Libraries/UniversalEditor.UserInterface/Panels/SolutionExplorerPanel.cs +++ b/Libraries/UniversalEditor.UserInterface/Panels/SolutionExplorerPanel.cs @@ -32,6 +32,8 @@ namespace UniversalEditor.UserInterface.Panels { public class SolutionExplorerPanel : Panel, IDocumentPropertiesProviderControl { + public static readonly Guid ID = new Guid("{1767c74b-b3ea-4919-a5cf-28433e4f6485}"); + private DefaultTreeModel tmSolutionExplorer = null; private ListViewControl tvSolutionExplorer = new ListViewControl(); diff --git a/Libraries/UniversalEditor.UserInterface/Panels/ToolboxPanel.cs b/Libraries/UniversalEditor.UserInterface/Panels/ToolboxPanel.cs new file mode 100644 index 00000000..ce191eb8 --- /dev/null +++ b/Libraries/UniversalEditor.UserInterface/Panels/ToolboxPanel.cs @@ -0,0 +1,88 @@ +// +// ToolboxPanel.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2021 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Controls.ListView; +using MBS.Framework.UserInterface.Layouts; + +namespace UniversalEditor.UserInterface.Panels +{ + public class ToolboxPanel : Panel + { + public static readonly Guid ID = new Guid("{25332d64-6acb-4611-bcd7-d0c652b8653d}"); + + private DefaultTreeModel tmToolbox = new DefaultTreeModel(new Type[] { typeof(string) }); + + public ToolboxPanel() + { + Layout = new BoxLayout(Orientation.Vertical); + + ListViewControl lvToolbox = new ListViewControl(); + lvToolbox.RowActivated += LvToolbox_RowActivated; + lvToolbox.Model = tmToolbox; + lvToolbox.Columns.Add(new ListViewColumn("Item", new CellRenderer[] { new CellRendererText(tmToolbox.Columns[0]) })); + lvToolbox.HeaderStyle = ColumnHeaderStyle.None; + + Controls.Add(lvToolbox, new BoxLayout.Constraints(true, true)); + } + + protected override void OnEditorChanged(EditorChangedEventArgs e) + { + base.OnEditorChanged(e); + + if (e.CurrentEditor != null) + { + // initialize toolbox items + EditorReference er = e.CurrentEditor.MakeReference(); + for (int i = 0; i < er.Toolbox.Items.Count; i++) + { + AddToolboxItem(er.Toolbox.Items[i]); + } + } + else + { + ClearToolboxItems(); + } + } + + void LvToolbox_RowActivated(object sender, ListViewRowActivatedEventArgs e) + { + MainWindow mw = (MainWindow)ParentWindow; + + Editor ed = mw.GetCurrentEditor(); + if (ed != null) + { + ed.ActivateToolboxItem(e.Row.GetExtraData("item")); + } + } + + public void AddToolboxItem(ToolboxItem item) + { + TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[] { new TreeModelRowColumn(tmToolbox.Columns[0], item.Name) }); + row.SetExtraData("item", item); + tmToolbox.Rows.Add(row); + } + public void ClearToolboxItems() + { + tmToolbox.Rows.Clear(); + } + } +} diff --git a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj index 7d75b401..dc9b7797 100644 --- a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj +++ b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj @@ -138,6 +138,8 @@ + +