flesh.out.AddRepositoryHandler
[tfs.git] / class / Gtk.TeamFoundation / RepositoryMenu.cs
blob6c2d2c316cca9dd963e9f3e91c851c41a0846af6
1 //
2 // RepositoryMenu.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.Collections.Generic;
31 using System.IO;
32 using System.Net;
33 using Gtk;
35 using Microsoft.TeamFoundation.Client;
36 using Microsoft.TeamFoundation.VersionControl.Common;
37 using Microsoft.TeamFoundation.VersionControl.Client;
38 using OpenTF.Common;
40 namespace Gtk.TeamFoundation
42 public class RepositoryMenu : MenuBase
44 //MenuItem
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);
79 ShowAll();
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;
94 currentPath = path;
96 Popup();
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)
115 ICredentials creds = new TFCredential(dialog.Username, dialog.Password);
116 TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(dialog.Server, creds);
118 VersionControlServer vcs = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
119 vcs.CreateWorkspace(dialog.WorkspaceName, dialog.Username,
120 "Created by OpenTF Gui", null, Environment.MachineName);
123 dialog.Destroy();
126 public void EditRepositoryHandler(object sender, EventArgs e)
128 RepositoryDialog dialog = new RepositoryDialog(currentWorkspace);
130 dialog.Run();
131 dialog.Destroy();
134 public void WorkingFolderHandler(object sender, EventArgs e)
136 WorkingFolderDialog dialog = new WorkingFolderDialog(currentWorkspace, currentPath);
138 int rc = dialog.Run();
139 if (dialog.Run() == (int)ResponseType.Ok)
141 List<WorkingFolder> folders = new List<WorkingFolder>();
142 bool found = false;
144 foreach (WorkingFolder folder in currentWorkspace.Folders)
146 if (folder.ServerItem != dialog.ServerPath)
148 folders.Add(folder);
149 continue;
152 folders.Add(new WorkingFolder(folder.ServerItem, dialog.LocalPath));
153 found = true;
156 if (!found)
157 folders.Add(new WorkingFolder(dialog.ServerPath, dialog.LocalPath));
159 currentWorkspace.Update(currentWorkspace.Name, currentWorkspace.Comment,
160 folders.ToArray());
162 else if (rc == (int)ResponseType.Reject)
164 List<WorkingFolder> folders = new List<WorkingFolder>();
166 foreach (WorkingFolder folder in currentWorkspace.Folders)
168 if (folder.ServerItem == dialog.ServerPath) continue;
169 folders.Add(folder);
172 currentWorkspace.Update(currentWorkspace.Name, currentWorkspace.Comment,
173 folders.ToArray());
176 dialog.Destroy();