make GridSettings pretty again (starting with OrderBook)
This commit is contained in:
1 parent
ecc96b24da
commit
ec4f6b16ca
26 files changed
+2203
-1069
No files matched your search
@@ -156,7 +156,7 @@ namespace mbts.spark {
|
||||
vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
|
||||
return dialog;
|
||||
}));
|
||||
grid_settings_manager = new OrderBookGridSettingsManager(bus, notification_service, model, rows, core_columns);
|
||||
grid_settings_manager = new OrderBookGridSettingsManager(bus, notification_service, rows, core_columns);
|
||||
grid_settings_manager.algo_tree_display_mode_changed += _on_filter_changed;
|
||||
IDisposable attach_vm_hooks = null;
|
||||
begin_attaching += on_begin_attaching;
|
||||
@@ -261,7 +261,8 @@ namespace mbts.spark {
|
||||
}),
|
||||
_columns);
|
||||
if (settings_manager != null) {
|
||||
concat_disposable(settings_manager.subscribe_current().OnDispatcher().Subscribe(grid_settings_manager));
|
||||
concat_disposable(
|
||||
settings_manager.subscribe_current().OnDispatcher().Subscribe(grid_settings_manager.load_from));
|
||||
}
|
||||
IObservable<Func<FillTuple, bool>> mk_fills_slave_predicate_src() =>
|
||||
Observable.Create<Func<FillTuple, bool>>(o => {
|
||||
|
||||
@@ -176,8 +176,10 @@ namespace mbts.spark {
|
||||
return _vm.grid_settings_manager.create_vm(s);
|
||||
}
|
||||
);
|
||||
gs_vm.SubscribeDisposed(literal_title_source.OnDispatcher().Subscribe(t => gs_vm.title = t));
|
||||
var dialog = new ShellSettingsDialog { DataContext = gs_vm };
|
||||
gs_vm.SubscribeDisposed(Disposable.Create(
|
||||
literal_title_source.OnDispatcher().Subscribe(t => gs_vm.title = t),
|
||||
_bus.subscribe(SparkTags.SecuritiesTag).OnDispatcher().Subscribe(sec_map => dialog.Resources[ResourceKeys.Securities] = sec_map)));
|
||||
gs_vm.RequestClose += (s, e) => WindowUtilities.force_close(dialog);
|
||||
return dialog;
|
||||
}));
|
||||
|
||||
@@ -7,6 +7,7 @@ using ProtoBuf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using GridSettings = mbts.ui.settings.GridSettings;
|
||||
|
||||
namespace bts.shell.orderbook {
|
||||
@@ -42,8 +43,8 @@ namespace bts.shell.orderbook {
|
||||
public IReadOnlyList<OrderRecordTuplePredicateAnimations> predicate_animations => _predicate_animations ?? (_predicate_animations = new List<OrderRecordTuplePredicateAnimations>());
|
||||
IEnumerable<IPredicateAnimationsData<OrderSecurity, OrderRecordTuplePredicate>> IGridSettingsWithNotifications<OrderSecurity, OrderRecordTuplePredicate>.predicate_animations => predicate_animations;
|
||||
|
||||
public OrderBookGridSettings with(GridSettings general) =>
|
||||
new OrderBookGridSettings(general ?? this.general, predicate_animations) {
|
||||
public OrderBookGridSettings with(GridSettings general = null, IEnumerable<OrderRecordTuplePredicateAnimations> predicate_animations = null) =>
|
||||
new OrderBookGridSettings(general ?? this.general, predicate_animations?.ToList() ?? this.predicate_animations) {
|
||||
algo_tree_display_mode = algo_tree_display_mode
|
||||
};
|
||||
|
||||
|
||||
+36
-47
@@ -1,23 +1,27 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Columns = mbts.spark.OrderBookGridView.ColumnKeys;
|
||||
using CompositeDisposable = System.Reactive.Disposables.CompositeDisposable;
|
||||
|
||||
namespace bts.shell.orderbook {
|
||||
class OrderBookGridSettingsManager : IDisposable, IObserver<OrderBookGridSettings> {
|
||||
class OrderBookGridSettingsManager : IDisposable {
|
||||
public static readonly IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> hard_column_flags;
|
||||
|
||||
readonly IObserver<OrderBookGridSettings> _core_man_as_observer;
|
||||
readonly IEnumerable<OrderBookRowVM> _rows;
|
||||
readonly ObservableCollection<OrderRecordTuplePredicateAnimations> _active_predicate_animations =
|
||||
new ObservableCollection<OrderRecordTuplePredicateAnimations>();
|
||||
|
||||
IReadOnlyList<OrderRecordTuplePredicateAnimations> _predicate_animations;
|
||||
AlgoTreeDisplayMode _algo_tree_display_mode;
|
||||
IDisposable _sound_hooks;
|
||||
|
||||
static OrderBookGridSettingsManager() {
|
||||
// make font-weight immutable for all columns (the font-weight rule is hard-coded: Regular for root-orders, Light for all others)
|
||||
@@ -36,36 +40,22 @@ namespace bts.shell.orderbook {
|
||||
public OrderBookGridSettingsManager(
|
||||
IBus bus,
|
||||
INotificationService notification_service,
|
||||
OrdersModel model,
|
||||
IEnumerable<OrderBookRowVM> rows,
|
||||
ObservableCollection<DIYGrid.ColumnBase> columns) {
|
||||
core_manager = new GridSettingsManager<OrderBookRowVM, OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings>(
|
||||
bus, model, rows, columns,
|
||||
() => new OrderRecordTuplePredicate(),
|
||||
() => {
|
||||
var pvm = PredicateVMWrapper.create<OrderSecurity, OrderRecordTuplePredicate, OrderRecordTuplePredicate.PredicateTypeOneofCase>(
|
||||
OrderRecordTuplePredicateVMFactory.get_oneofs(bus, model), rp => rp.predicate_type_case);
|
||||
pvm.selected_predicate_type = pvm.predicate_types.FirstOrDefault();
|
||||
return pvm;
|
||||
},
|
||||
col_id => {
|
||||
var pvm = PredicateVMWrapper.create<OrderSecurity, OrderRecordTuplePredicate, OrderRecordTuplePredicate.PredicateTypeOneofCase>(
|
||||
OrderRecordTuplePredicateVMFactory.get_oneofs(bus, model), rp => rp.predicate_type_case);
|
||||
pvm.selected_predicate_type = _corresponding_predicate_type(EnumHelper.parse_or_default<Columns>(col_id));
|
||||
return pvm;
|
||||
},
|
||||
(gen, anims) => new OrderBookGridSettings(gen, anims.empty_if_null().Select(a => new OrderRecordTuplePredicateAnimations(a.predicate_data, a.cell_animations, a.row_animations, a.sound_notifications))) { algo_tree_display_mode = _algo_tree_display_mode },
|
||||
p => p.create_predicate(notification_service.data_cache),
|
||||
p => p.create_notification_predicate(notification_service.data_cache),
|
||||
notification_service == null ? new Func<IPredicate<OrderSecurity>, SoundNotification, IDisposable>((p, sn) => Disposable.empty) : notification_service.link_to_order,
|
||||
notification_service == null ? new Func<INotificationPredicate<OrderSecurity>, IDisposable>(t => Disposable.empty) : notification_service.link_to_order,
|
||||
hard_column_flags);
|
||||
_core_man_as_observer = core_manager;
|
||||
_rows = rows;
|
||||
core_manager = new GridSettingsManager(columns, hard_column_flags);
|
||||
_sound_hooks = ObservableAutoWrapper.connect_item_hooks(
|
||||
_active_predicate_animations,
|
||||
a => {
|
||||
var pred = a.predicate_data.create_predicate(notification_service.data_cache);
|
||||
return new CompositeDisposable(
|
||||
a.sound_notifications.Select(s => notification_service.link_to_order(pred, s)));
|
||||
});
|
||||
}
|
||||
|
||||
public event Action algo_tree_display_mode_changed;
|
||||
|
||||
public GridSettingsManager<OrderBookRowVM, OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings> core_manager { get; }
|
||||
public GridSettingsManager core_manager { get; }
|
||||
|
||||
public AlgoTreeDisplayMode algo_tree_display_mode {
|
||||
get => _algo_tree_display_mode;
|
||||
@@ -78,23 +68,29 @@ namespace bts.shell.orderbook {
|
||||
}
|
||||
|
||||
public void load_from(OrderBookGridSettings gs) {
|
||||
core_manager.load_from(gs);
|
||||
core_manager.load_from(gs.general);
|
||||
algo_tree_display_mode = gs.algo_tree_display_mode;
|
||||
_predicate_animations = gs.predicate_animations;
|
||||
_active_predicate_animations.sync_with(_predicate_animations.Where(p => p.is_enabled));
|
||||
foreach (var r in _rows)
|
||||
r.raise_invalidated();
|
||||
}
|
||||
|
||||
public OrderBookGridSettings create(IEnumerable<SortingCriteria> sorting_criterion) {
|
||||
var gs = core_manager.create();
|
||||
gs.general = gs.general.with(sorting_criterion: sorting_criterion);
|
||||
gs.algo_tree_display_mode = _algo_tree_display_mode;
|
||||
return gs;
|
||||
}
|
||||
|
||||
public OrderBookSettingsVM create_vm(OrderBookGridSettings gs) =>
|
||||
new OrderBookSettingsVM(core_manager.create_vm(gs.general)) {
|
||||
algo_tree_display_mode = gs.algo_tree_display_mode
|
||||
public OrderBookGridSettings create(IEnumerable<SortingCriteria> sorting_criterion) =>
|
||||
new OrderBookGridSettings(
|
||||
core_manager.grid_settings,
|
||||
_predicate_animations.ToList()) {
|
||||
algo_tree_display_mode = _algo_tree_display_mode
|
||||
};
|
||||
|
||||
public void Dispose() => core_manager.Dispose();
|
||||
public OrderBookSettingsVM create_vm(OrderBookGridSettings gs) {
|
||||
var vm = new OrderBookSettingsVM(core_manager.create_vm());
|
||||
vm.load(gs);
|
||||
return vm;
|
||||
}
|
||||
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(ref _sound_hooks);
|
||||
|
||||
static OrderRecordTuplePredicate.PredicateTypeOneofCase _corresponding_predicate_type(Columns col) {
|
||||
switch (col) {
|
||||
@@ -122,12 +118,5 @@ namespace bts.shell.orderbook {
|
||||
default: return default;
|
||||
}
|
||||
}
|
||||
|
||||
void IObserver<OrderBookGridSettings>.OnNext(OrderBookGridSettings value) {
|
||||
_core_man_as_observer.OnNext(value);
|
||||
algo_tree_display_mode = value.algo_tree_display_mode;
|
||||
}
|
||||
void IObserver<OrderBookGridSettings>.OnError(Exception error) => _core_man_as_observer.OnError(error);
|
||||
void IObserver<OrderBookGridSettings>.OnCompleted() => _core_man_as_observer.OnCompleted();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,143 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace bts.shell.orderbook {
|
||||
class OrderBookSettingsVM : DisposableViewModelBase, IWindowSettingsVM<OrderBookGridSettings>, ITemplateSelectorKey {
|
||||
AlgoTreeDisplayMode _algo_tree_display_mode;
|
||||
|
||||
public OrderBookSettingsVM(GridSettingsVM<OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings> core_settings_vm) =>
|
||||
this.core_settings_vm = core_settings_vm;
|
||||
|
||||
public OrderBookSettingsVM(
|
||||
IBus bus,
|
||||
OrdersModel orders_model,
|
||||
Func<OrderRecordTuplePredicate> predicate_data_factory,
|
||||
Func<OrderRecordTuplePredicate, INotificationPredicate<OrderSecurity>> notification_predicate_factory,
|
||||
Func<IPropertyWrapperVM<OrderRecordTuplePredicate>> create_predicate_vm,
|
||||
Func<string, IPropertyWrapperVM<OrderRecordTuplePredicate>> create_column_predicate_vm,
|
||||
Func<GridSettings, IEnumerable<IPredicateAnimationsData<OrderSecurity, OrderRecordTuplePredicate>>, OrderBookGridSettings> create_settings_obj,
|
||||
IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> column_flags = null) {
|
||||
core_settings_vm = new GridSettingsVM<OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings>(
|
||||
bus, orders_model, predicate_data_factory, notification_predicate_factory, create_predicate_vm, create_column_predicate_vm, create_settings_obj, column_flags);
|
||||
}
|
||||
|
||||
public GridSettingsVM<OrderSecurity, OrderRecordTuplePredicate, OrderBookGridSettings> core_settings_vm { get; }
|
||||
public AlgoTreeDisplayMode algo_tree_display_mode { get => _algo_tree_display_mode; set => Set(ref _algo_tree_display_mode, value); }
|
||||
string ITemplateSelectorKey.key => GridSettingsTemplateKeys.OrderBook;
|
||||
|
||||
public void load(OrderBookGridSettings grid_settings) {
|
||||
core_settings_vm.load(grid_settings);
|
||||
algo_tree_display_mode = grid_settings.algo_tree_display_mode;
|
||||
}
|
||||
public OrderBookGridSettings get_result() {
|
||||
var gs = core_settings_vm.get_result();
|
||||
gs.algo_tree_display_mode = algo_tree_display_mode;
|
||||
return gs;
|
||||
}
|
||||
}
|
||||
using bts.api;
|
||||
using bts.utils;
|
||||
using mbts;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.spark;
|
||||
using mbts.ui.viewmodels;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace bts.shell.orderbook {
|
||||
class OrderBookSettingsVM : DisposableViewModelBase, IWindowSettingsVM<OrderBookGridSettings>, ITemplateSelectorKey {
|
||||
readonly BooleanParameterVM _show_full_algo_tree = new BooleanParameterVM("Show Full Algo Tree");
|
||||
|
||||
public OrderBookSettingsVM(GridSettingsVM core_settings_vm) {
|
||||
this.core_settings_vm = core_settings_vm;
|
||||
this.echo(_show_full_algo_tree, nameof(algo_tree_display_mode));
|
||||
add_alert_cmd = new DelegateCommand(() => {
|
||||
alerts.Add(new OrderAlertVM {
|
||||
is_enabled = true,
|
||||
predicate_type = OrderRecordTuplePredicate.PredicateTypeOneofCase.FilledEvent,
|
||||
sound_type = SoundNotification.SystemSound.BellCounter
|
||||
});
|
||||
});
|
||||
delete_alert_cmd = new DelegateCommand<OrderAlertVM>(vm => {
|
||||
if (vm != null)
|
||||
alerts.Remove(vm);
|
||||
});
|
||||
}
|
||||
|
||||
public GridSettingsVM core_settings_vm { get; }
|
||||
public AlgoTreeDisplayMode algo_tree_display_mode {
|
||||
get => _show_full_algo_tree.value ? AlgoTreeDisplayMode.FullTree : AlgoTreeDisplayMode.RootAndLeafNodes;
|
||||
set => _show_full_algo_tree.value = value == AlgoTreeDisplayMode.FullTree;
|
||||
}
|
||||
public IEnumerable parameters {
|
||||
get {
|
||||
yield return _show_full_algo_tree;
|
||||
}
|
||||
}
|
||||
public ICommand add_alert_cmd { get; }
|
||||
public ICommand delete_alert_cmd { get; }
|
||||
// TODO: make this generic (for now, all views orderbook settings can ignore it)
|
||||
public ObservableCollection<OrderAlertVM> alerts { get; } = new ObservableCollection<OrderAlertVM>();
|
||||
string ITemplateSelectorKey.key => GridSettingsTemplateKeys.OrderBook;
|
||||
|
||||
public void load(OrderBookGridSettings grid_settings) {
|
||||
core_settings_vm.load(grid_settings.general);
|
||||
algo_tree_display_mode = grid_settings.algo_tree_display_mode;
|
||||
CollectionHelper.add_or_update_existing(alerts,
|
||||
grid_settings.predicate_animations,
|
||||
pa => {
|
||||
var vm = new OrderAlertVM();
|
||||
vm.load_from(pa);
|
||||
return vm;
|
||||
},
|
||||
(vm, pa) => vm.load_from(pa));
|
||||
}
|
||||
|
||||
public OrderBookGridSettings get_result() {
|
||||
var gs = core_settings_vm.get_result();
|
||||
return new OrderBookGridSettings(gs, alerts.Select(vm => vm.create())) {
|
||||
algo_tree_display_mode = algo_tree_display_mode
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class OrderAlertVM : ViewModelBase, IValueFactory<OrderRecordTuplePredicateAnimations> {
|
||||
SecurityCriteria _security_criteria;
|
||||
SoundNotification.SystemSound _sound_type;
|
||||
OrderRecordTuplePredicate.PredicateTypeOneofCase _predicate_type;
|
||||
bool _is_enabled;
|
||||
|
||||
public bool is_enabled { get => _is_enabled; set => Set(ref _is_enabled, value); }
|
||||
public SecurityCriteria security_criteria { get => _security_criteria; set => Set(ref _security_criteria, value); }
|
||||
public SoundNotification.SystemSound sound_type { get => _sound_type; set => Set(ref _sound_type, value); }
|
||||
public OrderRecordTuplePredicate.PredicateTypeOneofCase predicate_type { get => _predicate_type; set => Set(ref _predicate_type, value); }
|
||||
public IEnumerable<OrderRecordTuplePredicate.PredicateTypeOneofCase> predicate_types { get; } =
|
||||
new[] {
|
||||
OrderRecordTuplePredicate.PredicateTypeOneofCase.FilledEvent,
|
||||
OrderRecordTuplePredicate.PredicateTypeOneofCase.CompletedEvent,
|
||||
OrderRecordTuplePredicate.PredicateTypeOneofCase.CanceledEvent
|
||||
};
|
||||
|
||||
public OrderRecordTuplePredicateAnimations create() {
|
||||
var pred = new OrderRecordTuplePredicate();
|
||||
switch (predicate_type) {
|
||||
case OrderRecordTuplePredicate.PredicateTypeOneofCase.CanceledEvent:
|
||||
pred.canceled_event = new OrderCanceledEventPredicate {
|
||||
security = security_criteria.is_defined() ?
|
||||
new SecurityPredicate { is_value = security_criteria } : null
|
||||
};
|
||||
break;
|
||||
case OrderRecordTuplePredicate.PredicateTypeOneofCase.FilledEvent:
|
||||
pred.filled_event = new OrderFilledEventPredicate {
|
||||
security = security_criteria.is_defined() ?
|
||||
new SecurityPredicate { is_value = security_criteria } : null
|
||||
};
|
||||
break;
|
||||
case OrderRecordTuplePredicate.PredicateTypeOneofCase.CompletedEvent:
|
||||
pred.completed_event = new OrderCompletedEventPredicate {
|
||||
security = security_criteria.is_defined() ?
|
||||
new SecurityPredicate { is_value = security_criteria } : null
|
||||
};
|
||||
break;
|
||||
}
|
||||
return new OrderRecordTuplePredicateAnimations(
|
||||
pred, null, null,
|
||||
new[] {
|
||||
new SoundNotification { system_sound = sound_type }
|
||||
},
|
||||
is_enabled);
|
||||
}
|
||||
|
||||
public void load_from(OrderRecordTuplePredicateAnimations value) {
|
||||
if (value.sound_notifications.Count == 0)
|
||||
return;
|
||||
is_enabled = value.is_enabled;
|
||||
var animation = value.sound_notifications[0];
|
||||
var pred = value.predicate_data;
|
||||
if (animation.sound_type_case == SoundNotification.SoundTypeOneofCase.System)
|
||||
sound_type = animation.system_sound.Value;
|
||||
if (pred != null) {
|
||||
predicate_type = pred.predicate_type_case;
|
||||
switch (pred.predicate_type_case) {
|
||||
case OrderRecordTuplePredicate.PredicateTypeOneofCase.CanceledEvent:
|
||||
security_criteria = pred.canceled_event.security?.is_value;
|
||||
break;
|
||||
case OrderRecordTuplePredicate.PredicateTypeOneofCase.CompletedEvent:
|
||||
security_criteria = pred.completed_event.security?.is_value;
|
||||
break;
|
||||
case OrderRecordTuplePredicate.PredicateTypeOneofCase.FilledEvent:
|
||||
security_criteria = pred.filled_event.security?.is_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<UserControl
|
||||
x:Class="mbts.ui.spark.OrderBookSettingsView"
|
||||
x:ClassModifier="internal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:shell="clr-namespace:bts.shell"
|
||||
xmlns:orderbook="clr-namespace:bts.shell.orderbook"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
xmlns:usp="clr-namespace:mbts.ui.spark"
|
||||
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
|
||||
Content="{Binding}"
|
||||
>
|
||||
<UserControl.Resources>
|
||||
<usp:GridSettingsResources/>
|
||||
</UserControl.Resources>
|
||||
<UserControl.ContentTemplate>
|
||||
<DataTemplate DataType="{x:Type orderbook:OrderBookSettingsVM}">
|
||||
<Grid>
|
||||
<c:ActionMenu
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,2,0,0"
|
||||
ItemsSource="{Binding DataContext.action_menu_items, RelativeSource={RelativeSource AncestorType=usp:ShellSettingsDialog}}"
|
||||
Style="{StaticResource SparkToolBarItem}"
|
||||
/>
|
||||
<TabControl HorizontalAlignment="Stretch" MinHeight="480" MinWidth="500" Margin="0,2,0,0">
|
||||
<TabControl.ItemContainerStyle>
|
||||
<Style TargetType="TabItem">
|
||||
<Setter Property="MinWidth" Value="60"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
</Style>
|
||||
</TabControl.ItemContainerStyle>
|
||||
<TabItem Header="Grid">
|
||||
<ItemsControl x:Name="ParameterItemsControl" Grid.IsSharedSizeScope="True" Margin="0,16,0,0">
|
||||
<ItemsControl.ItemsSource>
|
||||
<CompositeCollection>
|
||||
<CollectionContainer Collection="{Binding DataContext.parameters, Source={u:DirectReference ParameterItemsControl}}"/>
|
||||
<CollectionContainer Collection="{Binding DataContext.core_settings_vm.parameters, Source={u:DirectReference ParameterItemsControl}}"/>
|
||||
</CompositeCollection>
|
||||
</ItemsControl.ItemsSource>
|
||||
</ItemsControl>
|
||||
</TabItem>
|
||||
<TabItem Header="Columns" Content="{Binding core_settings_vm}" ContentTemplate="{StaticResource ColumnsTabContent}"/>
|
||||
<TabItem Header="Alerts" DataContext="{Binding DataContext.instance_vm, RelativeSource={RelativeSource AncestorType=usp:ShellSettingsDialog}}">
|
||||
<Grid VerticalAlignment="Top">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
|
||||
<c:DIYGrid
|
||||
Rows="{Binding alerts}"
|
||||
BorderBrush="Black"
|
||||
BorderThickness="1"
|
||||
RowsHorizontalScrollBarVisibility="Collapsed"
|
||||
SelectionMode="Single"
|
||||
>
|
||||
<c:DIYGrid.Columns>
|
||||
<c:DIYGridColumnCollection>
|
||||
<c:DIYGridColumn key="Delete" HeaderContainerStyle="{StaticResource DisabledColumnHeader}" Width="23" is_visible="True"/>
|
||||
<c:DIYGridColumn key="IsEnabled" HeaderContainerStyle="{StaticResource DisabledColumnHeader}" Width="66" is_visible="True"/>
|
||||
<c:DIYGridColumn key="Security" Header="Security" Width="130" is_visible="True"/>
|
||||
<c:DIYGridColumn key="EventType" Header="Event Type" Width="120" is_visible="True"/>
|
||||
<c:DIYGridColumn key="Sound" Header="Sound" Width="130" is_visible="True"/>
|
||||
</c:DIYGridColumnCollection>
|
||||
</c:DIYGrid.Columns>
|
||||
<c:DIYGrid.RowTemplate>
|
||||
<DataTemplate>
|
||||
<Grid c:DIYGrid.SyncWithColumnGeometry="True">
|
||||
<Button
|
||||
c:DIYGrid.ColumnKey="Delete"
|
||||
HorizontalAlignment="Center"
|
||||
Command="{Binding DataContext.delete_alert_cmd, RelativeSource={RelativeSource AncestorType=c:DIYGrid}}"
|
||||
CommandParameter="{Binding}"
|
||||
Style="{StaticResource RoundCloseButton}"
|
||||
ToolTip="Delete"
|
||||
/>
|
||||
<ToggleButton
|
||||
c:DIYGrid.ColumnKey="IsEnabled"
|
||||
IsChecked="{Binding is_enabled}"
|
||||
Style="{StaticResource ToggleSwitch}"
|
||||
/>
|
||||
<ComboBox
|
||||
c:DIYGrid.ColumnKey="EventType"
|
||||
Margin="{StaticResource CellPadding}"
|
||||
ItemsSource="{Binding predicate_types}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding predicate_type}"
|
||||
/>
|
||||
<c:ContractPickerPopup
|
||||
c:DIYGrid.ColumnKey="Security"
|
||||
Margin="{StaticResource CellPadding}"
|
||||
AllowEmpty="True"
|
||||
CloseOnOK="True"
|
||||
CloseOnCancel="True"
|
||||
MaxWidth="180"
|
||||
DataContext="{Binding predicate}"
|
||||
SecurityMap="{DynamicResource {x:Static u:ResourceKeys.Securities}}"
|
||||
Header="{Binding security_criteria}"
|
||||
ShowDialogSkirt="True"
|
||||
ToolTip="{Binding security_criteria, Converter={x:Static c:ContractPickerPopup.SecurityCriteriaTextConverter}, Mode=OneWay}"
|
||||
OKClick="{x:Static c:ContractPickerPopup.FlushSelectedCriteriaHandler}"
|
||||
SelectedCriteria="{Binding security_criteria, UpdateSourceTrigger=Explicit}"
|
||||
>
|
||||
<c:ContractPickerPopup.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={x:Static c:ContractPickerPopup.SecurityCriteriaTextConverter}}" TextTrimming="CharacterEllipsis"/>
|
||||
</DataTemplate>
|
||||
</c:ContractPickerPopup.HeaderTemplate>
|
||||
</c:ContractPickerPopup>
|
||||
<ComboBox
|
||||
x:Name="sound_dropdown"
|
||||
c:DIYGrid.ColumnKey="Sound"
|
||||
Margin="{StaticResource CellPadding}"
|
||||
ItemsSource="{u:EnumBindingSource Type={u:Nested shell:SoundNotification.SystemSound}, Except=None}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding sound_type}"
|
||||
>
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="DropDownClosed">
|
||||
<i:InvokeCommandAction Command="{x:Static c:SoundAnimationView.PreviewSoundCommand}" CommandParameter="{Binding SelectedItem, ElementName=sound_dropdown}"/>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
</ComboBox>
|
||||
<Rectangle Grid.Column="0" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="1" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="2" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="3" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</c:DIYGrid.RowTemplate>
|
||||
</c:DIYGrid>
|
||||
</ScrollViewer>
|
||||
<Button Grid.Row="1" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalAlignment="Top" VerticalContentAlignment="Center" Command="{Binding add_alert_cmd}">
|
||||
<TextBlock Margin="8,4" FontWeight="SemiBold">Add Alert</TextBlock>
|
||||
</Button>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</UserControl.ContentTemplate>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,35 @@
|
||||
using mbts.ui.converters;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
/// <summary>
|
||||
/// Interaction logic for OrderBookSettingsView.xaml
|
||||
/// </summary>
|
||||
partial class OrderBookSettingsView : UserControl {
|
||||
public static readonly IValueConverter
|
||||
DisplayNameVisualStateConverter = ValueConverter.create<bool, string>(can_override => can_override ? VisualStateNames.DisplayName.Active : VisualStateNames.DisplayName.Inactive),
|
||||
ColumnVisibilityToggleVisualStateConverter = ValueConverter.create<bool, string>(can_override => can_override ? VisualStateNames.ColumnVisibilityToggle.Active : VisualStateNames.ColumnVisibilityToggle.Inactive);
|
||||
|
||||
public OrderBookSettingsView() =>
|
||||
InitializeComponent();
|
||||
|
||||
public static class VisualStateNames {
|
||||
public static class DisplayName {
|
||||
public const string GroupName = nameof(DisplayName);
|
||||
|
||||
public static readonly string
|
||||
Active = $"{GroupName}{VisualStates.Active}",
|
||||
Inactive = $"{GroupName}{VisualStates.Inactive}";
|
||||
}
|
||||
|
||||
public static class ColumnVisibilityToggle {
|
||||
public const string GroupName = nameof(ColumnVisibilityToggle);
|
||||
|
||||
public static readonly string
|
||||
Active = $"{GroupName}{VisualStates.Active}",
|
||||
Inactive = $"{GroupName}{VisualStates.Inactive}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,15 @@
|
||||
using bts.api;
|
||||
using bts.api.orderman;
|
||||
using bts.api.orderman;
|
||||
using bts.shell;
|
||||
using bts.utils;
|
||||
using mbts.spark;
|
||||
using mbts.ui;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.utility;
|
||||
using mbts.utils;
|
||||
using ProtoBuf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using OrderType = bts.api.orderman.CustomOrderDefinition.CustomOneofCase;
|
||||
using System.ComponentModel;
|
||||
using PTOC = mbts.OrderRecordTuplePredicate.PredicateTypeOneofCase;
|
||||
|
||||
namespace mbts {
|
||||
static class OrderRecordTuplePredicateVMFactory {
|
||||
// TODO: uncomment the remaining cases when ready
|
||||
public static Dictionary<PTOC, ITemplatedPropertyWrapperVM<OrderRecordTuplePredicate>> get_oneofs(IBus bus, OrdersModel orders_model) {
|
||||
return new Dictionary<PTOC, ITemplatedPropertyWrapperVM<OrderRecordTuplePredicate>> {
|
||||
{ PTOC.FilledEvent, wrap(rp => rp.filled_event, (rp, p) => rp.filled_event = p, p => p.predicate_type_case, OrderFilledEventPredicateVMFactory.get_oneofs(bus)) },
|
||||
{ PTOC.CompletedEvent, wrap(rp => rp.completed_event, (rp, p) => rp.completed_event = p, p => p.predicate_type_case, OrderCompletedEventPredicateVMFactory.get_oneofs(bus)) },
|
||||
{ PTOC.CanceledEvent, wrap(rp => rp.canceled_event, (rp, p) => rp.canceled_event = p, p => p.predicate_type_case, OrderCanceledEventPredicateVMFactory.get_oneofs(bus)) },
|
||||
//{ PTOC.Security, wrap(rp => rp.security, (rp, p) => rp.security = p, p => p.predicate_type_case, SecurityCriteriaVMFactory.get_oneofs(bus)) },
|
||||
//{ PTOC.Time, wrap(rp => rp.time_created, (rp, p) => rp.time_created = p, t => t.predicate_type_case, TimePredicateVMFactory.get_oneofs()) },
|
||||
//{ PTOC.LastChange, wrap(rp => rp.last_change, (rp, p) => rp.last_change = p, t => t.predicate_type_case, TimePredicateVMFactory.get_oneofs()) },
|
||||
//{ PTOC.User, wrap(rp => rp.user, (rp, p) => rp.user = p, p => p.predicate_type_case, DiscreteValuesPredicateVMFactory.get_oneofs<uint, uint, uint?, uint[], DiscreteUIntPredicate>(
|
||||
// RXCollection.Create(orders_model.factory.subscribe_user_ids().Select(tups => tups.Select(convert_name_id))), id => id, id => id.Value, id => id, ids => ids, ids => ids.ToArray())) },
|
||||
//{ PTOC.Account, wrap(rp => rp.account, (rp, p) => rp.account = p, p => p.predicate_type_case, DiscreteValuesPredicateVMFactory.get_oneofs<uint, uint, uint?, uint[], DiscreteUIntPredicate>(
|
||||
// RXCollection.Create(orders_model.factory.subscribe_account_ids().Select(tups => tups.Select(convert_name_id))), id => id, id => id.Value, id => id, ids => ids, ids => ids.ToArray())) },
|
||||
//{ PTOC.Exchange, wrap(rp => rp.exchange, (rp, p) => rp.exchange = p, p => p.predicate_type_case, DiscreteValuesPredicateVMFactory.get_oneofs_value_type<Venue, ExchangePredicate>(EnumHelper.get_values_except(Venue.Unset))) },
|
||||
//{ PTOC.TimeInForce, wrap(rp => rp.time_in_force, (rp, p) => rp.time_in_force = p, p => p.predicate_type_case, DiscreteValuesPredicateVMFactory.get_oneofs_value_type<TimeInForce, TimeInForcePredicate>(EnumHelper.get_values_except(TimeInForce.Undefined))) },
|
||||
//{ PTOC.Side, wrap(rp => rp.side, (rp, p) => rp.side = p, p => p.predicate_type_case, SidePredicateVMFactory.get_oneofs()) },
|
||||
//{ PTOC.Price, wrap(rp => rp.price, (rp, p) => rp.price = p, p => p.predicate_type_case, DoublePredicateVMFactory.get_oneofs()) },
|
||||
//{ PTOC.Size, wrap(rp => rp.quantity, (rp, p) => rp.quantity = p, p => p.predicate_type_case, UIntPredicateVMFactory.get_oneofs()) },
|
||||
//{ PTOC.Filled, wrap(rp => rp.filled_quantity, (rp, p) => rp.filled_quantity = p, p => p.predicate_type_case, UIntPredicateVMFactory.get_oneofs()) },
|
||||
//{ PTOC.AvgFilled, wrap(rp => rp.avg_price, (rp, p) => rp.avg_price = p, p => p.predicate_type_case, DoublePredicateVMFactory.get_oneofs()) },
|
||||
//{ PTOC.LastPrice, wrap(rp => rp.last_price, (rp, p) => rp.last_price = p, p => p.predicate_type_case, DoublePredicateVMFactory.get_oneofs()) },
|
||||
//{ PTOC.OrderType, wrap(rp => rp.order_type, (rp, p) => rp.order_type = p, p => p.predicate_type_case, DiscreteValuesPredicateVMFactory.get_oneofs_value_type<OrderType, OrderTypePredicate>(EnumHelper.get_values_except(OrderType.None))) },
|
||||
//{ PTOC.SubType, wrap(rp => rp.order_sub_type, (rp, p) => rp.order_sub_type = p, p => p.predicate_type_case, DiscreteValuesPredicateVMFactory.get_oneofs_value_type<OrderSubType, OrderSubTypePredicate>(EnumHelper.get_values<OrderSubType>())) },
|
||||
//{ PTOC.Status, wrap(rp => rp.order_status, (rp, p) => rp.order_status = p, p => p.predicate_type_case, DiscreteValuesPredicateVMFactory.get_oneofs_value_type<OrderStatus, OrderStatusPredicate>(EnumHelper.get_values<OrderStatus>())) },
|
||||
//{ PTOC.LastMessage, wrap(rp => rp.last_message, (rp, p) => rp.last_message = p, p => p.predicate_type_case, StringPredicateVMFactory.get_oneofs()) },
|
||||
//{ PTOC.SecurityKey, wrap(rp => rp.security_key, (rp, p) => rp.security_key = p, p => p.predicate_type_case, UIntPredicateVMFactory.get_oneofs()) },
|
||||
//{ PTOC.OrderKey, wrap(rp => rp.order_key, (rp, p) => rp.order_key = p, p => p.predicate_type_case, UIntPredicateVMFactory.get_oneofs()) },
|
||||
//{ PTOC.ParentKey, wrap(rp => rp.parent_key, (rp, p) => rp.parent_key = p, p => p.predicate_type_case, UIntPredicateVMFactory.get_oneofs()) },
|
||||
};
|
||||
|
||||
//IViewValue<uint> convert_name_id((string name, uint id) tup) =>
|
||||
// new ViewValueTuple<uint>(tup.id, tup.name);
|
||||
|
||||
ITemplatedPropertyWrapperVM<OrderRecordTuplePredicate> wrap<TChildPredicate, TChildPredicateOneof>(
|
||||
Func<OrderRecordTuplePredicate, TChildPredicate> get,
|
||||
Action<OrderRecordTuplePredicate, TChildPredicate> set,
|
||||
Func<TChildPredicate, TChildPredicateOneof> key,
|
||||
Dictionary<TChildPredicateOneof, ITemplatedPropertyWrapperVM<TChildPredicate>> oneofs) where TChildPredicateOneof : struct where TChildPredicate : new() =>
|
||||
//
|
||||
PredicateVMWrapper.wrap_child_oneof<OrderRecordTuplePredicate, TChildPredicate, TChildPredicateOneof>(get, set, key, oneofs);
|
||||
}
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
class OrderRecordTuplePredicate : IEquatable<OrderRecordTuplePredicate> {
|
||||
SecurityPredicate _security;
|
||||
@@ -120,11 +70,11 @@ namespace mbts {
|
||||
OrderKey,
|
||||
[PredicateCase(is_toastable:false)]
|
||||
ParentKey,
|
||||
[PredicateCase("When order gets a fill", PredicateCategory.Event)]
|
||||
[PredicateCase("Order Filled", PredicateCategory.Event)]
|
||||
FilledEvent,
|
||||
[PredicateCase("When order is completed", PredicateCategory.Event)]
|
||||
[PredicateCase("Order Completed", PredicateCategory.Event)]
|
||||
CompletedEvent,
|
||||
[PredicateCase("When order is canceled", PredicateCategory.Event)]
|
||||
[PredicateCase("Order Canceled", PredicateCategory.Event)]
|
||||
CanceledEvent,
|
||||
[PredicateCase(is_toastable:false)]
|
||||
AttachedTargetOrderKey
|
||||
@@ -363,6 +313,7 @@ namespace mbts {
|
||||
|
||||
[ProtoContract]
|
||||
class OrderRecordTuplePredicateAnimations : IPredicateAnimationsData<OrderSecurity, OrderRecordTuplePredicate> {
|
||||
const bool _default_is_enabled = true;
|
||||
[ProtoMember(1)]
|
||||
OrderRecordTuplePredicate _predicate;
|
||||
[ProtoMember(2)]
|
||||
@@ -371,19 +322,31 @@ namespace mbts {
|
||||
List<RowAnimation> _row_animations;
|
||||
[ProtoMember(4)]
|
||||
List<SoundNotification> _sound_animations;
|
||||
// is_enabled
|
||||
[ProtoMember(5)]
|
||||
[DefaultValue(_default_is_enabled)]
|
||||
bool _is_enabled;
|
||||
|
||||
public OrderRecordTuplePredicateAnimations() { }
|
||||
public OrderRecordTuplePredicateAnimations() =>
|
||||
_is_enabled = _default_is_enabled;
|
||||
|
||||
public OrderRecordTuplePredicateAnimations(OrderRecordTuplePredicate predicate, IEnumerable<CellAnimation> cell_animations, IEnumerable<RowAnimation> row_animations, IEnumerable<SoundNotification> sound_animations) {
|
||||
public OrderRecordTuplePredicateAnimations(
|
||||
OrderRecordTuplePredicate predicate,
|
||||
IEnumerable<CellAnimation> cell_animations,
|
||||
IEnumerable<RowAnimation> row_animations,
|
||||
IEnumerable<SoundNotification> sound_animations,
|
||||
bool is_enabled = true) {
|
||||
_predicate = predicate;
|
||||
_cell_animations = new List<CellAnimation>(cell_animations);
|
||||
_row_animations = new List<RowAnimation> ( row_animations );
|
||||
_sound_animations = new List<SoundNotification> ( sound_animations );
|
||||
_cell_animations = new List<CellAnimation>(cell_animations.empty_if_null());
|
||||
_row_animations = new List<RowAnimation>(row_animations.empty_if_null());
|
||||
_sound_animations = new List<SoundNotification>(sound_animations.empty_if_null());
|
||||
_is_enabled = is_enabled;
|
||||
}
|
||||
|
||||
public OrderRecordTuplePredicate predicate_data => _predicate;
|
||||
public IReadOnlyList<CellAnimation> cell_animations => _cell_animations ?? (_cell_animations = new List<CellAnimation>());
|
||||
public IReadOnlyList<RowAnimation> row_animations => _row_animations ?? (_row_animations = new List<RowAnimation>());
|
||||
public IReadOnlyList<SoundNotification> sound_notifications => _sound_animations ?? (_sound_animations = new List<SoundNotification>());
|
||||
public bool is_enabled => _is_enabled;
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,13 @@ namespace mbts.ui.shell {
|
||||
public delegate void PropertyChange<T>(T oldval, T newval);
|
||||
|
||||
static class ValidationViewModelExtensions {
|
||||
public static IDisposable echo<T>(this IRaiseNotifyPropertyChanged vm, IProperty<T> source_property, string target_property_name) {
|
||||
source_property.Changed += on_changed;
|
||||
return Disposable.Create(() => source_property.Changed -= on_changed);
|
||||
void on_changed(T oldval, T newval) =>
|
||||
vm.raise_notify_property_changed(target_property_name);
|
||||
}
|
||||
|
||||
public static void assert(this IValidationViewModel vm, bool condition, string property, string message) {
|
||||
if (condition) vm.clear_error(property);
|
||||
else vm.set_error(property, message);
|
||||
|
||||
@@ -22,12 +22,20 @@ namespace bts.proto {
|
||||
}
|
||||
|
||||
public Color color => _color.rgb_color();
|
||||
public Color argb_color => Color.FromArgb((byte)(MathUtils.within_range(0, 1, _opacity) * 255.0), color.R, color.G, color.B);
|
||||
// TODO: get rid of this nonsense, all we need is a uint to store color & opacity
|
||||
// (opacity is just the alpha bits of the color)
|
||||
public Color argb_color =>
|
||||
opacity == 1 ?
|
||||
_color.argb_color() :
|
||||
Color.FromArgb((byte)(MathUtils.within_range(0, 1, _opacity) * 255.0), color.R, color.G, color.B);
|
||||
public double opacity => _opacity;
|
||||
|
||||
public ColorOpacityProto with(uint? color = null, double? opacity = null) =>
|
||||
new ColorOpacityProto(color ?? _color, opacity ?? _opacity);
|
||||
|
||||
public SolidColorBrush to_argb_brush() =>
|
||||
new SolidColorBrush(argb_color) { Opacity = _opacity };
|
||||
|
||||
public SolidColorBrush to_brush() =>
|
||||
new SolidColorBrush(_color.rgb_color()) { Opacity = _opacity };
|
||||
|
||||
|
||||
@@ -5,9 +5,19 @@
|
||||
xmlns:ui="clr-namespace:mbts.ui"
|
||||
>
|
||||
<!--Control Base Colors-->
|
||||
<Color x:Key="Control.LightGrayColor">#E5E5E5</Color>
|
||||
<Color x:Key="Control.LightMediumGrayColor">#CFCFCF</Color>
|
||||
<Color x:Key="Control.MediumGrayColor">#B3B3B3</Color>
|
||||
<Color x:Key="Control.AlphaLightGrayColor">#10000000</Color>
|
||||
<Color x:Key="Control.AlphaLightMediumGrayColor">#24000000</Color>
|
||||
<Color x:Key="Control.AlphaMediumGrayColor">#3A000000</Color>
|
||||
<Color x:Key="Control.AlphaMediumGrayColor2">#FF0000</Color>
|
||||
<Color x:Key="Text.Prompt.Foreground.Color">#FF999999</Color>
|
||||
|
||||
<SolidColorBrush x:Key="Control.AlphaLightGrayBrush" Color="{StaticResource Control.AlphaLightGrayColor}"/>
|
||||
<SolidColorBrush x:Key="Control.AlphaLightMediumGrayBrush" Color="{StaticResource Control.AlphaLightMediumGrayColor}"/>
|
||||
<SolidColorBrush x:Key="Control.LightGrayBrush" Color="{StaticResource Control.LightGrayColor}"/>
|
||||
<SolidColorBrush x:Key="Control.LightMediumGrayBrush" Color="{StaticResource Control.LightMediumGrayColor}"/>
|
||||
<SolidColorBrush x:Key="Control.MediumGrayBrush" Color="{StaticResource Control.MediumGrayColor}"/>
|
||||
<SolidColorBrush x:Key="CommonBackground" Color="{ui:BTSColor common_background}" />
|
||||
<SolidColorBrush x:Key="ControlBackground" Color="{x:Static mbts:BTSColors.common_background}" />
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace mbts.ui.controls {
|
||||
/// <summary>
|
||||
/// Interaction logic for ExpanderToggleButton.xaml
|
||||
/// </summary>
|
||||
class ExpanderToggleButton : ToggleButton {
|
||||
public static readonly RoutedCommand ToggleCommand = new RoutedCommand();
|
||||
public static readonly ExecutedRoutedEventHandler ToggleExecuted = (s, e) => {
|
||||
var bn = s as ToggleButton ?? e.Parameter as ToggleButton;
|
||||
if (bn != null)
|
||||
bn.SetCurrentValue(IsCheckedProperty, !bn.IsChecked.GetValueOrDefault());
|
||||
};
|
||||
|
||||
static ExpanderToggleButton() =>
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(ExpanderToggleButton), new FrameworkPropertyMetadata(typeof(ExpanderToggleButton)));
|
||||
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
using bts.collections;
|
||||
using bts.proto;
|
||||
using mbts.collections;
|
||||
using bts.utils;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using mbts.ui.viewmodels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using CellAnimation = mbts.ui.CellAnimation;
|
||||
|
||||
namespace mbts.spark {
|
||||
/// <summary>
|
||||
@@ -28,172 +23,108 @@ namespace mbts.spark {
|
||||
ImmutableFontColor = 1,
|
||||
ImmutableFontWeight = 1 << 1,
|
||||
ImmutableHeader = 1 << 2,
|
||||
ImmutableBackgroundColor = 1 << 3
|
||||
ImmutableBackgroundColor = 1 << 3,
|
||||
ImmutableVisibility = 1 << 4
|
||||
}
|
||||
|
||||
partial class GridSettingsVM<TRowData, TPredicateData, TSettingsData> {
|
||||
public interface IColumnVM : ISimpleColumnVM, IValueFactory<(GridColumnSettings settings, ILookup<TPredicateData, CellAnimation> animations)>, IDisposable {
|
||||
ObservableEditableCollection<PredicateCellAnimationVM> predicate_animations { get; }
|
||||
new (GridColumnSettings settings, ILookup<TPredicateData, CellAnimation> animations) create();
|
||||
new void load_from((GridColumnSettings settings, ILookup<TPredicateData, CellAnimation> animations) args);
|
||||
class GridColumnSettingsVM : DisposableViewModelBase {
|
||||
string _id = string.Empty;
|
||||
GridColumnSettings _settings;
|
||||
|
||||
public GridColumnSettingsVM() {
|
||||
if (font_color.override_value.A == 0)
|
||||
font_color.set_override(font_color.override_value.with(255));
|
||||
apply_flags(GridColumnSettingsFeatureFlags.None);
|
||||
}
|
||||
|
||||
public class ColumnVM : DisposableViewModelBase, IColumnVM {
|
||||
public readonly GridSettingsVM<TRowData, TPredicateData, TSettingsData> owner;
|
||||
public string id { get => _id; private set => Set(ref _id, value); }
|
||||
public StringOverrideParameterVM header { get; } = new StringOverrideParameterVM("Header");
|
||||
public BooleanOverrideParameterVM show { get; } = new BooleanOverrideParameterVM("Show");
|
||||
public DoubleParameterVM width { get; } = new DoubleParameterVM("Width");
|
||||
public ColorOverrideParameterVM background { get; } = new ColorOverrideParameterVM("Background");
|
||||
public ColorOverrideParameterVM font_color { get; } = new ColorOverrideParameterVM("Font Color");
|
||||
public FontWeightOverrideParameterVM font_weight { get; } = new FontWeightOverrideParameterVM();
|
||||
public HorizontalAlignmentParameterVM horizontal_alignment { get; } = new HorizontalAlignmentParameterVM("Horizontal Alignment");
|
||||
// display name
|
||||
public ObservableCollection<object> parameters { get; } = new ObservableCollection<object>();
|
||||
|
||||
string
|
||||
_id = string.Empty,
|
||||
_display_name = string.Empty;
|
||||
double _width = 70;
|
||||
HorizontalAlignment _horizontal_alignment = HorizontalAlignment.Left;
|
||||
bool
|
||||
_is_visible,
|
||||
_can_override_display_name = true,
|
||||
_can_override_font_color = true,
|
||||
_is_font_color_overridden,
|
||||
_can_override_font_weight = true,
|
||||
_is_font_weight_overridden,
|
||||
_can_override_background_color = true,
|
||||
_is_background_color_overridden;
|
||||
FontWeight _font_weight_override;
|
||||
GridColumnSettings _settings;
|
||||
|
||||
public ColumnVM(GridSettingsVM<TRowData, TPredicateData, TSettingsData> owner) {
|
||||
this.owner = owner;
|
||||
// animations
|
||||
predicate_animations = new ObservableEditableCollection<PredicateCellAnimationVM>(() =>
|
||||
new PredicateCellAnimationVM(id, owner._create_column_predicate_vm(id), owner._predicate_data_factory), true);
|
||||
predicate_animations.CollectionChanged += WPFHelper.create_collection_changed_cb(on_items_added: (_, __) => owner.show_cell_predicate_animations = true);
|
||||
_dispose = Disposable.Create(() => predicate_animations.OfType<IDisposable>().DisposeAll());
|
||||
}
|
||||
|
||||
public string id { get => _id; private set => Set(ref _id, value); }
|
||||
public double width { get => _width; set => Set(ref _width, value); }
|
||||
public HorizontalAlignment horizontal_alignment { get => _horizontal_alignment; set => Set(ref _horizontal_alignment, value); }
|
||||
public bool is_visible { get => _is_visible; set => Set(ref _is_visible, value); }
|
||||
// display name
|
||||
public bool can_override_display_name { get => _can_override_display_name; private set => Set(ref _can_override_display_name, value); }
|
||||
public string display_name { get => _display_name; set => Set(ref _display_name, value); }
|
||||
// font color override
|
||||
public bool can_override_font_color { get => _can_override_font_color; private set => Set(ref _can_override_font_color, value); }
|
||||
public bool is_font_color_overridden { get => _is_font_color_overridden; set => Set(ref _is_font_color_overridden, value); }
|
||||
public ColorPickerPopupVM font_color_override { get; } = new ColorPickerPopupVM();
|
||||
// font weight override
|
||||
public bool can_override_font_weight { get => _can_override_font_weight; private set => Set(ref _can_override_font_weight, value); }
|
||||
public bool is_font_weight_overridden { get => _is_font_weight_overridden; set => Set(ref _is_font_weight_overridden, value); }
|
||||
public FontWeight font_weight_override { get => _font_weight_override; set => Set(ref _font_weight_override, value); }
|
||||
// background color override
|
||||
public bool can_override_background_color { get => _can_override_background_color; private set => Set(ref _can_override_background_color, value); }
|
||||
public bool is_background_color_overridden { get => _is_background_color_overridden; set => Set(ref _is_background_color_overridden, value); }
|
||||
public ColorPickerPopupVM background_color_override { get; } = new ColorPickerPopupVM() { bind_opacity_to_alpha = true };
|
||||
// animations
|
||||
public ObservableEditableCollection<PredicateCellAnimationVM> predicate_animations { get; }
|
||||
|
||||
public (GridColumnSettings settings, ILookup<TPredicateData, CellAnimation> animations) create() {
|
||||
var settings = _settings.with(
|
||||
can_override_display_name ? display_name : null,
|
||||
is_visible,
|
||||
null,
|
||||
is_font_weight_overridden ? new NullableFontWeightProto(font_weight_override) : new NullableFontWeightProto(null),
|
||||
is_font_color_overridden ? new NullableColorProto(font_color_override.color) : new NullableColorProto(null),
|
||||
width,
|
||||
horizontal_alignment,
|
||||
background_color_override: is_background_color_overridden ?
|
||||
new NullableColorProto(background_color_override.color) : default);
|
||||
var animations_lookup = predicate_animations.ToFlatLookup(pa => pa.predicate.create_assigned(owner._predicate_data_factory), pa => pa.animations.Select(a => a.create()));
|
||||
return (settings, animations_lookup);
|
||||
}
|
||||
|
||||
public void load_from((GridColumnSettings settings, ILookup<TPredicateData, CellAnimation> animations) value) {
|
||||
_settings = value.settings;
|
||||
id = _settings.id;
|
||||
display_name = _settings.display_name;
|
||||
width = _settings.width;
|
||||
horizontal_alignment = _settings.horizontal_alignment;
|
||||
is_visible = _settings.is_visible;
|
||||
// font color
|
||||
is_font_color_overridden = _settings.font_color_override.HasValue;
|
||||
if (is_font_color_overridden) {
|
||||
font_color_override.load_from(new SolidColorBrush(_settings.font_color_override.Value));
|
||||
}
|
||||
// font weight
|
||||
is_font_weight_overridden = _settings.font_weight_override.HasValue;
|
||||
if (is_font_weight_overridden) {
|
||||
_font_weight_override = _settings.font_weight_override.Value;
|
||||
}
|
||||
// background color
|
||||
is_background_color_overridden = _settings.background_color_override.HasValue;
|
||||
if (is_background_color_overridden) {
|
||||
background_color_override.color = _settings.background_color_override.Value;
|
||||
}
|
||||
predicate_animations.SetItems(value.animations.empty_if_null().Select(g => {
|
||||
var vm = new PredicateCellAnimationVM(id, owner._create_column_predicate_vm(id), owner._predicate_data_factory);
|
||||
vm.load_from((g.Key, g));
|
||||
return vm;
|
||||
}));
|
||||
}
|
||||
|
||||
public void apply_flags(GridColumnSettingsFeatureFlags flags) {
|
||||
// display name
|
||||
can_override_display_name = (flags & GridColumnSettingsFeatureFlags.ImmutableHeader) == 0;
|
||||
if (!can_override_display_name)
|
||||
display_name = id;
|
||||
// font color
|
||||
can_override_font_color = (flags & GridColumnSettingsFeatureFlags.ImmutableFontColor) == 0;
|
||||
is_font_color_overridden &= can_override_font_color;
|
||||
// font weight
|
||||
can_override_font_weight = (flags & GridColumnSettingsFeatureFlags.ImmutableFontWeight) == 0;
|
||||
is_font_weight_overridden &= can_override_font_weight;
|
||||
// background color
|
||||
can_override_background_color = (flags & GridColumnSettingsFeatureFlags.ImmutableBackgroundColor) == 0;
|
||||
is_background_color_overridden &= can_override_background_color;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{display_name} ({id})";
|
||||
|
||||
GridColumnSettings IValueFactory<GridColumnSettings>.create() =>
|
||||
create().settings;
|
||||
|
||||
void IValueFactory<GridColumnSettings>.load_from(GridColumnSettings value) =>
|
||||
load_from((value, new Dictionary<TPredicateData, CellAnimation>().ToLookup(kv => kv.Key, kv => kv.Value)));
|
||||
public GridColumnSettings create() {
|
||||
return _settings.with(
|
||||
header.effective_is_overridden ? header.override_value : id,
|
||||
show.effective_value,
|
||||
null,
|
||||
_get_optional_font_weight_proto(font_weight),
|
||||
_get_optional_color_proto(font_color),
|
||||
width.value,
|
||||
horizontal_alignment.value,
|
||||
null,
|
||||
_get_optional_color_proto(background));
|
||||
}
|
||||
|
||||
public class PredicateCellAnimationVM : DisposableViewModelBase, IValueFactory<(TPredicateData predicate, IEnumerable<CellAnimation> animations)> {
|
||||
//
|
||||
readonly string _col_id;
|
||||
readonly Property<bool> _show_animations;
|
||||
readonly Func<TPredicateData> _predicate_data_factory;
|
||||
|
||||
public PredicateCellAnimationVM(string col_id, IPropertyWrapperVM<TPredicateData> predicate, Func<TPredicateData> predicate_data_factory) {
|
||||
_col_id = col_id;
|
||||
this.predicate = predicate;
|
||||
_predicate_data_factory = predicate_data_factory;
|
||||
_show_animations = backing(nameof(show_animations), true);
|
||||
animations = new ObservableEditableCollection<CellAnimationVM>(() => {
|
||||
var vm = new CellAnimationVM(col_id);
|
||||
vm.selected_animation_type = vm.animation_types.FirstOrDefault();
|
||||
return vm;
|
||||
}, true);
|
||||
animations.CollectionChanged += WPFHelper.create_collection_changed_cb(on_items_added: (_, __) => _show_animations.set(true));
|
||||
_dispose = predicate as IDisposable;
|
||||
}
|
||||
|
||||
public IPropertyWrapperVM<TPredicateData> predicate { get; }
|
||||
public ObservableEditableCollection<CellAnimationVM> animations { get; }
|
||||
public IEnumerable<CellAnimation.AnimationTypeOneofCase> animation_types { get; } = EnumHelper.get_values_except(CellAnimation.AnimationTypeOneofCase.None);
|
||||
public bool show_animations { get => _show_animations.Value; set => _show_animations.set(value); }
|
||||
|
||||
public (TPredicateData predicate, IEnumerable<CellAnimation> animations) create() =>
|
||||
(predicate.create_assigned(_predicate_data_factory), animations.Select(a => a.create()));
|
||||
|
||||
public void load_from((TPredicateData predicate, IEnumerable<CellAnimation> animations) args) {
|
||||
predicate.load_from(args.predicate);
|
||||
animations.SetItems(args.animations.Select(a => {
|
||||
var vm = new CellAnimationVM(_col_id);
|
||||
vm.load_from(a);
|
||||
return vm;
|
||||
}));
|
||||
public void load_from(GridColumnSettings value) {
|
||||
_settings = value;
|
||||
id = _settings.id;
|
||||
header.default_value = _settings.id;
|
||||
header.override_value = _settings.display_name;
|
||||
width.value = _settings.width;
|
||||
horizontal_alignment.value = _settings.horizontal_alignment;
|
||||
show.override_value = value.is_visible;
|
||||
// font color
|
||||
font_color.is_overridden = _settings.font_color_override.HasValue;
|
||||
if (font_color.can_override) {
|
||||
if (font_color.is_overridden)
|
||||
font_color.override_value = _settings.font_color_override.Value;
|
||||
}
|
||||
// font weight
|
||||
font_weight.is_overridden = _settings.font_weight_override.HasValue;
|
||||
if (font_weight.is_overridden)
|
||||
font_weight.override_value = _settings.font_weight_override.Value;
|
||||
// background
|
||||
background.is_overridden = _settings.background_color_override.HasValue;
|
||||
if (background.is_overridden)
|
||||
background.override_value = _settings.background_color_override.Value;
|
||||
}
|
||||
|
||||
public void apply_flags(GridColumnSettingsFeatureFlags flags) {
|
||||
header.can_override = (flags & GridColumnSettingsFeatureFlags.ImmutableHeader) == 0;
|
||||
show.can_override = (flags & GridColumnSettingsFeatureFlags.ImmutableVisibility) == 0;
|
||||
font_weight.can_override = (flags & GridColumnSettingsFeatureFlags.ImmutableFontWeight) == 0;
|
||||
font_color.can_override = (flags & GridColumnSettingsFeatureFlags.ImmutableFontColor) == 0;
|
||||
background.can_override = (flags & GridColumnSettingsFeatureFlags.ImmutableBackgroundColor) == 0;
|
||||
sync_params();
|
||||
}
|
||||
|
||||
public virtual void sync_params() {
|
||||
var layout = new HeaderedParameterGroupVM("Column Layout");
|
||||
var fonts_and_colors = new HeaderedParameterGroupVM("Fonts/Colors");
|
||||
if (header.can_override)
|
||||
layout.parameters.Add(header);
|
||||
layout.parameters.Add(width);
|
||||
layout.parameters.Add(horizontal_alignment);
|
||||
if (font_weight.can_override)
|
||||
fonts_and_colors.parameters.Add(font_weight);
|
||||
if (font_color.can_override)
|
||||
fonts_and_colors.parameters.Add(font_color);
|
||||
if (background.can_override)
|
||||
fonts_and_colors.parameters.Add(background);
|
||||
parameters.SetItems(layout, fonts_and_colors);
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
header.ToString();
|
||||
|
||||
static NullableColorProto? _get_optional_color_proto(ColorOverrideParameterVM optional_color) =>
|
||||
optional_color.can_override ?
|
||||
optional_color.is_overridden ?
|
||||
new NullableColorProto(optional_color.override_value) :
|
||||
new NullableColorProto() :
|
||||
(NullableColorProto?)null;
|
||||
|
||||
static NullableFontWeightProto? _get_optional_font_weight_proto(ParameterOverrideVM<FontWeight> optional_font_weight) =>
|
||||
optional_font_weight.can_override ?
|
||||
optional_font_weight.is_overridden ?
|
||||
new NullableFontWeightProto(optional_font_weight.override_value) :
|
||||
new NullableFontWeightProto() :
|
||||
(NullableFontWeightProto?)null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,7 @@
|
||||
using bts;
|
||||
using bts.api;
|
||||
using bts.collections;
|
||||
using bts.shell;
|
||||
using bts.utils;
|
||||
using mbts.spark;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.shell;
|
||||
using mbts.utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -16,73 +11,31 @@ using System.Windows.Media;
|
||||
using static mbts.ui.controls.DIYGrid;
|
||||
|
||||
namespace mbts.ui {
|
||||
class GridSettingsManager<TRow, TRowData, TPredicateData, TSettingsData> :
|
||||
ViewModelBase, IValueFactory<TSettingsData>, IObserver<TSettingsData>, IDisposable
|
||||
where TRow : IRowVM
|
||||
where TSettingsData : class, IGridSettingsWithNotifications<TRowData, TPredicateData> {
|
||||
class GridSettingsManager : ViewModelBase {
|
||||
//
|
||||
readonly IBus _bus;
|
||||
readonly OrdersModel _orders_model;
|
||||
readonly List<IDisposable> _notification_subs = new List<IDisposable>();
|
||||
readonly ObservableCollection<ColumnBase> _columns;
|
||||
readonly IEnumerable<TRow> _rows;
|
||||
readonly Property<GridSettings> _grid_settings;
|
||||
readonly DelegateProperty<FontFamily> _font_family;
|
||||
readonly DelegateProperty<FontWeight> _font_weight;
|
||||
readonly DelegateProperty<double> _font_size;
|
||||
readonly DelegateProperty<SolidColorBrush> _font_color, _selection_highlight, _background_color;
|
||||
readonly SetMap<IPredicate<TRowData>, AnimationDefinitionWrapper<TRow>> _animation_defs = new SetMap<IPredicate<TRowData>, AnimationDefinitionWrapper<TRow>>();
|
||||
readonly Func<TPredicateData> _predicate_data_factory;
|
||||
readonly Func<TPredicateData, IPredicate<TRowData>> _predicate_factory;
|
||||
readonly Func<TPredicateData, INotificationPredicate<TRowData>> _notification_predicate_factory;
|
||||
readonly Func<IPropertyWrapperVM<TPredicateData>> _create_predicate_vm;
|
||||
readonly Func<string, IPropertyWrapperVM<TPredicateData>> _create_column_predicate_vm;
|
||||
readonly Func<GridSettings, IEnumerable<IPredicateAnimationsData<TRowData, TPredicateData>>, TSettingsData> _create_settings_obj;
|
||||
readonly Func<IPredicate<TRowData>, SoundNotification, IDisposable> _link_sound;
|
||||
readonly Func<INotificationPredicate<TRowData>, IDisposable> _link_toast_notification;
|
||||
readonly IReadOnlyDictionary<string, ImmutableColumnSettingStore> _column_flags;
|
||||
IEnumerable<IPredicateAnimationsData<TRowData, TPredicateData>> _predicate_animations_data;
|
||||
|
||||
public GridSettingsManager(
|
||||
IBus bus,
|
||||
OrdersModel orders_model,
|
||||
IEnumerable<TRow> rows,
|
||||
ObservableCollection<ColumnBase> columns,
|
||||
Func<TPredicateData> predicate_data_factory,
|
||||
Func<IPropertyWrapperVM<TPredicateData>> create_predicate_vm,
|
||||
Func<string, IPropertyWrapperVM<TPredicateData>> create_column_predicate_vm,
|
||||
Func<GridSettings, IEnumerable<IPredicateAnimationsData<TRowData, TPredicateData>>, TSettingsData> create_settings_obj,
|
||||
Func<TPredicateData, IPredicate<TRowData>> predicate_factory,
|
||||
Func<TPredicateData, INotificationPredicate<TRowData>> notification_predicate_factory,
|
||||
Func<IPredicate<TRowData>, SoundNotification, IDisposable> link_sound,
|
||||
Func<INotificationPredicate<TRowData>, IDisposable> link_toast_notification,
|
||||
IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> column_flags = null) {
|
||||
//
|
||||
_bus = bus;
|
||||
_orders_model = orders_model;
|
||||
_rows = rows;
|
||||
_columns = columns;
|
||||
_predicate_data_factory = predicate_data_factory;
|
||||
_predicate_factory = predicate_factory;
|
||||
_notification_predicate_factory = notification_predicate_factory;
|
||||
_create_predicate_vm = create_predicate_vm;
|
||||
_create_column_predicate_vm = create_column_predicate_vm;
|
||||
_create_settings_obj = create_settings_obj;
|
||||
_link_sound = link_sound;
|
||||
_link_toast_notification = link_toast_notification;
|
||||
_column_flags = column_flags.ToDictionary(kv => kv.Key, kv => ImmutableColumnSettingStore.create(kv.Value));
|
||||
_column_flags = column_flags?.ToDictionary(kv => kv.Key, kv => ImmutableColumnSettingStore.create(kv.Value));
|
||||
_grid_settings = backing(nameof(grid_settings), GridSettings.Default);
|
||||
_font_family = backing(nameof(font_family), () => new FontFamily(grid_settings.font_family), nameof(grid_settings));
|
||||
_font_weight = backing(nameof(font_weight), () => grid_settings.font_weight, nameof(grid_settings));
|
||||
_font_size = backing(nameof(font_size), () => grid_settings.font_size, nameof(font_size));
|
||||
_font_color = backing(nameof(font_color), () => grid_settings.font_color.rgb_solid_brush().frozen(), nameof(grid_settings));
|
||||
_selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_brush().frozen(), nameof(grid_settings));
|
||||
_selection_highlight = backing(nameof(selection_highlight), () => grid_settings.selection_highlight.to_argb_brush().frozen(), nameof(grid_settings));
|
||||
_background_color = backing(nameof(background_color), () => grid_settings.background_color.argb_color().to_solid_brush().frozen(), nameof(grid_settings));
|
||||
}
|
||||
|
||||
public void Dispose() =>
|
||||
Disposable.dispose(_notification_subs);
|
||||
|
||||
public GridSettings grid_settings => _grid_settings.Value;
|
||||
public FontFamily font_family => _font_family.Value;
|
||||
public FontWeight font_weight => _font_weight.Value;
|
||||
@@ -91,52 +44,16 @@ namespace mbts.ui {
|
||||
public SolidColorBrush selection_highlight => _selection_highlight.Value;
|
||||
public SolidColorBrush background_color => _background_color.Value;
|
||||
|
||||
public GridSettingsVM<TRowData, TPredicateData, TSettingsData> create_vm(GridSettings settings) {
|
||||
var vm = new GridSettingsVM<TRowData, TPredicateData, TSettingsData>(_bus, _orders_model, _predicate_data_factory, _notification_predicate_factory, _create_predicate_vm, _create_column_predicate_vm, _create_settings_obj, _column_flags.ToDictionary(kv => kv.Key, kv => kv.Value.flags));
|
||||
vm.load(_create_settings_obj(settings, _predicate_animations_data));
|
||||
return vm;
|
||||
}
|
||||
public GridSettingsVM create_vm() =>
|
||||
new GridSettingsVM(_column_flags?.ToDictionary(kv => kv.Key, kv => kv.Value.flags));
|
||||
|
||||
public TSettingsData create() {
|
||||
_grid_settings.set(grid_settings.with(_columns.Select(c => {
|
||||
var col_settings = c.create();
|
||||
if (_column_flags.TryGetValue(c.id, out ImmutableColumnSettingStore store))
|
||||
col_settings = store.apply(col_settings);
|
||||
return col_settings;
|
||||
})));
|
||||
return _create_settings_obj(grid_settings, _predicate_animations_data);
|
||||
}
|
||||
|
||||
public void load_from(TSettingsData value) => _load_from_core(value, true);
|
||||
|
||||
void _load_from_core(TSettingsData value, bool reset_immutables) {
|
||||
Disposable.dispose(_notification_subs);
|
||||
var grid = value.general ?? GridSettings.Default;
|
||||
public void load_from(GridSettings grid) {
|
||||
_grid_settings.set(grid);
|
||||
foreach (ColumnBase col in _columns)
|
||||
col.set_fallback_font_params(new FontFamily(grid.font_family), grid.font_size, grid.font_color.rgb_color(), grid.font_weight, grid.background_color.argb_color());
|
||||
_predicate_animations_data = value.predicate_animations;
|
||||
_animation_defs.clear();
|
||||
foreach (var pa in _predicate_animations_data) {
|
||||
var predicate = _predicate_factory(pa.predicate_data);
|
||||
if (predicate == null)
|
||||
continue;
|
||||
foreach (var s in pa.sound_notifications) {
|
||||
_notification_subs.Add(_link_sound(predicate, s));
|
||||
}
|
||||
var notification_predicate = _notification_predicate_factory(pa.predicate_data);
|
||||
if (notification_predicate != null)
|
||||
_notification_subs.Add(_link_toast_notification(notification_predicate));
|
||||
}
|
||||
// ** in the unfortunate event that we botch backwards compatability, and the columns don't bear a 1:1 relationship with the column-settings
|
||||
// don't add insult to injury by crashing **
|
||||
if (grid_settings.columns != null && _columns != null) {
|
||||
if (reset_immutables) {
|
||||
foreach (var kv in _column_flags) {
|
||||
if (grid.columns.TryGetFirst(c => c.id == kv.Key, out GridColumnSettings cs))
|
||||
kv.Value.store(cs);
|
||||
}
|
||||
}
|
||||
var col_settings_id_map = grid_settings.columns.ToDictionary(cs => id_key(cs.id));
|
||||
var columns_id_map = _columns.ToDictionary(c => id_key(c.id));
|
||||
if (col_settings_id_map.Count == columns_id_map.Count && col_settings_id_map.Count == grid_settings.columns.Count) {
|
||||
@@ -150,31 +67,8 @@ namespace mbts.ui {
|
||||
col.load_from(cs);
|
||||
}
|
||||
// invalidate all the rows to draw them again to reflect the latest settings
|
||||
foreach (var r in _rows) r.raise_invalidated();
|
||||
//
|
||||
string id_key(string id) => id.ToLower();
|
||||
}
|
||||
}
|
||||
|
||||
void IObserver<TSettingsData>.OnNext(TSettingsData sd) {
|
||||
if (sd == null) return;
|
||||
try {
|
||||
var grid = sd.general;
|
||||
if (grid.columns != null) {
|
||||
var cols_with_applied_flags = grid.columns.ToList();
|
||||
for (int i = 0; i < cols_with_applied_flags.Count; i++) {
|
||||
if (_column_flags.TryGetValue(cols_with_applied_flags[i].id, out ImmutableColumnSettingStore store)) {
|
||||
cols_with_applied_flags[i] = store.apply(cols_with_applied_flags[i]);
|
||||
}
|
||||
}
|
||||
sd = _create_settings_obj(grid.with(cols_with_applied_flags), sd.predicate_animations);
|
||||
}
|
||||
_load_from_core(sd, false);
|
||||
} catch (Exception ex) {
|
||||
Log.Ui.error($"Error loading GridSettings (as observer): {ex}");
|
||||
}
|
||||
}
|
||||
void IObserver<TSettingsData>.OnError(Exception error) { }
|
||||
void IObserver<TSettingsData>.OnCompleted() { }
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,16 @@
|
||||
using mbts.ui.converters;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.spark {
|
||||
/// <summary>
|
||||
/// Interaction logic for GridSettingsView.xaml
|
||||
/// </summary>
|
||||
partial class GridSettingsResources : ResourceDictionary {
|
||||
public GridSettingsResources() =>
|
||||
InitializeComponent();
|
||||
|
||||
public static IMultiValueConverter ColumnDisplayNameVisibilityConverter =>
|
||||
ValueConverter.create<string, string, Visibility>((id, header) => id == header ? Visibility.Collapsed : Visibility.Visible);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,22 @@
|
||||
using bts.api;
|
||||
using bts.collections;
|
||||
using bts.proto;
|
||||
using bts.shell;
|
||||
using bts.utils;
|
||||
using mbts.collections;
|
||||
using mbts.ui;
|
||||
using mbts.ui.controls;
|
||||
using mbts.ui.settings;
|
||||
using mbts.ui.shell;
|
||||
using mbts.ui.utility;
|
||||
using mbts.ui.utility.text;
|
||||
using mbts.ui.viewmodels;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Windows;
|
||||
using CellAnimation = mbts.ui.CellAnimation;
|
||||
using FontFamily = System.Windows.Media.FontFamily;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.spark {
|
||||
interface IGridSettingsWithNotifications<TRowData, TPredicateData> {
|
||||
@@ -45,70 +44,52 @@ namespace mbts.spark {
|
||||
EqualityComparer.safe_aggregate_hash(predicate_animations_data));
|
||||
}
|
||||
|
||||
partial class GridSettingsVM<TRowData, TPredicateData, TSettingsData> : DisposableViewModelBase, IRequestViewClose, IWindowSettingsVM<TSettingsData>, ITemplateSelectorKey
|
||||
where TSettingsData :class, IGridSettingsWithNotifications<TRowData, TPredicateData> {
|
||||
class GridSettingsVM : DisposableViewModelBase, IRequestViewClose, IWindowSettingsVM<GridSettings>, ITemplateSelectorKey {
|
||||
//
|
||||
protected readonly Func<IPropertyWrapperVM<TPredicateData>> _create_predicate_vm;
|
||||
protected readonly Func<string, IPropertyWrapperVM<TPredicateData>> _create_column_predicate_vm;
|
||||
readonly Func<TPredicateData> _predicate_data_factory;
|
||||
readonly Func<GridSettings, IEnumerable<IPredicateAnimationsData<TRowData, TPredicateData>>, TSettingsData> _create_settings_obj;
|
||||
readonly Property<IColumnVM> _current_column;
|
||||
readonly Property<FontFamily> _font_family;
|
||||
readonly Property<FontWeight> _font_weight;
|
||||
readonly Property<string> _font_display_name;
|
||||
readonly Property<double> _font_size;
|
||||
readonly Property<bool> _show_predicate_animations, _show_cell_predicate_animations, _show_background_color;
|
||||
readonly OrdersModel _orders_model;
|
||||
readonly FontParameterVM _font_vm = new FontParameterVM("Cell Font");
|
||||
readonly ColorParameterVM
|
||||
_font_color = new ColorParameterVM("Cell Font Color"),
|
||||
_selection_highlight = new ColorParameterVM("Selection Highlight"),
|
||||
_background = new ColorParameterVM("Background");
|
||||
readonly Property<GridColumnSettingsVM> _current_column;
|
||||
readonly IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> _column_flags;
|
||||
readonly ObservableCollection<object> _parameters = new ObservableCollection<object>();
|
||||
bool _background_enabled;
|
||||
|
||||
public GridSettingsVM(
|
||||
IBus bus,
|
||||
OrdersModel orders_model,
|
||||
Func<TPredicateData> predicate_data_factory,
|
||||
Func<TPredicateData, INotificationPredicate<TRowData>> notification_predicate_factory,
|
||||
Func<IPropertyWrapperVM<TPredicateData>> create_predicate_vm,
|
||||
Func<string, IPropertyWrapperVM<TPredicateData>> create_column_predicate_vm,
|
||||
Func<GridSettings, IEnumerable<IPredicateAnimationsData<TRowData, TPredicateData>>, TSettingsData> create_settings_obj,
|
||||
IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> column_flags = null) {
|
||||
public GridSettingsVM(IReadOnlyDictionary<string, GridColumnSettingsFeatureFlags> column_flags = null) {
|
||||
//
|
||||
this.bus = bus;
|
||||
_orders_model = orders_model;
|
||||
_predicate_data_factory = predicate_data_factory;
|
||||
_create_predicate_vm = create_predicate_vm;
|
||||
_create_column_predicate_vm = create_column_predicate_vm;
|
||||
_create_settings_obj = create_settings_obj;
|
||||
_column_flags = column_flags ?? new Dictionary<string, GridColumnSettingsFeatureFlags>();
|
||||
_font_family = backing(nameof(font_family), TextUtils.StandardFontFamily);
|
||||
_font_size = backing(nameof(font_size), FontSizes.Small);
|
||||
_font_weight = backing(nameof(font_weight), FontWeights.Normal);
|
||||
_font_display_name = backing(nameof(font_display_name), () => TextUtils.display_name(font_family, font_size), new[] { nameof(font_family), nameof(font_size) });
|
||||
_show_predicate_animations = backing(nameof(show_predicate_animations), true);
|
||||
_show_cell_predicate_animations = backing(nameof(show_cell_predicate_animations), true);
|
||||
_show_background_color = backing(nameof(show_background_color), false);
|
||||
_current_column = backing<IColumnVM>(nameof(current_column));
|
||||
predicate_animations = new ObservableEditableCollection<PredicateRowAnimationVM>(() =>
|
||||
new PredicateRowAnimationVM(_create_predicate_vm(), _predicate_data_factory), true);
|
||||
predicate_animations.CollectionChanged += WPFHelper.create_collection_changed_cb(on_items_added: (_, __) => _show_predicate_animations.set(true));
|
||||
_current_column = backing<GridColumnSettingsVM>(nameof(current_column));
|
||||
_parameters.sync_with(_visible_parameters);
|
||||
// font
|
||||
_dispose = ObservableAutoWrapper.connect_item_hooks(columns, c => {
|
||||
_font_vm.PropertyChanged += on_prop_changed;
|
||||
_background.PropertyChanged += on_prop_changed;
|
||||
_font_color.Changed += on_font_color_changed;
|
||||
on_font_color_changed(default, _font_color.value);
|
||||
on_prop_changed(null, null);
|
||||
return Disposable.Create(() => {
|
||||
_font_vm.PropertyChanged -= on_prop_changed;
|
||||
_font_color.Changed -= on_font_color_changed;
|
||||
});
|
||||
// set the whole state everytime, bc it's simpler and less error prone
|
||||
// than coordinating between specific properties.
|
||||
void on_prop_changed(object sender, PropertyChangedEventArgs e) {
|
||||
c.background.default_value = _background.value;
|
||||
c.font_weight.family = _font_vm.family;
|
||||
c.font_weight.default_value = _font_vm.weight;
|
||||
c.font_weight.size = _font_vm.size;
|
||||
}
|
||||
void on_font_color_changed(Color oldval, Color newval) =>
|
||||
c.font_color.default_value = newval;
|
||||
});
|
||||
}
|
||||
|
||||
public event EventHandler RequestClose;
|
||||
public event Action committed;
|
||||
|
||||
public IBus bus { get; }
|
||||
public ObservableCollection<IColumnVM> columns { get; } = new ObservableCollection<IColumnVM>();
|
||||
public IColumnVM current_column { get => _current_column.Value; set => _current_column.set(value); }
|
||||
public string font_display_name => _font_display_name.Value;
|
||||
public FontFamily font_family { get => _font_family.Value; set => _font_family.set(value); }
|
||||
public FontWeight font_weight { get => _font_weight.Value; set => _font_weight.set(value); }
|
||||
public ColorPickerPopupVM font_color { get; } = new ColorPickerPopupVM();
|
||||
public ColorPickerPopupVM selection_highlight { get; } = new ColorPickerPopupVM();
|
||||
public ColorPickerPopupVM background_color { get; } = new ColorPickerPopupVM();
|
||||
public bool show_background_color => _show_background_color.Value;
|
||||
public double font_size { get => _font_size.Value; set => _font_size.set(value); }
|
||||
public bool enable_sound_triggers => true;
|
||||
public bool show_predicate_animations { get => _show_predicate_animations.Value; set => _show_predicate_animations.set(value); }
|
||||
public bool show_cell_predicate_animations { get => _show_cell_predicate_animations.Value; set => _show_cell_predicate_animations.set(value); }
|
||||
public ObservableEditableCollection<PredicateRowAnimationVM> predicate_animations { get; }
|
||||
public ObservableCollection<GridColumnSettingsVM> columns { get; } = new ObservableCollection<GridColumnSettingsVM>();
|
||||
public GridColumnSettingsVM current_column { get => _current_column.Value; set => _current_column.set(value); }
|
||||
public IReadOnlyList<DialogSkirtItem> dialog_skirt_items => new[] {
|
||||
new DialogSkirtItem("OK", new DelegateCommand(() => {
|
||||
committed?.Invoke();
|
||||
@@ -120,60 +101,52 @@ namespace mbts.spark {
|
||||
|
||||
public string key => ui.spark.GridSettingsTemplateKeys.SimpleGrid;
|
||||
|
||||
public TSettingsData get_result() {
|
||||
var animation_map = predicate_animations
|
||||
.Select(p => p.create())
|
||||
.GroupBy(d => d.predicate)
|
||||
.ToDictionary(g => g.Key, g => animation_tuple(
|
||||
g.SelectMany(v => v.animations).ToList(),
|
||||
g.SelectMany(v => v.sounds).ToList()));
|
||||
var col_settings = new List<GridColumnSettings>();
|
||||
foreach (var c in columns) {
|
||||
var (settings, animations) = c.create();
|
||||
col_settings.Add(settings);
|
||||
foreach (IGrouping<TPredicateData, CellAnimation> g in animations)
|
||||
animation_map.AddOrUpdate(g.Key, p => animation_tuple(c: g), (p, t) => t.cell_animations.AddRange(g));
|
||||
public IEnumerable parameters => _parameters;
|
||||
|
||||
IEnumerable<object> _visible_parameters {
|
||||
get {
|
||||
yield return _selection_highlight;
|
||||
if (_background_enabled)
|
||||
yield return _background;
|
||||
yield return _font_vm;
|
||||
yield return _font_color;
|
||||
}
|
||||
return _create_settings_obj(new GridSettings(font_family.name(), font_size, font_weight, font_color.color.rgb_color(), selection_highlight.to_proto(), col_settings,
|
||||
background: background_color.color.with((byte)(MathUtils.within_range(0, 1, background_color.opacity) * 255.0)).rgb_color()),
|
||||
animation_map.Select(kv => PredicateAnimations.create_data<TRowData, TPredicateData>(kv.Key, kv.Value.cell_animations, kv.Value.row_animations, kv.Value.sounds)));
|
||||
//
|
||||
(List<RowAnimation> row_animations, List<SoundNotification> sounds, List<CellAnimation> cell_animations) animation_tuple(IEnumerable<RowAnimation> r = null, IEnumerable<SoundNotification> s = null, IGrouping<TPredicateData, CellAnimation> c = null) =>
|
||||
(r?.ToList() ?? new List<RowAnimation>(), s?.ToList() ?? new List<SoundNotification>(), c?.ToList() ?? new List<CellAnimation>());
|
||||
}
|
||||
|
||||
public void load(TSettingsData sd) {
|
||||
_font_family.set(new FontFamily(sd.general.font_family));
|
||||
_font_weight.set(sd.general.font_weight);
|
||||
font_color.load_from(sd.general.font_color.rgb_solid_brush());
|
||||
selection_highlight.load_from(sd.general.selection_highlight.to_brush());
|
||||
_show_background_color.set(sd.general.enable_background_color);
|
||||
if (sd.general.enable_background_color) {
|
||||
// note that when the OB is moved to allow background colors
|
||||
// we can just background_color.color instead of load_from
|
||||
// so that we get all the alpha goodness similar to SimpleGridSettingsVM
|
||||
// assuming bind_opacity_to_alpha on the picker.
|
||||
background_color.load_from(sd.general.background_color.argb_color().to_solid_brush());
|
||||
}
|
||||
_font_size.set(sd.general.font_size);
|
||||
var col_animations = new Dictionary<string, Dictionary<TPredicateData, List<CellAnimation>>>();
|
||||
predicate_animations.Clear();
|
||||
foreach (var pa in sd.predicate_animations) {
|
||||
if (pa.row_animations.Count > 0 || pa.sound_notifications.Count > 0) {
|
||||
var vm = new PredicateRowAnimationVM(_create_predicate_vm(), _predicate_data_factory);
|
||||
vm.load_from((pa.predicate_data, pa.row_animations, pa.sound_notifications));
|
||||
predicate_animations.Add(vm);
|
||||
}
|
||||
foreach (var ca in pa.cell_animations) {
|
||||
col_animations.AddOrUpdate(ca.column_id,
|
||||
col => new Dictionary<TPredicateData, List<CellAnimation>> { { pa.predicate_data, new List<CellAnimation> { ca } } },
|
||||
(col, d) => d.AddOrUpdate(pa.predicate_data, p => new List<CellAnimation> { ca }, (p, l) => l.Add(ca)));
|
||||
}
|
||||
public GridSettings get_result() {
|
||||
var col_settings = new List<GridColumnSettings>();
|
||||
foreach (var c in columns) {
|
||||
var settings = c.create();
|
||||
col_settings.Add(settings);
|
||||
}
|
||||
return new GridSettings(
|
||||
_font_vm.family.name(),
|
||||
_font_vm.size,
|
||||
_font_vm.weight,
|
||||
_font_color.value.rgb_color(),
|
||||
new ColorOpacityProto(_selection_highlight.value.rgb_color()),
|
||||
col_settings,
|
||||
background: _background_enabled ? _background.value.rgb_color() : 0,
|
||||
enable_background_color: _background_enabled);
|
||||
}
|
||||
|
||||
public void load(GridSettings settings) {
|
||||
_font_vm.family = new FontFamily(settings.font_family);
|
||||
_font_vm.weight = settings.font_weight;
|
||||
_font_vm.size = settings.font_size;
|
||||
_font_color.value = settings.font_color.rgb_color();
|
||||
_selection_highlight.value = settings.selection_highlight.argb_color;
|
||||
// note that when the OB is moved to allow background colors
|
||||
// we can just background_color.color instead of load_from
|
||||
// so that we get all the alpha goodness similar to SimpleGridSettingsVM
|
||||
// assuming bind_opacity_to_alpha on the picker.
|
||||
_background_enabled = settings.enable_background_color;
|
||||
_background.value = settings.background;
|
||||
|
||||
var curr_col_id = current_column?.id;
|
||||
columns.SetItems(sd.general.columns.Select(col => {
|
||||
var vm = new ColumnVM(this);
|
||||
vm.load_from((col, col_animations.GetValueOrDefault(col.id)?.ToFlatLookup(kv => kv.Key, kv => kv.Value)));
|
||||
columns.SetItems(settings.columns.Select(col => {
|
||||
var vm = new GridColumnSettingsVM();
|
||||
vm.load_from(col);
|
||||
// reapply our favorite column flags
|
||||
// this comes in handy when performing Load From Factory - the editor will contain
|
||||
// a consistent view of what can be overridden and what cannot
|
||||
@@ -181,55 +154,10 @@ namespace mbts.spark {
|
||||
vm.apply_flags(flags);
|
||||
return vm;
|
||||
}));
|
||||
if (curr_col_id == null || !columns.TryGetFirst(c => c.id == curr_col_id, out IColumnVM curr_column))
|
||||
if (curr_col_id == null || !columns.TryGetFirst(c => c.id == curr_col_id, out var curr_column))
|
||||
curr_column = columns.FirstOrDefault();
|
||||
_current_column.set(curr_column);
|
||||
}
|
||||
|
||||
public class PredicateRowAnimationVM : DisposableViewModelBase, IValueFactory<(TPredicateData predicate, IEnumerable<RowAnimation> animations, IEnumerable<SoundNotification> sounds)> {
|
||||
readonly Property<bool> _show_animations/*, _play_sound*/;
|
||||
readonly Func<TPredicateData> _predicate_state_factory;
|
||||
|
||||
public PredicateRowAnimationVM(IPropertyWrapperVM<TPredicateData> predicate, Func<TPredicateData> predicate_state_factory) {
|
||||
this.predicate = predicate;
|
||||
_predicate_state_factory = predicate_state_factory;
|
||||
_show_animations = backing(nameof(show_animations), true);
|
||||
//_play_sound = backing(nameof(play_sound), true);
|
||||
animations = new ObservableEditableCollection<RowAnimationVM>(() => {
|
||||
var vm = new RowAnimationVM();
|
||||
vm.selected_animation_type = vm.animation_types.FirstOrDefault();
|
||||
return vm;
|
||||
}, true);
|
||||
animations.CollectionChanged += WPFHelper.create_collection_changed_cb(on_items_added: (_, __) => _show_animations.set(true));
|
||||
_dispose = predicate as IDisposable;
|
||||
}
|
||||
|
||||
public IPropertyWrapperVM<TPredicateData> predicate { get; }
|
||||
public ObservableEditableCollection<RowAnimationVM> animations { get; }
|
||||
public IEnumerable<CellAnimation.AnimationTypeOneofCase> animation_types { get; } = EnumHelper.get_values_except(CellAnimation.AnimationTypeOneofCase.None);
|
||||
public bool show_animations { get => _show_animations.Value; set => _show_animations.set(value); }
|
||||
//public bool play_sound { get => _play_sound.Value; set => _play_sound.set(value); }
|
||||
public IPropertyWrapperVM<SoundNotification> sound { get; } = SoundAnimationVM.create_system_sound_vm();
|
||||
|
||||
public (TPredicateData predicate, IEnumerable<RowAnimation> animations, IEnumerable<SoundNotification> sounds) create() =>
|
||||
(predicate.create_assigned(_predicate_state_factory),
|
||||
animations.Select(a => a.create_assigned()),
|
||||
new[] { sound.create_assigned() });
|
||||
//EnumerableExtensions.return_if(play_sound, () => sound.create_assigned()));
|
||||
|
||||
public void load_from((TPredicateData predicate, IEnumerable<RowAnimation> animations, IEnumerable<SoundNotification> sounds) args) {
|
||||
predicate.load_from(args.predicate);
|
||||
animations.SetItems(args.animations.Select(a => {
|
||||
var vm = new RowAnimationVM();
|
||||
vm.load_from(a);
|
||||
return vm;
|
||||
}));
|
||||
var en = args.sounds.GetEnumerator();
|
||||
if (en.MoveNext()) {
|
||||
//_play_sound.set(true);
|
||||
sound.load_from(en.Current);
|
||||
} //else _play_sound.set(false);
|
||||
}
|
||||
_parameters.sync_with(_visible_parameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
xmlns:proto="clr-namespace:bts.proto"
|
||||
xmlns:m="clr-namespace:mbts"
|
||||
xmlns:sp="clr-namespace:mbts.spark"
|
||||
xmlns:shell="clr-namespace:bts.shell"
|
||||
xmlns:pnl="clr-namespace:bts.shell.pnl"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:c="clr-namespace:mbts.ui.controls"
|
||||
@@ -40,6 +41,8 @@
|
||||
<sys:Double x:Key="ControlShortestWidth">30</sys:Double>
|
||||
<sys:Double x:Key="CollapsedAnimationItemsHeight">24</sys:Double>
|
||||
<sys:Double x:Key="AnimationExpanderToggleWidth">142</sys:Double>
|
||||
<sys:Double x:Key="SoundWidth">163</sys:Double>
|
||||
<Thickness x:Key="CellPadding">10,8</Thickness>
|
||||
<Thickness x:Key="OutterMarginTL" Left="8" Top="{StaticResource HorizontalPush}" />
|
||||
<Thickness x:Key="LeftPush" Left="{StaticResource HorizontalPush}"/>
|
||||
<Thickness x:Key="ExpanderChildMargin" Left="8" Top="{StaticResource VerticalPush}"/>
|
||||
@@ -72,6 +75,16 @@
|
||||
</cv:KeyValue.Value>
|
||||
</cv:KeyValue>
|
||||
</cv:ValueMap>
|
||||
<!--Styles-->
|
||||
<Style x:Key="DisabledColumnHeader" TargetType="GridViewColumnHeader">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="GridViewColumnHeader">
|
||||
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{x:Static u:BTSColors.header_brush}"/>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<Style x:Key="DisabledPlaceholderComboBox" TargetType="ComboBox">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Setter Property="Foreground" Value="Gray"/>
|
||||
@@ -681,413 +694,196 @@
|
||||
</DataTemplate>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid Margin="{StaticResource FullPadding}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalSplit}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalSplit}}"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<GroupBox
|
||||
Content="{Binding GridSectionContent, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}"
|
||||
ContentTemplate="{Binding GridSectionContentTemplate, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}"
|
||||
>
|
||||
<GroupBox.Style>
|
||||
<Style TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsChecked, ElementName=GridExpanderToggle}" Value="{u:False}">
|
||||
<Setter Property="Height" Value="{StaticResource CollapsedAnimationItemsHeight}"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
<Grid>
|
||||
<Grid.Margin>
|
||||
<Thickness Left="{StaticResource HorizontalPush2}" Top="-8" Right="{StaticResource HorizontalPush2}"/>
|
||||
</Grid.Margin>
|
||||
<TabControl HorizontalAlignment="Stretch" MinHeight="400" MinWidth="500" Padding="6">
|
||||
<TabControl.ItemContainerStyle>
|
||||
<Style TargetType="TabItem">
|
||||
<Setter Property="MinWidth" Value="60"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
</Style>
|
||||
</GroupBox.Style>
|
||||
<GroupBox.Header>
|
||||
<c:ExpanderToggleButton x:Name="GridExpanderToggle" IsChecked="True">
|
||||
Grid
|
||||
</c:ExpanderToggleButton>
|
||||
</GroupBox.Header>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Row="2" Grid.IsSharedSizeScope="True" VerticalAlignment="Top">
|
||||
<GroupBox.Style>
|
||||
<Style TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding enable_sound_triggers}" Value="{u:False}">
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding show_predicate_animations}" Value="{u:False}">
|
||||
<Setter Property="Height" Value="{StaticResource CollapsedAnimationItemsHeight}"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</GroupBox.Style>
|
||||
<GroupBox.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<c:ExpanderToggleButton x:Name="PredicateAnimationsExpanderToggle" IsChecked="{Binding show_predicate_animations}">
|
||||
Sound/Notification Triggers
|
||||
</c:ExpanderToggleButton>
|
||||
<TextBlock Margin="{StaticResource LeftPush}">
|
||||
<Hyperlink Command="{Binding predicate_animations.AddItemCommand}">(click to add)</Hyperlink>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</GroupBox.Header>
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
|
||||
<ItemsControl
|
||||
AlternationCount="2"
|
||||
ItemsSource="{Binding predicate_animations}"
|
||||
>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border x:Name="PredicateAnimationItemRoot" BorderBrush="LightGray" BorderThickness="1" Padding="6,8">
|
||||
<Grid Margin="0,8">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="20" SharedSizeGroup="c0"/>
|
||||
<ColumnDefinition Width="Auto" SharedSizeGroup="c1"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Button
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,2,0,0"
|
||||
Command="{Binding DataContext.predicate_animations.RemoveItemCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
||||
CommandParameter="{Binding}"
|
||||
Style="{StaticResource RoundCloseButton}"
|
||||
/>
|
||||
<ContentControl Grid.Column="1" Content="{Binding predicate, Mode=OneWay}" ContentTemplateSelector="{StaticResource PredicateTemplateSelector}"/>
|
||||
<!--TODO: Make this visible when row animations are ready-->
|
||||
<GroupBox
|
||||
x:Name="AnimationsGroupBox"
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Stretch"
|
||||
Margin="{StaticResource ExpanderChildMargin}"
|
||||
Visibility="Collapsed"
|
||||
>
|
||||
<GroupBox.Style>
|
||||
<Style TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding show_animations}" Value="{u:False}">
|
||||
<Setter Property="Height" Value="{StaticResource CollapsedAnimationItemsHeight}"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</GroupBox.Style>
|
||||
<GroupBox.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Grid Width="{StaticResource AnimationExpanderToggleWidth}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<c:ExpanderToggleButton x:Name="AnimationsExpanderToggle" IsChecked="{Binding show_animations}" Visibility="{Binding animations.Count, Converter={StaticResource IntNotZeroVisibilityConverter}}">
|
||||
Animations
|
||||
</c:ExpanderToggleButton>
|
||||
<TextBlock FontStyle="Italic" Foreground="Gray" Visibility="{Binding Visibility, ElementName=AnimationsExpanderToggle, Converter={StaticResource ReverseVisibilityConverter}}">
|
||||
No Animations
|
||||
</TextBlock>
|
||||
<Line Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2" Stroke="Black" X2="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" StrokeDashArray="2 2" StrokeThickness="1"/>
|
||||
</Grid>
|
||||
<TextBlock>
|
||||
<Hyperlink Command="{Binding animations.AddItemCommand}">(click to add)</Hyperlink>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</GroupBox.Header>
|
||||
<ItemsControl
|
||||
x:Name="RowTriggerAnimations"
|
||||
Grid.IsSharedSizeScope="True"
|
||||
ItemsSource="{Binding animations}"
|
||||
ItemTemplate="{StaticResource RowAnimationItemTemplate}"
|
||||
/>
|
||||
</GroupBox>
|
||||
<Grid
|
||||
Grid.Row="4"
|
||||
Grid.Column="1"
|
||||
>
|
||||
<!--<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>-->
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource PredicateRootColumnWidth}}"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid HorizontalAlignment="Stretch">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center">Play</TextBlock>
|
||||
<ComboBox
|
||||
Grid.Column="2"
|
||||
ItemsSource="{Binding sound.items}"
|
||||
SelectedItem="{Binding sound.value}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
/>
|
||||
</Grid>
|
||||
<!--<CheckBox Grid.Column="1" VerticalAlignment="Center" IsChecked="{Binding play_sound}">Play Sound</CheckBox>-->
|
||||
<!--<ComboBox
|
||||
Grid.Column="1"
|
||||
Visibility="{Binding play_sound, Converter={StaticResource FalseVisibilityConverter}}"
|
||||
Style="{StaticResource DisabledPlaceholderComboBox}"
|
||||
/>-->
|
||||
<Button
|
||||
Grid.Column="2"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="2,0,0,0"
|
||||
Command="{x:Static c:SoundAnimationView.PreviewSoundCommand}"
|
||||
CommandParameter="{Binding sound.value}"
|
||||
Visibility="{Binding play_sound, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
Style="{StaticResource RoundPlayButton}"
|
||||
ToolTip="{Binding sound.value, Converter={x:Static c:SoundAnimationView.LicenseInfoTextConverter}}"
|
||||
>
|
||||
<Button.CommandBindings>
|
||||
<CommandBinding
|
||||
Command="{x:Static u:ApplicationCommandsEx.CopyToClipboardCommand}"
|
||||
Executed="{x:Static u:ApplicationCommandsEx.CopyToClipboardExecutedHandler}"
|
||||
/>
|
||||
<CommandBinding
|
||||
Command="{x:Static u:ApplicationCommandsEx.OpenUriCommand}"
|
||||
CanExecute="{x:Static u:ApplicationCommandsEx.OpenUriCanExecuteHandler}"
|
||||
Executed="{x:Static u:ApplicationCommandsEx.OpenUriExecutedHandler}"
|
||||
/>
|
||||
</Button.CommandBindings>
|
||||
<Button.InputBindings>
|
||||
<MouseBinding Command="{x:Static u:ApplicationCommandsEx.CopyToClipboardCommand}" CommandParameter="{Binding sound.value, Converter={x:Static c:SoundAnimationView.LicenseInfoClipboardTextConverter}}">
|
||||
<MouseBinding.Gesture>
|
||||
<MouseGesture MouseAction="LeftClick" Modifiers="Ctrl"/>
|
||||
</MouseBinding.Gesture>
|
||||
</MouseBinding>
|
||||
</Button.InputBindings>
|
||||
</Button>
|
||||
<!--<CheckBox Grid.Row="2" Grid.Column="1" IsEnabled="{Binding predicate.can_enable_toast_notifications}" IsChecked="{Binding predicate.toast_notifications_enabled}">
|
||||
Show Notification
|
||||
</CheckBox>-->
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
<DataTemplate.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter Property="Background" Value="{StaticResource AltPredicateBackground}" TargetName="PredicateAnimationItemRoot"/>
|
||||
</Trigger>
|
||||
<DataTrigger Binding="{Binding animations.Count}" Value="0">
|
||||
<Setter TargetName="AnimationsGroupBox" Property="Padding" Value="0"/>
|
||||
<Setter TargetName="AnimationsGroupBox" Property="BorderThickness" Value="0"/>
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</GroupBox>
|
||||
<GroupBox Grid.Row="4">
|
||||
<GroupBox.Style>
|
||||
<Style TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsChecked, ElementName=ColumnsExpanderToggle}" Value="{u:False}">
|
||||
<Setter Property="Height" Value="{StaticResource CollapsedAnimationItemsHeight}"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</GroupBox.Style>
|
||||
<GroupBox.Header>
|
||||
<c:ExpanderToggleButton x:Name="ColumnsExpanderToggle" IsChecked="True">
|
||||
Columns
|
||||
</c:ExpanderToggleButton>
|
||||
</GroupBox.Header>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalGap}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<c:DragDropListBox Grid.RowSpan="3" MinWidth="200" MaxHeight="500" ItemsSource="{Binding columns}" SelectedItem="{Binding current_column}">
|
||||
<c:DragDropListBox.ItemContainerStyle>
|
||||
<Style TargetType="c:DraggableListBoxItem">
|
||||
<Setter Property="Cursor" Value="Arrow"/>
|
||||
</Style>
|
||||
</c:DragDropListBox.ItemContainerStyle>
|
||||
<c:DragDropListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid x:Name="column_item_content_root">
|
||||
<u:StateManager.Groups>
|
||||
<u:StateGroupsManager>
|
||||
<u:StateDefinitionCollection>
|
||||
<u:StateDefinition State="{Binding DataContext.can_override_display_name, Source={u:DirectReference column_item_content_root}, Converter={x:Static usp:GridSettingsView.ColumnVisibilityToggleVisualStateConverter}}"/>
|
||||
</u:StateDefinitionCollection>
|
||||
</u:StateGroupsManager>
|
||||
</u:StateManager.Groups>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested usp:GridSettingsView.VisualStateNames.ColumnVisibilityToggle}}">
|
||||
<VisualState Name="{x:Static Active, MemberType={u:Nested usp:GridSettingsView.VisualStateNames.ColumnVisibilityToggle}}"/>
|
||||
<VisualState Name="{x:Static Inactive, MemberType={u:Nested usp:GridSettingsView.VisualStateNames.ColumnVisibilityToggle}}">
|
||||
<Storyboard>
|
||||
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="visibility_toggle" Storyboard.TargetProperty="(UIElement.IsEnabled)">
|
||||
<DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
|
||||
</BooleanAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="visibility_toggle" Storyboard.TargetProperty="(FrameworkElement.ToolTip)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="(N/A)"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox x:Name="visibility_toggle" ToolTipService.ShowOnDisabled="True" IsChecked="{Binding is_visible}" Focusable="False"/>
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" Focusable="False">
|
||||
<TextBlock Text="{Binding id, Converter={x:Static ut:DisplayNameHelper.CamelCaseSpacesConverter}}" Focusable="False"/>
|
||||
<TextBlock Margin="2,0,0,0" FontStyle="Italic" Text="{Binding display_name, Mode=OneWay, StringFormat='{} ({0})'}" Focusable="False">
|
||||
<TextBlock.Visibility>
|
||||
<MultiBinding Converter="{x:Static usp:GridSettingsView.ColumnDisplayNameVisibilityConverter}">
|
||||
<Binding Path="id" Converter="{x:Static ut:DisplayNameHelper.CamelCaseSpacesConverter}"/>
|
||||
<Binding Path="display_name"/>
|
||||
</MultiBinding>
|
||||
</TextBlock.Visibility>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</c:DragDropListBox.ItemTemplate>
|
||||
</c:DragDropListBox>
|
||||
<GroupBox Grid.Column="2" MinWidth="280" Content="{Binding current_column}" ContentTemplate="{Binding CellContentTemplate, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}">
|
||||
<GroupBox.Header>
|
||||
<TextBlock Text="{Binding current_column.display_name, StringFormat='{}\'{0}\' Cell Appearance'}"/>
|
||||
</GroupBox.Header>
|
||||
</GroupBox>
|
||||
<!--TODO: Make this visible when cell animations are ready-->
|
||||
<GroupBox Grid.Row="2" Grid.Column="2" VerticalAlignment="Top" Visibility="Collapsed">
|
||||
<GroupBox.Style>
|
||||
<Style TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding show_cell_predicate_animations}" Value="{u:False}">
|
||||
<Setter Property="Height" Value="{StaticResource CollapsedAnimationItemsHeight}"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</GroupBox.Style>
|
||||
<GroupBox.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<c:ExpanderToggleButton x:Name="CellAnimationsExpanderToggle" IsChecked="{Binding show_cell_predicate_animations}">
|
||||
<TextBlock Text="{Binding current_column.display_name, StringFormat='{}\'{0}\' Cell Animations'}"/>
|
||||
</c:ExpanderToggleButton>
|
||||
<TextBlock Margin="{StaticResource LeftPush}">
|
||||
<Hyperlink Command="{Binding current_column.predicate_animations.AddItemCommand}">(click to add)</Hyperlink>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</GroupBox.Header>
|
||||
</TabControl.ItemContainerStyle>
|
||||
<TabItem
|
||||
Header="Grid"
|
||||
Content="{Binding GridSectionContent, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}"
|
||||
ContentTemplate="{Binding GridSectionContentTemplate, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}"
|
||||
/>
|
||||
<TabItem Header="Sound/Notification Triggers" DataContext="{Binding DataContext.instance_vm, RelativeSource={RelativeSource AncestorType=usp:ShellSettingsDialog}}">
|
||||
<Grid VerticalAlignment="Top">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
|
||||
<ItemsControl
|
||||
x:Name="PredicateTriggers"
|
||||
AlternationCount="2"
|
||||
ItemsSource="{Binding current_column.predicate_animations}"
|
||||
<c:DIYGrid
|
||||
Rows="{Binding order_sound_animations}"
|
||||
BorderBrush="Black"
|
||||
BorderThickness="1"
|
||||
RowsHorizontalScrollBarVisibility="Collapsed"
|
||||
SelectionMode="Single"
|
||||
>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<c:DIYGrid.Columns>
|
||||
<c:DIYGridColumnCollection>
|
||||
<c:DIYGridColumn key="Delete" HeaderContainerStyle="{StaticResource DisabledColumnHeader}" Width="23" is_visible="True"/>
|
||||
<c:DIYGridColumn key="IsEnabled" HeaderContainerStyle="{StaticResource DisabledColumnHeader}" Width="66" is_visible="True"/>
|
||||
<c:DIYGridColumn key="Security" Header="Security" Width="130" is_visible="True"/>
|
||||
<c:DIYGridColumn key="EventType" Header="Event Type" Width="120" is_visible="True"/>
|
||||
<c:DIYGridColumn key="Sound" Header="Sound" Width="130" is_visible="True"/>
|
||||
</c:DIYGridColumnCollection>
|
||||
</c:DIYGrid.Columns>
|
||||
<c:DIYGrid.RowTemplate>
|
||||
<DataTemplate>
|
||||
<Border x:Name="PredicateAnimationItemRoot" BorderBrush="LightGray" BorderThickness="1" Padding="6,8">
|
||||
<Grid>
|
||||
<Grid c:DIYGrid.SyncWithColumnGeometry="True">
|
||||
<Button
|
||||
c:DIYGrid.ColumnKey="Delete"
|
||||
HorizontalAlignment="Center"
|
||||
Command="{Binding DataContext.delete_alert_cmd, RelativeSource={RelativeSource AncestorType=c:DIYGrid}}"
|
||||
CommandParameter="{Binding}"
|
||||
Style="{StaticResource RoundCloseButton}"
|
||||
ToolTip="Delete"
|
||||
/>
|
||||
<ToggleButton
|
||||
c:DIYGrid.ColumnKey="IsEnabled"
|
||||
IsChecked="{Binding is_enabled}"
|
||||
Style="{StaticResource ToggleSwitch}"
|
||||
/>
|
||||
<ComboBox
|
||||
c:DIYGrid.ColumnKey="EventType"
|
||||
Margin="{StaticResource CellPadding}"
|
||||
ItemsSource="{Binding predicate_types}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding predicate_type}"
|
||||
/>
|
||||
<c:ContractPickerPopup
|
||||
c:DIYGrid.ColumnKey="Security"
|
||||
Margin="{StaticResource CellPadding}"
|
||||
AllowEmpty="True"
|
||||
CloseOnOK="True"
|
||||
CloseOnCancel="True"
|
||||
MaxWidth="180"
|
||||
DataContext="{Binding predicate}"
|
||||
SecurityMap="{DynamicResource {x:Static u:ResourceKeys.Securities}}"
|
||||
Header="{Binding security_criteria}"
|
||||
ShowDialogSkirt="True"
|
||||
ToolTip="{Binding security_criteria, Converter={x:Static c:ContractPickerPopup.SecurityCriteriaTextConverter}, Mode=OneWay}"
|
||||
OKClick="{x:Static c:ContractPickerPopup.FlushSelectedCriteriaHandler}"
|
||||
SelectedCriteria="{Binding security_criteria, UpdateSourceTrigger=Explicit}"
|
||||
>
|
||||
<c:ContractPickerPopup.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={x:Static c:ContractPickerPopup.SecurityCriteriaTextConverter}}" TextTrimming="CharacterEllipsis"/>
|
||||
</DataTemplate>
|
||||
</c:ContractPickerPopup.HeaderTemplate>
|
||||
</c:ContractPickerPopup>
|
||||
<Grid c:DIYGrid.ColumnKey="Sound" Margin="{StaticResource CellPadding}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="20"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Button
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,2,0,0"
|
||||
Command="{Binding DataContext.current_column.predicate_animations.RemoveItemCommand, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
|
||||
CommandParameter="{Binding}"
|
||||
Style="{StaticResource RoundCloseButton}"
|
||||
<ComboBox
|
||||
ItemsSource="{u:EnumBindingSource Type={u:Nested shell:SoundNotification.SystemSound}, Except=None}"
|
||||
ItemTemplate="{StaticResource EnumDescriptionTemplate}"
|
||||
SelectedItem="{Binding sound_type}"
|
||||
/>
|
||||
<ContentControl Grid.Column="1" Content="{Binding predicate, Mode=OneWay}" ContentTemplateSelector="{StaticResource PredicateTemplateSelector}"/>
|
||||
<GroupBox
|
||||
x:Name="AnimationsGroupBox"
|
||||
Grid.Row="2"
|
||||
<Button
|
||||
Grid.Column="1"
|
||||
Margin="{StaticResource ExpanderChildMargin}"
|
||||
>
|
||||
<GroupBox.Style>
|
||||
<Style TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding show_animations}" Value="{u:False}">
|
||||
<Setter Property="Height" Value="{StaticResource CollapsedAnimationItemsHeight}"/>
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</GroupBox.Style>
|
||||
<GroupBox.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Grid Width="{StaticResource AnimationExpanderToggleWidth}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<c:ExpanderToggleButton x:Name="CellAnimationsExpanderToggle" IsChecked="{Binding show_animations}" Visibility="{Binding animations.Count, Converter={StaticResource IntNotZeroVisibilityConverter}}">
|
||||
Animations
|
||||
</c:ExpanderToggleButton>
|
||||
<TextBlock FontStyle="Italic" Foreground="Gray" Visibility="{Binding Visibility, ElementName=CellAnimationsExpanderToggle, Converter={StaticResource ReverseVisibilityConverter}}">
|
||||
No Animations
|
||||
</TextBlock>
|
||||
<Line Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2" Stroke="Black" X2="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" StrokeDashArray="2 2" StrokeThickness="1"/>
|
||||
</Grid>
|
||||
<TextBlock>
|
||||
<Hyperlink Command="{Binding animations.AddItemCommand}">(click to add)</Hyperlink>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</GroupBox.Header>
|
||||
<ItemsControl
|
||||
x:Name="CellTriggerAnimations"
|
||||
Grid.IsSharedSizeScope="True"
|
||||
HorizontalAlignment="Stretch"
|
||||
ItemsSource="{Binding animations}"
|
||||
ItemTemplate="{StaticResource CellAnimationItemTemplate}"
|
||||
/>
|
||||
</GroupBox>
|
||||
Margin="4,0,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
Command="{x:Static c:SoundAnimationView.PreviewSoundCommand}"
|
||||
CommandParameter="{Binding sound.system_sound}"
|
||||
Style="{StaticResource RoundPlayButton}"
|
||||
/>
|
||||
</Grid>
|
||||
</Border>
|
||||
<DataTemplate.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter TargetName="PredicateAnimationItemRoot" Property="Background" Value="{StaticResource AltPredicateBackground}"/>
|
||||
</Trigger>
|
||||
<DataTrigger Binding="{Binding animations.Count}" Value="0">
|
||||
<Setter TargetName="AnimationsGroupBox" Property="Padding" Value="0"/>
|
||||
<Setter TargetName="AnimationsGroupBox" Property="BorderThickness" Value="0"/>
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
<Rectangle Grid.Column="0" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="1" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="2" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
<Rectangle Grid.Column="3" HorizontalAlignment="Right" Width="1" Fill="Gray"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</c:DIYGrid.RowTemplate>
|
||||
</c:DIYGrid>
|
||||
</ScrollViewer>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<TextBlock Grid.Row="1" VerticalAlignment="Top">
|
||||
<TextBlock.Margin>
|
||||
<Thickness Left="{StaticResource HorizontalPush1}" Top="{StaticResource HorizontalPush1}"/>
|
||||
</TextBlock.Margin>
|
||||
<Hyperlink Command="{Binding add_alert_cmd}">Click to Add Alert</Hyperlink>
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="Columns">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="{Binding Source={StaticResource VerticalPush}}"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalGap}}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<c:DragDropListBox Grid.RowSpan="3" MinWidth="200" MaxHeight="500" ItemsSource="{Binding columns}" SelectedItem="{Binding current_column}">
|
||||
<c:DragDropListBox.ItemContainerStyle>
|
||||
<Style TargetType="c:DraggableListBoxItem">
|
||||
<Setter Property="Cursor" Value="Arrow"/>
|
||||
</Style>
|
||||
</c:DragDropListBox.ItemContainerStyle>
|
||||
<c:DragDropListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid x:Name="column_item_content_root">
|
||||
<u:StateManager.Groups>
|
||||
<u:StateGroupsManager>
|
||||
<u:StateDefinitionCollection>
|
||||
<u:StateDefinition State="{Binding DataContext.can_override_display_name, Source={u:DirectReference column_item_content_root}, Converter={x:Static usp:GridSettingsView.ColumnVisibilityToggleVisualStateConverter}}"/>
|
||||
</u:StateDefinitionCollection>
|
||||
</u:StateGroupsManager>
|
||||
</u:StateManager.Groups>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup Name="{x:Static GroupName, MemberType={u:Nested usp:GridSettingsView.VisualStateNames.ColumnVisibilityToggle}}">
|
||||
<VisualState Name="{x:Static Active, MemberType={u:Nested usp:GridSettingsView.VisualStateNames.ColumnVisibilityToggle}}"/>
|
||||
<VisualState Name="{x:Static Inactive, MemberType={u:Nested usp:GridSettingsView.VisualStateNames.ColumnVisibilityToggle}}">
|
||||
<Storyboard>
|
||||
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="visibility_toggle" Storyboard.TargetProperty="(UIElement.IsEnabled)">
|
||||
<DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
|
||||
</BooleanAnimationUsingKeyFrames>
|
||||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="visibility_toggle" Storyboard.TargetProperty="(FrameworkElement.ToolTip)">
|
||||
<DiscreteObjectKeyFrame KeyTime="0" Value="(N/A)"/>
|
||||
</ObjectAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="{Binding Source={StaticResource HorizontalPush}}"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox x:Name="visibility_toggle" ToolTipService.ShowOnDisabled="True" IsChecked="{Binding is_visible}" Focusable="False"/>
|
||||
<StackPanel Grid.Column="2" Orientation="Horizontal" Focusable="False">
|
||||
<TextBlock Text="{Binding id, Converter={x:Static ut:DisplayNameHelper.CamelCaseSpacesConverter}}" Focusable="False"/>
|
||||
<TextBlock Margin="2,0,0,0" FontStyle="Italic" Text="{Binding display_name, Mode=OneWay, StringFormat='{} ({0})'}" Focusable="False">
|
||||
<TextBlock.Visibility>
|
||||
<MultiBinding Converter="{x:Static usp:GridSettingsView.ColumnDisplayNameVisibilityConverter}">
|
||||
<Binding Path="id" Converter="{x:Static ut:DisplayNameHelper.CamelCaseSpacesConverter}"/>
|
||||
<Binding Path="display_name"/>
|
||||
</MultiBinding>
|
||||
</TextBlock.Visibility>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</c:DragDropListBox.ItemTemplate>
|
||||
</c:DragDropListBox>
|
||||
<GroupBox Grid.Column="2" MinWidth="280" Content="{Binding current_column}" ContentTemplate="{Binding CellContentTemplate, RelativeSource={RelativeSource AncestorType=usp:GridSettingsView}}">
|
||||
<GroupBox.Header>
|
||||
<TextBlock Text="{Binding current_column.display_name, StringFormat='{}\'{0}\' Cell Appearance'}"/>
|
||||
</GroupBox.Header>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@@ -1,7 +1,10 @@
|
||||
using bts.spark;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace mbts.ui.converters {
|
||||
static class ValueConverter {
|
||||
@@ -25,8 +28,12 @@ namespace mbts.ui.converters {
|
||||
public static readonly IValueConverter
|
||||
DoubleTextConverter = new DoubleTextConverter(),
|
||||
DoubleGreaterThanZero = new DoubleGreaterThanConverter { Value = 0 },
|
||||
GeometryParser = new TypeConverterWrapper {
|
||||
TypeConverter = new GeometryConverter()
|
||||
},
|
||||
IntTextConverter = new IntTextConverter(),
|
||||
UIntTextConverter = new UIntTextConverter(),
|
||||
NotNull = ValueConverter.create(obj => obj != null),
|
||||
QuantityMeasureTextConverter = ValueConverter.create<QuantityMeasureImmutable?, string>(fmt),
|
||||
SecuritySelectorText,
|
||||
SimpleString = new AnonymousValueConverter(obj => obj?.ToString()),
|
||||
@@ -44,7 +51,8 @@ namespace mbts.ui.converters {
|
||||
SliderPercentage = ValueConverter.create<double, double, double, double>((value, min, max) =>
|
||||
DoubleHelper.AnyNaN(value, min, max) || min >= max ?
|
||||
double.NaN :
|
||||
(value - min) / (max - min));
|
||||
(value - min) / (max - min)),
|
||||
Any = new AnonymousMultiValueConverter(objs => objs.OfTypeSafe<bool>().Any(_ => _), null);
|
||||
|
||||
public static string fmt(QuantityMeasureImmutable? qm) {
|
||||
if (qm.HasValue) {
|
||||
@@ -84,6 +92,22 @@ namespace mbts.ui.converters {
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return _convert_back(ConvertUtils.try_convert<TOut>(value)); }
|
||||
}
|
||||
|
||||
class AnonymousMultiValueConverter : IMultiValueConverter {
|
||||
readonly Func<object[], object> _convert;
|
||||
readonly Func<object, object[]> _convert_back;
|
||||
|
||||
public AnonymousMultiValueConverter(Func<object[], object> convert, Func<object, object[]> convert_back) {
|
||||
_convert = convert;
|
||||
_convert_back = convert_back;
|
||||
}
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) =>
|
||||
_convert(values);
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) =>
|
||||
_convert_back == null ? throw new InvalidOperationException() : _convert_back(value);
|
||||
}
|
||||
|
||||
public class AnonymousMultiValueConverter<TIn1, TIn2, TOut> : IMultiValueConverter {
|
||||
readonly Func<TIn1, TIn2, TOut> _convert;
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using bts.utils;
|
||||
using mbts.ui.utility.text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace mbts.ui.converters {
|
||||
class FontWeightDisplayTextConverter : IValueConverter {
|
||||
// TODO (when there reallllly isn't anything else to do):
|
||||
// come up with interpolation naming system (e.g., if weight is between 'Light' and 'Super Light,' name it 'Semi Light');
|
||||
// below is the beginning of such an effort.
|
||||
|
||||
//static SortedList<FontWeight, string> _font_weight_cache =
|
||||
// new SortedList<FontWeight, string>(Comparer<int>.Default.wrap<int, FontWeight>(fw => fw.ToOpenTypeWeight()));
|
||||
|
||||
//static FontWeightDisplayTextConverter() {
|
||||
// foreach (var fw in TextUtils.SystemFontWeights)
|
||||
// _font_weight_cache.Add(fw, fw.ToString());
|
||||
//}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
||||
if (value is FontWeight fw) {
|
||||
string rv = fw.ToString();
|
||||
if (int.TryParse(rv, out var open_type_weight)) {
|
||||
// msoft doesn't have a pretty name
|
||||
rv = _fallback_name(open_type_weight);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
static string _fallback_name(int open_type_weight) {
|
||||
switch (open_type_weight) {
|
||||
case 350: return "Semi Light";
|
||||
default: return open_type_weight.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,15 @@ namespace mbts.ui {
|
||||
CommitAndRelease
|
||||
}
|
||||
|
||||
// RoutedEventHandlers
|
||||
public static RoutedEventHandler FocusTextBoxRoutedEventHandler => _focus_text_box_routed_event_handler;
|
||||
static void _focus_text_box_routed_event_handler(object sender, RoutedEventArgs e) {
|
||||
if (sender is TextBox tb || sender is FrameworkElement el && el.try_find_descendent_of_type(out tb)) {
|
||||
e.Handled = true;
|
||||
Keyboard.Focus(tb);
|
||||
}
|
||||
}
|
||||
|
||||
#region RoutedCommands/Handlers
|
||||
public static readonly RoutedCommand
|
||||
ReleaseCaptureCommand = new RoutedCommand(),
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mbts="clr-namespace:mbts.ui"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:controls="clr-namespace:mbts.ui.controls">
|
||||
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mbts="clr-namespace:mbts.ui"
|
||||
xmlns:u="clr-namespace:mbts.ui"
|
||||
xmlns:controls="clr-namespace:mbts.ui.controls"
|
||||
xmlns:cv="clr-namespace:mbts.ui.converters"
|
||||
>
|
||||
<SolidColorBrush x:Key="StartMenuMouseOverBorderBrush" Color="#FFFFB700" />
|
||||
<SolidColorBrush x:Key="StartMenuMouseOverBackground" Color="#6ddbff" />
|
||||
<SolidColorBrush x:Key="StartMenuPressedBorderBrush" Color="#FFC29B29" />
|
||||
@@ -269,7 +270,6 @@
|
||||
</Setter>
|
||||
|
||||
</Style>
|
||||
|
||||
<!-- The Expander used in spark menus (Tool Bar) -->
|
||||
<Style x:Key="MenuExpanderButtonBase" TargetType="ToggleButton">
|
||||
<Setter Property="Background" Value="{mbts:BTSColor UI.spark_menu_background}"/>
|
||||
@@ -491,6 +491,35 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<ControlTemplate x:Key="HelpButtonGenericTemplate" TargetType="{x:Type Control}">
|
||||
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
|
||||
<Grid.ToolTip>
|
||||
<ToolTip Content="{TemplateBinding ToolTip}" Style="{DynamicResource HelpButtonToolTipStyleKey}"/>
|
||||
</Grid.ToolTip>
|
||||
<Ellipse HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Fill="{TemplateBinding Background}" Opacity="0" x:Name="_el" />
|
||||
<TextBlock Text="?" HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
<Trigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="_el" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.05" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</Trigger.EnterActions>
|
||||
<Trigger.ExitActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="_el" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.2" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</Trigger.ExitActions>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<Style TargetType="Button" BasedOn="{StaticResource RoundMinimizeButton}" x:Key="HelpButtonBaseStyle">
|
||||
<Setter Property="Background" Value="{x:Static mbts:BTSColors.yellow_brush}" />
|
||||
<Setter Property="ToolTip" Value="Click here for help" />
|
||||
@@ -770,6 +799,30 @@
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
|
||||
<DataTemplate x:Key="CheckableListBoxItemContentTemplate">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Path
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="4,0,6,2"
|
||||
Fill="Black"
|
||||
Data="{Binding Source={StaticResource {x:Static u:Icons.CheckMarkGeometryKey}}, Converter={x:Static cv:ValueConverters.GeometryParser}}"
|
||||
>
|
||||
<Path.Visibility>
|
||||
<Binding Path="IsSelected" RelativeSource="{RelativeSource AncestorType=ListBoxItem}">
|
||||
<Binding.Converter>
|
||||
<cv:BooleanToObjectConverter ValueForFalse="{x:Static Visibility.Hidden}" ValueForTrue="{x:Static Visibility.Visible}"/>
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</Path.Visibility>
|
||||
</Path>
|
||||
<ContentControl Grid.Column="1" Content="{Binding}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
<Style x:Key="LargeMenuListBoxItem" TargetType="ListBoxItem">
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Left"/>
|
||||
@@ -783,6 +836,7 @@
|
||||
</Setter>
|
||||
<Setter Property="Padding" Value="6"/>
|
||||
<Setter Property="Template" Value="{StaticResource LargeMenuListBoxItemTemplate}"/>
|
||||
<Setter Property="ContentTemplate" Value="{StaticResource CheckableListBoxItemContentTemplate}"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="LargeMenuListBox" TargetType="ListBox">
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
Title="{Binding title, StringFormat='{}{0} Settings'}"
|
||||
Icon="{x:Static u:Icons.Admin}"
|
||||
Style="{StaticResource BTSDialog}"
|
||||
UseLayoutRounding="True"
|
||||
>
|
||||
<Window.Resources>
|
||||
<!--Primitive Constants-->
|
||||
@@ -34,6 +35,30 @@
|
||||
<cv:KeyValue Key="{u:True}" Value="{u:FontWeight Bold}"/>
|
||||
</cv:ValueMap>
|
||||
<!--Styles (Shared/Common)-->
|
||||
<DataTemplate x:Key="FontPickerTemplate">
|
||||
<c:FontPicker SelectedFontFamily="{Binding font_family}" SelectedFontSize="{Binding font_size}" SelectedFontWeight="{Binding font_weight}"/>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="FontDisplayTemplate">
|
||||
<TextBlock FontFamily="{Binding font_family}" FontSize="{Binding font_size}" FontWeight="{Binding font_weight}">
|
||||
<TextBlock.Text>
|
||||
<MultiBinding StringFormat="{}{0}, {1:#0.##} pt">
|
||||
<Binding Path="font_family"/>
|
||||
<Binding Path="font_size"/>
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
<DataTemplate x:Key="FontFamilyAndWeightDisplayTemplate">
|
||||
<TextBlock FontFamily="{Binding font_family}" FontSize="{Binding font_size}" FontWeight="{Binding font_weight}">
|
||||
<TextBlock.Text>
|
||||
<MultiBinding StringFormat="{}{0}, {1}, {2:#0.##} pt">
|
||||
<Binding Path="font_family"/>
|
||||
<Binding Path="font_weight"/>
|
||||
<Binding Path="font_size"/>
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
<Style x:Key="FontPickerPopupControl" TargetType="c:PopupControl">
|
||||
<Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"/>
|
||||
@@ -41,27 +66,8 @@
|
||||
<Setter Property="MinHeight" Value="24"/>
|
||||
<Setter Property="Header" Value="{Binding}"/>
|
||||
<Setter Property="Content" Value="{Binding}"/>
|
||||
<Setter Property="HeaderTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock FontFamily="{Binding font_family}" FontSize="{Binding font_size}" FontWeight="{Binding font_weight}">
|
||||
<TextBlock.Text>
|
||||
<MultiBinding StringFormat="{}{0}, {1:#0.##} pt">
|
||||
<Binding Path="font_family"/>
|
||||
<Binding Path="font_size"/>
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="ContentTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<c:FontPicker SelectedFontFamily="{Binding font_family}" SelectedFontSize="{Binding font_size}" SelectedFontWeight="{Binding font_weight}"/>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="ContentTemplate" Value="{StaticResource FontPickerTemplate}"/>
|
||||
<Setter Property="HeaderTemplate" Value="{StaticResource FontDisplayTemplate}"/>
|
||||
</Style>
|
||||
<!--DataTemplates-->
|
||||
<DataTemplate x:Key="GridSectionCoreContentTemplate">
|
||||
@@ -240,6 +246,7 @@
|
||||
</Style>
|
||||
</u:StyleSelectorKeyValue>
|
||||
</u:KeyedStyleSelector>
|
||||
|
||||
<DataTemplate x:Key="AnchorItemContentTemplate">
|
||||
<Border Padding="4">
|
||||
<Grid>
|
||||
@@ -337,7 +344,13 @@
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<c:ActionMenu HorizontalAlignment="Right" Margin="0,2,0,0" DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=usp:ShellSettingsDialog}}" ItemsSource="{Binding action_menu_items}"/>
|
||||
<c:ActionMenu
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,2,0,0"
|
||||
DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=usp:ShellSettingsDialog}}"
|
||||
ItemsSource="{Binding action_menu_items}"
|
||||
Style="{StaticResource SparkToolBarItem}"
|
||||
/>
|
||||
<usp:GridSettingsView
|
||||
Grid.Row="1"
|
||||
GridSectionContent="{Binding}"
|
||||
@@ -374,6 +387,7 @@
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border Grid.ColumnSpan="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{StaticResource HeaderBackgroundBrush}" BorderBrush="{StaticResource HeaderBackgroundBorderBrush}" BorderThickness="1,0,1,1"/>
|
||||
<TextBlock Grid.Column="1" VerticalAlignment="Center">Profile:</TextBlock>
|
||||
<ComboBox Grid.Column="2" Margin="8,4" ItemsSource="{Binding Source={StaticResource ProfilesViewSource}}" SelectedItem="{Binding selected_profile}" ItemTemplateSelector="{StaticResource ProfileItemTemplateSelector}">
|
||||
<ComboBox.GroupStyle>
|
||||
@@ -547,49 +561,15 @@
|
||||
</MenuItem.ToolTip>
|
||||
</MenuItem>
|
||||
<Separator VerticalAlignment="Stretch" Width="1" Margin="2,2,1,2" Background="Gray"/>
|
||||
<c:ActionMenu Grid.Column="4" HorizontalAlignment="Right" Margin="0,0,4,0" VerticalAlignment="Center" ItemsSource="{Binding action_menu_items}"/>
|
||||
<c:ActionMenu Grid.Column="4" HorizontalAlignment="Right" Margin="0,0,4,0" ItemsSource="{Binding action_menu_items}" Style="{StaticResource SparkToolBarItem}"/>
|
||||
</ToolBar>
|
||||
<usp:LadderSettingsView Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" HorizontalAlignment="Left" Width="758" MinHeight="234" Margin="0,10,8,0" DataContext="{Binding selected_profile.value}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</u:TemplateSelectorKeyValue>
|
||||
<u:TemplateSelectorKeyValue Key="{x:Static usp:GridSettingsTemplateKeys.OrderBook}">
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<c:ActionMenu HorizontalAlignment="Right" Margin="0,2,0,0" DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=usp:ShellSettingsDialog}}" ItemsSource="{Binding action_menu_items}"/>
|
||||
<usp:GridSettingsView
|
||||
Grid.Row="1"
|
||||
DataContext="{Binding core_settings_vm}"
|
||||
GridSectionContent="{Binding DataContext.instance_vm, RelativeSource={RelativeSource AncestorType=usp:ShellSettingsDialog}}"
|
||||
CellContentTemplate="{DynamicResource DefaultCellContentTemplate}"
|
||||
>
|
||||
<usp:GridSettingsView.GridSectionContentTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Grid.IsSharedSizeScope="True">
|
||||
<ContentControl Content="{Binding core_settings_vm}" ContentTemplate="{StaticResource GridSectionCoreContentTemplate}"/>
|
||||
<CheckBox Content="Show Full Algo Tree">
|
||||
<CheckBox.Margin>
|
||||
<Thickness Top="{StaticResource VerticalPush1}"/>
|
||||
</CheckBox.Margin>
|
||||
<CheckBox.IsChecked>
|
||||
<Binding Path="(orderbook:OrderBookSettingsVM.algo_tree_display_mode)">
|
||||
<Binding.Converter>
|
||||
<cv:ReverseConverter>
|
||||
<cv:BooleanToObjectConverter ValueForFalse="{x:Static orderbook:AlgoTreeDisplayMode.RootAndLeafNodes}" ValueForTrue="{x:Static orderbook:AlgoTreeDisplayMode.FullTree}"/>
|
||||
</cv:ReverseConverter>
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</CheckBox.IsChecked>
|
||||
</CheckBox>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</usp:GridSettingsView.GridSectionContentTemplate>
|
||||
</usp:GridSettingsView>
|
||||
</Grid>
|
||||
<DataTemplate DataType="{x:Type orderbook:OrderBookSettingsVM}">
|
||||
<usp:OrderBookSettingsView/>
|
||||
</DataTemplate>
|
||||
</u:TemplateSelectorKeyValue>
|
||||
<u:TemplateSelectorKeyValue Key="{x:Static usp:GridSettingsTemplateKeys.PNL}">
|
||||
@@ -770,17 +750,7 @@
|
||||
LeftItems="{Binding left_skirt_items}"
|
||||
LeftItemContainerStyleSelector="{StaticResource LeftButtonStyleSelector}"
|
||||
RightItems="{Binding right_skirt_items}"
|
||||
BorderBrush="DarkGray"
|
||||
BorderThickness="0,1,0,0"
|
||||
>
|
||||
<c:DialogSkirt.Background>
|
||||
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
|
||||
<LinearGradientBrush.GradientStops>
|
||||
<GradientStop Color="Transparent"/>
|
||||
<GradientStop Color="{x:Static u:BTSColors.dialog_skirt}" Offset="1"/>
|
||||
</LinearGradientBrush.GradientStops>
|
||||
</LinearGradientBrush>
|
||||
</c:DialogSkirt.Background>
|
||||
</c:DialogSkirt>
|
||||
BorderThickness="0"
|
||||
/>
|
||||
</Grid>
|
||||
</Window>
|
||||
</Window>
|
||||
@@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace mbts.ui {
|
||||
// This class is a FrameworkElement so it can be generated by a DataTemplate.
|
||||
// Such a DataTemplate may be referenced by multiple grids,
|
||||
// which is useful because single instances of row/column definitions cannot be shared.
|
||||
class GridArchitectureProxy : FrameworkElement {
|
||||
public static readonly DependencyProperty TemplateProperty =
|
||||
DependencyProperty.RegisterAttached("Template", typeof(DataTemplate), typeof(GridArchitectureProxy), new PropertyMetadata(OnTemplateChanged));
|
||||
|
||||
static void OnTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
|
||||
if (e.NewValue is DataTemplate dt) {
|
||||
var target = (Grid)d;
|
||||
var content = dt.LoadContent();
|
||||
if (content is GridArchitectureProxy gtp) {
|
||||
var row_defs = gtp.RowDefinitions;
|
||||
if (row_defs != null) {
|
||||
target.RowDefinitions.Clear();
|
||||
target.RowDefinitions.AddRange(row_defs);
|
||||
}
|
||||
var col_defs = gtp.ColumnDefinitions;
|
||||
if (col_defs != null) {
|
||||
target.ColumnDefinitions.Clear();
|
||||
target.ColumnDefinitions.AddRange(col_defs);
|
||||
}
|
||||
}
|
||||
} else if (e.NewValue is GridArchitectureProxy gp) {
|
||||
var target = (Grid)d;
|
||||
// Note that this does not react to the rows/columns changing,
|
||||
// the expectation was that these would be assigned once in practice,
|
||||
// so implementing such 'row/columndefs changed' events/callbacks appeared unneccesary.
|
||||
// Anyone can implement it later, if the need arises.
|
||||
var row_defs = gp.RowDefinitions;
|
||||
if (row_defs != null) {
|
||||
target.RowDefinitions.Clear();
|
||||
target.RowDefinitions.AddRange(row_defs);
|
||||
}
|
||||
var col_defs = gp.ColumnDefinitions;
|
||||
if (col_defs != null) {
|
||||
target.ColumnDefinitions.Clear();
|
||||
target.ColumnDefinitions.AddRange(col_defs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static DataTemplate GetTemplate(DependencyObject d) => d.GetValue(TemplateProperty) as DataTemplate;
|
||||
public static void SetTemplate(DependencyObject d, object value) => d.SetValue(TemplateProperty, value);
|
||||
|
||||
public static readonly DependencyProperty RowDefinitionsProperty =
|
||||
WPFHelper.create_dp<IEnumerable, GridArchitectureProxy>(nameof(RowDefinitions));
|
||||
|
||||
public IEnumerable RowDefinitions {
|
||||
get => GetValue(RowDefinitionsProperty) as IEnumerable;
|
||||
set => SetValue(RowDefinitionsProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ColumnDefinitionsProperty =
|
||||
WPFHelper.create_dp<IEnumerable, GridArchitectureProxy>(nameof(ColumnDefinitions));
|
||||
|
||||
public IEnumerable ColumnDefinitions {
|
||||
get => GetValue(ColumnDefinitionsProperty) as IEnumerable;
|
||||
set => SetValue(ColumnDefinitionsProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,13 @@ namespace bts.collections {
|
||||
collection.AddRange(items);
|
||||
}
|
||||
|
||||
public static void SetItems<T>(this ICollection<T> collection, params T[] items) {
|
||||
if (collection.Count > 0)
|
||||
collection.Clear();
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
collection.Add(items[i]);
|
||||
}
|
||||
|
||||
public static bool within_range<T>(this ICollection<T> collection, int index) =>
|
||||
index >= 0 && index < collection.Count;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,38 @@ namespace bts.utils {
|
||||
static class CollectionHelper {
|
||||
public const string indexer_name = "Item[]";
|
||||
|
||||
/// <summary>
|
||||
/// Enumerates through <paramref name="dest"/> and <paramref name="src"/> simultaneously (zip), and invokes the <paramref name="update_existing"/> delegate
|
||||
/// for each pair. If there are remaining items in <paramref name="dest"/>, they are removed; if there are remaining items in <paramref name="src"/> they are converted with the specified delegate and added to <paramref name="dest"/>.
|
||||
/// </summary>
|
||||
public static void add_or_update_existing<T, TModel>(IList<T> dest, IEnumerable<TModel> src, Func<TModel, T> create, Action<T, TModel> update_existing) {
|
||||
using (var en = src.GetEnumerator()) {
|
||||
int i = 0;
|
||||
while (en.MoveNext()) {
|
||||
if (i == dest.Count) {
|
||||
do dest.Add(create(en.Current));
|
||||
while (en.MoveNext());
|
||||
return;
|
||||
}
|
||||
update_existing(dest[i++], en.Current);
|
||||
}
|
||||
if (dest.Count > i)
|
||||
remove_range(dest, i, dest.Count - i);
|
||||
}
|
||||
}
|
||||
|
||||
public static void add_or_update_existing<T, TModel>(IList<T> dest, IList<TModel> src, Func<TModel, T> create, Action<T, TModel> update_existing) {
|
||||
while (dest.Count > src.Count) {
|
||||
dest.RemoveAt(src.Count);
|
||||
}
|
||||
for (int i = 0; i < dest.Count; i++) {
|
||||
update_existing(dest[i], src[i]);
|
||||
}
|
||||
while (dest.Count < src.Count) {
|
||||
dest.Add(create(src[dest.Count]));
|
||||
}
|
||||
}
|
||||
|
||||
public static int binary_search<T>(IList<T> items, T value, IComparer<T> comparer) =>
|
||||
binary_search(items, value, 0, items.Count, comparer);
|
||||
|
||||
@@ -201,6 +233,17 @@ namespace bts.utils {
|
||||
}
|
||||
}
|
||||
|
||||
// checks if source is List<T>; if so, calls List<T>.RemoveRange.
|
||||
public static void remove_range<T>(IList<T> source, int index, int count) {
|
||||
if (source is List<T> l)
|
||||
l.RemoveRange(index, count);
|
||||
else {
|
||||
// remove from top to bottom, bc it (most likely) requires less array copying.
|
||||
for (int i = index + count - 1; i >= index; i--)
|
||||
source.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: this is not optimized, be wary of use with large collections
|
||||
public static void sync_with_never_duplicate<T>(IList<T> dest, IEnumerable<T> src) =>
|
||||
sync_with_never_duplicate(dest, src, EqualityComparer<T>.Default);
|
||||
|
||||
Reference in new issue
Block a user