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.
30 using System
.Collections
.Generic
;
35 using Microsoft
.TeamFoundation
.Client
;
36 using Microsoft
.TeamFoundation
.VersionControl
.Common
;
37 using Microsoft
.TeamFoundation
.VersionControl
.Client
;
40 namespace Gtk
.TeamFoundation
42 public class RepositoryMenu
: MenuBase
45 private MenuItem getLatestItem
;
46 private MenuItem workingFolderItem
;
47 private MenuItem addRepoItem
;
48 private MenuItem editRepoItem
;
49 private MenuItem deleteRepoItem
;
50 private Workspace currentWorkspace
;
51 private string currentPath
;
52 private ExploreView exploreView
;
54 public MenuItem GetLatestItem
56 get { return getLatestItem; }
59 public RepositoryMenu(ExploreView exploreView
)
61 this.exploreView
= exploreView
;
63 getLatestItem
= AddImageMenuItem("Get Latest", Images
.Update
);
64 getLatestItem
.Activated
+= GetLatestHandler
;
66 workingFolderItem
= AddImageMenuItem("Working Folder...", Images
.Folder
);
67 workingFolderItem
.Activated
+= WorkingFolderHandler
;
69 Append(new SeparatorMenuItem());
71 addRepoItem
= AddImageMenuItem("Add Repository...", Stock
.Add
);
72 addRepoItem
.Activated
+= AddRepositoryHandler
;
74 editRepoItem
= AddImageMenuItem("Edit Repository...", Stock
.Edit
);
75 editRepoItem
.Activated
+= EditRepositoryHandler
;
77 deleteRepoItem
= AddImageMenuItem("Delete Repository", Stock
.Delete
);
82 public void Show(Workspace workspace
, string path
)
84 bool root_folder
= (path
== VersionControlPath
.RootFolder
);
85 bool path_mapped
= (workspace
!= null && workspace
.IsServerPathMapped(path
));
87 getLatestItem
.Sensitive
= (path_mapped
&& !root_folder
);
88 workingFolderItem
.Sensitive
= (workspace
!= null && !root_folder
);
90 editRepoItem
.Sensitive
= root_folder
;
91 deleteRepoItem
.Sensitive
= root_folder
;
93 currentWorkspace
= workspace
;
99 public void GetLatestHandler(object sender
, EventArgs e
)
101 List
<GetRequest
> requests
= new List
<GetRequest
>();
103 string lpath
= currentWorkspace
.GetLocalItemForServerItem(currentPath
);
104 requests
.Add(new GetRequest(System
.IO
.Path
.GetFullPath(lpath
), RecursionType
.Full
,
105 VersionSpec
.Latest
));
107 exploreView
.GetFromRepository(currentWorkspace
, requests
.ToArray());
110 public void AddRepositoryHandler(object sender
, EventArgs e
)
112 RepositoryDialog dialog
= new RepositoryDialog(null);
113 if (dialog
.Run() == (int)ResponseType
.Ok
)
117 ICredentials creds
= new TFCredential(dialog
.Username
, dialog
.Password
);
118 TeamFoundationServer tfs
= TeamFoundationServerFactory
.GetServer(dialog
.Server
, creds
);
120 VersionControlServer vcs
= tfs
.GetService(typeof(VersionControlServer
)) as VersionControlServer
;
121 vcs
.CreateWorkspace(dialog
.WorkspaceName
, dialog
.Username
,
122 "Created by OpenTF Gui", null, Environment
.MachineName
);
124 catch (WebException ex
)
126 Console
.WriteLine(ex
.ToString());
133 public void EditRepositoryHandler(object sender
, EventArgs e
)
135 RepositoryDialog dialog
= new RepositoryDialog(currentWorkspace
);
141 public void WorkingFolderHandler(object sender
, EventArgs e
)
143 WorkingFolderDialog dialog
= new WorkingFolderDialog(currentWorkspace
, currentPath
);
145 int rc
= dialog
.Run();
146 if (dialog
.Run() == (int)ResponseType
.Ok
)
148 List
<WorkingFolder
> folders
= new List
<WorkingFolder
>();
151 foreach (WorkingFolder folder
in currentWorkspace
.Folders
)
153 if (folder
.ServerItem
!= dialog
.ServerPath
)
159 folders
.Add(new WorkingFolder(folder
.ServerItem
, dialog
.LocalPath
));
164 folders
.Add(new WorkingFolder(dialog
.ServerPath
, dialog
.LocalPath
));
166 currentWorkspace
.Update(currentWorkspace
.Name
, currentWorkspace
.Comment
,
169 else if (rc
== (int)ResponseType
.Reject
)
171 List
<WorkingFolder
> folders
= new List
<WorkingFolder
>();
173 foreach (WorkingFolder folder
in currentWorkspace
.Folders
)
175 if (folder
.ServerItem
== dialog
.ServerPath
) continue;
179 currentWorkspace
.Update(currentWorkspace
.Name
, currentWorkspace
.Comment
,