support.left.arrow.for.collapsing.rows
[tfs.git] / class / Gtk.TeamFoundation / TreeViewBase.cs
blob4f9f4a3783eee56095c047d29024a8db2f30ac98
1 //
2 // TreeViewBase.cs
3 //
4 // Authors:
5 // Joel Reed (joelwreed@gmail.com)
6 //
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System;
30 using System.IO;
31 using System.Net;
32 using Gtk;
34 using Microsoft.TeamFoundation.Client;
35 using Microsoft.TeamFoundation.VersionControl.Common;
36 using Microsoft.TeamFoundation.VersionControl.Client;
38 namespace Gtk.TeamFoundation
40 public class TreeViewBase : Gtk.TreeView
42 public TreeViewBase()
44 RowExpanded += MyRowExpandedHandler;
45 ButtonPressEvent += MyButtonPressedHandler;
48 private void MyRowExpandedHandler (object o, RowExpandedArgs args)
50 PopulateRowChildren(args.Iter);
53 protected override bool OnKeyPressEvent(Gdk.EventKey evnt)
55 if (evnt.Key == Gdk.Key.Return || evnt.Key == Gdk.Key.Right)
57 TreeIter iter; TreeModel model;
59 if (Selection.GetSelected (out model, out iter))
61 TreePath path = model.GetPath(iter);
62 PopulateRowChildren(iter);
63 ExpandRow(path, false);
66 else if (evnt.Key == Gdk.Key.Left)
68 TreeIter iter; TreeModel model;
70 if (Selection.GetSelected (out model, out iter))
72 TreePath path = model.GetPath(iter);
73 CollapseRow(path);
77 return base.OnKeyPressEvent(evnt);
80 protected virtual void PopulateRowChildren (TreeIter iter)
84 protected Gtk.TreeIter SetRowValue(Gtk.TreeStore store, Gtk.TreeIter parent,
85 int childIndx, params object[] values)
87 Gtk.TreeIter child;
88 if (store.IterNthChild(out child, parent, childIndx))
90 for (int i=0; i < values.Length; i++)
92 if (null == values[i]) continue;
93 store.SetValue(child, i, values[i]);
96 else
97 child = store.AppendValues (parent, values);
99 return child;
102 [GLib.ConnectBefore]
103 void MyButtonPressedHandler (object o, ButtonPressEventArgs args)
105 if (args.Event.Button == 3)
107 int x = (int)args.Event.X;
108 int y = (int)args.Event.Y;
110 TreePath path = null;
111 GetPathAtPos(x, y, out path);
112 ShowPopupMenu(path);
116 protected virtual void ShowPopupMenu(TreePath path)