view.cleanups
[tfs.git] / class / Gtk.TeamFoundation / RepositoryView.cs
blob4ce9bfc26f7bb9fc4acd9bc061129e53bf8a1b8b
1 using System;
2 using System.IO;
3 using System.Net;
4 using Gtk;
6 using Microsoft.TeamFoundation.Client;
7 using Microsoft.TeamFoundation.VersionControl.Common;
8 using Microsoft.TeamFoundation.VersionControl.Client;
10 namespace Gtk.TeamFoundation
12 public class RepositoryView : Gtk.TreeView
14 private TreeStore store = new TreeStore(typeof(string), typeof(string));
15 private ICredentialsProvider credentialsProvider;
17 public RepositoryView(ICredentialsProvider credentialsProvider)
19 this.credentialsProvider = credentialsProvider;
20 AppendColumn("name", new CellRendererText (), "text", 0);
22 WorkspaceInfo[] infos = Workstation.Current.GetAllLocalWorkspaceInfo();
23 foreach (WorkspaceInfo info in infos)
25 Gtk.TreeIter serverIter = store.AppendValues(info.ServerUri.ToString(), VersionControlPath.RootFolder);
26 store.AppendValues(serverIter, "", "");
29 Model = store;
30 HeadersVisible = false;
32 ShowAll();
33 RowExpanded += MyRowExpandedHandler;
36 private void MyRowExpandedHandler (object o, RowExpandedArgs args)
38 string path = store.GetValue(args.Iter, 1).ToString();
40 string url = String.Empty;
41 TreeIter iterParent;
43 TreeIter current = args.Iter;
44 while (store.IterParent(out iterParent, current))
46 current = iterParent;
48 url = store.GetValue(current, 0).ToString();
50 //Console.WriteLine("path=" + path + ", url=" + url);
52 ICredentials credentials = credentialsProvider.GetCredentials(new Uri(url), null);
53 TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(url, credentials);
54 VersionControlServer versionControlServer = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
56 int indx = 0;
57 ItemSpec itemSpec = new ItemSpec (path, RecursionType.OneLevel);
58 ItemSet itemSet = versionControlServer.GetItems (itemSpec, VersionSpec.Latest,
59 DeletedState.NonDeleted, ItemType.Any, false);
60 if (itemSet.Items.Length == 0)
61 SetRowValue(args.Iter, indx, " - item list not available - ", "");
63 foreach (Microsoft.TeamFoundation.VersionControl.Client.Item item in itemSet.Items)
65 if (item.ServerItem == path) continue;
67 string shortPath = item.ServerItem.Substring(item.ServerItem.LastIndexOf('/') + 1);
68 if (item.ItemType == ItemType.Folder)
69 shortPath += "/";
71 Gtk.TreeIter child = SetRowValue(args.Iter, indx, shortPath, item.ServerItem);
73 if (item.ItemType == ItemType.Folder)
74 store.AppendValues(child, "", "");
76 indx++;
80 private Gtk.TreeIter SetRowValue(Gtk.TreeIter parent, int childIndx,
81 string cell1, string cell2)
83 Gtk.TreeIter child;
84 if (store.IterNthChild(out child, parent, childIndx))
86 store.SetValue(child, 0, cell1);
87 store.SetValue(child, 1, cell2);
89 else
90 child = store.AppendValues (parent, cell1, cell2);
92 return child;