Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriain holmes <iain@xamarin.com>2018-01-31 14:48:50 +0300
committeriain holmes <iain@xamarin.com>2018-02-01 14:48:21 +0300
commitff17b483ffd259ba9e3dd05db96a5f627fdb81b7 (patch)
treef9d7456693e6c3f983f3621ce0195ca778e71b23 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components
parent21051dadfe98aac7bac09bbdba9f3e871fbb65c0 (diff)
[IDE] Use ContextMenu on the Errors and Tasks pad
Use the cross platform ContextMenu on for the Error and Tasks pads' popup menu. Means that - An ugly Gtk menu isn't used on Cocoa - Fixes refcycles and leaks Create a ColumnSelectorMenu for automatically generating context menus for hiding or showing treeview columns
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/PadTreeView.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/PadTreeView.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/PadTreeView.cs
index c4463dbef1..3dcbbc5cf8 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/PadTreeView.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/PadTreeView.cs
@@ -26,7 +26,10 @@
using System;
using System.Collections.Generic;
+using System.Text;
using Gtk;
+using MonoDevelop.Components;
+using MonoDevelop.Core;
namespace MonoDevelop.Ide.Gui.Components
{
@@ -120,5 +123,75 @@ namespace MonoDevelop.Ide.Gui.Components
renderer.FontDesc = IdeApp.Preferences.CustomPadFont;
renderers.Add (renderer);
}
+
+ // Util helper to check for column visibility
+ public bool IsAColumnVisible ()
+ {
+ foreach (var c in Columns) {
+ if (c.Visible) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ // A ContextMenu to hide and show columns.
+ public class ColumnSelectorMenu : ContextMenu
+ {
+ class ColumnSelectorMenuItem : CheckBoxContextMenuItem
+ {
+ TreeViewColumn column;
+
+ public ColumnSelectorMenuItem (TreeViewColumn column, string label) : base (label)
+ {
+ this.column = column;
+
+ Checked = column.Visible;
+ Clicked += OnItemClicked;
+ }
+
+ void OnItemClicked (object sender, EventArgs args)
+ {
+ column.Visible = Checked;
+ ColumnVisibilityChanged?.Invoke (this, EventArgs.Empty);
+ }
+
+ public event EventHandler ColumnVisibilityChanged;
+ }
+
+ string id;
+
+ public ColumnSelectorMenu (TreeView treeview, string restoreID, params string[] columnNames)
+ {
+ id = restoreID;
+
+ int i = 0;
+ foreach (var column in treeview.Columns) {
+ var name = i < columnNames.Length ? columnNames[i] : null;
+
+ var item = new ColumnSelectorMenuItem (column, string.IsNullOrEmpty(name) ? column.Title : name);
+ item.ColumnVisibilityChanged += OnColumnVisibilityChanged;
+
+ Add (item);
+
+ i++;
+ }
+ }
+
+ void OnColumnVisibilityChanged (object sender, EventArgs args)
+ {
+ StringBuilder builder = new StringBuilder ();
+ foreach (var c in Items) {
+ var item = c as CheckBoxContextMenuItem;
+ if (item == null) {
+ continue;
+ }
+ builder.AppendFormat ("{0};", item.Checked);
+ }
+ builder.Remove (builder.Length - 1, 1);
+
+ PropertyService.Set (id, builder.ToString ());
+ }
}
} \ No newline at end of file