diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/Editor.cs b/CSharp/Libraries/UniversalEditor.UserInterface/Editor.cs index f4e5dc19..c614a818 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/Editor.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/Editor.cs @@ -17,6 +17,8 @@ namespace UniversalEditor.UserInterface /// public abstract class Editor : MBS.Framework.UserInterface.Container { + public EditorContext Context { get; private set; } = null; + public EditorSelection.EditorSelectionCollection Selections { get; } = new EditorSelection.EditorSelectionCollection(); public abstract void UpdateSelections(); public EditorSelection[] GetSelections() @@ -227,6 +229,9 @@ namespace UniversalEditor.UserInterface public Editor() { + EditorReference er = MakeReference(); + Context = new EditorContext(er.ID, er.Title, er); + // mvarLargeImageList.ColorDepth = ColorDepth.Depth32Bit; // mvarLargeImageList.ImageSize = new System.Drawing.Size(32, 32); // mvarLargeImageList.PopulateSystemIcons(); diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/EditorContext.cs b/CSharp/Libraries/UniversalEditor.UserInterface/EditorContext.cs new file mode 100644 index 00000000..8e8cda39 --- /dev/null +++ b/CSharp/Libraries/UniversalEditor.UserInterface/EditorContext.cs @@ -0,0 +1,48 @@ +// +// EditorContext.cs +// +// Author: +// Mike Becker +// +// Copyright (c) 2019 Mike Becker +// +// 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; + +namespace UniversalEditor.UserInterface +{ + /// + /// Represents a associated with an . + /// + public class EditorContext : Context + { + public EditorReference Reference { get; private set; } = null; + + public EditorContext(Guid id, string name, EditorReference reference) + : base(id, name) + { + Reference = reference; + + for (int i = 0; i < reference.Commands.Count; i++) + { + Commands.Add(reference.Commands[i]); + } + for (int i = 0; i < reference.MenuBar.Items.Count; i++) + { + MenuItems.Add(reference.MenuBar.Items[i]); + } + } + } +} diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs b/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs index 800f757d..f400639c 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs +++ b/CSharp/Libraries/UniversalEditor.UserInterface/MainWindow.cs @@ -283,39 +283,12 @@ namespace UniversalEditor.UserInterface if (editor != _prevEditor) { - foreach (MBS.Framework.UserInterface.MenuItem mi in _editorScopedMenuItems) - { - MenuBar.Items.Remove(mi); - } - _editorScopedMenuItems.Clear(); + if (_prevEditor != null) + Application.Contexts.Remove(_prevEditor.Context); - foreach (Command cmd in _editorScopedCommands) + if (editor != null) { - Application.Commands.Remove(cmd); - } - _editorScopedCommands.Clear(); - - if (editor == null) - { - Console.WriteLine("Editor is null"); - } - else - { - Console.WriteLine("Editor is NOT null"); - - EditorReference er = editor.MakeReference(); - foreach (Command cmd in er.Commands) - { - Application.Commands.Add(cmd); - _editorScopedCommands.Add(cmd); - } - - foreach (CommandItem ci in er.MenuBar.Items) - { - MBS.Framework.UserInterface.MenuItem mi = MBS.Framework.UserInterface.MenuItem.LoadMenuItem(ci, MainWindow_MenuBar_Item_Click); - MenuBar.Items.Add(mi); - _editorScopedMenuItems.Add(mi); - } + Application.Contexts.Add(editor.Context); } } _prevEditor = editor; diff --git a/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj b/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj index 555d42e2..9b9fb7a9 100644 --- a/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj +++ b/CSharp/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj @@ -126,6 +126,7 @@ +