2
using System.Collections;
7
using MonoDevelop.Components;
8
using MonoDevelop.Core;
9
using MonoDevelop.Ide.Gui;
11
namespace MonoDevelop.VersionControl.Views
13
internal class LogView : BaseView
22
ListStore changedpathstore;
25
public static bool Show (Repository vc, string filepath, bool isDirectory, Revision since, bool test)
27
if (vc.IsHistoryAvailable (filepath)) {
28
if (test) return true;
29
new Worker(vc, filepath, isDirectory, since).Start();
35
private class Worker : Task {
42
public Worker (Repository vc, string filepath, bool isDirectory, Revision since) {
44
this.filepath = filepath;
45
this.isDirectory = isDirectory;
49
protected override string GetDescription() {
50
return GettextCatalog.GetString ("Retrieving history for {0}...", Path.GetFileName(filepath));
53
protected override void Run() {
54
history = vc.GetHistory (filepath, since);
57
protected override void Finished() {
58
if (history == null) return;
59
LogView d = new LogView(filepath, isDirectory, history, vc);
60
MonoDevelop.Ide.Gui.IdeApp.Workbench.OpenDocument (d, true);
64
public LogView (string filepath, bool isDirectory, Revision[] history, Repository vc)
65
: base(Path.GetFileName(filepath) + " Log")
68
this.filepath = filepath;
69
this.history = history;
72
this.vinfo = vc.GetVersionInfo (filepath, false);
74
catch (Exception ex) {
75
IdeApp.Services.MessageService.ShowError (ex, GettextCatalog.GetString ("Version control command failed."));
80
VBox box = new VBox(false, 6);
86
if (!isDirectory && vinfo != null) {
87
commandbar = new Toolbar ();
88
commandbar.ToolbarStyle = Gtk.ToolbarStyle.BothHoriz;
89
commandbar.IconSize = Gtk.IconSize.Menu;
90
box.PackStart (commandbar, false, false, 0);
92
Gtk.ToolButton button = new Gtk.ToolButton (new Gtk.Image ("vc-diff", Gtk.IconSize.Menu), GettextCatalog.GetString ("View Changes"));
93
button.IsImportant = true;
94
button.Clicked += new EventHandler(DiffButtonClicked);
95
commandbar.Insert (button, -1);
97
button = new Gtk.ToolButton (new Gtk.Image (Gtk.Stock.Open, Gtk.IconSize.Menu), GettextCatalog.GetString ("View File"));
98
button.IsImportant = true;
99
button.Clicked += new EventHandler (ViewTextButtonClicked);
100
commandbar.Insert (button, -1);
103
// A paned with two trees
105
Gtk.VPaned paned = new Gtk.VPaned ();
106
box.PackStart (paned, true, true, 0);
108
// Create the log list
110
loglist = new TreeView ();
111
ScrolledWindow loglistscroll = new ScrolledWindow();
112
loglistscroll.ShadowType = Gtk.ShadowType.In;
113
loglistscroll.Add (loglist);
114
loglistscroll.HscrollbarPolicy = PolicyType.Automatic;
115
loglistscroll.VscrollbarPolicy = PolicyType.Automatic;
116
paned.Add1 (loglistscroll);
117
((Paned.PanedChild)paned [loglistscroll]).Resize = true;
119
TreeView changedPaths = new TreeView();
120
ScrolledWindow changedPathsScroll = new ScrolledWindow();
121
changedPathsScroll.ShadowType = Gtk.ShadowType.In;
122
changedPathsScroll.HscrollbarPolicy = PolicyType.Automatic;
123
changedPathsScroll.VscrollbarPolicy = PolicyType.Automatic;
124
changedPathsScroll.Add (changedPaths);
125
paned.Add2 (changedPathsScroll);
126
((Paned.PanedChild)paned [changedPathsScroll]).Resize = false;
130
// Revision list setup
132
CellRendererText textRenderer = new CellRendererText();
133
textRenderer.Yalign = 0;
135
TreeViewColumn colRevNum = new TreeViewColumn(GettextCatalog.GetString ("Revision"), textRenderer, "text", 0);
136
TreeViewColumn colRevDate = new TreeViewColumn(GettextCatalog.GetString ("Date"), textRenderer, "text", 1);
137
TreeViewColumn colRevAuthor = new TreeViewColumn(GettextCatalog.GetString ("Author"), textRenderer, "text", 2);
138
TreeViewColumn colRevMessage = new TreeViewColumn(GettextCatalog.GetString ("Message"), textRenderer, "text", 3);
140
loglist.AppendColumn(colRevNum);
141
loglist.AppendColumn(colRevDate);
142
loglist.AppendColumn(colRevAuthor);
143
loglist.AppendColumn(colRevMessage);
145
ListStore logstore = new ListStore (typeof (string), typeof (string), typeof (string), typeof (string));
146
loglist.Model = logstore;
148
foreach (Revision d in history) {
149
logstore.AppendValues(
153
d.Message == "" ? GettextCatalog.GetString ("(No message)") : d.Message);
156
// Changed paths list setup
158
changedpathstore = new ListStore (typeof(string), typeof (string), typeof(string), typeof (string));
159
changedPaths.Model = changedpathstore;
161
TreeViewColumn colOperation = new TreeViewColumn ();
162
CellRendererText crt = new CellRendererText();
163
CellRendererPixbuf crp = new CellRendererPixbuf();
164
colOperation.Title = GettextCatalog.GetString ("Operation");
165
colOperation.PackStart (crp, false);
166
colOperation.PackStart (crt, true);
167
colOperation.AddAttribute (crp, "stock-id", 0);
168
colOperation.AddAttribute (crt, "text", 1);
169
changedPaths.AppendColumn (colOperation);
171
TreeViewColumn colChangedPath = new TreeViewColumn ();
172
crp = new CellRendererPixbuf();
173
crt = new CellRendererText();
174
colChangedPath.Title = GettextCatalog.GetString ("File Path");
175
colChangedPath.PackStart (crp, false);
176
colChangedPath.PackStart (crt, true);
177
colChangedPath.AddAttribute (crp, "stock-id", 2);
178
colChangedPath.AddAttribute (crt, "text", 3);
179
changedPaths.AppendColumn (colChangedPath);
181
loglist.Selection.Changed += new EventHandler(TreeSelectionChanged);
184
Revision GetSelectedRev()
188
loglist.GetCursor(out path, out col);
189
if (path == null) return null;
190
return history [path.Indices[0]];
193
void TreeSelectionChanged(object o, EventArgs args) {
194
Revision d = GetSelectedRev();
195
changedpathstore.Clear();
196
foreach (RevisionPath rp in d.ChangedFiles)
199
string action = null;
200
if (rp.Action == RevisionAction.Add) {
201
action = GettextCatalog.GetString ("Add");
202
actionIcon = Gtk.Stock.Add;
204
else if (rp.Action == RevisionAction.Delete) {
205
action = GettextCatalog.GetString ("Delete");
206
actionIcon = Gtk.Stock.Remove;
208
else if (rp.Action == RevisionAction.Modify) {
209
action = GettextCatalog.GetString ("Modify");
210
actionIcon = "gtk-edit";
212
else if (rp.Action == RevisionAction.Replace) {
213
action = GettextCatalog.GetString ("Replace");
214
actionIcon = "gtk-edit";
216
action = rp.ActionDescription;
217
actionIcon = MonoDevelop.Core.Gui.Stock.Empty;
221
/* if (n.IsDirectory)
222
fileIcon = MonoDevelop.Core.Gui.Stock.ClosedFolder;
224
*/ fileIcon = IdeApp.Services.Icons.GetImageForFile (rp.Path);
226
changedpathstore.AppendValues (actionIcon, action, fileIcon, rp.Path);
230
void DiffButtonClicked(object src, EventArgs args) {
231
Revision d = GetSelectedRev();
232
if (d == null) return;
233
new DiffWorker(Path.GetFileName(filepath), vc, vinfo.RepositoryPath, d).Start();
236
void ViewTextButtonClicked(object src, EventArgs args) {
237
Revision d = GetSelectedRev();
238
if (d == null) return;
239
HistoricalFileView.Show(filepath, vc, vinfo.RepositoryPath, d);
242
public override Gtk.Widget Control {
248
public override void Dispose ()
255
internal class DiffWorker : Task {
262
public DiffWorker(string name, Repository vc, string revPath, Revision revision) {
265
this.revPath = revPath;
266
this.revision = revision;
269
protected override string GetDescription() {
270
return GettextCatalog.GetString ("Retreiving changes in {0} at revision {1}...", name, revision);
273
protected override void Run() {
274
Log (GettextCatalog.GetString ("Getting text of {0} at revision {1}...", revPath, revision.GetPrevious()));
276
text1 = vc.GetTextAtRevision(revPath, revision.GetPrevious());
278
// If the file was added in this revision, no previous
282
Log (GettextCatalog.GetString ("Getting text of {0} at revision {1}...", revPath, revision));
283
text2 = vc.GetTextAtRevision(revPath, revision);
286
protected override void Finished() {
287
if (text1 == null || text2 == null) return;
288
DiffView.Show(name + " (revision " + revision.ToString() + ")", text1, text2);
294
internal class HistoricalFileView
296
public static void Show(string name, string file, string text) {
297
string mimeType = IdeApp.Services.PlatformService.GetMimeTypeForUri (file);
298
if (mimeType == null || mimeType.Length == 0)
299
mimeType = "text/plain";
300
Document doc = MonoDevelop.Ide.Gui.IdeApp.Workbench.NewDocument (name, mimeType, text);
304
public static void Show(string file, Repository vc, string revPath, Revision revision) {
305
new Worker(Path.GetFileName(file) + " (revision " + revision.ToString() + ")",
306
file, vc, revPath, revision).Start();
310
internal class Worker : Task {
317
public Worker(string name, string file, Repository vc, string revPath, Revision revision) {
321
this.revPath = revPath;
322
this.revision = revision;
325
protected override string GetDescription() {
326
return GettextCatalog.GetString ("Retreiving content of {0} at revision {1}...", name, revision);
329
protected override void Run() {
330
text = vc.GetTextAtRevision(revPath, revision);
333
protected override void Finished() {
334
if (text == null) return;
335
HistoricalFileView.Show(name, file, text);