From 598356fe86ffb6b146655228fa8d8ad42c05fe14 Mon Sep 17 00:00:00 2001 From: Gabor Apati-Nagy Date: Mon, 18 May 2015 17:51:46 +0100 Subject: [PATCH] CA-147164: Filter by status doesn't notice changes of status Fixed the bug by subscribing to events of all actions and not only to the ones that are displayed in the grid. Besides this, the visibility of the row is being used instead of removing and re-adding rows on status changes. Signed-off-by: Gabor Apati-Nagy --- XenAdmin/TabPages/HistoryPage.cs | 54 ++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/XenAdmin/TabPages/HistoryPage.cs b/XenAdmin/TabPages/HistoryPage.cs index ebe275c35..5b2ed5d83 100644 --- a/XenAdmin/TabPages/HistoryPage.cs +++ b/XenAdmin/TabPages/HistoryPage.cs @@ -98,7 +98,6 @@ namespace XenAdmin.TabPages { case CollectionChangeAction.Add: var actions = new List(ConnectionsManager.History); - actions.RemoveAll(FilterAction); SortActions(actions); var index = actions.IndexOf(action); if (index > -1) @@ -124,8 +123,25 @@ namespace XenAdmin.TabPages Program.Invoke(Program.MainWindow, () => { var row = FindRowFromAction(sender); + if (row != null) - row.RefreshSelf(); + { + //the row is already in the grid, refresh and show or hide it + if (!FilterAction(sender)) + { + row.RefreshSelf(); + row.Visible = true; + } + else + { + row.Visible = false; + } + } + else if (!FilterAction(sender)) + { + //adding the row to the grid, because it has not been there and now it should be visible based on active filters + CreateActionRow(sender); + } UpdateButtons(); }); @@ -158,20 +174,17 @@ namespace XenAdmin.TabPages dataGridView.SuspendLayout(); dataGridView.Rows.Clear(); - var actions = new List(ConnectionsManager.History); - actions.RemoveAll(FilterAction); + //creating a sorted list of actions that should currently be visible + var actions = ConnectionsManager.History.Where(a => !FilterAction(a)).ToList(); SortActions(actions); - - var rows = new List(); - foreach (ActionBase action in actions) - { - var row = CreateActionRow(action); - rows.Add(row); - } + + //adding a row to the grid for each action + var rows = actions.Select(a => CreateActionRow(a)).ToList(); dataGridView.Rows.AddRange(rows.ToArray()); - foreach(var actionRow in rows) - RegisterActionEvents(actionRow.Action); + //registering to action events of all the actions + foreach (var action in ConnectionsManager.History) + RegisterActionEvents(action); SetFilterLabel(); } @@ -200,6 +213,11 @@ namespace XenAdmin.TabPages } } + /// + /// Returns true when the action needs to be filtered out + /// + /// + /// private bool FilterAction(ActionBase action) { bool hide = false; @@ -225,6 +243,7 @@ namespace XenAdmin.TabPages private DataGridViewActionRow CreateActionRow(ActionBase action) { var row = new DataGridViewActionRow(action); + row.Visible = !FilterAction(action); row.DismissalRequested += row_DismissalRequested; row.GoToXenObjectRequested += row_GoToXenObjectRequested; return row; @@ -240,11 +259,12 @@ namespace XenAdmin.TabPages private void RemoveActionRow(ActionBase action) { + action.Changed -= action_Changed; + action.Completed -= action_Changed; + var row = FindRowFromAction(action); if (row != null) { - action.Changed -= action_Changed; - action.Completed -= action_Changed; dataGridView.Rows.Remove(row); } } @@ -387,7 +407,7 @@ namespace XenAdmin.TabPages } var actions = result == DialogResult.No - ? (from DataGridViewActionRow row in dataGridView.Rows where row.Action != null && row.Action.IsCompleted select row.Action) + ? (from DataGridViewActionRow row in dataGridView.Rows where row.Action != null && row.Action.IsCompleted && row.Visible select row.Action) : ConnectionsManager.History.Where(action => action != null && action.IsCompleted); ConnectionsManager.History.RemoveAll(actions.Contains); @@ -405,7 +425,7 @@ namespace XenAdmin.TabPages return; } - var actions = from DataGridViewActionRow row in dataGridView.SelectedRows where row != null && row.Action != null && row.Action.IsCompleted select row.Action; + var actions = from DataGridViewActionRow row in dataGridView.SelectedRows where row != null && row.Action != null && row.Action.IsCompleted && row.Visible select row.Action; ConnectionsManager.History.RemoveAll(actions.Contains); }