separate Application contexts (added/removed to Application) and other contexts (e.g. Universal Editor's EditorContext)
This commit is contained in:
parent
a594833143
commit
489544e372
@ -25,10 +25,69 @@ namespace MBS.Framework
|
|||||||
{
|
{
|
||||||
public class Application
|
public class Application
|
||||||
{
|
{
|
||||||
|
public class ApplicationContextCollection
|
||||||
|
: Context.ContextCollection
|
||||||
|
{
|
||||||
|
protected override void ClearItems()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < this.Count; i++)
|
||||||
|
{
|
||||||
|
Instance.RemoveContext(this[i]);
|
||||||
|
}
|
||||||
|
base.ClearItems();
|
||||||
|
}
|
||||||
|
protected override void InsertItem(int index, Context item)
|
||||||
|
{
|
||||||
|
base.InsertItem(index, item);
|
||||||
|
Instance.AddContext(item);
|
||||||
|
}
|
||||||
|
protected override void RemoveItem(int index)
|
||||||
|
{
|
||||||
|
Instance.RemoveContext(this[index]);
|
||||||
|
base.RemoveItem(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Application Instance { get; set; } = null;
|
public static Application Instance { get; set; } = null;
|
||||||
|
|
||||||
|
protected virtual Command FindCommandInternal(string commandID)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public Command FindCommand(string commandID)
|
||||||
|
{
|
||||||
|
Command cmd = FindCommandInternal(commandID);
|
||||||
|
if (cmd != null) return cmd;
|
||||||
|
|
||||||
|
cmd = Commands[commandID];
|
||||||
|
if (cmd != null) return cmd;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual Context FindContextInternal(Guid contextID)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public Context FindContext(Guid contextID)
|
||||||
|
{
|
||||||
|
Context ctx = FindContextInternal(contextID);
|
||||||
|
if (ctx != null) return ctx;
|
||||||
|
|
||||||
|
ctx = Contexts[contextID];
|
||||||
|
if (ctx != null) return ctx;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public Guid ID { get; set; } = Guid.Empty;
|
public Guid ID { get; set; } = Guid.Empty;
|
||||||
|
|
||||||
|
protected virtual void EnableDisableCommandInternal(Command command, bool enable)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
internal void _EnableDisableCommand(Command command, bool enable)
|
||||||
|
{
|
||||||
|
EnableDisableCommandInternal(command, enable);
|
||||||
|
}
|
||||||
|
|
||||||
private string _UniqueName = null;
|
private string _UniqueName = null;
|
||||||
public string UniqueName
|
public string UniqueName
|
||||||
{
|
{
|
||||||
@ -86,6 +145,7 @@ namespace MBS.Framework
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExecuteCommand(string id, KeyValuePair<string, object>[] namedParameters = null)
|
public void ExecuteCommand(string id, KeyValuePair<string, object>[] namedParameters = null)
|
||||||
{
|
{
|
||||||
Command cmd = Commands[id];
|
Command cmd = Commands[id];
|
||||||
@ -154,7 +214,7 @@ namespace MBS.Framework
|
|||||||
/// Gets a collection of <see cref="Context" /> objects representing system, application, user, and custom contexts for settings and other items.
|
/// Gets a collection of <see cref="Context" /> objects representing system, application, user, and custom contexts for settings and other items.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>A collection of <see cref="Context" /> objects representing cpublic for settings and other items.</value>
|
/// <value>A collection of <see cref="Context" /> objects representing cpublic for settings and other items.</value>
|
||||||
public Context.ContextCollection Contexts { get; } = new Context.ContextCollection();
|
public ApplicationContextCollection Contexts { get; } = new ApplicationContextCollection();
|
||||||
|
|
||||||
public ContextChangedEventHandler ContextAdded;
|
public ContextChangedEventHandler ContextAdded;
|
||||||
protected virtual void OnContextAdded(ContextChangedEventArgs e)
|
protected virtual void OnContextAdded(ContextChangedEventArgs e)
|
||||||
@ -171,7 +231,7 @@ namespace MBS.Framework
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles updating the menus, toolbars, keyboard shortcuts, and other UI elements associated with the application <see cref="Context" />.
|
/// Handles updating the menus, toolbars, keyboard shortcuts, and other UI elements associated with the application <see cref="Context" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal void AddContext(Context ctx)
|
private void AddContext(Context ctx)
|
||||||
{
|
{
|
||||||
OnContextAdded(new ContextChangedEventArgs(ctx));
|
OnContextAdded(new ContextChangedEventArgs(ctx));
|
||||||
}
|
}
|
||||||
@ -179,7 +239,7 @@ namespace MBS.Framework
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles updating the menus, toolbars, keyboard shortcuts, and other UI elements associated with the application <see cref="Context" />.
|
/// Handles updating the menus, toolbars, keyboard shortcuts, and other UI elements associated with the application <see cref="Context" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal void RemoveContext(Context ctx)
|
private void RemoveContext(Context ctx)
|
||||||
{
|
{
|
||||||
OnContextRemoved(new ContextChangedEventArgs(ctx));
|
OnContextRemoved(new ContextChangedEventArgs(ctx));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,22 +28,36 @@ namespace MBS.Framework
|
|||||||
public class ContextCollection
|
public class ContextCollection
|
||||||
: System.Collections.ObjectModel.Collection<Context>
|
: System.Collections.ObjectModel.Collection<Context>
|
||||||
{
|
{
|
||||||
|
private Dictionary<Guid, Context> _ItemsByID = new Dictionary<Guid, Context>();
|
||||||
|
|
||||||
|
public bool Contains(Guid contextID)
|
||||||
|
{
|
||||||
|
return _ItemsByID.ContainsKey(contextID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Context this[Guid id]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_ItemsByID.ContainsKey(id))
|
||||||
|
return _ItemsByID[id];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void ClearItems()
|
protected override void ClearItems()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < this.Count; i++)
|
|
||||||
{
|
|
||||||
Application.Instance.RemoveContext(this[i]);
|
|
||||||
}
|
|
||||||
base.ClearItems();
|
base.ClearItems();
|
||||||
|
_ItemsByID.Clear();
|
||||||
}
|
}
|
||||||
protected override void InsertItem(int index, Context item)
|
protected override void InsertItem(int index, Context item)
|
||||||
{
|
{
|
||||||
base.InsertItem(index, item);
|
base.InsertItem(index, item);
|
||||||
Application.Instance.AddContext(item);
|
_ItemsByID[item.ID] = item;
|
||||||
}
|
}
|
||||||
protected override void RemoveItem(int index)
|
protected override void RemoveItem(int index)
|
||||||
{
|
{
|
||||||
Application.Instance.RemoveContext(this[index]);
|
_ItemsByID.Remove(this[index].ID);
|
||||||
base.RemoveItem(index);
|
base.RemoveItem(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user