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
;
39 namespace Gtk
.TeamFoundation
41 public class RepositoryMenu
: MenuBase
44 private MenuItem getLatestItem
;
45 private MenuItem workingFolderItem
;
46 private MenuItem addRepoItem
;
47 private MenuItem editRepoItem
;
48 private MenuItem deleteRepoItem
;
49 private Workspace currentWorkspace
;
50 private string currentPath
;
51 private ExploreView exploreView
;
53 public MenuItem GetLatestItem
55 get { return getLatestItem; }
58 public RepositoryMenu(ExploreView exploreView
)
60 this.exploreView
= exploreView
;
62 getLatestItem
= AddImageMenuItem("Get Latest", Images
.Update
);
63 getLatestItem
.Activated
+= GetLatestHandler
;
65 workingFolderItem
= AddImageMenuItem("Working Folder...", Images
.Folder
);
66 workingFolderItem
.Activated
+= WorkingFolderHandler
;
68 Append(new SeparatorMenuItem());
70 addRepoItem
= AddImageMenuItem("Add Repository...", Stock
.Add
);
71 addRepoItem
.Activated
+= AddRepositoryHandler
;
73 editRepoItem
= AddImageMenuItem("Edit Repository...", Stock
.Edit
);
74 editRepoItem
.Activated
+= EditRepositoryHandler
;
76 deleteRepoItem
= AddImageMenuItem("Delete Repository", Stock
.Delete
);
81 public void Show(Workspace workspace
, string path
)
83 bool root_folder
= (path
== VersionControlPath
.RootFolder
);
84 bool path_mapped
= workspace
.IsServerPathMapped(path
);
86 getLatestItem
.Sensitive
= (path_mapped
&& !root_folder
);
87 workingFolderItem
.Sensitive
= !root_folder
;
89 editRepoItem
.Sensitive
= root_folder
;
90 deleteRepoItem
.Sensitive
= root_folder
;
92 currentWorkspace
= workspace
;
98 public void GetLatestHandler(object sender
, EventArgs e
)
100 List
<GetRequest
> requests
= new List
<GetRequest
>();
102 string lpath
= currentWorkspace
.GetLocalItemForServerItem(currentPath
);
103 requests
.Add(new GetRequest(System
.IO
.Path
.GetFullPath(lpath
), RecursionType
.Full
,
104 VersionSpec
.Latest
));
106 exploreView
.GetFromRepository(currentWorkspace
, requests
.ToArray());
109 public void AddRepositoryHandler(object sender
, EventArgs e
)
111 RepositoryDialog dialog
= new RepositoryDialog(null);
116 public void EditRepositoryHandler(object sender
, EventArgs e
)
118 RepositoryDialog dialog
= new RepositoryDialog(currentWorkspace
);
124 public void WorkingFolderHandler(object sender
, EventArgs e
)
126 WorkingFolderDialog dialog
= new WorkingFolderDialog(currentWorkspace
, currentPath
);
128 int rc
= dialog
.Run();
129 if (dialog
.Run() == (int)ResponseType
.Ok
)
131 List
<WorkingFolder
> folders
= new List
<WorkingFolder
>();
134 foreach (WorkingFolder folder
in currentWorkspace
.Folders
)
136 if (folder
.ServerItem
!= dialog
.ServerPath
)
142 folders
.Add(new WorkingFolder(folder
.ServerItem
, dialog
.LocalPath
));
147 folders
.Add(new WorkingFolder(dialog
.ServerPath
, dialog
.LocalPath
));
149 currentWorkspace
.Update(currentWorkspace
.Name
, currentWorkspace
.Comment
,
152 else if (rc
== (int)ResponseType
.Reject
)
154 List
<WorkingFolder
> folders
= new List
<WorkingFolder
>();
156 foreach (WorkingFolder folder
in currentWorkspace
.Folders
)
158 if (folder
.ServerItem
== dialog
.ServerPath
) continue;
162 currentWorkspace
.Update(currentWorkspace
.Name
, currentWorkspace
.Comment
,