diff --git a/Libraries/UniversalEditor.UserInterface/Common/Reflection.cs b/Libraries/UniversalEditor.UserInterface/Common/Reflection.cs index f4eef34f..bb33ce1b 100644 --- a/Libraries/UniversalEditor.UserInterface/Common/Reflection.cs +++ b/Libraries/UniversalEditor.UserInterface/Common/Reflection.cs @@ -57,6 +57,11 @@ namespace UniversalEditor.UserInterface.Common InitializeFromXML(ref listEditors); + for (int i = 0; i < listEditors.Count; i++) + { + listEditors[i].InitializeConfiguration(); + } + if (mvarAvailableEditors == null) mvarAvailableEditors = listEditors.ToArray(); } @@ -130,7 +135,14 @@ namespace UniversalEditor.UserInterface.Common if (er != null) { - er.Configuration = tagEditor; + if (er.Configuration == null) + { + er.Configuration = tagEditor; + } + else + { + er.Configuration.Combine(tagEditor); + } MarkupTagElement tagCommands = (tagEditor.Elements["Commands"] as MarkupTagElement); if (tagCommands != null) diff --git a/Libraries/UniversalEditor.UserInterface/Editor.cs b/Libraries/UniversalEditor.UserInterface/Editor.cs index cc93770f..8345dff1 100644 --- a/Libraries/UniversalEditor.UserInterface/Editor.cs +++ b/Libraries/UniversalEditor.UserInterface/Editor.cs @@ -210,8 +210,6 @@ namespace UniversalEditor.UserInterface private bool mvarInhibitUndo = false; protected bool InhibitUndo { get { return mvarInhibitUndo; } set { mvarInhibitUndo = value; } } - protected Toolbox Toolbox { get; } = new Toolbox(); - // private AwesomeControls.PropertyGrid.PropertyGroup.PropertyGroupCollection mvarPropertyGroups = new AwesomeControls.PropertyGrid.PropertyGroup.PropertyGroupCollection(null); // public AwesomeControls.PropertyGrid.PropertyGroup.PropertyGroupCollection PropertyGroups { get { return mvarPropertyGroups; } } @@ -225,13 +223,22 @@ namespace UniversalEditor.UserInterface if (ToolboxItemSelected != null) ToolboxItemSelected(this, e); } /// - /// The event raised when a toolbox item is added to the Editor. Use this to adjust the content of the ObjectModel - /// based on which toolbox item was added. + /// The event raised when a toolbox item is activated in the Editor. Use this to adjust the content of the ObjectModel + /// based on which toolbox item was activated. /// - public event ToolboxItemEventHandler ToolboxItemAdded; - protected virtual void OnToolboxItemAdded(ToolboxItemEventArgs e) + public event ToolboxItemEventHandler ToolboxItemActivated; + protected virtual void OnToolboxItemActivated(ToolboxItemEventArgs e) { - if (ToolboxItemAdded != null) ToolboxItemAdded(this, e); + if (ToolboxItemActivated != null) ToolboxItemActivated(this, e); + } + /// + /// The event raised when a toolbox item is dropped onto the Editor. Use this to adjust the content of the ObjectModel + /// based on which toolbox item was dropped. + /// + public event ToolboxItemEventHandler ToolboxItemDropped; + protected virtual void OnToolboxItemDropped(ToolboxItemEventArgs e) + { + if (ToolboxItemDropped != null) ToolboxItemDropped(this, e); } /// @@ -247,6 +254,19 @@ namespace UniversalEditor.UserInterface return true; } + /// + /// Causes the editor to activate the specified toolbox item. + /// + /// + /// True if the editor accepted the new selection; false otherwise. Update the toolbox user interface accordingly. + public bool ActivateToolboxItem(ToolboxItem item) + { + ToolboxItemEventArgs e = new ToolboxItemEventArgs(item); + OnToolboxItemActivated(e); + if (e.Cancel) return false; + return true; + } + protected override void OnDragEnter(DragEventArgs e) { base.OnDragEnter(e); @@ -262,7 +282,7 @@ namespace UniversalEditor.UserInterface { ToolboxItem item = (e.Data.GetData(typeof(ToolboxItem)) as ToolboxItem); ToolboxItemEventArgs e1 = new ToolboxItemEventArgs(item); - OnToolboxItemAdded(e1); + OnToolboxItemDropped(e1); } } @@ -344,29 +364,6 @@ namespace UniversalEditor.UserInterface DataPath, "Configuration" }); - - // FIXME: refactor this into a single XML configuration file loader at the beginning of engine launch - if (System.IO.Directory.Exists(configurationPath)) - { - string configurationFileNameFilter = System.Configuration.ConfigurationManager.AppSettings["UniversalEditor.Configuration.ConfigurationFileNameFilter"]; - if (configurationFileNameFilter == null) configurationFileNameFilter = "*.uexml"; - - string[] fileNames = System.IO.Directory.GetFiles(configurationPath, configurationFileNameFilter); - XMLPropertyListDataFormat xmpl = new XMLPropertyListDataFormat(); - - foreach (string fileName in fileNames) - { - try - { - PropertyListObjectModel plom = new PropertyListObjectModel(); - Document.Load(plom, xmpl, new FileAccessor(fileName), true); - plom.CopyTo(mvarConfiguration); - } - catch (InvalidDataFormatException ex) - { - } - } - } } #region Implementation diff --git a/Libraries/UniversalEditor.UserInterface/EditorReference.cs b/Libraries/UniversalEditor.UserInterface/EditorReference.cs index 6f530916..823d5409 100644 --- a/Libraries/UniversalEditor.UserInterface/EditorReference.cs +++ b/Libraries/UniversalEditor.UserInterface/EditorReference.cs @@ -20,6 +20,8 @@ namespace UniversalEditor.UserInterface public Type EditorType { get { return mvarEditorType; } set { mvarEditorType = value; } } private ObjectModelReference.ObjectModelReferenceCollection mvarSupportedObjectModels = new ObjectModelReference.ObjectModelReferenceCollection(); + public event EventHandler ConfigurationLoaded; + public ObjectModelReference.ObjectModelReferenceCollection SupportedObjectModels { get { return mvarSupportedObjectModels; } } public MarkupTagElement Configuration { get; set; } = null; @@ -30,6 +32,15 @@ namespace UniversalEditor.UserInterface public EditorView.EditorViewCollection Views { get; } = new EditorView.EditorViewCollection(); public Variable.VariableCollection Variables { get; } = new Variable.VariableCollection(); + public Toolbox Toolbox { get; } = new Toolbox(); + + private bool _ConfigurationInitialized = false; + public void InitializeConfiguration() + { + if (_ConfigurationInitialized) return; + ConfigurationLoaded?.Invoke(this, EventArgs.Empty); + _ConfigurationInitialized = true; + } public EditorReference(Type type) { diff --git a/Libraries/UniversalEditor.UserInterface/Engine.cs b/Libraries/UniversalEditor.UserInterface/Engine.cs index deecf51c..27c65e8c 100644 --- a/Libraries/UniversalEditor.UserInterface/Engine.cs +++ b/Libraries/UniversalEditor.UserInterface/Engine.cs @@ -117,67 +117,6 @@ namespace UniversalEditor.UserInterface } } #endregion - #region Editor Configuration - { - UpdateSplashScreenStatus("Loading editor configuration"); - - MarkupTagElement tagEditors = (Application.RawMarkup.FindElement("UniversalEditor", "Editors") as MarkupTagElement); - if (tagEditors != null) - { - foreach (MarkupElement el in tagEditors.Elements) - { - MarkupTagElement tag = (el as MarkupTagElement); - if (tag == null) continue; - if (tag.FullName != "Editor") continue; - - MarkupAttribute attID = tag.Attributes["ID"]; - MarkupAttribute attTypeName = tag.Attributes["TypeName"]; - - switch (System.Environment.OSVersion.Platform) - { - case PlatformID.MacOSX: - case PlatformID.Unix: - case PlatformID.Xbox: - { - // TODO: this fails on Linux and I don't know why - Console.WriteLine("skipping load editor configuration on Mac OS X, Unix, or Xbox because it fails on Linux and I don't know why"); - break; - } - case PlatformID.Win32NT: - case PlatformID.Win32S: - case PlatformID.Win32Windows: - case PlatformID.WinCE: - { - EditorReference editor = null; - try - { - if (attID != null) - { - Common.Reflection.GetAvailableEditorByID(new Guid(attID.Value)); - } - else if (attTypeName != null) - { - Common.Reflection.GetAvailableEditorByTypeName(attTypeName.Value); - } - } - catch (Exception ex) - { - if (attID != null) - { - Console.WriteLine("couldn't load editor with ID '{0}'", (new Guid(attID.Value)).ToString("B")); - } - else if (attTypeName != null) - { - Console.WriteLine("couldn't load editor with typename '{0}'", attTypeName.Value); - } - } - break; - } - } - } - } - } - #endregion #region Object Model Configuration { UpdateSplashScreenStatus("Loading object model configuration"); diff --git a/Libraries/UniversalEditor.UserInterface/MainWindow.cs b/Libraries/UniversalEditor.UserInterface/MainWindow.cs index 8886d543..cd68153c 100644 --- a/Libraries/UniversalEditor.UserInterface/MainWindow.cs +++ b/Libraries/UniversalEditor.UserInterface/MainWindow.cs @@ -168,6 +168,8 @@ namespace UniversalEditor.UserInterface Application.ExecuteCommand(cmd.ID); } + private DefaultTreeModel tmToolbox = new DefaultTreeModel(new Type[] { typeof(string) }); + public MainWindow() { Layout = new BoxLayout(Orientation.Vertical); @@ -192,9 +194,12 @@ namespace UniversalEditor.UserInterface InitStartPage(); - Label lblToolbox = new Label(); - lblToolbox.Text = "TOOLBOX PLACEHOLDER"; - AddPanel("Toolbox", DockingItemPlacement.Left, lblToolbox); + ListView lvToolbox = new ListView(); + lvToolbox.RowActivated += LvToolbox_RowActivated; + lvToolbox.Model = tmToolbox; + lvToolbox.Columns.Add(new ListViewColumnText(tmToolbox.Columns[0], "Item")); + lvToolbox.HeaderStyle = ColumnHeaderStyle.None; + AddPanel("Toolbox", DockingItemPlacement.Left, lvToolbox); AddPanel("Document Explorer", DockingItemPlacement.Bottom, pnlDocumentExplorer); @@ -222,6 +227,16 @@ namespace UniversalEditor.UserInterface UpdateSuperDuperButtonBar(); } + void LvToolbox_RowActivated(object sender, ListViewRowActivatedEventArgs e) + { + Editor ed = GetCurrentEditor(); + if (ed != null) + { + ed.ActivateToolboxItem(e.Row.GetExtraData("item")); + } + } + + void Application_ContextChanged(object sender, ContextChangedEventArgs e) { UpdateSuperDuperButtonBar(); @@ -335,6 +350,19 @@ namespace UniversalEditor.UserInterface if (editor != null) { Application.Contexts.Add(editor.Context); + + // initialize toolbox items + EditorReference er = editor.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); + } + } + else + { + tmToolbox.Rows.Clear(); } } _prevEditor = editor; diff --git a/Libraries/UniversalEditor.UserInterface/Toolbox.cs b/Libraries/UniversalEditor.UserInterface/Toolbox.cs index 49719a5c..0f98648f 100644 --- a/Libraries/UniversalEditor.UserInterface/Toolbox.cs +++ b/Libraries/UniversalEditor.UserInterface/Toolbox.cs @@ -7,7 +7,9 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; +using System.Collections.Generic; using System.ComponentModel; +using MBS.Framework.UserInterface; namespace UniversalEditor.UserInterface { @@ -16,14 +18,35 @@ namespace UniversalEditor.UserInterface /// public sealed class Toolbox { - private ToolboxItem.ToolboxItemCollection mvarItems = new ToolboxItem.ToolboxItemCollection(); - public ToolboxItem.ToolboxItemCollection Items { get { return mvarItems; } } + public Toolbox() + { + Items = new ToolboxItem.ToolboxItemCollection(this); + } + + public ToolboxItem.ToolboxItemCollection Items { get; private set; } = null; + + + internal void ClearItems() + { + } + internal void InsertItem(ToolboxItem item) + { + } + internal void RemoveItem(ToolboxItem item) + { + } } - public abstract class ToolboxItem + public abstract class ToolboxItem : ISupportsExtraData { public sealed class ToolboxItemCollection : System.Collections.ObjectModel.Collection { + private Toolbox _toolbox = null; + internal ToolboxItemCollection(Toolbox parent) + { + _toolbox = parent; + } + public ToolboxCommandItem AddCommand(string name) { return AddCommand(name, name); @@ -49,6 +72,22 @@ namespace UniversalEditor.UserInterface Add(group); return group; } + + protected override void ClearItems() + { + base.ClearItems(); + _toolbox.ClearItems(); + } + protected override void InsertItem(int index, ToolboxItem item) + { + base.InsertItem(index, item); + _toolbox.InsertItem(item); + } + protected override void RemoveItem(int index) + { + _toolbox.RemoveItem(this[index]); + base.RemoveItem(index); + } } private string mvarName = String.Empty; @@ -61,18 +100,44 @@ namespace UniversalEditor.UserInterface { mvarName = name; } + + private Dictionary _ExtraData = new Dictionary(); + public T GetExtraData(string key, T defaultValue = default(T)) + { + if (_ExtraData.ContainsKey(key) && _ExtraData[key] is T) + return (T)_ExtraData[key]; + return defaultValue; + } + + public void SetExtraData(string key, T value) + { + _ExtraData[key] = value; + } + + public object GetExtraData(string key, object defaultValue = null) + { + if (_ExtraData.ContainsKey(key)) + return _ExtraData[key]; + return defaultValue; + } + + public void SetExtraData(string key, object value) + { + _ExtraData[key] = value; + } } public class ToolboxGroupItem : ToolboxItem { private string mvarTitle = String.Empty; public string Title { get { return mvarTitle; } set { mvarTitle = value; } } - private ToolboxItem.ToolboxItemCollection mvarItems = new ToolboxItem.ToolboxItemCollection(); - public ToolboxItem.ToolboxItemCollection Items { get { return mvarItems; } } + public ToolboxItem.ToolboxItemCollection Items { get; internal set; } public ToolboxGroupItem(string name, string title) : base(name) { mvarTitle = title; + Items = new ToolboxItemCollection(null); + throw new NotImplementedException(); } } public class ToolboxCommandItem : ToolboxItem