~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/Logs.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
using System;
2
 
using System.Collections;
3
 
using System.IO;
4
 
 
5
 
using Gtk;
6
 
 
7
 
using MonoDevelop.Components;
8
 
using MonoDevelop.Core;
9
 
using MonoDevelop.Ide.Gui;
10
 
 
11
 
namespace MonoDevelop.VersionControl.Views
12
 
{
13
 
        internal class LogView : BaseView
14
 
        {
15
 
                string filepath;
16
 
                Widget widget;
17
 
                Revision[] history;
18
 
                Repository vc;
19
 
                VersionInfo vinfo;
20
 
                
21
 
                TreeView loglist;
22
 
                ListStore changedpathstore;
23
 
                Toolbar commandbar;
24
 
                
25
 
                public static bool Show (Repository vc, string filepath, bool isDirectory, Revision since, bool test)
26
 
                {
27
 
                        if (vc.IsHistoryAvailable (filepath)) {
28
 
                                if (test) return true;
29
 
                                new Worker(vc, filepath, isDirectory, since).Start();
30
 
                                return true;
31
 
                        }
32
 
                        return false;
33
 
                }
34
 
                
35
 
                private class Worker : Task {
36
 
                        Repository vc;
37
 
                        string filepath;
38
 
                        bool isDirectory;
39
 
                        Revision since;
40
 
                        Revision[] history;
41
 
                                                
42
 
                        public Worker (Repository vc, string filepath, bool isDirectory, Revision since) {
43
 
                                this.vc = vc;
44
 
                                this.filepath = filepath;
45
 
                                this.isDirectory = isDirectory;
46
 
                                this.since = since;
47
 
                        }
48
 
                        
49
 
                        protected override string GetDescription() {
50
 
                                return GettextCatalog.GetString ("Retrieving history for {0}...", Path.GetFileName(filepath));
51
 
                        }
52
 
                        
53
 
                        protected override void Run() {
54
 
                                history = vc.GetHistory (filepath, since);
55
 
                        }
56
 
                
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);
61
 
                        }
62
 
                }
63
 
                
64
 
                public LogView (string filepath, bool isDirectory, Revision[] history, Repository vc) 
65
 
                        : base(Path.GetFileName(filepath) + " Log")
66
 
                {
67
 
                        this.vc = vc;
68
 
                        this.filepath = filepath;
69
 
                        this.history = history;
70
 
                        
71
 
                        try {
72
 
                                this.vinfo = vc.GetVersionInfo (filepath, false);
73
 
                        }
74
 
                        catch (Exception ex) {
75
 
                                IdeApp.Services.MessageService.ShowError (ex, GettextCatalog.GetString ("Version control command failed."));
76
 
                        }
77
 
 
78
 
                        // Widget setup
79
 
                        
80
 
                        VBox box = new VBox(false, 6);
81
 
                        
82
 
                        widget = box;
83
 
 
84
 
                        // Create the toolbar
85
 
                        
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);
91
 
                                
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);
96
 
                                
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);
101
 
                        }
102
 
                        
103
 
                        // A paned with two trees
104
 
                        
105
 
                        Gtk.VPaned paned = new Gtk.VPaned ();
106
 
                        box.PackStart (paned, true, true, 0);
107
 
                        
108
 
                        // Create the log list
109
 
                        
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;
118
 
                        
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;
127
 
 
128
 
                        widget.ShowAll();
129
 
                        
130
 
                        // Revision list setup
131
 
                        
132
 
                        CellRendererText textRenderer = new CellRendererText();
133
 
                        textRenderer.Yalign = 0;
134
 
                        
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);
139
 
                        
140
 
                        loglist.AppendColumn(colRevNum);
141
 
                        loglist.AppendColumn(colRevDate);
142
 
                        loglist.AppendColumn(colRevAuthor);
143
 
                        loglist.AppendColumn(colRevMessage);
144
 
                        
145
 
                        ListStore logstore = new ListStore (typeof (string), typeof (string), typeof (string), typeof (string));
146
 
                        loglist.Model = logstore;
147
 
                         
148
 
                        foreach (Revision d in history) {
149
 
                                logstore.AppendValues(
150
 
                                        d.ToString(),
151
 
                                        d.Time.ToString(),
152
 
                                        d.Author,
153
 
                                        d.Message == "" ? GettextCatalog.GetString ("(No message)") : d.Message);
154
 
                        }
155
 
 
156
 
                        // Changed paths list setup
157
 
                        
158
 
                        changedpathstore = new ListStore (typeof(string), typeof (string), typeof(string), typeof (string));
159
 
                        changedPaths.Model = changedpathstore;
160
 
                        
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);
170
 
                        
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);
180
 
                        
181
 
                        loglist.Selection.Changed += new EventHandler(TreeSelectionChanged);
182
 
                }
183
 
                
184
 
                Revision GetSelectedRev()
185
 
                {
186
 
                        TreePath path;
187
 
                        TreeViewColumn col;
188
 
                        loglist.GetCursor(out path, out col);
189
 
                        if (path == null) return null;
190
 
                        return history [path.Indices[0]];
191
 
                }
