WebHistoryView: Use diff callbacks to display history list

This is the start of a callback system we can use to 
make the diff more interactive
This commit is contained in:
Pieter de Bie
2008-12-01 15:09:48 +01:00
parent 61994be15e
commit 7a3166c0e6
3 changed files with 31 additions and 21 deletions
+7 -2
View File
@@ -6,7 +6,9 @@ if (typeof Controller == 'undefined') {
Controller.log_ = console.log;
}
var highlightDiff = function(diff, element) {
var highlightDiff = function(diff, element, callbacks) {
if (!callbacks)
callbacks = {};
var start = new Date().getTime();
element.className = "diff"
var content = diff.escapeHTML().replace(/\t/g, " ");;
@@ -51,8 +53,11 @@ var highlightDiff = function(diff, element) {
diffContent = "";
}
if(match = l.match(/diff --git a\/(\S*)/))
if(match = l.match(/diff --git a\/(\S*)/)) {
filename = match[1];
if (callbacks["newfile"])
callbacks["newfile"](filename, "file_index_" + (file_index - 1));
}
continue;
}
+12 -4
View File
@@ -8,13 +8,21 @@
<script type="text/javascript" charset="utf-8">
var doeHet = function() {
highlightDiff($("orig_diff").value, $("diff"));
}
var newFile = function(name, id) {
$("filelist").innerHTML += "<a href='#" + id + "'>" + name + "</a><br>";
}
var doeHet = function() {
highlightDiff($("orig_diff").value,
$("diff"),
{ "newfile" : newFile }
);
}
</script>
</head>
<body style="padding: 0px; border: 0px" onLoad="doeHet()">
<body style="padding: 0px; border: 0px; font-size:60%" onLoad="doeHet()">
<div id="title"></div>
<div id="filelist"></div>
<textarea style='display:none' id="orig_diff" rows="8" cols="40">
diff --git a/English.lproj/RepositoryWindow.xib b/English.lproj/RepositoryWindow.xib
index 6cd49fa..7474752 100644
+12 -15
View File
@@ -174,6 +174,14 @@ var loadCommit = function(commitObject, currentRef) {
scroll(0, 0);
}
var showDiff = function() {
var newfile = function(name, id) {
$("files").innerHTML += "<a href='#" + id + "'>" + name + "</a><br>";
}
highlightDiff(commit.diff, $("diff"), { "newfile" : newfile });
}
var loadExtendedCommit = function(commit)
{
if (commit.author_email)
@@ -182,21 +190,10 @@ var loadExtendedCommit = function(commit)
$("date").innerHTML = commit.author_date;
$("message").innerHTML = commit.message.replace(/\n/g,"<br>");
if (commit.files) {
var commit_file_links = commit.files;
for (var i=0; i < commit_file_links.length; i++) {
index = i+1;
commit_file_links[i] = "<a href='#file_index_" + i + "'>" + commit.files[i] + "</a>";
}
$("files").innerHTML = commit_file_links.join("<br>");
}
if (commit.diff.length < 200000) {
highlightDiff(commit.diff, $("diff"));
} else {
$("diff").innerHTML = "<a class='showdiff' href='' onclick='showDiffs(); return false;'>This is a large commit. Click here or press 'v' to view.</a>";
}
if (commit.diff.length < 200000)
showDiff();
else
$("diff").innerHTML = "<a class='showdiff' href='' onclick='showDiff(); return false;'>This is a large commit. Click here or press 'v' to view.</a>";
hideNotification();
setGravatar(commit.author_email, $("gravatar"));