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.
31 using System
.Collections
;
32 using System
.Collections
.Generic
;
36 using Microsoft
.TeamFoundation
.Client
;
37 using Microsoft
.TeamFoundation
.VersionControl
.Common
;
38 using Microsoft
.TeamFoundation
.VersionControl
.Client
;
40 namespace Gtk
.TeamFoundation
42 public class ChangesetView
: TreeViewBase
, IExploreViewChild
44 private Gtk
.ListStore store
;
45 private int stopAfter
;
46 private int currentCid
= 0;
47 private SortableColumns sortableColumns
;
48 private VersionControlServer currentVcs
;
49 private ExploreView exploreView
;
51 private TreeViewColumn
AppendColumn(string name
, int indx
)
53 TreeViewColumn column
= AppendColumn (name
, new Gtk
.CellRendererText (), "text", indx
);
55 column
.Clickable
= true;
56 column
.Resizable
= true;
57 column
.SortColumnId
= indx
;
58 column
.Clicked
+= new EventHandler (sortableColumns
.OnColumnClick
);
63 public void InitializeChangesetList()
65 store
= new Gtk
.ListStore (typeof(int), typeof(string), typeof(string), typeof(string));
68 sortableColumns
= new SortableColumns(this, store
);
70 TreeViewColumn id
= AppendColumn("Id", 0);
71 id
.SortIndicator
= true;
72 id
.SortOrder
= SortType
.Descending
;
74 AppendColumn("Owner", 1);
75 AppendColumn("Date", 2);
76 AppendColumn("Comment", 3);
78 Selection
.Mode
= SelectionMode
.Multiple
;
79 Selection
.Changed
+= OnSelectionChanged
;
80 KeyReleaseEvent
+= MyKeyReleaseEventHandler
;
81 ButtonPressEvent
+= MyButtonPressEventHandler
;
83 #if HAVE_ATLEAST_GTK_210
84 EnableGridLines
= TreeViewGridLines
.Vertical
;
88 public ChangesetView(ExploreView exploreView
, int stopAfter
)
90 this.exploreView
= exploreView
;
91 this.stopAfter
= stopAfter
;
93 InitializeChangesetList();
97 protected void MyButtonPressEventHandler (object o
, ButtonPressEventArgs args
)
99 if (args
.Event
.Type
== Gdk
.EventType
.TwoButtonPress
)
101 ShowChangesetEventArgs scArgs
= new ShowChangesetEventArgs(currentVcs
, currentCid
);
102 exploreView
.OnShowChangeset(this, scArgs
);
106 void OnSelectionChanged (object o
, EventArgs args
)
111 TreeSelection treeSelection
= o
as TreeSelection
;
112 int count
= treeSelection
.CountSelectedRows();
113 if (count
== 0 || count
> 1) return;
115 TreePath
[] paths
= treeSelection
.GetSelectedRows(out model
);
116 foreach (TreePath path
in paths
)
118 model
.GetIter(out iter
, path
);
119 currentCid
= Convert
.ToInt32(model
.GetValue (iter
, 0));
123 public void UpdatePath(VersionControlServer vcs
, string path
)
125 if (String
.IsNullOrEmpty(path
)) return;
129 bool detailed
= false;
130 IEnumerable changeSets
= vcs
.QueryHistory(path
, VersionSpec
.Latest
, 0, RecursionType
.Full
, null,
131 null, null, stopAfter
, detailed
, false, false);
133 foreach (Changeset changeSet
in changeSets
)
135 store
.AppendValues(changeSet
.ChangesetId
,
137 changeSet
.CreationDate
.ToString("d"),
141 // this would be nice be seems to cause a segfault
145 public void MyKeyReleaseEventHandler (object o
, KeyReleaseEventArgs args
)
147 TreeIter iter
; TreeModel model
;
148 TreePath
[] paths
= Selection
.GetSelectedRows(out model
);
150 if (Gdk
.Key
.Return
== args
.Event
.Key
&& paths
.Length
== 1)
152 ShowChangesetEventArgs scArgs
= new ShowChangesetEventArgs(currentVcs
, currentCid
);
153 exploreView
.OnShowChangeset(this, scArgs
);
155 else if ((Gdk
.Key
.c
== args
.Event
.Key
) && ((args
.Event
.State
& Gdk
.ModifierType
.ControlMask
) != 0))
157 StringBuilder sb
= new StringBuilder();
158 foreach (TreePath path
in paths
)
160 model
.GetIter(out iter
, path
);
161 sb
.Append(String
.Format("{0} {1} {2} {3}\n",
162 Convert
.ToInt32(model
.GetValue (iter
, 0)),
163 Convert
.ToString(model
.GetValue (iter
, 1)),
164 Convert
.ToString(model
.GetValue (iter
, 2)),
165 Convert
.ToString(model
.GetValue (iter
, 3)) ));
168 Clipboard primary
= Clipboard
.Get(Gdk
.Atom
.Intern ("PRIMARY", false));
169 primary
.Text
= sb
.ToString();