Skip to content

Commit a780ad9

Browse files
author
Pieter de Bie
committed
Add an example of how drag-selection for staging lines could work.
1 parent 85f2c72 commit a780ad9

File tree

1 file changed

+195
-0
lines changed

1 file changed

+195
-0
lines changed

html/dragtest.html

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<html>
2+
<head>
3+
4+
<link rel="stylesheet" href="css/GitX.css" type="text/css" media="screen" title="no title" charset="utf-8">
5+
<link rel="stylesheet" href="css/diff.css" type="text/css" media="screen" title="no title" charset="utf-8">
6+
<script src="lib/GitX.js" type="text/javascript" charset="utf-8"></script>
7+
<script src="lib/diffHighlighter.js" type="text/javascript" charset="utf-8"></script>
8+
9+
<style type="text/css" media="screen">
10+
#lijstmetdingen {
11+
font-size: 50%;
12+
}
13+
.line {
14+
}
15+
#selected {
16+
background-color: #B5D5FE !important;
17+
-webkit-border-radius: 3px;
18+
-webkit-box-sizing: border-box;
19+
width: 100%;
20+
/* border: 1px solid red;*/
21+
padding-left: 3px !important;
22+
padding-right: 3px !important;
23+
/* margin-left: -3px !important;
24+
margin-right: -3px !important;
25+
*/ }
26+
27+
#selected div {
28+
background-color: #B5D5FE;
29+
}
30+
31+
#stageButton {
32+
float: right;
33+
34+
display: block;
35+
height: 12px;
36+
padding: 4px;
37+
-webkit-border-radius: 4px;
38+
background-color: white !important;
39+
border: 1px solid blue;
40+
margin-top: 4px;
41+
z-index: -100;
42+
}
43+
44+
</style>
45+
46+
<script type="text/javascript" charset="utf-8">
47+
var nodeIndex = function(list, element)
48+
{
49+
for (i = 0; i < list.childNodes.length; ++i)
50+
if (list.childNodes[i] == element)
51+
return i;
52+
return -1
53+
}
54+
55+
var deselect = function()
56+
{
57+
var selection = document.getElementById("selected");
58+
if (selection) {
59+
while (selection.childNodes[1])
60+
selection.parentNode.insertBefore(selection.childNodes[1], selection);
61+
selection.parentNode.removeChild(selection);
62+
}
63+
}
64+
65+
var showSelection = function(list, from, to)
66+
{
67+
deselect();
68+
var startIndex = nodeIndex(list, from);
69+
var endIndex = nodeIndex(list, to);
70+
71+
if (startIndex == -1 || endIndex == -1)
72+
return;
73+
74+
if (startIndex > endIndex)
75+
{
76+
var tmp = endIndex;
77+
endIndex = startIndex;
78+
startIndex = tmp;
79+
tmp = to;
80+
to = from;
81+
from = tmp;
82+
}
83+
84+
// new Array().slice() doesn't work with elementnodes :(
85+
// So we create an array ourselves
86+
var elementList = [];
87+
for (i = startIndex; i <= endIndex; ++i)
88+
elementList.push(from.parentNode.childNodes[i]);
89+
90+
var selection = document.createElement("div");
91+
selection.setAttribute("id", "selected");
92+
var button = document.createElement("div");
93+
button.setAttribute("id", "stageButton");
94+
button.appendChild(document.createTextNode("Stage lines"));
95+
button.onmousedown = function() {
96+
while (selection.firstChild)
97+
selection.removeChild(selection.firstChild);
98+
return false;
99+
}
100+
selection.appendChild(button);
101+
list.insertBefore(selection, from);
102+
103+
var element;
104+
for (i = 0; i < elementList.length; i++)
105+
selection.appendChild(elementList[i]);
106+
}
107+
108+
var load = function()
109+
{
110+
document.onmousedown = function(event) {
111+
var cur = event.target;
112+
while (cur) {
113+
if (cur.getAttribute && cur.getAttribute("class") && cur.getAttribute("class").indexOf("lines") != -1)
114+
return;
115+
cur = cur.parentNode;
116+
}
117+
deselect();
118+
}
119+
120+
highlightDiff($("orig_diff").value,
121+
$("lijstmetdingen"),
122+
{ }
123+
);
124+
125+
var list = document.getElementsByClassName("lines");
126+
127+
for (i = 0; i < list.length; ++i) {
128+
file = list[i];
129+
file.onmousedown = function(event) {
130+
file.onmouseover = function(event2) {
131+
showSelection(file, event.srcElement, event2.target);
132+
return false;
133+
};
134+
135+
file.onmouseup = function(event2) {
136+
file.onmouseover = null;
137+
file.onmouseup = null;
138+
};
139+
140+
showSelection(file, event.srcElement, event.srcElement);
141+
return false;
142+
}
143+
}
144+
}
145+
</script>
146+
</head>
147+
<body onload="load()">
148+
<textarea style='display:none' id="orig_diff" rows="8" cols="40">
149+
diff --git a/.gitignore b/.gitignore
150+
index b89b7b7..3367a4e 100644
151+
--- a/.gitignore
152+
+++ b/.gitignore
153+
@@ -1,4 +1,5 @@
154+
build
155+
+build/revision
156+
*.xcodeproj/*.pbxuser
157+
*.xcodeproj/*.perspectivev3
158+
*.xcodeproj/*.mode1v3
159+
diff --git a/ApplicationController.m b/ApplicationController.m
160+
index 86252cd..3a86d38 100644
161+
--- a/ApplicationController.m
162+
+++ b/ApplicationController.m
163+
@@ -21,7 +21,7 @@ @implementation ApplicationController
164+
165+
- (ApplicationController*)init
166+
{
167+
-#ifndef NDEBUG
168+
+#ifdef DEBUG_BUILD
169+
[NSApp activateIgnoringOtherApps:YES];
170+
#endif
171+
172+
@@ -92,12 +92,16 @@ - (IBAction)openPreferencesWindow:(id)sender
173+
- (IBAction)installCliTool:(id)sender;
174+
{
175+
BOOL success = NO;
176+
- NSString* installationPath = @"/usr/local/bin/gitx";
177+
+ NSString* installationPath = @"/usr/local/bin/";
178+
+ NSString* installationName = @"gitx";
179+
NSString* toolPath = [[NSBundle mainBundle] pathForResource:@"gitx" ofType:@""];
180+
if (toolPath) {
181+
AuthorizationRef auth;
182+
if (AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth) == errAuthorizationSuccess) {
183+
- char const* arguments[] = { "-f", "-s", [toolPath UTF8String], [installationPath UTF8String], NULL };
184+
+ char const* mkdir_arg[] = { "-p", [installationPath UTF8String], NULL};
185+
+ char const* mkdir = "/bin/mkdir";
186+
+ AuthorizationExecuteWithPrivileges(auth, mkdir, kAuthorizationFlagDefaults, (char**)mkdir_arg, NULL);
187+
+ char const* arguments[] = { "-f", "-s", [toolPath UTF8String], [[installationPath stringByAppendingString: installationName] UTF8String], NULL };
188+
char const* helperTool = "/bin/ln";
189+
if (AuthorizationExecuteWithPrivileges(auth, helperTool, kAuthorizationFlagDefaults, (char**)arguments, NULL) == errAuthorizationSuccess) {
190+
int status;
191+
</textarea>
192+
<div id='lijstmetdingen'></div>
193+
</body>
194+
</body>
195+
</html>

0 commit comments

Comments
 (0)