sync
[tfs.git] / class / Gtk.TeamFoundation / ExploreView.cs
blob3df52159716598671ea356d65b7005564daf9fec
1 //
2 // ExploreView.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.Net;
32 using System.Reflection;
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 interface IExploreViewChild
44 void UpdatePath(VersionControlServer vcs, string path);
47 public class ExploreView : Gtk.VBox
49 private RepositoryView repositoryView;
50 private ChangesetView changesetView;
51 private DirectoryView directoryView;
52 private VPaned viewChildren;
53 private string currentSelectedPath;
54 private VersionControlServer currentVcs;
55 private ICredentialsProvider credentialsProvider;
56 private Statusbar statusbar;
57 private List<string> getLatestList = new List<string>();
59 public event GetLatestEventHandler GetLatest;
60 public event ShowChangesetEventHandler ShowChangeset;
61 public event ShowFileEventHandler ShowFile;
63 public ExploreView(ICredentialsProvider credentialsProvider,
64 int stopAfter) : base (false, 1)
66 this.credentialsProvider = credentialsProvider;
68 HPaned hPaned = new HPaned();
69 Add(hPaned);
72 ScrolledWindowBase scrolledWindow1 = new ScrolledWindowBase();
73 hPaned.Add1(scrolledWindow1);
75 repositoryView = new RepositoryView(this, credentialsProvider);
76 scrolledWindow1.Add(repositoryView);
79 viewChildren = new VPaned();
81 ScrolledWindowBase scrolledWindow2 = new ScrolledWindowBase();
82 viewChildren.Pack1(scrolledWindow2, true, true);
84 directoryView = new DirectoryView(this);
85 scrolledWindow2.Add(directoryView);
87 ScrolledWindowBase scrolledWindow3 = new ScrolledWindowBase();
88 viewChildren.Pack2(scrolledWindow3, true, true);
90 changesetView = new ChangesetView(this, stopAfter);
91 scrolledWindow3.Add(changesetView);
93 int x, y, width, height, depth;
94 RootWindow.GetGeometry (out x, out y, out width, out height, out depth);
96 hPaned.Add2(viewChildren);
97 hPaned.Position = (width - 50) / 3;
100 // add status bar
101 statusbar = new Statusbar ();
102 statusbar.HasResizeGrip = false;
103 PackEnd(statusbar, false, false, 1);
105 Assembly entry = Assembly.GetEntryAssembly();
106 StatusMessage(String.Format("{0} version {1}", entry.GetName().Name,
107 entry.GetName().Version.ToString()));
109 ShowAll();
110 repositoryView.Selection.Changed += OnPathSelectionChanged;
113 public void StatusMessage(string msg)
115 statusbar.Push(1, msg);
118 public void MyGettingEventHandler(object sender, GettingEventArgs e)
120 GetLatestEventArgs args = null;
122 if (e.DeletionId != 0)
124 args = new GetLatestEventArgs("deleting", e.SourceLocalItem);
126 else
128 if ((!String.IsNullOrEmpty(e.TargetLocalItem))&&
129 (!String.IsNullOrEmpty(e.SourceLocalItem))&&
130 (e.SourceLocalItem != e.TargetLocalItem))
131 args = new GetLatestEventArgs("renaming", e.TargetLocalItem);
132 else
133 args = new GetLatestEventArgs("updating", e.TargetLocalItem);
136 if (GetLatest != null) GetLatest(this, args);
138 if (e.ItemType == ItemType.Folder) return;
139 getLatestList.Add(e.TargetLocalItem);
142 public void GetFromRepository(Workspace workspace, GetRequest[] requests)
144 getLatestList.Clear();
145 GetStatus status = workspace.Get(requests, GetOptions.None);
147 foreach (string file in getLatestList)
149 StatusMessage("Setting permissions: " + file);
150 if (! FileTypeDatabase.ShouldBeExecutable(file)) continue;
151 FileType.MakeExecutable(file);
155 public void OnShowChangeset(object sender, ShowChangesetEventArgs args)
157 if (ShowChangeset != null) ShowChangeset(sender, args);
160 public void OnShowFile(object sender, ShowFileEventArgs args)
162 if (ShowFile != null) ShowFile(sender, args);
165 void OnPathSelectionChanged (object o, EventArgs args)
167 TreeIter iter;
168 TreeModel model;
170 if (!((TreeSelection)o).GetSelected (out model, out iter)) return;
172 TreeIter iterParent;
173 bool not_root = false;
174 TreeIter current = iter;
175 while (model.IterParent(out iterParent, current))
177 current = iterParent;
178 not_root = true;
181 if (not_root)
183 string url = (string) model.GetValue (current, RepositoryView.ColumnIndex.Url);
184 ICredentials credentials = credentialsProvider.GetCredentials(new System.Uri(url), null);
185 TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(url, credentials);
187 currentVcs = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
188 if (currentVcs == null) return;
190 currentSelectedPath = (string) model.GetValue(iter, RepositoryView.ColumnIndex.Path);
192 GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch);
193 directoryView.UpdatePath(currentVcs, currentSelectedPath);
194 changesetView.UpdatePath(currentVcs, currentSelectedPath);
195 GdkWindow.Cursor = null;