From 0d0daa4ddb6cbf92129321f532101d40c02dadab Mon Sep 17 00:00:00 2001 From: Gabor Apati-Nagy Date: Mon, 8 Sep 2014 18:05:51 +0100 Subject: [PATCH] CA-143826: When in Notifications view, the context should be empty -I defined save and restore selection functionality in SelectionBroadcaster and implemented them in SelectionManager. The NavigationPanel now uses these to: 1) save the current Selection (context) when the user switches to the Notification view, 2) to restore previous selection when switching away from the Notifications view. --- XenAdmin/Commands/SelectionBroadcaster.cs | 3 +++ XenAdmin/Commands/SelectionManager.cs | 16 ++++++++++++++++ .../MainWindowControls/NavigationPane.cs | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/XenAdmin/Commands/SelectionBroadcaster.cs b/XenAdmin/Commands/SelectionBroadcaster.cs index 1eaa3fabf..78196e160 100644 --- a/XenAdmin/Commands/SelectionBroadcaster.cs +++ b/XenAdmin/Commands/SelectionBroadcaster.cs @@ -109,6 +109,9 @@ namespace XenAdmin.Commands /// public event EventHandler SelectionChanged; + public abstract void SaveAndClearSelection(); + public abstract void RestoreSavedSelection(); + #region IDisposable Members /// diff --git a/XenAdmin/Commands/SelectionManager.cs b/XenAdmin/Commands/SelectionManager.cs index 6cd7db7b3..fd46c3830 100644 --- a/XenAdmin/Commands/SelectionManager.cs +++ b/XenAdmin/Commands/SelectionManager.cs @@ -42,6 +42,7 @@ namespace XenAdmin.Commands internal class SelectionManager : SelectionBroadcaster { private SelectedItemCollection _selection = new SelectedItemCollection(); + private SelectedItemCollection savedSelection = new SelectedItemCollection(); /// /// Sets the main selection for XenCenter. @@ -86,5 +87,20 @@ namespace XenAdmin.Commands { SetSelection(Selection); } + + public override void SaveAndClearSelection() + { + savedSelection = new SelectedItemCollection(_selection); + SetSelection(new SelectedItemCollection()); + } + + public override void RestoreSavedSelection() + { + if (savedSelection != null) + { + SetSelection(new SelectedItemCollection(savedSelection)); + savedSelection = null; + } + } } } diff --git a/XenAdmin/Controls/MainWindowControls/NavigationPane.cs b/XenAdmin/Controls/MainWindowControls/NavigationPane.cs index 076d1700e..370d9f6f9 100644 --- a/XenAdmin/Controls/MainWindowControls/NavigationPane.cs +++ b/XenAdmin/Controls/MainWindowControls/NavigationPane.cs @@ -278,11 +278,15 @@ namespace XenAdmin.Controls.MainWindowControls { if (currentMode == NavigationMode.Notifications) { + SelectionManager.SaveAndClearSelection(); + //restore the last selected view SwitchToNotificationsView(lastNotificationsMode); } else { + SelectionManager.RestoreSavedSelection(); + //show the navigationView first and then hide the notificationsView //to avoid instantaneous appearance of empty panels navigationView.Visible = true;