dynamic menu items are built-in to UWT now, yay!

This commit is contained in:
Michael Becker 2019-11-05 16:24:37 -05:00
parent 9e7c774b15
commit ae76749954
No known key found for this signature in database
GPG Key ID: 389DFF5D73781A12
4 changed files with 58 additions and 31 deletions

View File

@ -17,6 +17,8 @@ namespace UniversalEditor.UserInterface
/// </summary>
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();

View File

@ -0,0 +1,48 @@
//
// EditorContext.cs
//
// Author:
// Mike Becker <alcexhim@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
using System;
using MBS.Framework.UserInterface;
namespace UniversalEditor.UserInterface
{
/// <summary>
/// Represents a <see cref="MBS.Framework.UserInterface.Context" /> associated with an <see cref="Editor" />.
/// </summary>
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]);
}
}
}
}

View File

@ -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;

View File

@ -126,6 +126,7 @@
<Compile Include="EditorViewChangingEvent.cs" />
<Compile Include="EditorViewChangedEvent.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="EditorContext.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">