Skip to content

Commit

Permalink
Adding or removing favorites updates main window in realtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Jan 22, 2024
1 parent 0e119c0 commit 96651e4
Showing 1 changed file with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 96651e4

Please sign in to comment.