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.
35 using Microsoft
.TeamFoundation
.Client
;
36 using Microsoft
.TeamFoundation
.VersionControl
.Common
;
37 using Microsoft
.TeamFoundation
.VersionControl
.Client
;
39 namespace Gtk
.TeamFoundation
41 public class RepositoryView
: TreeViewBase
43 public static class ColumnIndex
45 public static int Url
= 2;
46 public static int Path
= 3;
47 public static int Workspace
= 4;
50 private TreeStore store
= new TreeStore(typeof(Gdk
.Pixbuf
), typeof(string), typeof(string), typeof(string), typeof(Workspace
));
51 private ICredentialsProvider credentialsProvider
;
52 private RepositoryMenu menu
= new RepositoryMenu();
54 public RepositoryView(ICredentialsProvider credentialsProvider
)
56 this.credentialsProvider
= credentialsProvider
;
58 // setup main column with image/text data
59 TreeViewColumn column
= new TreeViewColumn ();
60 CellRendererText crt
= new CellRendererText();
61 CellRendererPixbuf crp
= new CellRendererPixbuf();
62 column
.Title
= "Repository";
63 column
.PackStart(crp
, false);
64 column
.PackStart(crt
, true);
65 column
.AddAttribute(crp
, "pixbuf", 0);
66 column
.AddAttribute(crt
, "text", 1);
67 column
.SetCellDataFunc(crt
, new Gtk
.TreeCellDataFunc (RenderRepositoryName
));
70 WorkspaceInfo
[] infos
= Workstation
.Current
.GetAllLocalWorkspaceInfo();
71 foreach (WorkspaceInfo info
in infos
)
73 ICredentials credentials
= credentialsProvider
.GetCredentials(info
.ServerUri
, null);
74 TeamFoundationServer tfs
= TeamFoundationServerFactory
.GetServer(info
.ServerUri
.ToString(), credentials
);
75 VersionControlServer vcs
= tfs
.GetService(typeof(VersionControlServer
)) as VersionControlServer
;
76 Workspace workspace
= vcs
.GetWorkspace(info
.Name
, info
.OwnerName
);
78 string label
= String
.Format("{0}@{1}", info
.Name
, info
.ServerUri
.Host
.ToString());
79 Gtk
.TreeIter serverIter
= store
.AppendValues(Images
.Repository
, label
, info
.ServerUri
.ToString(), VersionControlPath
.RootFolder
, workspace
);
80 store
.AppendValues(serverIter
, null, "", "", "", null);
84 HeadersVisible
= true;
85 KeyReleaseEvent
+= MyKeyReleaseEventHandler
;
90 protected override void PopulateRowChildren (TreeIter iter
)
92 string path
= store
.GetValue(iter
, ColumnIndex
.Path
).ToString();
94 string url
= String
.Empty
;
95 Workspace workspace
= null;
97 TreeIter iterParent
; TreeIter current
= iter
;
98 while (store
.IterParent(out iterParent
, current
))
101 url
= store
.GetValue(current
, ColumnIndex
.Url
).ToString();
102 workspace
= store
.GetValue(current
, ColumnIndex
.Workspace
) as Workspace
;
104 ICredentials credentials
= credentialsProvider
.GetCredentials(new Uri(url
), null);
105 TeamFoundationServer tfs
= TeamFoundationServerFactory
.GetServer(url
, credentials
);
106 VersionControlServer versionControlServer
= tfs
.GetService(typeof(VersionControlServer
)) as VersionControlServer
;
109 ItemSpec itemSpec
= new ItemSpec(path
, RecursionType
.OneLevel
);
110 ItemSet itemSet
= versionControlServer
.GetItems(itemSpec
, VersionSpec
.Latest
,
111 DeletedState
.NonDeleted
, ItemType
.Folder
, false);
112 if (itemSet
.Items
.Length
== 1)
115 store
.IterChildren(out citer
, iter
);
116 store
.Remove(ref citer
);
120 foreach (Microsoft
.TeamFoundation
.VersionControl
.Client
.Item item
in itemSet
.Items
)
122 if (item
.ServerItem
== path
) continue;
124 string shortPath
= item
.ServerItem
.Substring(item
.ServerItem
.LastIndexOf('/') + 1);
125 Gtk
.TreeIter child
= SetRowValue(store
, iter
, indx
, Images
.Folder
, shortPath
, url
, item
.ServerItem
, workspace
);
127 store
.AppendValues(child
, null, "", "", "", null);
132 protected override void ShowPopupMenu(TreePath path
)
134 string tfpath
= String
.Empty
;
135 Workspace workspace
= null;
140 store
.GetIter(out iter
, path
);
142 tfpath
= store
.GetValue(iter
, ColumnIndex
.Path
).ToString();
143 workspace
= store
.GetValue(iter
, ColumnIndex
.Workspace
) as Workspace
;
146 menu
.Show(workspace
, tfpath
);
149 private void RenderRepositoryName(Gtk
.TreeViewColumn column
,
150 Gtk
.CellRenderer cell
,
151 Gtk
.TreeModel model
, Gtk
.TreeIter iter
)
153 string path
= model
.GetValue(iter
, ColumnIndex
.Path
).ToString();
154 Workspace workspace
= model
.GetValue(iter
, ColumnIndex
.Workspace
) as Workspace
;
156 Gtk
.CellRendererText crt
= cell
as Gtk
.CellRendererText
;
157 crt
.Foreground
= "black";
159 if (path
== VersionControlPath
.RootFolder
) return;
160 if (workspace
== null) return;
162 if (!workspace
.IsServerPathMapped(path
))
164 (cell
as Gtk
.CellRendererText
).Foreground
= "dark grey";
168 public void MyKeyReleaseEventHandler (object o
, KeyReleaseEventArgs args
)
170 TreeIter iter
; TreeModel model
;
171 TreePath
[] paths
= Selection
.GetSelectedRows(out model
);
173 if ((Gdk
.Key
.c
== args
.Event
.Key
) && ((args
.Event
.State
& Gdk
.ModifierType
.ControlMask
) != 0))
175 StringBuilder sb
= new StringBuilder();
176 foreach (TreePath path
in paths
)
178 model
.GetIter(out iter
, path
);
179 sb
.Append(String
.Format("{0}\n",
180 Convert
.ToString(model
.GetValue(iter
, 3))));
183 Clipboard primary
= Clipboard
.Get(Gdk
.Atom
.Intern("PRIMARY", false));
184 primary
.Text
= sb
.ToString();