import more stuff from MBS.Framework
This commit is contained in:
parent
7a884cfd21
commit
a5028581a0
@ -1,4 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using MBS.Core.Extensibility;
|
||||
|
||||
namespace MBS.Core;
|
||||
|
||||
@ -492,4 +493,12 @@ public class Application
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void _EnableDisableCommand(Command command, bool enable)
|
||||
{
|
||||
}
|
||||
|
||||
protected internal virtual Plugin[] GetAdditionalPlugins()
|
||||
{
|
||||
return new Plugin[0];
|
||||
}
|
||||
}
|
||||
|
||||
149
framework-dotnet/src/lib/MBS.Core/Command.cs
Normal file
149
framework-dotnet/src/lib/MBS.Core/Command.cs
Normal file
@ -0,0 +1,149 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of MBS Framework for .NET Core.
|
||||
//
|
||||
// MBS Framework for .NET Core 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.
|
||||
//
|
||||
// MBS Framework for .NET Core 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 MBS Framework for .NET Core. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
namespace MBS.Core;
|
||||
|
||||
public class Command
|
||||
{
|
||||
public class CommandCollection
|
||||
: System.Collections.ObjectModel.Collection<Command>
|
||||
{
|
||||
public Command this[string ID]
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (Command command in this)
|
||||
{
|
||||
if (command.ID == ID) return command;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Command()
|
||||
{
|
||||
}
|
||||
public Command(string id, string title, CommandItem[] items = null)
|
||||
{
|
||||
ID = id;
|
||||
Title = title;
|
||||
if (items != null)
|
||||
{
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
{
|
||||
Items.Add(items[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Determines whether this command displays as checked.
|
||||
/// </summary>
|
||||
public bool Checked { get; set; } = false;
|
||||
/// <summary>
|
||||
/// The ID of the command, used to reference it in <see cref="CommandReferenceCommandItem"/>.
|
||||
/// </summary>
|
||||
public string ID { get; set; } = String.Empty;
|
||||
/// <summary>
|
||||
/// The title of the command (including mnemonic prefix, if applicable).
|
||||
/// </summary>
|
||||
public string Title { get; set; } = String.Empty;
|
||||
|
||||
private string mvarDefaultCommandID = String.Empty;
|
||||
public string DefaultCommandID { get { return mvarDefaultCommandID; } set { mvarDefaultCommandID = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="StockType"/> that represents a predefined, platform-themed command.
|
||||
/// </summary>
|
||||
public StockType StockType { get; set; } = StockType.None;
|
||||
|
||||
private string mvarImageFileName = String.Empty;
|
||||
/// <summary>
|
||||
/// The file name of the image to be displayed on the command.
|
||||
/// </summary>
|
||||
public string ImageFileName { get { return mvarImageFileName; } set { mvarImageFileName = value; } }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The child <see cref="CommandItem"/>s that are contained within this <see cref="Command"/>.
|
||||
/// </summary>
|
||||
public CommandItem.CommandItemCollection Items { get; } = new CommandItem.CommandItemCollection();
|
||||
|
||||
/// <summary>
|
||||
/// The event that is fired when the command is executed.
|
||||
/// </summary>
|
||||
public event EventHandler Executed;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this <see cref="Command" /> is enabled in all <see cref="CommandBar" />s and <see cref="MenuBar" />s
|
||||
/// that reference it.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
|
||||
private bool _Enabled = true;
|
||||
public bool Enabled { get { return _Enabled; } set { _Enabled = value; Application.Instance._EnableDisableCommand(this, value); } }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this <see cref="Command" /> is visible in all <see cref="CommandBar" />s and <see cref="MenuBar" />s
|
||||
/// that reference it.
|
||||
/// </summary>
|
||||
/// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
|
||||
public bool Visible { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Executes this <see cref="Command"/>.
|
||||
/// </summary>
|
||||
[Obsolete("Please use Application.ExecuteCommand. Command.Execute does not always work and will be removed in a future release.")]
|
||||
public void Execute()
|
||||
{
|
||||
if (Executed != null) Executed(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} [{1}]", ID, Title);
|
||||
}
|
||||
|
||||
private Dictionary<string, object> _extraData = new Dictionary<string, object>();
|
||||
public T GetExtraData<T>(string key, T defaultValue = default(T))
|
||||
{
|
||||
if (_extraData.ContainsKey(key))
|
||||
{
|
||||
if (_extraData[key] is T)
|
||||
{
|
||||
return (T)_extraData[key];
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void SetExtraData<T>(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;
|
||||
}
|
||||
}
|
||||
50
framework-dotnet/src/lib/MBS.Core/CommandEventArgs.cs
Normal file
50
framework-dotnet/src/lib/MBS.Core/CommandEventArgs.cs
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of MBS Framework for .NET Core.
|
||||
//
|
||||
// MBS Framework for .NET Core 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.
|
||||
//
|
||||
// MBS Framework for .NET Core 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 MBS Framework for .NET Core. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
namespace MBS.Core;
|
||||
|
||||
public class CommandEventArgs : EventArgs
|
||||
{
|
||||
public Command Command { get; private set; }
|
||||
|
||||
private Dictionary<string, object> _NamedParameters = new Dictionary<string, object>();
|
||||
public T GetNamedParameter<T>(string key, T defaultValue = default(T))
|
||||
{
|
||||
if (_NamedParameters.ContainsKey(key))
|
||||
return (T)_NamedParameters[key];
|
||||
return defaultValue;
|
||||
}
|
||||
public object GetNamedParameter(string key, object defaultValue = null)
|
||||
{
|
||||
if (_NamedParameters.ContainsKey(key))
|
||||
return _NamedParameters[key];
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
||||
public CommandEventArgs(Command command, KeyValuePair<string, object>[] namedParameters = null)
|
||||
{
|
||||
Command = command;
|
||||
if (namedParameters != null)
|
||||
{
|
||||
for (int i = 0; i < namedParameters.Length; i++)
|
||||
{
|
||||
_NamedParameters[namedParameters[i].Key] = namedParameters[i].Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
93
framework-dotnet/src/lib/MBS.Core/CommandItem.cs
Normal file
93
framework-dotnet/src/lib/MBS.Core/CommandItem.cs
Normal file
@ -0,0 +1,93 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of Mocha.NET.
|
||||
//
|
||||
// Mocha.NET 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.
|
||||
//
|
||||
// Mocha.NET 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 Mocha.NET. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
namespace MBS.Core;
|
||||
|
||||
public abstract class CommandItem
|
||||
{
|
||||
public string InsertAfterID { get; set; } = null;
|
||||
public string InsertBeforeID { get; set; } = null;
|
||||
|
||||
public class CommandItemCollection
|
||||
: System.Collections.ObjectModel.Collection<CommandItem>
|
||||
{
|
||||
public int IndexOf(string value)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (this[i] is CommandReferenceCommandItem)
|
||||
{
|
||||
if ((this[i] as CommandReferenceCommandItem).CommandID.Equals(value))
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class ActionCommandItem : CommandItem
|
||||
{
|
||||
public string ID { get; }
|
||||
public string Title { get; }
|
||||
|
||||
public event EventHandler Executed;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
Executed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public ActionCommandItem(string id, string title, EventHandler execute = null)
|
||||
{
|
||||
ID = id;
|
||||
Title = title;
|
||||
if (execute != null)
|
||||
{
|
||||
Executed += execute;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class CommandReferenceCommandItem : CommandItem
|
||||
{
|
||||
private string mvarCommandID = String.Empty;
|
||||
public string CommandID { get { return mvarCommandID; } set { mvarCommandID = value; } }
|
||||
|
||||
public CommandReferenceCommandItem()
|
||||
{
|
||||
}
|
||||
public CommandReferenceCommandItem(string commandID)
|
||||
{
|
||||
mvarCommandID = commandID;
|
||||
}
|
||||
}
|
||||
public class CommandPlaceholderCommandItem : CommandItem
|
||||
{
|
||||
private string mvarPlaceholderID = String.Empty;
|
||||
public string PlaceholderID { get { return mvarPlaceholderID; } set { mvarPlaceholderID = value; } }
|
||||
|
||||
public CommandPlaceholderCommandItem(string placeholderID)
|
||||
{
|
||||
mvarPlaceholderID = placeholderID;
|
||||
}
|
||||
}
|
||||
public class SeparatorCommandItem : CommandItem
|
||||
{
|
||||
}
|
||||
public class GroupCommandItem : CommandItem
|
||||
{
|
||||
public CommandItemCollection Items { get; } = new CommandItemCollection();
|
||||
}
|
||||
115
framework-dotnet/src/lib/MBS.Core/Context.cs
Normal file
115
framework-dotnet/src/lib/MBS.Core/Context.cs
Normal file
@ -0,0 +1,115 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of Mocha.NET.
|
||||
//
|
||||
// Mocha.NET 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.
|
||||
//
|
||||
// Mocha.NET 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 Mocha.NET. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
namespace MBS.Core;
|
||||
|
||||
public class Context
|
||||
{
|
||||
public class ContextCollection
|
||||
: 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()
|
||||
{
|
||||
base.ClearItems();
|
||||
_ItemsByID.Clear();
|
||||
}
|
||||
protected override void InsertItem(int index, Context item)
|
||||
{
|
||||
base.InsertItem(index, item);
|
||||
_ItemsByID[item.ID] = item;
|
||||
}
|
||||
protected override void RemoveItem(int index)
|
||||
{
|
||||
_ItemsByID.Remove(this[index].ID);
|
||||
base.RemoveItem(index);
|
||||
}
|
||||
}
|
||||
|
||||
public Guid ID { get; private set; } = Guid.Empty;
|
||||
public string Name { get; private set; } = String.Empty;
|
||||
|
||||
// public MenuBar MenuBar { get; } = new MenuBar();
|
||||
public Command.CommandCollection Commands { get; } = new Command.CommandCollection();
|
||||
|
||||
public Context(Guid id, string name)
|
||||
{
|
||||
ID = id;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} {1}", Name, ID);
|
||||
}
|
||||
|
||||
private Dictionary<string, List<EventHandler>> _CommandEventHandlers = new Dictionary<string, List<EventHandler>>();
|
||||
/// <summary>
|
||||
/// Attachs an event handler for the command with the ID specified by <paramref name="commandID" />.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c>, if command event handler was attached, <c>false</c> otherwise.</returns>
|
||||
/// <param name="commandID">The ID of the <see cref="Command" /> for which to attach an event handler.</param>
|
||||
/// <param name="handler">The event handler to invoke when the <see cref="Command" /> is executed.</param>
|
||||
public bool AttachCommandEventHandler(string commandID, EventHandler handler)
|
||||
{
|
||||
// handle command event handlers attached without a Command instance
|
||||
if (!_CommandEventHandlers.ContainsKey(commandID))
|
||||
{
|
||||
_CommandEventHandlers.Add(commandID, new List<EventHandler>());
|
||||
}
|
||||
if (!_CommandEventHandlers[commandID].Contains(handler))
|
||||
{
|
||||
_CommandEventHandlers[commandID].Add(handler);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Executes the command (i.e., calls all attached <see cref="EventHandler" />s for the <see cref="Command" />) with
|
||||
/// the given <paramref name="commandID" />, passing in the given parameters in an instance of <see cref="CommandEventArgs" />.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c>, if command was executed, <c>false</c> otherwise.</returns>
|
||||
/// <param name="commandID">Command identifier.</param>
|
||||
/// <param name="namedParameters">Named parameters.</param>
|
||||
public bool ExecuteCommand(string commandID, KeyValuePair<string, object>[] namedParameters = null)
|
||||
{
|
||||
if (_CommandEventHandlers.ContainsKey(commandID))
|
||||
{
|
||||
for (int i = 0; i < _CommandEventHandlers[commandID].Count; i++)
|
||||
{
|
||||
_CommandEventHandlers[commandID][i](this, new CommandEventArgs(Commands[commandID], namedParameters));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
61
framework-dotnet/src/lib/MBS.Core/Extensibility/Feature.cs
Normal file
61
framework-dotnet/src/lib/MBS.Core/Extensibility/Feature.cs
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of MBS Framework for .NET Core.
|
||||
//
|
||||
// MBS Framework for .NET Core 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.
|
||||
//
|
||||
// MBS Framework for .NET Core 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 MBS Framework for .NET Core. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
namespace MBS.Core.Extensibility;
|
||||
|
||||
public class Feature
|
||||
{
|
||||
public class FeatureCollection
|
||||
: System.Collections.ObjectModel.Collection<Feature>
|
||||
{
|
||||
}
|
||||
|
||||
public Guid ID { get; private set; } = Guid.Empty;
|
||||
public string Title { get; private set; } = null;
|
||||
|
||||
public Feature(Guid id, string title)
|
||||
{
|
||||
ID = id;
|
||||
Title = title;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(this is null) && (obj is null)) return false;
|
||||
if (this is null && !(obj is null)) return false;
|
||||
|
||||
if (obj is Feature)
|
||||
{
|
||||
Feature feat = (obj as Feature);
|
||||
return feat.ID.Equals(ID);
|
||||
}
|
||||
return base.Equals(obj);
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public static bool operator ==(Feature left, Feature right)
|
||||
{
|
||||
return (left.ID == right.ID);
|
||||
}
|
||||
public static bool operator !=(Feature left, Feature right)
|
||||
{
|
||||
return (left.ID != right.ID);
|
||||
}
|
||||
}
|
||||
175
framework-dotnet/src/lib/MBS.Core/Extensibility/Plugin.cs
Normal file
175
framework-dotnet/src/lib/MBS.Core/Extensibility/Plugin.cs
Normal file
@ -0,0 +1,175 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of MBS Framework for .NET Core.
|
||||
//
|
||||
// MBS Framework for .NET Core 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.
|
||||
//
|
||||
// MBS Framework for .NET Core 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 MBS Framework for .NET Core. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
namespace MBS.Core.Extensibility;
|
||||
|
||||
public class Plugin
|
||||
{
|
||||
public Context Context { get; protected set; }
|
||||
public virtual string Title { get; set; } = null;
|
||||
public Feature.FeatureCollection ProvidedFeatures { get; } = new Feature.FeatureCollection();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="PropertyBag" /> containing the plugin-specific
|
||||
/// settings for this <see cref="Plugin" />.
|
||||
/// </summary>
|
||||
/// <value>The settings.</value>
|
||||
public PropertyBag Settings { get; }
|
||||
|
||||
public Plugin()
|
||||
{
|
||||
Settings = new PluginPropertyBag(this);
|
||||
}
|
||||
|
||||
public bool Initialized { get; private set; } = false;
|
||||
public void Initialize()
|
||||
{
|
||||
if (Initialized)
|
||||
return;
|
||||
|
||||
InitializeInternal();
|
||||
|
||||
Settings.Initialize();
|
||||
Initialized = true;
|
||||
}
|
||||
|
||||
public Guid ID { get; set; } = Guid.Empty;
|
||||
|
||||
protected virtual void InitializeInternal()
|
||||
{
|
||||
// this method intentionally left blank
|
||||
}
|
||||
|
||||
protected virtual bool AutoRegister => true;
|
||||
|
||||
protected virtual bool IsSupportedInternal()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public bool IsSupported()
|
||||
{
|
||||
return IsSupportedInternal();
|
||||
}
|
||||
private static Plugin[] _plugins = null;
|
||||
public static TPlugin[] Get<TPlugin>(bool resetCache = false) where TPlugin : Plugin
|
||||
{
|
||||
Plugin[] plugins = Get(resetCache);
|
||||
return plugins.OfType<TPlugin>().ToArray();
|
||||
}
|
||||
public static Plugin[] Get(bool resetCache = false)
|
||||
{
|
||||
if (resetCache)
|
||||
{
|
||||
_plugins = null; // should not be cached? // actually, yes it should...
|
||||
|
||||
// 2020-12-12 20:54 by beckermj
|
||||
// ACTUALLY, it depends on whether the configuration needs to be persisted across calls to Get()
|
||||
// [it does] and whether the list of plugins needs to be reloaded when CustomPlugins is modified
|
||||
// [it shouldn't, but it does] .
|
||||
//
|
||||
// The safest way we can handle this RIGHT NOW is to prevent any plugin from being loaded until after CustomPlugins
|
||||
// is initialized by UIApplication.
|
||||
//
|
||||
// We call Plugins.Get(new Feature[] { KnownFeatures.UWTPlatform }) to retrieve the available User Interface plugins
|
||||
// that supply the UWT Platform implementation (e.g. GTK, Windows Forms, etc.) - and this causes CustomPlugins to not
|
||||
// load properly since it loads AFTER this initial call to Plugins.Get().
|
||||
//
|
||||
// So I add ed a resetCache parameter that when specified TRUE will clear the cache and then return the appropriate
|
||||
// plugin. This way we can continue caching future calls to Get() without missing out on CustomPlugins.
|
||||
}
|
||||
|
||||
if (_plugins == null)
|
||||
{
|
||||
Type[] types = Reflection.TypeLoader.GetAvailableTypes(new Type[] { typeof(Plugin) });
|
||||
System.Collections.Generic.List<Plugin> plugins = new System.Collections.Generic.List<Plugin>();
|
||||
for (int i = 0; i < types.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
/*
|
||||
if (types[i].IsSubclassOf(typeof(ICustomPlugin)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
|
||||
Plugin plg = (Plugin)types[i].Assembly.CreateInstance(types[i].FullName);
|
||||
plugins.Add(plg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Plugin[] plugins2 = Application.Instance.GetAdditionalPlugins();
|
||||
for (int i = 0; i < plugins2.Length; i++)
|
||||
{
|
||||
plugins.Add(plugins2[i]);
|
||||
}
|
||||
_plugins = plugins.ToArray();
|
||||
|
||||
if (resetCache)
|
||||
{
|
||||
_plugins = null;
|
||||
return plugins.ToArray();
|
||||
}
|
||||
}
|
||||
return _plugins;
|
||||
}
|
||||
|
||||
public static TPlugin[] Get<TPlugin>(Feature[] providedFeatures, bool resetCache = false) where TPlugin : Plugin
|
||||
{
|
||||
Plugin[] plugins = Get(providedFeatures, resetCache);
|
||||
return plugins.OfType<TPlugin>().ToArray();
|
||||
}
|
||||
public static Plugin[] Get(Feature[] providedFeatures, bool resetCache = false)
|
||||
{
|
||||
System.Collections.Generic.List<Plugin> list = new System.Collections.Generic.List<Plugin>();
|
||||
Plugin[] plugins = Get(resetCache);
|
||||
for (int i = 0; i < plugins.Length; i++)
|
||||
{
|
||||
if (!plugins[i].AutoRegister)
|
||||
continue;
|
||||
|
||||
if (!plugins[i].IsSupported())
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < providedFeatures.Length; j++)
|
||||
{
|
||||
if (plugins[i].ProvidedFeatures.Contains(providedFeatures[j]))
|
||||
list.Add(plugins[i]);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static TPlugin Get<TPlugin>(Guid id) where TPlugin : Plugin
|
||||
{
|
||||
Plugin plugin = Get(id);
|
||||
return (TPlugin)plugin;
|
||||
}
|
||||
public static Plugin Get(Guid id)
|
||||
{
|
||||
Plugin[] plugins = Get();
|
||||
for (int i = 0; i < plugins.Length; i++)
|
||||
{
|
||||
if (plugins[i].ID == id)
|
||||
return plugins[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of MBS Framework for .NET Core.
|
||||
//
|
||||
// MBS Framework for .NET Core 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.
|
||||
//
|
||||
// MBS Framework for .NET Core 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 MBS Framework for .NET Core. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
namespace MBS.Core.Extensibility;
|
||||
|
||||
|
||||
public class PluginPropertyBag : PropertyBag
|
||||
{
|
||||
private Plugin Plugin { get; }
|
||||
|
||||
protected override void OnInitialized(EventArgs e)
|
||||
{
|
||||
base.OnInitialized(e);
|
||||
|
||||
string[] paths = Application.Instance.EnumerateDataPaths();
|
||||
foreach (string datapath in paths)
|
||||
{
|
||||
string path = String.Format("{0}/plugins/{1}/config.xml", datapath, this.Plugin.ID.ToString("b"));
|
||||
if (System.IO.File.Exists(path))
|
||||
{
|
||||
Console.WriteLine("found config in {0}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal PluginPropertyBag(Plugin plugin)
|
||||
{
|
||||
Plugin = plugin;
|
||||
}
|
||||
|
||||
protected override void OnPropertyValueRequested<T>(PropertyValueRequestedEventArgs<T> e)
|
||||
{
|
||||
base.OnPropertyValueRequested(e);
|
||||
}
|
||||
}
|
||||
187
framework-dotnet/src/lib/MBS.Core/Extensibility/PropertyBag.cs
Normal file
187
framework-dotnet/src/lib/MBS.Core/Extensibility/PropertyBag.cs
Normal file
@ -0,0 +1,187 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of MBS Framework for .NET Core.
|
||||
//
|
||||
// MBS Framework for .NET Core 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.
|
||||
//
|
||||
// MBS Framework for .NET Core 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 MBS Framework for .NET Core. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
namespace MBS.Core.Extensibility;
|
||||
|
||||
public class PropertyValueRequestedEventArgs : EventArgs
|
||||
{
|
||||
public Guid ID { get; }
|
||||
public object Value { get; set; }
|
||||
|
||||
public bool Cache { get; set; } = true;
|
||||
public bool Handled { get; set; } = false;
|
||||
|
||||
public PropertyValueRequestedEventArgs(Guid id, object value)
|
||||
{
|
||||
ID = id;
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
public class PropertyValueRequestedEventArgs<T> : PropertyValueRequestedEventArgs
|
||||
{
|
||||
public new T Value { get { return (T)base.Value; } set { base.Value = value; } }
|
||||
|
||||
public PropertyValueRequestedEventArgs(Guid id, T value) : base(id, value)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class PropertyValueChangingEventArgs : System.ComponentModel.CancelEventArgs
|
||||
{
|
||||
public Guid ID { get; }
|
||||
public object OldValue { get; }
|
||||
public object NewValue { get; set; }
|
||||
|
||||
public PropertyValueChangingEventArgs(Guid id, object oldValue, object newValue)
|
||||
{
|
||||
ID = id;
|
||||
OldValue = oldValue;
|
||||
NewValue = newValue;
|
||||
}
|
||||
}
|
||||
public class PropertyValueChangedEventArgs : EventArgs
|
||||
{
|
||||
public Guid ID { get; }
|
||||
public object OldValue { get; }
|
||||
public object NewValue { get; }
|
||||
|
||||
public PropertyValueChangedEventArgs(Guid id, object oldValue, object newValue)
|
||||
{
|
||||
ID = id;
|
||||
OldValue = oldValue;
|
||||
NewValue = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
public class PropertyBag
|
||||
{
|
||||
private Dictionary<Guid, object> _settings = new Dictionary<Guid, object>();
|
||||
private Dictionary<Guid, string> _names = new Dictionary<Guid, string>();
|
||||
public string GetName(Guid id)
|
||||
{
|
||||
if (_names.ContainsKey(id))
|
||||
return _names[id];
|
||||
return null;
|
||||
}
|
||||
public void SetName(Guid id, string name)
|
||||
{
|
||||
_names[id] = name;
|
||||
}
|
||||
|
||||
private Dictionary<Guid, object> _PropertyValues = new Dictionary<Guid, object>();
|
||||
public bool Contains(Guid id)
|
||||
{
|
||||
return _PropertyValues.ContainsKey(id);
|
||||
}
|
||||
public bool SetValue<T>(Guid id, T value)
|
||||
{
|
||||
bool changed = false;
|
||||
lock (_PropertyValues)
|
||||
{
|
||||
object oldValue = null;
|
||||
if (!_PropertyValues.ContainsKey(id) || (!(
|
||||
(_PropertyValues[id] == null && (value as object) == null) ||
|
||||
(_PropertyValues[id] != null && _PropertyValues[id].Equals(value)))))
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
if (_PropertyValues.ContainsKey(id))
|
||||
{
|
||||
oldValue = _PropertyValues[id];
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
PropertyValueChangingEventArgs e = new PropertyValueChangingEventArgs(id, oldValue, value);
|
||||
OnPropertyValueChanging(e);
|
||||
if (e.Cancel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_PropertyValues[id] = value;
|
||||
if (changed)
|
||||
{
|
||||
OnPropertyValueChanged(new PropertyValueChangedEventArgs(id, oldValue, value));
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
public event EventHandler<PropertyValueChangingEventArgs> PropertyValueChanging;
|
||||
protected virtual void OnPropertyValueChanging(PropertyValueChangingEventArgs e)
|
||||
{
|
||||
PropertyValueChanging?.Invoke(this, e);
|
||||
}
|
||||
public event EventHandler<PropertyValueChangedEventArgs> PropertyValueChanged;
|
||||
protected virtual void OnPropertyValueChanged(PropertyValueChangedEventArgs e)
|
||||
{
|
||||
PropertyValueChanged?.Invoke(this, e);
|
||||
}
|
||||
|
||||
public T GetValue<T>(Guid id, T defaultValue = default(T))
|
||||
{
|
||||
lock (_PropertyValues)
|
||||
{
|
||||
if (_PropertyValues.ContainsKey(id))
|
||||
{
|
||||
if (_PropertyValues[id] is T val)
|
||||
{
|
||||
return val;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PropertyValueRequestedEventArgs<T> e = new PropertyValueRequestedEventArgs<T>(id, defaultValue);
|
||||
OnPropertyValueRequested(e);
|
||||
if (e.Handled)
|
||||
{
|
||||
if (e.Cache)
|
||||
{
|
||||
_PropertyValues[id] = e.Value;
|
||||
}
|
||||
return e.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public event EventHandler<PropertyValueRequestedEventArgs> PropertyValueRequested;
|
||||
protected virtual void OnPropertyValueRequested<T>(PropertyValueRequestedEventArgs<T> e)
|
||||
{
|
||||
PropertyValueRequested?.Invoke(this, e);
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<Guid, object>> GetAll()
|
||||
{
|
||||
return _PropertyValues;
|
||||
}
|
||||
|
||||
public bool Initialized { get; private set; } = false;
|
||||
protected virtual void OnInitialized(EventArgs e)
|
||||
{
|
||||
}
|
||||
public void Initialize()
|
||||
{
|
||||
if (Initialized)
|
||||
return;
|
||||
|
||||
OnInitialized(EventArgs.Empty);
|
||||
Initialized = true;
|
||||
}
|
||||
}
|
||||
35
framework-dotnet/src/lib/MBS.Core/IO/DirectoryExtensions.cs
Normal file
35
framework-dotnet/src/lib/MBS.Core/IO/DirectoryExtensions.cs
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of Mocha.NET.
|
||||
//
|
||||
// Mocha.NET 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.
|
||||
//
|
||||
// Mocha.NET 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 Mocha.NET. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
namespace MBS.Core.IO;
|
||||
|
||||
public static class DirectoryExtensions
|
||||
{
|
||||
public static string[] GetFiles(string path, string[] searchPatterns, SearchOption options)
|
||||
{
|
||||
string[] result = new string[0];
|
||||
int j = 0;
|
||||
foreach (string ext in searchPatterns)
|
||||
{
|
||||
string[] filenames = Directory.GetFiles(path, ext, options);
|
||||
Array.Resize<string>(ref result, result.Length + filenames.Length);
|
||||
Array.Copy(filenames, 0, result, j, filenames.Length);
|
||||
j += filenames.Length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
137
framework-dotnet/src/lib/MBS.Core/StockType.cs
Normal file
137
framework-dotnet/src/lib/MBS.Core/StockType.cs
Normal file
@ -0,0 +1,137 @@
|
||||
// Copyright (C) 2024 Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// This file is part of MBS Framework for .NET Core.
|
||||
//
|
||||
// MBS Framework for .NET Core 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.
|
||||
//
|
||||
// MBS Framework for .NET Core 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 MBS Framework for .NET Core. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
namespace MBS.Core;
|
||||
|
||||
public enum StockType
|
||||
{
|
||||
None,
|
||||
About,
|
||||
Add,
|
||||
Apply,
|
||||
|
||||
// these four do not have gtk-stock equivalents
|
||||
ArrowDown,
|
||||
ArrowLeft,
|
||||
ArrowRight,
|
||||
ArrowUp,
|
||||
|
||||
Bold,
|
||||
Bookmarks,
|
||||
Cancel,
|
||||
CapsLockWarning, // not for buttons
|
||||
CDROM,
|
||||
Clear,
|
||||
Close,
|
||||
ColorPicker, // not for buttons
|
||||
Connect,
|
||||
Convert,
|
||||
Copy,
|
||||
Cut,
|
||||
Delete,
|
||||
DialogAuthentication, // not for buttons
|
||||
DialogInfo,
|
||||
DialogWarning,
|
||||
DialogError,
|
||||
DialogQuestion,
|
||||
Directory, // not for buttons
|
||||
Discard,
|
||||
Disconnect,
|
||||
DragAndDrop, // not for buttons
|
||||
DragAndDropMultiple, // not for buttons
|
||||
Edit,
|
||||
Execute,
|
||||
File,
|
||||
Find,
|
||||
FindAndReplace,
|
||||
Floppy,
|
||||
Folder,
|
||||
Fullscreen,
|
||||
GotoBottom,
|
||||
GotoFirst,
|
||||
GotoLast,
|
||||
GotoTop,
|
||||
GoBack,
|
||||
GoDown,
|
||||
GoForward,
|
||||
GoUp,
|
||||
HardDisk,
|
||||
Help,
|
||||
Home,
|
||||
Index,
|
||||
Indent,
|
||||
Info,
|
||||
Italic,
|
||||
JumpTo,
|
||||
JustifyCenter,
|
||||
JustifyFill,
|
||||
JustifyLeft,
|
||||
JustifyRight,
|
||||
LeaveFullscreen,
|
||||
MissingImage, // not for buttons
|
||||
MediaForward,
|
||||
MediaNext,
|
||||
MediaPause,
|
||||
MediaPlay,
|
||||
MediaPrevious,
|
||||
MediaRecord,
|
||||
MediaRewind,
|
||||
MediaStop,
|
||||
Network,
|
||||
New,
|
||||
No,
|
||||
OK,
|
||||
Open,
|
||||
OrientationPortrait,
|
||||
OrientationLandscape,
|
||||
OrientationReverseLandscape,
|
||||
OrientationReversePortrait,
|
||||
PageSetup,
|
||||
Paste,
|
||||
Preferences,
|
||||
Print,
|
||||
PrintError, // not for buttons
|
||||
PrintPaused, // not for buttons
|
||||
PrintPreview,
|
||||
PrintReport, // not for buttons
|
||||
PrintWarning, // not for buttons
|
||||
Properties,
|
||||
Quit,
|
||||
Redo,
|
||||
Refresh,
|
||||
Remove,
|
||||
RevertToSaved,
|
||||
Save,
|
||||
SaveAs,
|
||||
SelectAll,
|
||||
SelectColor,
|
||||
SelectFont,
|
||||
SortAscending,
|
||||
SortDescending,
|
||||
SpellCheck,
|
||||
Stop,
|
||||
Strikethrough,
|
||||
Undelete,
|
||||
Underline,
|
||||
Undo,
|
||||
Unindent,
|
||||
Yes,
|
||||
Zoom100,
|
||||
ZoomFit,
|
||||
ZoomIn,
|
||||
ZoomOut
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user