5 // Joel Reed (joelwreed@gmail.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
31 using System
.Collections
;
32 using System
.Collections
.Generic
;
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
: ScrolledWindowBase
, IExploreViewChild
44 private Gtk
.TreeView directoryList
;
45 private Gtk
.ListStore directoryListStore
;
46 private SortableColumns sortableColumns
;
47 private VersionControlServer currentVcs
;
48 private ExploreView exploreView
;
49 private Gdk
.Pixbuf folderPixbuf
;
50 private Gdk
.Pixbuf filePixbuf
;
52 public DirectoryView(ExploreView exploreView
)
54 this.exploreView
= exploreView
;
55 directoryList
= new Gtk
.TreeView();
57 folderPixbuf
= IconTheme
.Default
.LoadIcon("folder", 16, (Gtk
.IconLookupFlags
)0);
58 filePixbuf
= IconTheme
.Default
.LoadIcon("gnome-fs-regular", 16, (Gtk
.IconLookupFlags
)0);
60 directoryListStore
= new Gtk
.ListStore(typeof(Gdk
.Pixbuf
), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string));
61 directoryList
.Model
= directoryListStore
;
62 sortableColumns
= new SortableColumns(directoryList
, directoryListStore
);
64 #if HAVE_ATLEAST_GTK_210
65 directoryList
.EnableGridLines
= TreeViewGridLines
.Vertical
;
67 // setup main column with image/text data
68 TreeViewColumn column
= new TreeViewColumn ();
69 CellRendererText crt
= new CellRendererText();
70 CellRendererPixbuf crp
= new CellRendererPixbuf();
71 column
.Title
= "Name";
72 column
.PackStart(crp
, false);
73 column
.PackStart(crt
, true);
74 column
.AddAttribute(crp
, "pixbuf", 0);
75 column
.AddAttribute(crt
, "text", 1);
76 directoryList
.AppendColumn(column
);
77 AppendColumn("Status", 1);
78 AppendColumn("Owner", 2);
79 AppendColumn("Latest", 3);
81 directoryList
.Selection
.Mode
= SelectionMode
.Multiple
;
82 directoryList
.KeyReleaseEvent
+= MyKeyReleaseEventHandler
;
83 directoryList
.ButtonPressEvent
+= MyButtonPressEventHandler
;
88 private TreeViewColumn
AppendColumn(string name
, int indx
)
90 TreeViewColumn column
= directoryList
.AppendColumn(name
, new Gtk
.CellRendererText (), "text", indx
);
92 column
.Clickable
= true;
93 column
.Resizable
= true;
94 column
.SortColumnId
= indx
;
95 column
.Clicked
+= new EventHandler (sortableColumns
.OnColumnClick
);
101 protected void MyButtonPressEventHandler (object o
, ButtonPressEventArgs args
)
103 if (args
.Event
.Type
== Gdk
.EventType
.TwoButtonPress
)
107 private void OnShowFile()
109 TreeIter iter
; TreeModel model
;
110 TreePath
[] paths
= directoryList
.Selection
.GetSelectedRows(out model
);
112 if (paths
.Length
== 1)
114 model
.GetIter(out iter
, paths
[0]);
115 string serverItem
= Convert
.ToString(model
.GetValue(iter
, 5));
117 ShowFileEventArgs sfArgs
= new ShowFileEventArgs(currentVcs
, serverItem
);
118 exploreView
.OnShowFile(this, sfArgs
);
122 public void MyKeyReleaseEventHandler (object o
, KeyReleaseEventArgs args
)
124 if (Gdk
.Key
.Return
== args
.Event
.Key
)
128 public void UpdatePath(VersionControlServer vcs
, string path
)
130 if (String
.IsNullOrEmpty(path
)) return;
132 directoryListStore
.Clear();
134 ExtendedItem
[] items
= vcs
.GetExtendedItems (path
, DeletedState
.NonDeleted
, ItemType
.Any
);
136 foreach (ExtendedItem item
in items
)
138 string latest
= item
.IsLatest
? "Yes" : "No";
139 string status
= item
.LockStatus
.ToString();
140 if (status
== "None") status
= String
.Empty
;
142 string shortPath
= item
.TargetServerItem
.Substring(item
.TargetServerItem
.LastIndexOf('/') + 1);
143 Gdk
.Pixbuf pixbuf
= filePixbuf
;
145 if (item
.ItemType
== ItemType
.Folder
)
148 pixbuf
= folderPixbuf
;
151 directoryListStore
.AppendValues(pixbuf
, shortPath
, status
, item
.LockOwner
, latest
, item
.TargetServerItem
);