From cb8d13fe085e8bbc96c8531f0eda066e1b5f9e18 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:33:05 +0200 Subject: [PATCH] Fix closing tab causes browser to load the website of the first tab & some safety checks --- .../ViewModels/MainWindowViewModel.cs | 18 ++++++++- src/Markdowser/Views/MainWindow.axaml | 37 +++++++++++++++---- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/Markdowser/ViewModels/MainWindowViewModel.cs b/src/Markdowser/ViewModels/MainWindowViewModel.cs index 78dbad7..2c70421 100644 --- a/src/Markdowser/ViewModels/MainWindowViewModel.cs +++ b/src/Markdowser/ViewModels/MainWindowViewModel.cs @@ -47,7 +47,7 @@ public partial class MainWindowViewModel : ViewModelBase _ = this.RaiseAndSetIfChanged(ref currentTab!, value); - Url = currentTab?.Tag?.ToString() ?? string.Empty; + Url = value?.Tag?.ToString() ?? string.Empty; FetchUrl(); } @@ -132,18 +132,32 @@ public partial class MainWindowViewModel : ViewModelBase public ICommand CloseTab => ReactiveCommand.Create(() => { + if (IsBusy) + { + WindowNotificationManager.Show(new Notification("Busy", "The browser is currently busy.", NotificationType.Warning)); + return; + } + if (Tabs.Count > 1) { int currentIndex = Tabs.IndexOf(CurrentTab); - _ = Tabs.Remove(CurrentTab); CurrentTab = currentIndex > 0 ? Tabs[currentIndex - 1] : Tabs[0]; + + Tabs.RemoveAt(currentIndex); + this.RaisePropertyChanged(nameof(CloseTabEnabled)); } }); public ICommand NewTab => ReactiveCommand.Create(() => { + if (IsBusy) + { + WindowNotificationManager.Show(new Notification("Busy", "The browser is currently busy.", NotificationType.Warning)); + return; + } + TabItem tab = new() { Header = "New Tab", Name = Guid.NewGuid().ToString() }; Tabs.Add(tab); CurrentTab = tab; diff --git a/src/Markdowser/Views/MainWindow.axaml b/src/Markdowser/Views/MainWindow.axaml index e634897..16f77a7 100644 --- a/src/Markdowser/Views/MainWindow.axaml +++ b/src/Markdowser/Views/MainWindow.axaml @@ -45,9 +45,16 @@ - - + + +