192
 
                
193
 
                void TreeSelectionChanged(object o, EventArgs args) {
194
 
                        Revision d = GetSelectedRev();
195
 
                        changedpathstore.Clear();
196
 
                        foreach (RevisionPath rp in d.ChangedFiles) 
197
 
                        {
198
 
                                string actionIcon;
199
 
                                string action = null;
200
 
                                if (rp.Action == RevisionAction.Add) {
201
 
                                        action = GettextCatalog.GetString ("Add");
202
 
                                        actionIcon = Gtk.Stock.Add;
203
 
                                }
204
 
                                else if (rp.Action == RevisionAction.Delete) {
205
 
                                        action = GettextCatalog.GetString ("Delete");
206
 
                                        actionIcon = Gtk.Stock.Remove;
207
 
                                }
208
 
                                else if (rp.Action == RevisionAction.Modify) {
209
 
                                        action = GettextCatalog.GetString ("Modify");
210
 
                                        actionIcon = "gtk-edit";
211
 
                                }
212
 
                                else if (rp.Action == RevisionAction.Replace) {
213
 
                                        action = GettextCatalog.GetString ("Replace");
214
 
                                        actionIcon = "gtk-edit";
215
 
                                } else {
216
 
                                        action = rp.ActionDescription;
217
 
                                        actionIcon = MonoDevelop.Core.Gui.Stock.Empty;
218
 
                                }
219
 
                                
220
 
                                string fileIcon;
221
 
/*                              if (n.IsDirectory)
222
 
                                        fileIcon = MonoDevelop.Core.Gui.Stock.ClosedFolder;
223
 
                                else
224
 
*/                                      fileIcon = IdeApp.Services.Icons.GetImageForFile (rp.Path);
225
 
                                
226
 
                                changedpathstore.AppendValues (actionIcon, action, fileIcon, rp.Path);
227
 
                        }
228
 
                }
229
 
                
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();
234
 
                }
235
 
                
236
 
                void ViewTextButtonClicked(object src, EventArgs args) {
237
 
                        Revision d = GetSelectedRev();
238
 
                        if (d == null) return;
239
 
                        HistoricalFileView.Show(filepath, vc, vinfo.RepositoryPath, d);
240
 
                }
241
 
                
242
 
                public override Gtk.Widget Control { 
243
 
                        get {
244
 
                                return widget;
245
 
                        }
246
 
                }
247
 
                
248
 
                public override void Dispose ()
249
 
                {
250
 
                        widget.Destroy ();
251
 
                        base.Dispose ();
252
 
                }
253
 
 
254
 
                
255
 
                internal class DiffWorker : Task {
256
 
                        Repository vc;
257
 
                        string name;
258
 
                        Revision revision;
259
 
                        string text1, text2;
260
 
                        string revPath;
261
 
                                                
262
 
                        public DiffWorker(string name, Repository vc, string revPath, Revision revision) {
263
 
                                this.name = name;
264
 
                                this.vc = vc;
265
 
                                this.revPath = revPath;
266
 
                                this.revision = revision;
267
 
                        }
268
 
                        
269
 
                        protected override string GetDescription() {
270
 
                                return GettextCatalog.GetString ("Retreiving changes in {0} at revision {1}...", name, revision);
271
 
                        }
272
 
                        
273
 
                        protected override void Run() {
274
 
                                Log (GettextCatalog.GetString ("Getting text of {0} at revision {1}...", revPath, revision.GetPrevious()));
275
 
                                try {
276
 
                                        text1 = vc.GetTextAtRevision(revPath, revision.GetPrevious());
277
 
                                } catch {
278
 
                                        // If the file was added in this revision, no previous
279
 
                                        // text exists.
280
 
                                        text1 = "";
281
 
                                }
282
 
                                Log (GettextCatalog.GetString ("Getting text of {0} at revision {1}...", revPath, revision));
283
 
                                text2 = vc.GetTextAtRevision(revPath, revision);
284
 
                        }
285
 
                
286
 
                        protected override void Finished() {
287
 
                                if (text1 == null || text2 == null) return;
288
 
                                DiffView.Show(name + " (revision " + revision.ToString() + ")", text1, text2);
289
 
                        }
290
 
                }
291
 
                
292
 
        }
293
 
 
294
 
        internal class HistoricalFileView
295
 
        {
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);
301
 
                        doc.IsDirty = false;
302
 
                }
303
 
                        
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();
307
 
                }
308
 
                
309
 
                        
310
 
                internal class Worker : Task {
311
 
                        Repository vc;
312
 
                        string name, file;
313
 
                        string revPath;
314
 
                        Revision revision;
315
 
                        string text;
316
 
                                                
317
 
                        public Worker(string name, string file, Repository vc, string revPath, Revision revision) {
318
 
                                this.name = name;
319
 
                                this.file = file;
320
 
                                this.vc = vc;
321
 
                                this.revPath = revPath;
322
 
                                this.revision = revision;
323
 
                        }
324
 
                        
325
 
                        protected override string GetDescription() {
326
 
                                return GettextCatalog.GetString ("Retreiving content of {0} at revision {1}...", name, revision);
327
 
                        }
328
 
                        
329
 
                        protected override void Run() {
330
 
                                text = vc.GetTextAtRevision(revPath, revision);
331
 
                        }
332
 
                
333
 
                        protected override void Finished() {
334
 
                                if (text == null) return;
335
 
                                HistoricalFileView.Show(name, file, text);
336
 
                        }
337
 
                }
338
 
        }
339
 
 
340
 
}