-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainView.qml
90 lines (71 loc) · 2.45 KB
/
MainView.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import QtQuick 2.0
Rectangle {
id: root
property int commitCount: 0
property string currentCommitHash: ""
property string currentCommitHeader: ""
property string currentCommitDiff: ""
property var commitModel
signal reseted();
SystemPalette { id: palette }
onCurrentCommitHashChanged: {
update();
}
Component.onCompleted: {
reset();
update();
}
function reset() {
currentCommitHeader = "";
currentCommitDiff = "";
currentCommitIndex = 0;
reseted();
}
function update() {
var commit = commitModel.getCommit(currentCommitHash);
if (!commit)
return;
currentCommitHeader = commitHeader(commit);
currentCommitDiff = commitDiff(commit);
}
function commitHeader(commit) {
var text = "";
text += "<pre>";
text += "<font color='#c7c524'>commit " + commit.hash + "</font><br>";
text += "Author: " + commit.authorName + " <" + commit.authorEmail + "><br>";
text += "Date: " + commit.time;
text += "</pre>";
text += "<pre style=\"text-indent:30px\">";
text += commit.message;
text += "</pre>";
return text;
}
function commitDiff(commit) {
var text = "";
text += "<pre style='color:#999999'>";
var lines = commit.diff.split('\n');
for (var i = 0; i < lines.length; ++i) {
var line = lines[i];
line = line.replace(/</g, "<");
line = line.replace(/>/g, ">");
if (line.match("^diff --git.*$") ||
line.match("^index .*$") ||
line.match("^--- .*$") ||
line.match("^[+]{3} .*$") ||
line.match("^new file mode.*$") ||
line.match("^deleted file mode.*$")) {
line = "<font color='#000000'>" + line + "</font>";
} else if (line.match("^-.*$")) {
line = "<font color='#ff0000'>" + line + "</font>";
} else if (line.match("^[+].*$")) {
line = "<font color='#008000'>" + line + "</font>";
} else if (line.match("^@@ .*$")) {
var parts = line.match("^(@@.*?@@)(.*)$");
line = "<font color='#00a0a0'>" + parts[1] + "</font>"+ parts[2];
}
text += line + "\n";
}
text += "</pre>";
return text;
}
}