From acaea61f2cb35becce45c249b74e35fedb7aafc5 Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 22 Feb 2025 22:24:55 -0500 Subject: [PATCH] Fix menus. Fix Parameter sorting. Fix erroneous bindings. Fix issue with display of model name not showing an underscore in the name. Label control was interpreting it as an accelerator. Other code cleanup. --- ViewModels/CMMomentumViewModel.cs | 4 +- ViewModels/CMTTrendViewModel.cs | 4 +- ViewModels/MGSHMomentumViewModel.cs | 15 ++-- ViewModels/MainWindowViewModel.cs | 38 +++++++-- ViewModels/MomentumViewModel.cs | 4 +- ViewModels/ViewModelBase.cs | 10 ++- ViewModels/WorkspaceViewModel.cs | 25 +++++- Views/AnalystRatingsView.xaml | 6 +- Views/CMMomentumView.xaml | 6 +- Views/CMTTrendView.xaml | 9 ++- Views/HeadlinesView.xaml | 10 ++- Views/MGSHMomentumView.xaml | 120 ++++++++++++++-------------- Views/MomentumView.xaml | 7 +- Views/SECFilingView.xaml | 3 +- Views/TradeModelView.xaml | 3 +- Views/WatchListView.xaml | 10 --- 16 files changed, 170 insertions(+), 104 deletions(-) diff --git a/ViewModels/CMMomentumViewModel.cs b/ViewModels/CMMomentumViewModel.cs index bfd3c1d..2ec1981 100644 --- a/ViewModels/CMMomentumViewModel.cs +++ b/ViewModels/CMMomentumViewModel.cs @@ -1140,7 +1140,9 @@ namespace TradeBlotter.ViewModels cmParams = sessionParams.CMParams; NVPCollection nvpCollection = sessionParams.CMParams.ToNVPCollection(); nvpDictionary = nvpCollection.ToDictionary(); - nvpDictionaryKeys = new ObservableCollection(nvpDictionary.Keys); + List dictionaryKeys = new List(nvpDictionary.Keys); + dictionaryKeys.Sort(); + nvpDictionaryKeys = new ObservableCollection(dictionaryKeys); selectedParameter = nvpDictionaryKeys[0]; positions = new CMPositionModelCollection(); positions.Add(sessionParams.ActivePositions); diff --git a/ViewModels/CMTTrendViewModel.cs b/ViewModels/CMTTrendViewModel.cs index 0fedc03..c68bdd1 100644 --- a/ViewModels/CMTTrendViewModel.cs +++ b/ViewModels/CMTTrendViewModel.cs @@ -1255,7 +1255,9 @@ namespace TradeBlotter.ViewModels configuration=sessionParams.CMTParams; NVPCollection nvpCollection=sessionParams.CMTParams.ToNVPCollection(); nvpDictionary=nvpCollection.ToDictionary(); - nvpDictionaryKeys=new ObservableCollection(nvpDictionary.Keys); + List dictionaryKeys=new List(nvpDictionary.Keys); + dictionaryKeys.Sort(); + nvpDictionaryKeys=new ObservableCollection(dictionaryKeys); selectedParameter=nvpDictionaryKeys[0]; positions=new CMTPositionModelCollection(); positions.Add(sessionParams.ActivePositions); diff --git a/ViewModels/MGSHMomentumViewModel.cs b/ViewModels/MGSHMomentumViewModel.cs index 3839811..358fdda 100644 --- a/ViewModels/MGSHMomentumViewModel.cs +++ b/ViewModels/MGSHMomentumViewModel.cs @@ -60,7 +60,7 @@ namespace TradeBlotter.ViewModels // session section private ModelStatistics modelStatistics=null; private NVPDictionary nvpDictionary=null; - private ObservableCollection nvpDictionaryKeys=null; + private ObservableCollection nvpDictionaryKeys = default; private MGSHConfiguration configuration=null; private MGSHSessionParams sessionParams; private String selectedParameter=null; @@ -132,6 +132,7 @@ namespace TradeBlotter.ViewModels StopMonitor(); base.OnDispose(); } + // ******************************************************************************************** P E R S I S T E N C E ******************************************************************************************** public override bool CanPersist() { @@ -233,7 +234,7 @@ namespace TradeBlotter.ViewModels return collection; } } - + private void OnMomentumViewModelPropertyChanged(object sender, PropertyChangedEventArgs eventArgs) { } @@ -1371,7 +1372,7 @@ namespace TradeBlotter.ViewModels sessionParams=MGSHSessionManager.RestoreSession(pathFileName); if(null==sessionParams) { - MessageBox.Show(String.Format("Unable to open {0}",pathFileName)); + MessageBox.Show(String.Format("Unable to open {0}",pathFileName),"Error",MessageBoxButton.OK,MessageBoxImage.Exclamation ,MessageBoxResult.OK,MessageBoxOptions.DefaultDesktopOnly); pathFileName=null; return false; } @@ -1380,12 +1381,14 @@ namespace TradeBlotter.ViewModels configuration=sessionParams.Configuration; NVPCollection nvpCollection=sessionParams.Configuration.ToNVPCollection(); nvpDictionary=nvpCollection.ToDictionary(); - nvpDictionaryKeys=new ObservableCollection(nvpDictionary.Keys); + List dictionaryKeys=new List(nvpDictionary.Keys); + dictionaryKeys.Sort(); + nvpDictionaryKeys=new ObservableCollection(dictionaryKeys); selectedParameter=nvpDictionaryKeys[0]; positions=new MGSHPositionModelCollection(); positions.Add(sessionParams.ActivePositions); // active positions will go into their assigned slot + positions.Add(sessionParams.HedgePositions, sessionParams.ActivePositions.GetMaxSlotNumber()+1); // -1 is a special slot so active hedge positions will always appear in the slot position 1 past the max positions.Add(sessionParams.AllPositions); - //// positions.Add(sessionParams.HedgePositions, -1); // hedge positions will go into slot -1 UpdatePositionPrices(false); UpdatePositionRSI3(true); RunPerformance(); @@ -1393,7 +1396,7 @@ namespace TradeBlotter.ViewModels } catch(Exception exception) { - MessageBox.Show(String.Format("Unable to open {0}",pathFileName)); + MessageBox.Show(String.Format("Unable to open {0}",pathFileName),"Error",MessageBoxButton.OK,MessageBoxImage.Exclamation ,MessageBoxResult.OK,MessageBoxOptions.DefaultDesktopOnly); pathFileName=null; return false; } diff --git a/ViewModels/MainWindowViewModel.cs b/ViewModels/MainWindowViewModel.cs index f9225aa..13f0070 100644 --- a/ViewModels/MainWindowViewModel.cs +++ b/ViewModels/MainWindowViewModel.cs @@ -57,6 +57,7 @@ namespace TradeBlotter.ViewModels }; Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() => { HeadlinesThreadProc(); }), DispatcherPriority.Normal); } + private void DisplaySplashScreen() { if(System.Diagnostics.Debugger.IsAttached)return; @@ -90,8 +91,6 @@ namespace TradeBlotter.ViewModels { workspaceViewModel.Dispose(); } -// PriceCache.GetInstance().Dispose(); -// try{MGPriceCache.GetInstance().Dispose();}catch(Exception){;} try{LocalPriceCache.GetInstance().Dispose();}catch(Exception){;} try{GBPriceCache.GetInstance().Dispose();}catch(Exception){;} try{PriceCache.GetInstance().Dispose();}catch(Exception){;} @@ -123,7 +122,20 @@ namespace TradeBlotter.ViewModels { try { - System.Windows.Controls.MenuItem menuItem=new System.Windows.Controls.MenuItem() { Header = viewModel.Title,Command = new RelayCommand(param=>{this.SetActiveWorkspace(viewModel);return;})}; + System.Windows.Controls.MenuItem menuItem=new System.Windows.Controls.MenuItem() + { + Name = "MainWindowViewModelMenu", + Header = viewModel.Title,Command = new RelayCommand(param=> + { + this.SetActiveWorkspace(viewModel); + return; + } + ), + HorizontalAlignment=HorizontalAlignment.Left, + VerticalAlignment=VerticalAlignment.Center, + VerticalContentAlignment=VerticalAlignment.Center, + HorizontalContentAlignment=HorizontalAlignment.Left + }; menuItem.FontWeight=FontWeights.DemiBold; menuItem.FontStyle=FontStyles.Italic; @@ -141,8 +153,12 @@ namespace TradeBlotter.ViewModels multiBinding.Bindings.Add(headerBinding); multiBinding.Converter=new NameMultiValueConverter(); BindingOperations.SetBinding(menuItem,System.Windows.Controls.MenuItem.HeaderProperty,multiBinding); + menuCollection.Add(menuItem); - if(!menuCollectionDictionary.ContainsKey(viewModel))menuCollectionDictionary.Add(viewModel,menuItem); + if(!menuCollectionDictionary.ContainsKey(viewModel)) + { + menuCollectionDictionary.Add(viewModel,menuItem); + } UIServices.SortMenuItems(menuCollection); } catch(Exception exception) @@ -152,7 +168,6 @@ namespace TradeBlotter.ViewModels finally { } - // base.OnPropertyChanged("MenuItems"); } public void RemoveMenuItem(WorkspaceViewModel viewModel) { @@ -165,7 +180,6 @@ namespace TradeBlotter.ViewModels // **************************************************************************************************************************************************************** public void InstantiateWorkspace(SaveParameters saveParameters) { -// WorkspacePersistenceHelper.Load(saveParameters, workspaces,InstantiateWorkspace); WorkspaceViewModel workspaceViewModel=WorkspacePersistenceHelper.Load(saveParameters, workspaces, InstantiateWorkspace); AddMenuItem(workspaceViewModel); } @@ -243,12 +257,20 @@ namespace TradeBlotter.ViewModels private void OnWorkspacesChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.NewItems != null && e.NewItems.Count != 0) + { foreach (WorkspaceViewModel workspace in e.NewItems) + { workspace.RequestClose += this.OnWorkspaceRequestClose; + } + } if (e.OldItems != null && e.OldItems.Count != 0) + { foreach (WorkspaceViewModel workspace in e.OldItems) + { workspace.RequestClose -= this.OnWorkspaceRequestClose; + } + } } private void OnWorkspaceRequestClose(object sender, EventArgs e) { @@ -259,7 +281,8 @@ namespace TradeBlotter.ViewModels RemoveMenuItem(workspace); if(null!=workspace.Referer)this.SetActiveWorkspace(workspace.Referer); } - // ********************************************************************************************************************************************************* + + // ********************************************************************************************************************************************************* private void ShowAllTrades() { BlotterViewModel workspace = this.Workspaces.FirstOrDefault(vm => vm is BlotterViewModel) as BlotterViewModel; @@ -288,7 +311,6 @@ namespace TradeBlotter.ViewModels BlotterTradeModel trade = TradeRepository.GetInstance().GetTrade(tradeId); if(null==trade)return; trade=trade.Clone(); -// workspace = new TradeEntryViewModel(trade, TradeRepository.GetInstance(),false); workspace=new TradeEntryViewModel(trade,TradeRepository.GetInstance()); this.Workspaces.Add(workspace); } diff --git a/ViewModels/MomentumViewModel.cs b/ViewModels/MomentumViewModel.cs index c7b6aac..4ac36cf 100644 --- a/ViewModels/MomentumViewModel.cs +++ b/ViewModels/MomentumViewModel.cs @@ -1132,7 +1132,9 @@ namespace TradeBlotter.ViewModels configuration=sessionParams.Configuration; NVPCollection nvpCollection=sessionParams.Configuration.ToNVPCollection(); nvpDictionary=nvpCollection.ToDictionary(); - nvpDictionaryKeys=new ObservableCollection(nvpDictionary.Keys); + List dictionaryKeys=new List(nvpDictionary.Keys); + dictionaryKeys.Sort(); + nvpDictionaryKeys=new ObservableCollection(dictionaryKeys); selectedParameter=nvpDictionaryKeys[0]; positions=new MGPositionModelCollection(); positions.Add(sessionParams.ActivePositions); diff --git a/ViewModels/ViewModelBase.cs b/ViewModels/ViewModelBase.cs index 177e359..9c29802 100644 --- a/ViewModels/ViewModelBase.cs +++ b/ViewModels/ViewModelBase.cs @@ -46,15 +46,23 @@ namespace TradeBlotter.ViewModels protected ViewModelBase() { } + public abstract SaveParameters GetSaveParameters(); + public abstract void SetSaveParameters(SaveParameters saveParameters); + public abstract bool CanPersist(); + public virtual void Dispose() { this.OnDispose(); } - public virtual String DisplayName { get; protected set; } + public virtual String DisplayName + { + get; + protected set; + } protected virtual void OnDispose() { diff --git a/ViewModels/WorkspaceViewModel.cs b/ViewModels/WorkspaceViewModel.cs index ef71a76..9fb4703 100644 --- a/ViewModels/WorkspaceViewModel.cs +++ b/ViewModels/WorkspaceViewModel.cs @@ -4,23 +4,30 @@ using System.Windows.Input; using System.Linq; using System.Text; using TradeBlotter.Command; +using Telerik.Windows.Input.Touch; namespace TradeBlotter.ViewModels { public delegate void InstantiateWorkspace(SaveParameters saveParameters); public abstract class WorkspaceViewModel : ViewModelBase { +// Relay Command private RelayCommand closeCommand; + +// Events public event EventHandler RequestClose; + private InstantiateWorkspace workspaceInstantiator; private bool canClose=true; private bool isClosed=false; + private String title="WorkspaceViewModel"; public WorkspaceViewModel Referer{get;set;} protected WorkspaceViewModel() { } + public InstantiateWorkspace WorkspaceInstantiator { get @@ -32,14 +39,19 @@ namespace TradeBlotter.ViewModels workspaceInstantiator = value; } } + public ICommand CloseCommand { get { - if (null == closeCommand) closeCommand = new RelayCommand(param => this.OnRequestClose()); + if (null == closeCommand) + { + closeCommand = new RelayCommand(param => this.OnRequestClose()); + } return closeCommand; } } + public bool IsClosed { get { return isClosed; } @@ -52,6 +64,7 @@ namespace TradeBlotter.ViewModels } } } + public bool CanClose { get { return canClose; } @@ -64,6 +77,7 @@ namespace TradeBlotter.ViewModels } } } + public virtual String Title { get @@ -76,6 +90,15 @@ namespace TradeBlotter.ViewModels base.OnPropertyChanged("Title"); } } + + public virtual String Header + { + get + { + return title; + } + } + private void OnRequestClose() { EventHandler handler = this.RequestClose; diff --git a/Views/AnalystRatingsView.xaml b/Views/AnalystRatingsView.xaml index 5f1a979..b22b95d 100644 --- a/Views/AnalystRatingsView.xaml +++ b/Views/AnalystRatingsView.xaml @@ -30,7 +30,8 @@ - + + @@ -38,7 +39,8 @@ - + + diff --git a/Views/CMMomentumView.xaml b/Views/CMMomentumView.xaml index 8a2e201..b82d73f 100644 --- a/Views/CMMomentumView.xaml +++ b/Views/CMMomentumView.xaml @@ -34,7 +34,9 @@ - + + + @@ -232,7 +234,7 @@ - + diff --git a/Views/CMTTrendView.xaml b/Views/CMTTrendView.xaml index 12f28f9..3dbc856 100644 --- a/Views/CMTTrendView.xaml +++ b/Views/CMTTrendView.xaml @@ -36,7 +36,9 @@ - + + + @@ -132,7 +134,6 @@ - @@ -327,7 +328,7 @@ - + @@ -362,7 +363,7 @@ - + diff --git a/Views/HeadlinesView.xaml b/Views/HeadlinesView.xaml index c668008..3035366 100644 --- a/Views/HeadlinesView.xaml +++ b/Views/HeadlinesView.xaml @@ -50,16 +50,18 @@ - - + + + - - + + + diff --git a/Views/MGSHMomentumView.xaml b/Views/MGSHMomentumView.xaml index a48de8d..5a26802 100644 --- a/Views/MGSHMomentumView.xaml +++ b/Views/MGSHMomentumView.xaml @@ -36,10 +36,8 @@ - + - - @@ -116,11 +114,17 @@ + + + + + + @@ -158,7 +162,6 @@ - @@ -171,7 +174,6 @@ - @@ -248,7 +250,7 @@ - + @@ -259,6 +261,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -337,57 +392,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -412,8 +416,6 @@ - - diff --git a/Views/MomentumView.xaml b/Views/MomentumView.xaml index b448ddf..7a6f368 100644 --- a/Views/MomentumView.xaml +++ b/Views/MomentumView.xaml @@ -33,7 +33,10 @@ - + + + + @@ -251,7 +254,7 @@ - + diff --git a/Views/SECFilingView.xaml b/Views/SECFilingView.xaml index 69230aa..ede1446 100644 --- a/Views/SECFilingView.xaml +++ b/Views/SECFilingView.xaml @@ -26,7 +26,8 @@ - + + diff --git a/Views/TradeModelView.xaml b/Views/TradeModelView.xaml index 7ac8deb..2261998 100644 --- a/Views/TradeModelView.xaml +++ b/Views/TradeModelView.xaml @@ -32,7 +32,8 @@ - + + diff --git a/Views/WatchListView.xaml b/Views/WatchListView.xaml index 115de08..c0f6ba0 100644 --- a/Views/WatchListView.xaml +++ b/Views/WatchListView.xaml @@ -30,16 +30,6 @@ - - -