Ejemplo n.º 1
0
		void HandleTreeviewFilesTestExpandRow (object o, TestExpandRowArgs args)
		{
			TreeIter iter;
			if (changedpathstore.IterChildren (out iter, args.Iter)) {
				string[] diff = changedpathstore.GetValue (iter, colDiff) as string[];
				if (diff != null)
					return;

				string path = (string)changedpathstore.GetValue (args.Iter, colPath);

				changedpathstore.SetValue (iter, colDiff, new string[] { GettextCatalog.GetString ("Loading data...") });
				var rev = SelectedRevision;
				ThreadPool.QueueUserWorkItem (delegate {
					string text = "";
					try {
						text = info.Repository.GetTextAtRevision (path, rev);
					} catch (Exception e) {
						Application.Invoke (delegate {
							LoggingService.LogError ("Error while getting revision text", e);
							MessageService.ShowError ("Error while getting revision text.", "The file may not be part of the working copy.");
						});
						return;
					}
					Revision prevRev = null;
					try {
						prevRev = rev.GetPrevious ();
					} catch (Exception e) {
						Application.Invoke (delegate {
							LoggingService.LogError ("Error while getting previous revision", e);
							MessageService.ShowException (e, "Error while getting previous revision.");
						});
						return;
					}
					string[] lines;
					// Indicator that the file was binary
					if (text == null) {
						lines = new [] { " Binary files differ" };
					} else {
						var changedDocument = new Mono.TextEditor.TextDocument (text);
						if (prevRev == null) {
							lines = new string [changedDocument.LineCount];
							for (int i = 0; i < changedDocument.LineCount; i++) {
								lines[i] = "+ " + changedDocument.GetLineText (i + 1).TrimEnd ('\r','\n');
							}
						} else {
							string prevRevisionText = "";
							try {
								prevRevisionText = info.Repository.GetTextAtRevision (path, prevRev);
							} catch (Exception e) {
								Application.Invoke (delegate {
									LoggingService.LogError ("Error while getting revision text", e);
									MessageService.ShowError ("Error while getting revision text.", "The file may not be part of the working copy.");
								});
								return;
							}

							if (String.IsNullOrEmpty (text)) {
								if (!String.IsNullOrEmpty (prevRevisionText)) {
									lines = new string [changedDocument.LineCount];
									for (int i = 0; i < changedDocument.LineCount; i++) {
										lines [i] = "- " + changedDocument.GetLineText (i + 1).TrimEnd ('\r','\n');
									}
								}
							}

							var originalDocument = new Mono.TextEditor.TextDocument (prevRevisionText);
							originalDocument.FileName = "Revision " + prevRev;
							changedDocument.FileName = "Revision " + rev;
							lines = Mono.TextEditor.Utils.Diff.GetDiffString (originalDocument, changedDocument).Split ('\n');
						}
					}
					Application.Invoke (delegate {
						changedpathstore.SetValue (iter, colDiff, lines);
					});
				});
			}
		}
Ejemplo n.º 2
0
        void HandleTreeviewFilesTestExpandRow(object o, TestExpandRowArgs args)
        {
            TreeIter iter;

            if (changedpathstore.IterChildren(out iter, args.Iter))
            {
                string[] diff = changedpathstore.GetValue(iter, colDiff) as string[];
                if (diff != null)
                {
                    return;
                }

                string path = (string)changedpathstore.GetValue(args.Iter, colPath);
                changedpathstore.SetValue(iter, colDiff, new string[] { GettextCatalog.GetString("Loading data...") });
                var rev = SelectedRevision;
                ThreadPool.QueueUserWorkItem(delegate {
                    string text;
                    try {
                        text = info.Repository.GetTextAtRevision(path, rev);
                    } catch (Exception e) {
                        Application.Invoke(delegate {
                            LoggingService.LogError("Error while getting revision text", e);
                            MessageService.ShowError("Error while getting revision text.", "The file may not be part of the working copy.");
                        });
                        return;
                    }
                    Revision prevRev = null;
                    try {
                        prevRev = rev.GetPrevious();
                    } catch (Exception e) {
                        Application.Invoke(delegate {
                            LoggingService.LogError("Error while getting previous revision", e);
                            MessageService.ShowException(e, "Error while getting previous revision.");
                        });
                        return;
                    }
                    string[] lines;
                    // Indicator that the file was binary
                    if (text == null)
                    {
                        lines = new [] { " Binary files differ" };
                    }
                    else
                    {
                        var changedDocument = new Mono.TextEditor.TextDocument(text);
                        if (prevRev == null)
                        {
                            lines = new string[changedDocument.LineCount];
                            for (int i = 0; i < changedDocument.LineCount; i++)
                            {
                                lines[i] = "+ " + changedDocument.GetLineText(i + 1).TrimEnd('\r', '\n');
                            }
                        }
                        else
                        {
                            string prevRevisionText = "";
                            try {
                                prevRevisionText = info.Repository.GetTextAtRevision(path, prevRev);
                            } catch (Exception e) {
                                // The file did not exist at this point in time, so just treat it as empty
                            }

                            var originalDocument      = new Mono.TextEditor.TextDocument(prevRevisionText);
                            originalDocument.FileName = "Revision " + prevRev.ToString();
                            changedDocument.FileName  = "Revision " + rev.ToString();
                            lines = Mono.TextEditor.Utils.Diff.GetDiffString(originalDocument, changedDocument).Split('\n');
                        }
                    }
                    Application.Invoke(delegate {
                        changedpathstore.SetValue(iter, colDiff, lines);
                    });
                });
            }
        }