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.
34 using Microsoft
.TeamFoundation
.Client
;
35 using Microsoft
.TeamFoundation
.VersionControl
.Common
;
36 using Microsoft
.TeamFoundation
.VersionControl
.Client
;
38 namespace Gtk
.TeamFoundation
40 public class RepositoryView
: TreeViewBase
42 public static class ColumnIndex
44 public static int Url
= 2;
45 public static int Path
= 3;
46 public static int Workspace
= 4;
49 private TreeStore store
= new TreeStore(typeof(Gdk
.Pixbuf
), typeof(string), typeof(string), typeof(string), typeof(Workspace
));
50 private ICredentialsProvider credentialsProvider
;
51 private RepositoryMenu menu
= new RepositoryMenu();
52 private Gdk
.Pixbuf repositoryPixbuf
;
53 private Gdk
.Pixbuf folderPixbuf
;
55 public RepositoryView(ICredentialsProvider credentialsProvider
)
57 this.credentialsProvider
= credentialsProvider
;
60 repositoryPixbuf
= Gdk
.Pixbuf
.LoadFromResource("repository.png");
61 folderPixbuf
= Gdk
.Pixbuf
.LoadFromResource("folder.png");
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
= "Repository";
68 column
.PackStart(crp
, false);
69 column
.PackStart(crt
, true);
70 column
.AddAttribute(crp
, "pixbuf", 0);
71 column
.AddAttribute(crt
, "text", 1);
72 column
.SetCellDataFunc(crt
, new Gtk
.TreeCellDataFunc (RenderRepositoryName
));
75 WorkspaceInfo
[] infos
= Workstation
.Current
.GetAllLocalWorkspaceInfo();
76 foreach (WorkspaceInfo info
in infos
)
78 ICredentials credentials
= credentialsProvider
.GetCredentials(info
.ServerUri
, null);
79 TeamFoundationServer tfs
= TeamFoundationServerFactory
.GetServer(info
.ServerUri
.ToString(), credentials
);
80 VersionControlServer vcs
= tfs
.GetService(typeof(VersionControlServer
)) as VersionControlServer
;
81 Workspace workspace
= vcs
.GetWorkspace(info
.Name
, info
.OwnerName
);
83 string label
= String
.Format("{0}@{1}", info
.Name
, info
.ServerUri
.Host
.ToString());
84 Gtk
.TreeIter serverIter
= store
.AppendValues(repositoryPixbuf
, label
, info
.ServerUri
.ToString(), VersionControlPath
.RootFolder
, workspace
);
85 store
.AppendValues(serverIter
, null, "", "", "", null);
89 HeadersVisible
= true;
94 protected override void PopulateRowChildren (TreeIter iter
)
96 string path
= store
.GetValue(iter
, ColumnIndex
.Path
).ToString();
98 string url
= String
.Empty
;
99 Workspace workspace
= null;
101 TreeIter iterParent
; TreeIter current
= iter
;
102 while (store
.IterParent(out iterParent
, current
))
103 current
= iterParent
;
105 url
= store
.GetValue(current
, ColumnIndex
.Url
).ToString();
106 workspace
= store
.GetValue(current
, ColumnIndex
.Workspace
) as Workspace
;
108 ICredentials credentials
= credentialsProvider
.GetCredentials(new Uri(url
), null);
109 TeamFoundationServer tfs
= TeamFoundationServerFactory
.GetServer(url
, credentials
);
110 VersionControlServer versionControlServer
= tfs
.GetService(typeof(VersionControlServer
)) as VersionControlServer
;
113 ItemSpec itemSpec
= new ItemSpec(path
, RecursionType
.OneLevel
);
114 ItemSet itemSet
= versionControlServer
.GetItems(itemSpec
, VersionSpec
.Latest
,
115 DeletedState
.NonDeleted
, ItemType
.Folder
, false);
116 if (itemSet
.Items
.Length
== 0)
117 SetRowValue(store
, iter
, indx
, null, " - item list not available - ", "", "", null);
119 foreach (Microsoft
.TeamFoundation
.VersionControl
.Client
.Item item
in itemSet
.Items
)
121 if (item
.ServerItem
== path
) continue;
123 string shortPath
= item
.ServerItem
.Substring(item
.ServerItem
.LastIndexOf('/') + 1);
124 Gtk
.TreeIter child
= SetRowValue(store
, iter
, indx
, folderPixbuf
, shortPath
, url
, item
.ServerItem
, workspace
);
126 store
.AppendValues(child
, null, "", "", "", null);
131 protected override void ShowPopupMenu(TreePath path
)
133 string tfpath
= String
.Empty
;
138 store
.GetIter(out iter
, path
);
139 tfpath
= store
.GetValue(iter
, ColumnIndex
.Path
).ToString();;
140 Console
.WriteLine(tfpath
);
146 private void RenderRepositoryName(Gtk
.TreeViewColumn column
,
147 Gtk
.CellRenderer cell
,
148 Gtk
.TreeModel model
, Gtk
.TreeIter iter
)
150 string path
= model
.GetValue(iter
, ColumnIndex
.Path
).ToString();
151 Workspace workspace
= model
.GetValue(iter
, ColumnIndex
.Workspace
) as Workspace
;
153 Gtk
.CellRendererText crt
= cell
as Gtk
.CellRendererText
;
154 crt
.Foreground
= "black";
156 if (path
== VersionControlPath
.RootFolder
) return;
157 if (workspace
== null) return;
159 if (!workspace
.IsServerPathMapped(path
))
161 (cell
as Gtk
.CellRendererText
).Foreground
= "grey";
166 void OnAddRepository(object sender
, EventArgs args
)
168 RepositoryDialog dialog
= new RepositoryDialog();