diff options
author | Marius Ungureanu <therzok@gmail.com> | 2017-04-28 15:33:47 +0300 |
---|---|---|
committer | Marius Ungureanu <therzok@gmail.com> | 2017-05-03 23:51:45 +0300 |
commit | 8b512a6efcaaf266e91325e304d778a4def96b4c (patch) | |
tree | a318f233ff2b7547bbd98bc7b0cf75e5596ba1a9 /main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook | |
parent | 0c4a18f2b8057ee07f74b697b0403e86df05dc4b (diff) |
[Ide] Fix leak of document tabs.
The tabstrip code was not removing the tabs from the tabstrip list. Fix this by correctly using the events.
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook/DockNotebook.cs | 15 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook/TabStrip.cs | 71 |
2 files changed, 34 insertions, 52 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook/DockNotebook.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook/DockNotebook.cs index c06a73ef6b..eac94c4102 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook/DockNotebook.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook/DockNotebook.cs @@ -36,7 +36,7 @@ using MonoDevelop.Core; namespace MonoDevelop.Components.DockNotebook { - delegate void TabsReorderedHandler (Widget widget, int oldPlacement, int newPlacement); + delegate void TabsReorderedHandler (DockNotebookTab tab, int oldPlacement, int newPlacement); class DockNotebook : Gtk.VBox { @@ -135,8 +135,8 @@ namespace MonoDevelop.Components.DockNotebook public event EventHandler<TabEventArgs> TabClosed; public event EventHandler<TabEventArgs> TabActivated; - public event EventHandler PageAdded; - public event EventHandler PageRemoved; + public event EventHandler<TabEventArgs> PageAdded; + public event EventHandler<TabEventArgs> PageRemoved; public event EventHandler SwitchPage; public event EventHandler PreviousButtonClicked { @@ -315,8 +315,7 @@ namespace MonoDevelop.Components.DockNotebook tabStrip.Update (); tabStrip.DropDownButton.Sensitive = pages.Count > 0; - if (PageAdded != null) - PageAdded (this, EventArgs.Empty); + PageAdded?.Invoke (this, new TabEventArgs { Tab = tab, }); NotebookChanged?.Invoke (this, EventArgs.Empty); @@ -352,8 +351,7 @@ namespace MonoDevelop.Components.DockNotebook tabStrip.Update (); tabStrip.DropDownButton.Sensitive = pages.Count > 0; - if (PageRemoved != null) - PageRemoved (this, EventArgs.Empty); + PageRemoved?.Invoke (this, new TabEventArgs { Tab = tab }); NotebookChanged?.Invoke (this, EventArgs.Empty); } @@ -370,7 +368,8 @@ namespace MonoDevelop.Components.DockNotebook pages.Insert (targetPos + 1, tab); pages.RemoveAt (tab.Index); } - IdeApp.Workbench.ReorderDocuments (tab.Index, targetPos); + if (TabsReordered != null) + TabsReordered (tab, tab.Index, targetPos); UpdateIndexes (Math.Min (tab.Index, targetPos)); tabStrip.Update (); } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook/TabStrip.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook/TabStrip.cs index 1014b8fd9e..070fcab200 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook/TabStrip.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.DockNotebook/TabStrip.cs @@ -71,7 +71,6 @@ namespace MonoDevelop.Components.DockNotebook int animationTarget; Dictionary<int, DockNotebookTab> closingTabs; - List<DockNotebookTab> allTabs; public Button PreviousButton; public Button NextButton; @@ -218,16 +217,14 @@ namespace MonoDevelop.Components.DockNotebook QueueDraw (); } }; - - // Create a copy of the tabs so we can track which tabs have been added or removed - // for accessibility purposes. - allTabs = new List<DockNotebookTab> (); + foreach (var tab in notebook.Tabs) { - allTabs.Add (tab); - Accessible.AddAccessibleElement (tab.Accessible); + Accessible.AddAccessibleElement (tab.Accessible);
+ UpdateAccessibilityTabs (); } notebook.PageAdded += PageAddedHandler; notebook.PageRemoved += PageRemovedHandler; + notebook.TabsReordered += PageReorderedHandler; closingTabs = new Dictionary<int, DockNotebookTab> (); } @@ -240,60 +237,46 @@ namespace MonoDevelop.Components.DockNotebook base.OnDestroyed (); } - void PageAddedHandler (object sender, EventArgs args) + void PageAddedHandler (object sender, TabEventArgs args) { - int idx = 0; - foreach (var tab in notebook.Tabs) { - if (idx >= allTabs.Count || tab != allTabs [idx]) { - allTabs.Insert (idx, tab); - Accessible.AddAccessibleElement (tab.Accessible); - - tab.AccessibilityPressTab += OnAccessibilityPressTab; - tab.AccessibilityPressCloseButton += OnAccessibilityPressCloseButton; - tab.AccessibilityShowMenu += OnAccessibilityShowMenu; - break; - } - - idx++; - } + var tab = args.Tab;
+
+ Accessible.AddAccessibleElement (tab.Accessible);
+
+ tab.AccessibilityPressTab += OnAccessibilityPressTab;
+ tab.AccessibilityPressCloseButton += OnAccessibilityPressCloseButton;
+ tab.AccessibilityShowMenu += OnAccessibilityShowMenu; QueueResize (); UpdateAccessibilityTabs (); } - void PageRemovedHandler (object sender, EventArgs args) + void PageRemovedHandler (object sender, TabEventArgs args) { - int idx = 0; - foreach (var tab in notebook.Tabs) { - if (tab != allTabs [idx]) { - tab.AccessibilityPressTab -= OnAccessibilityPressTab; - tab.AccessibilityPressCloseButton -= OnAccessibilityPressCloseButton; - tab.AccessibilityShowMenu -= OnAccessibilityShowMenu; - - Accessible.RemoveAccessibleElement (tab.Accessible); - allTabs.RemoveAt (idx); - break; - } - - idx++; - } + var tab = args.Tab;
+
+ tab.AccessibilityPressTab -= OnAccessibilityPressTab;
+ tab.AccessibilityPressCloseButton -= OnAccessibilityPressCloseButton;
+ tab.AccessibilityShowMenu -= OnAccessibilityShowMenu;
+
+ Accessible.RemoveAccessibleElement (tab.Accessible); QueueResize (); UpdateAccessibilityTabs (); } - void UpdateAccessibilityTabs () + void PageReorderedHandler (DockNotebookTab tab, int oldPlacement, int newPlacement)
{ - int idx = 0; - var tabs = new AtkCocoaHelper.AccessibilityElementProxy [allTabs.Count]; + QueueResize (); - foreach (var tab in allTabs) { - tabs [idx] = tab.Accessible; - idx++; - } + UpdateAccessibilityTabs ();
+ } + void UpdateAccessibilityTabs () + { + var tabs = notebook.Tabs.OrderBy (x => x.Index).Select (x => x.Accessible).ToArray (); Accessible.SetTabs (tabs); } |