more.gui.work
[tfs.git] / class / Gtk.TeamFoundation / DirectoryView.cs
blob4cac2b155f838743fe6cb9be5bffef7b769c86ec
1 //
2 // DirectoryView.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.Collections;
32 using System.Collections.Generic;
33 using System.Net;
34 using System.Text;
35 using Gtk;
36 using Microsoft.TeamFoundation.Client;
37 using Microsoft.TeamFoundation.VersionControl.Common;
38 using Microsoft.TeamFoundation.VersionControl.Client;
40 namespace Gtk.TeamFoundation
42 public class DirectoryView : TreeViewBase, IExploreViewChild
44 private ExploreView exploreView;
45 private Gtk.ListStore store;
46 private SortableColumns sortableColumns;
47 private VersionControlServer currentVcs;
48 private DirectoryMenu menu;
50 public DirectoryView(ExploreView exploreView)
52 this.exploreView = exploreView;
53 menu = new DirectoryMenu(exploreView);
55 store = new Gtk.ListStore(typeof(Gdk.Pixbuf), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string));
56 Model = store;
58 sortableColumns = new SortableColumns(this, store);
60 #if HAVE_ATLEAST_GTK_210
61 EnableGridLines = TreeViewGridLines.Vertical;
62 #endif
63 // setup main column with image/text data
64 TreeViewColumn column = new TreeViewColumn ();
65 CellRendererText crt = new CellRendererText();
66 CellRendererPixbuf crp = new CellRendererPixbuf();
67 column.Title = "Name";
68 column.PackStart(crp, false);
69 column.PackStart(crt, true);
70 column.AddAttribute(crp, "pixbuf", 0);
71 column.AddAttribute(crt, "text", 1);
72 AppendColumn(column);
73 AppendColumn("Status", 2);
74 AppendColumn("Owner", 3);
75 AppendColumn("Latest", 4);
77 Selection.Mode = SelectionMode.Multiple;
78 KeyReleaseEvent += MyKeyReleaseEventHandler;
79 ButtonPressEvent += MyButtonPressEventHandler;
82 private TreeViewColumn AppendColumn(string name, int indx)
84 TreeViewColumn column = AppendColumn(name, new Gtk.CellRendererText (), "text", indx);
86 column.Clickable = true;
87 column.Resizable = true;
88 column.SortColumnId = indx;
89 column.Clicked += new EventHandler(sortableColumns.OnColumnClick);
91 return column;
94 [GLib.ConnectBefore]
95 protected void MyButtonPressEventHandler (object o, ButtonPressEventArgs args)
97 if (args.Event.Type == Gdk.EventType.TwoButtonPress)
98 OnShowFile();
101 private void OnShowFile()
103 TreeIter iter; TreeModel model;
104 TreePath[] paths = Selection.GetSelectedRows(out model);
106 if (paths.Length == 1)
108 model.GetIter(out iter, paths[0]);
109 string serverItem = Convert.ToString(model.GetValue(iter, 5));
111 ShowFileEventArgs sfArgs = new ShowFileEventArgs(currentVcs, serverItem);
112 exploreView.OnShowFile(this, sfArgs);
116 public void MyKeyReleaseEventHandler (object o, KeyReleaseEventArgs args)
118 if (Gdk.Key.Return == args.Event.Key)
119 OnShowFile();
122 protected override void ShowPopupMenu(TreePath path)
124 string tfpath = String.Empty;
125 Workspace workspace = null;
127 if (path != null)
129 TreeIter iter;
130 store.GetIter(out iter, path);
132 // tfpath = store.GetValue(iter, ColumnIndex.Path).ToString();
135 //menu.Show(workspace, tfpath);
138 public void UpdatePath(VersionControlServer vcs, string path)
140 if (String.IsNullOrEmpty(path)) return;
141 currentVcs = vcs;
142 store.Clear();
144 ExtendedItem[] items = vcs.GetExtendedItems(path, DeletedState.NonDeleted, ItemType.Any);
146 foreach (ExtendedItem item in items)
148 if (item.TargetServerItem == path) continue;
150 string shortPath = item.TargetServerItem.Substring(item.TargetServerItem.LastIndexOf('/') + 1);
151 string latest = item.IsLatest ? "Yes" : "No";
153 string status = item.LockStatus.ToString();
154 if (status == "None") status = String.Empty;
156 Gdk.Pixbuf pixbuf = Images.File;
157 if (item.ItemType == ItemType.Folder) pixbuf = Images.Folder;
159 store.AppendValues(pixbuf, shortPath, status, item.LockOwner, latest, item.TargetServerItem);