Control-C will copy currently selected path to the clipboard.
[tfs.git] / tools / tf / RepositoryView.cs
blob4b6a8b9aba0686636f3e5f08051a8f7cf87e528a
1 using System;
2 using System.Net;
3 using Gtk;
4 using Microsoft.TeamFoundation.Client;
5 using Microsoft.TeamFoundation.VersionControl.Common;
6 using Microsoft.TeamFoundation.VersionControl.Client;
8 public class RepositoryView : Gtk.TreeView
10 private Gtk.TreeStore itemStore;
11 private Driver driver;
13 private Gtk.TreeIter SetRowValue(Gtk.TreeIter parent, int childIndx,
14 string cell1, string cell2)
16 Gtk.TreeIter child;
17 if (itemStore.IterNthChild(out child, parent, childIndx))
19 itemStore.SetValue(child, 0, cell1);
20 itemStore.SetValue(child, 1, cell2);
22 else
23 child = itemStore.AppendValues (parent, cell1, cell2);
25 return child;
28 private void MyRowExpandedHandler (object o, RowExpandedArgs args)
30 string path = itemStore.GetValue(args.Iter, 1).ToString() + "/*";
31 //Console.WriteLine(path);
33 int indx = 0;
34 Microsoft.TeamFoundation.VersionControl.Client.Item[] items = ItemsForPath(path);
35 if (items.Length == 0)
36 SetRowValue(args.Iter, indx, " - item list not available - ", "");
38 foreach (Microsoft.TeamFoundation.VersionControl.Client.Item item in items)
40 string shortPath = item.ServerItem.Substring(item.ServerItem.LastIndexOf('/') + 1);
41 if (item.ItemType == ItemType.Folder)
42 shortPath += "/";
44 Gtk.TreeIter child = SetRowValue(args.Iter, indx, shortPath, item.ServerItem);
46 if (item.ItemType == ItemType.Folder)
47 itemStore.AppendValues(child, "", "");
49 indx++;
53 private Microsoft.TeamFoundation.VersionControl.Client.Item[] ItemsForPath(string path)
55 ItemSpec itemSpec = new ItemSpec (path, RecursionType.OneLevel);
56 ItemSet itemSet = driver.VersionControlServer.GetItems (itemSpec, VersionSpec.Latest,
57 DeletedState.NonDeleted, ItemType.Any, false);
59 return itemSet.Items;
62 public RepositoryView(Driver driver)
64 this.driver = driver;
65 HeadersVisible = false;
67 AppendColumn ("", new Gtk.CellRendererText (), "text", 0);
68 TreeViewColumn fullPath = AppendColumn ("", new Gtk.CellRendererText (), "text", 0);
69 fullPath.Visible = false;
71 itemStore = new Gtk.TreeStore (typeof (string), typeof (string));
72 Gtk.TreeIter root = itemStore.AppendValues(VersionControlPath.RootFolder, VersionControlPath.RootFolder);
74 Microsoft.TeamFoundation.VersionControl.Client.Item[] items = ItemsForPath("$/");
75 foreach (Microsoft.TeamFoundation.VersionControl.Client.Item item in items)
77 if (item.ServerItem == VersionControlPath.RootFolder) continue;
79 string shortPath = item.ServerItem.Substring(item.ServerItem.LastIndexOf('/') + 1) + "/";
80 Gtk.TreeIter iter = itemStore.AppendValues (root, shortPath, item.ServerItem);
82 itemStore.AppendValues(iter, "");
85 Model = itemStore;
87 ExpandRow(TreePath.NewFirst(), false);
88 RowExpanded += MyRowExpandedHandler;
89 KeyReleaseEvent += MyKeyReleaseEventHandler;
92 public void MyKeyReleaseEventHandler (object o, KeyReleaseEventArgs args)
94 if ((Gdk.Key.c == args.Event.Key) && ((args.Event.State & Gdk.ModifierType.ControlMask) != 0))
96 TreeIter iter;
97 TreeModel model;
98 if (!(Selection.GetSelected (out model, out iter))) return;
100 string path = model.GetValue(iter, 1).ToString();
101 Clipboard primary = Clipboard.Get(Gdk.Atom.Intern ("PRIMARY", false));
102 primary.Text = path;