Support changes to icon in SparkMenuItem

This commit is contained in:
John Colvin committed 2022-04-19 11:42:39 -04:00
1 parent acf140e670
commit 7cdfcbf6dc
1 file changed
+27 -3
+27 -3
View File
@@ -1,10 +1,13 @@
namespace bts.spark {
using bts.api;
using bts.api.core;
using mbts;
using mbts.ui;
using mbts.ui.utility;
using Spark.Core.Reactive;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -16,22 +19,36 @@ namespace bts.spark {
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using static mbts.spark.SparkTags;
public abstract class SparkCommand {
public readonly KeyGesture key_gesture;
readonly IObservableValue<ImageSource> _icon =
ObservableValue.create<ImageSource>(multi_threaded: true);
string _title, _group;
bool _show_in_toolbar, _show_in_context_menu;
public SparkCommand(string title, ImageSource icon, bool show_in_toolbar = true, bool show_in_context_menu = true, KeyGesture key_gesture = null) {
_title = title;
this.icon = icon;
_icon.value = icon;
_show_in_toolbar = show_in_toolbar;
_show_in_context_menu = show_in_context_menu;
this.key_gesture = key_gesture;
}
public event Action title_changed, show_in_toolbar_changed, show_in_context_menu_changed, group_changed;
public event Action title_changed;
public event Action show_in_toolbar_changed;
public event Action show_in_context_menu_changed;
public event Action group_changed;
public event Action<Change<ImageSource>> icon_changed {
add => _icon.value_changed += value;
remove => _icon.value_changed -= value;
}
public string group {
get => _group;
set {
@@ -50,7 +67,12 @@ namespace bts.spark {
}
}
}
public ImageSource icon { get; }
public ImageSource icon {
get => _icon.value;
set => _icon.value = value;
}
public bool show_in_toolbar {
get => _show_in_toolbar;
set {
@@ -365,6 +387,7 @@ namespace bts.spark {
readonly SparkCommand _cmd;
readonly IBus _bus;
readonly ISelectable _selectable_cmd;
readonly Dispatcher _dispatcher = Dispatcher.CurrentDispatcher;
object _first_child_group;
public SparkCommandVM(SparkCommand cmd, IBus bus) {
@@ -374,6 +397,7 @@ namespace bts.spark {
cmd.group_changed += () => RaisePropertyChanged(nameof(group));
cmd.show_in_toolbar_changed += () => RaisePropertyChanged(nameof(show_in_toolbar));
cmd.show_in_context_menu_changed += () => RaisePropertyChanged(nameof(show_in_context_menu));
cmd.icon_changed += c => _dispatcher.check_invoke_async(() => RaisePropertyChanged(nameof(icon))).ignore();
if (cmd.child_items != null) {
ObservableAutoWrapper.connect(cmd.child_items, child_items, item => new SparkCommandVM(item, bus));
child_items_view = new ListCollectionView(child_items);