copy.paste.file.names
[tfs.git] / class / Gtk.TeamFoundation / DirectoryView.cs
blob695a5001151cbc8548453ebc7f6ab5300506b4cd
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 public static class ColumnIndex
46 public static int Name = 1;
47 public static int Status = 2;
48 public static int Owner = 3;
49 public static int Latest = 4;
50 public static int ServerPath = 5;
51 public static int ItemType = 6;
54 private ExploreView exploreView;
55 private Gtk.ListStore store;
56 private SortableColumns sortableColumns;
57 private VersionControlServer currentVcs;
58 private DirectoryMenu menu;
60 public DirectoryView(ExploreView exploreView)
62 this.exploreView = exploreView;
63 menu = new DirectoryMenu(exploreView);
65 store = new Gtk.ListStore(typeof(Gdk.Pixbuf), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(ItemType));
66 Model = store;
68 sortableColumns = new SortableColumns(this, store);
70 #if HAVE_ATLEAST_GTK_210
71 EnableGridLines = TreeViewGridLines.Vertical;
72 #endif
73 // setup main column with image/text data
74 TreeViewColumn column = new TreeViewColumn ();
75 CellRendererText crt = new CellRendererText();
76 CellRendererPixbuf crp = new CellRendererPixbuf();
77 column.Title = "Name";
78 column.PackStart(crp, false);
79 column.PackStart(crt, true);
80 column.AddAttribute(crp, "pixbuf", 0);
81 column.AddAttribute(crt, "text", 1);
82 AppendColumn(column);
83 AppendColumn("Status", ColumnIndex.Status);
84 AppendColumn("Owner", ColumnIndex.Owner);
85 AppendColumn("Latest", ColumnIndex.Latest);
87 Selection.Mode = SelectionMode.Multiple;
88 KeyReleaseEvent += MyKeyReleaseEventHandler;
89 ButtonPressEvent += MyButtonPressEventHandler;
92 private TreeViewColumn AppendColumn(string name, int indx)
94 TreeViewColumn column = AppendColumn(name, new Gtk.CellRendererText (), "text", indx);
96 column.Clickable = true;
97 column.Resizable = true;
98 column.SortColumnId = indx;
99 column.Clicked += new EventHandler(sortableColumns.OnColumnClick);
101 return column;
104 [GLib.ConnectBefore]
105 protected void MyButtonPressEventHandler (object o, ButtonPressEventArgs args)
107 if (args.Event.Type == Gdk.EventType.TwoButtonPress)
108 OnShowFile();
111 private void OnShowFile()
113 TreeIter iter; TreeModel model;
114 TreePath[] paths = Selection.GetSelectedRows(out model);
116 if (paths.Length == 1)
118 model.GetIter(out iter, paths[0]);
119 string serverItem = Convert.ToString(model.GetValue(iter, ColumnIndex.ServerPath));
121 ItemType itemType = (ItemType) model.GetValue(iter, ColumnIndex.ItemType);
122 if (itemType == ItemType.Folder)
123 UpdatePath(currentVcs, serverItem);
124 else
126 ShowFileEventArgs sfArgs = new ShowFileEventArgs(currentVcs, serverItem);
127 exploreView.OnShowFile(this, sfArgs);
132 public void MyKeyReleaseEventHandler (object o, KeyReleaseEventArgs args)
134 if (Gdk.Key.Return == args.Event.Key)
135 OnShowFile();
136 else if ((Gdk.Key.c == args.Event.Key) && ((args.Event.State & Gdk.ModifierType.ControlMask) != 0))
138 TreeIter iter; TreeModel model;
139 TreePath[] paths = Selection.GetSelectedRows(out model);
141 StringBuilder sb = new StringBuilder();
142 foreach (TreePath path in paths)
144 model.GetIter(out iter, path);
145 sb.Append(Convert.ToString(model.GetValue(iter, ColumnIndex.Name)));
148 Clipboard primary = Clipboard.Get(Gdk.Atom.Intern ("PRIMARY", false));
149 primary.Text = sb.ToString();
153 protected override void ShowPopupMenu(TreePath path)
155 //string tfpath = String.Empty;
156 //Workspace workspace = null;
158 if (path != null)
160 TreeIter iter;
161 store.GetIter(out iter, path);
162 //tfpath = store.GetValue(iter, ColumnIndex.Path).ToString();
165 //menu.Show(workspace, tfpath);
168 public void UpdatePath(VersionControlServer vcs, string path)
170 if (String.IsNullOrEmpty(path)) return;
171 currentVcs = vcs;
172 store.Clear();
174 ExtendedItem[] items = vcs.GetExtendedItems(path, DeletedState.NonDeleted, ItemType.Any);
176 foreach (ExtendedItem item in items)
178 if (item.TargetServerItem == path) continue;
180 string shortPath = item.TargetServerItem.Substring(item.TargetServerItem.LastIndexOf('/') + 1);
181 string latest = item.IsLatest ? "Yes" : "No";
183 string status = item.LockStatus.ToString();
184 if (status == "None") status = String.Empty;
186 Gdk.Pixbuf pixbuf = Images.File;
187 if (item.ItemType == ItemType.Folder) pixbuf = Images.Folder;
189 store.AppendValues(pixbuf, shortPath, status, item.LockOwner,
190 latest, item.TargetServerItem, item.ItemType);