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:
authorMichael Hutchinson <m.j.hutchinson@gmail.com>2011-11-17 03:44:24 +0400
committerMichael Hutchinson <m.j.hutchinson@gmail.com>2011-11-17 19:39:47 +0400
commitfeff890b6d7570a6676d54f42623b40c6a4e4090 (patch)
treece75efeb41bd4097807ce521925e4e2a29fe85c2 /main/src/core/MonoDevelop.Ide/MonoDevelop.Components
parentc8b60757713a28d0384fcaf77e6ea1922b904ee0 (diff)
Work around GTK context menu bug
Triggering context menu from a button press event (which is the correct thing to do) on mac is problematic because the release event sometimes causes the menu to hide again (e.g. sln pad but only when docked on left side). Work around this by triggering it on the release event instead.
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Components')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components/ContextMenuTreeView.cs104
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Components/GtkUtil.cs3
2 files changed, 106 insertions, 1 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/ContextMenuTreeView.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/ContextMenuTreeView.cs
new file mode 100644
index 0000000000..83c8aadb07
--- /dev/null
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/ContextMenuTreeView.cs
@@ -0,0 +1,104 @@
+//
+// ContextMenuTreeView.cs
+//
+// Author:
+// Michael Hutchinson <mhutch@xamarin.com>
+//
+// Copyright (c) 2011 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using Mono.TextEditor;
+
+namespace MonoDevelop.Components
+{
+ /// <summary>
+ /// TreeView with context menu support.
+ /// </summary>
+ public class ContextMenuTreeView : Gtk.TreeView
+ {
+ const Gdk.ModifierType selectionModifiers = Gdk.ModifierType.ShiftMask | Gdk.ModifierType.ControlMask;
+
+ public ContextMenuTreeView ()
+ {
+ }
+
+ public ContextMenuTreeView (Gtk.TreeModel model) : base (model)
+ {
+ }
+
+ public Action<Gdk.EventButton> DoPopupMenu { get; set; }
+
+ protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
+ {
+ bool res = false;
+ bool withModifier = (evnt.State & selectionModifiers) != 0;
+ if (IsClickedNodeSelected ((int)evnt.X, (int)evnt.Y) && MultipleNodesSelected () && !withModifier) {
+ res = true;
+ }
+
+ if (!res)
+ res = base.OnButtonPressEvent (evnt);
+
+ //HACK: show context menu in release event instead of show event to work around gtk bug
+ if (DoPopupMenu != null && evnt.TriggersContextMenu ()) {
+ // DoPopupMenu (evnt);
+ return true;
+ }
+
+ return res;
+ }
+
+ protected override bool OnButtonReleaseEvent (Gdk.EventButton evnt)
+ {
+ bool res = base.OnButtonReleaseEvent (evnt);
+
+ //HACK: show context menu in release event instead of show event to work around gtk bug
+ if (DoPopupMenu != null && evnt.IsContextMenuButton ()) {
+ DoPopupMenu (evnt);
+ return true;
+ }
+
+ return res;
+ }
+
+ protected override bool OnPopupMenu ()
+ {
+ if (DoPopupMenu != null) {
+ DoPopupMenu (null);
+ return true;
+ }
+ return base.OnPopupMenu ();
+ }
+
+ bool IsClickedNodeSelected (int x, int y)
+ {
+ Gtk.TreePath path;
+ if (this.GetPathAtPos (x, y, out path))
+ return this.Selection.PathIsSelected (path);
+ else
+ return false;
+ }
+
+ bool MultipleNodesSelected ()
+ {
+ return this.Selection.GetSelectedRows ().Length > 1;
+ }
+ }
+} \ No newline at end of file
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/GtkUtil.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/GtkUtil.cs
index 5b36081558..4f3d39c277 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/GtkUtil.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/GtkUtil.cs
@@ -376,6 +376,7 @@ namespace MonoDevelop.Components
public Gdk.ScrollDirection direction;
public IntPtr device;
public double x_root;
- public double y_root;
+ public double y_root;
+ //FIXME: scroll deltas
}
}