From 96651e4173d9a620c6868db77ff0bd1252b42781 Mon Sep 17 00:00:00 2001 From: Victor Chelaru Date: Mon, 22 Jan 2024 07:13:02 -0700 Subject: [PATCH] Adding or removing favorites updates main window in realtime. --- .../MainRecentFilesPlugin.cs | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/LoadRecentFilesPlugin/MainRecentFilesPlugin.cs b/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/LoadRecentFilesPlugin/MainRecentFilesPlugin.cs index 7a0c63c17..def6924e9 100644 --- a/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/LoadRecentFilesPlugin/MainRecentFilesPlugin.cs +++ b/FRBDK/Glue/Glue/Plugins/EmbeddedPlugins/LoadRecentFilesPlugin/MainRecentFilesPlugin.cs @@ -53,7 +53,7 @@ private void RefreshMenuItems() } } - recentFilesMenuItem.DropDownItems.Add(L.Texts.More, null, HandleLoadRecentClicked); + recentFilesMenuItem.DropDownItems.Add(L.Texts.More, null, HandleMoreClicked); void AddToRecentFilesMenuItem(RecentFileSave item) { @@ -77,7 +77,7 @@ void AddToRecentFilesMenuItem(RecentFileSave item) } } - private async void HandleLoadRecentClicked(object sender, EventArgs e) + private async void HandleMoreClicked(object sender, EventArgs e) { var viewModel = new LoadRecentViewModel(); var recentFiles = GlueState.Self.GlueSettingsSave?.RecentFileList; @@ -93,10 +93,11 @@ private async void HandleLoadRecentClicked(object sender, EventArgs e) }; vm.RemoveClicked += () => HandleRemovedRecentFile(vm, viewModel); viewModel.AllItems.Add(vm); - } } + + viewModel.RefreshFilteredItems(); var window = new LoadRecentWindow(); @@ -127,6 +128,28 @@ private async void HandleLoadRecentClicked(object sender, EventArgs e) GlueCommands.Self.GluxCommands.SaveSettings(); } + foreach (var item in viewModel.AllItems) + { + item.PropertyChanged += (sender, args) => + { + if (args.PropertyName == nameof(item.IsFavorite)) + { + var isFavorite = item.IsFavorite; + + var existing = GlueSettings.RecentFileList.FirstOrDefault(candidate => candidate.FileName == item.FullPath); + + if (existing != null) + { + existing.IsFavorite = isFavorite; + } + + GlueCommands.Self.GluxCommands.SaveSettings(); + + RefreshMenuItems(); + + } + }; + } } private void HandleRemovedRecentFile(RecentItemViewModel vm, LoadRecentViewModel mainViewModel)