Skip to content

Commit

Permalink
setup.py: Modified walk_data_files() so that it will skip .pyc and .p…
Browse files Browse the repository at this point in the history
…yo files in addition to .git directories.

gateone.js:  Modified GateOne.Input.capture() to use named functions for goDiv.onmousedown and goDiv.onmouseup so they can be overridden easier by plugins.
gateone.js:  More tweaks to the code that handles copy & paste in various situations.  Sigh, the complexity of copy & paste is ridiculous!
gateone.js:  Related to copy & paste, the pastearea.onmouseover event has been changed to use onmousemove instead.  It is more efficient this way.  It has also been modified to work better with elements in the terminal screen that have the 'clickable' class.  The cursor should stay set to a pointer and 'extra special stuff' that has been assigned to such elements such as context menus will work properly.
All Plugins Static JS:  Made sure that every one of them starts and begins with a newline.  This is so they are easier to delineate (visually) when they're all combined into one big honkin' JS file (combined_js).
CSS Themes:  Added a :hover psuedoclass for the pastearea to ensure that the mouse stays looking like it is hovering over text.
  • Loading branch information
liftoff committed Oct 11, 2012
1 parent 3b928e6 commit d108312
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 78 deletions.
2 changes: 1 addition & 1 deletion gateone/gateone.py
Expand Up @@ -851,7 +851,7 @@ def get(self):
if os.path.exists(combined_plugins):
with open(combined_plugins) as f:
js_data = f.read()
if len(js_data) < 100: # Needs to be created
if len(js_data) < 200: # Needs to be created
self.write(self._combine_plugins())
return
else: # It hasn't changed, send it as-is
Expand Down
11 changes: 7 additions & 4 deletions gateone/plugins/convenience/static/convenience.js
@@ -1,14 +1,17 @@

(function(window, undefined) {
var document = window.document; // Have to do this because we're sandboxed

"use strict";

var document = window.document, // Have to do this because we're sandboxed
// These are just convenient shortcuts:
go = GateOne,
// These are just convenient shortcuts:
var go = GateOne,
u = go.Utils,
t = go.Terminal,
v = go.Visual,
prefix = go.prefs.prefix;

// Tunable playback prefs
// Tunable prefs
if (typeof(go.prefs.disableLSConvenience) == "undefined") {
go.prefs.disableLSConvenience = false;
}
Expand Down
1 change: 1 addition & 0 deletions gateone/plugins/example/static/example.js
@@ -1,3 +1,4 @@

// An example of how to add Google Analytics to your plugin:
var _gaq = _gaq || []; // We'll actually make our plugin-specific Google Analytics call inside of init()
(function() { // Load the GA script the Gate One way (you can include this in your own plugin without having to worry about duplicates/conflicts)
Expand Down
1 change: 1 addition & 0 deletions gateone/plugins/logging/static/logging.js
@@ -1,3 +1,4 @@

(function(window, undefined) {
var document = window.document; // Have to do this because we're sandboxed

Expand Down
1 change: 1 addition & 0 deletions gateone/plugins/mobile/static/mobile.js
@@ -1,3 +1,4 @@

(function(window, undefined) {
var document = window.document; // Have to do this because we're sandboxed

Expand Down
1 change: 1 addition & 0 deletions gateone/plugins/playback/static/playback.js
@@ -1,3 +1,4 @@

(function(window, undefined) {
var document = window.document; // Have to do this because we're sandboxed

Expand Down
3 changes: 2 additions & 1 deletion gateone/plugins/ssh/static/ssh.js
@@ -1,3 +1,4 @@

(function(window, undefined) { // Sandbox it all
var document = window.document; // Have to do this because we're sandboxed

Expand Down Expand Up @@ -1121,4 +1122,4 @@ GateOne.Base.update(GateOne.SSH, {
}
});

})(window);
})(window);
192 changes: 121 additions & 71 deletions gateone/static/gateone.js
Expand Up @@ -1813,6 +1813,80 @@ GateOne.Input.shortcuts = {}; // Shortcuts added via registerShortcut() wind up
// 'KEY_N': [{'modifiers': {'ctrl': true, 'alt': true, 'meta': false, 'shift': false}, 'action': 'GateOne.Terminal.newTerminal()'}]
GateOne.Base.update(GateOne.Input, {
// GateOne.Input is in charge of all keyboard input as well as copy & paste stuff
onMouseDown: function(e) {
// TODO: Add a shift-click context menu for special operations. Why shift and not ctrl-click or alt-click? Some platforms use ctrl-click to emulate right-click and some platforms use alt-click to move windows around.
logDebug("goDiv.onmousedown() button: " + e.button + ", which: " + e.which);
var go = GateOne,
u = go.Utils,
prefix = go.prefs.prefix,
goDiv = u.getNode(go.prefs.goDiv),
m = go.Input.mouse(e),
selectedTerm = localStorage[prefix+'selectedTerminal'],
selectedPastearea = go.terminals[selectedTerm]['pasteNode'],
selectedText = u.getSelText();
go.Input.mouseDown = true;
// This is kinda neat: By setting "contentEditable = true" we can right-click to paste.
// However, we only want this when the user is actually bringing up the context menu because
// having it enabled slows down screen updates by a non-trivial amount.
if (m.button.middle) {
u.showElement(selectedPastearea);
selectedPastearea.focus();
if (selectedText.length) {
go.Input.handlingPaste = true; // We're emulating a paste so we might as well act like one
// Only preventDefault if text is selected so we don't muck up X11-style middle-click pasting
e.preventDefault();
go.Input.queue(selectedText);
go.Net.sendChars();
setTimeout(function() {
go.Input.handlingPaste = false;
}, 250);
}
} else if (m.button.right) {
if (!selectedText.length) {
// Redisplay the pastearea so we can get a proper context menu in case the user wants to paste
// NOTE: On Firefox this behavior is broken. See: https://bugzilla.mozilla.org/show_bug.cgi?id=785773
u.showElement(selectedPastearea);
selectedPastearea.focus();
} else {
goDiv.focus();
}
} else {
goDiv.focus();
}
},
onMouseUp: function(e) {
var go = GateOne,
u = go.Utils,
prefix = go.prefs.prefix,
selectedTerm = localStorage[prefix+'selectedTerminal'],
selectedPastearea = go.terminals[selectedTerm]['pasteNode'],
goDiv = u.getNode(go.prefs.goDiv),
selectedText = u.getSelText();
logDebug("goDiv.onmouseup: e.button: " + e.button + ", e.which: " + e.which);
// Once the user is done pasting (or clicking), set it back to false for speed
// goDiv.contentEditable = false; // Having this as false makes screen updates faster
go.Input.mouseDown = false;
if (selectedText) {
// Don't show the pastearea as it will prevent the user from right-clicking to copy.
return;
}
if (document.activeElement.tagName == "INPUT" || document.activeElement.tagName == "TEXTAREA" || document.activeElement.tagName == "SELECT" || document.activeElement.tagName == "BUTTON") {
return; // Don't do anything if the user is editing text in an input/textarea or is using a select element (so the up/down arrows work)
}
if (!go.Visual.gridView) {
setTimeout(function() {
if (!u.getSelText()) {
u.showElement(selectedPastearea);
}
}, 750); // NOTE: For this to work (to allow users to double-click-to-highlight a word) they must double-click before this timer fires.
}
// If the Firefox bug timer hasn't fired by now it wasn't a click-and-drag event
if (go.Input.firefoxBugTimer) {
clearTimeout(go.Input.firefoxBugTimer);
go.Input.firefoxBugTimer = null;
}
goDiv.focus();
},
capture: function() {
// Returns focus to goDiv and ensures that it is capturing onkeydown events properly
logDebug('capture()');
Expand All @@ -1829,70 +1903,8 @@ GateOne.Base.update(GateOne.Input, {
// After the copy we need to bring the pastearea back up so the context menu will work to paste again
u.showElements('.pastearea');
}
goDiv.onmousedown = function(e) {
// TODO: Add a shift-click context menu for special operations. Why shift and not ctrl-click or alt-click? Some platforms use ctrl-click to emulate right-click and some platforms use alt-click to move windows around.
logDebug("goDiv.onmousedown() button: " + e.button + ", which: " + e.which);
var m = go.Input.mouse(e),
selectedTerm = localStorage[prefix+'selectedTerminal'],
selectedPastearea = go.terminals[selectedTerm]['pasteNode'],
selectedText = u.getSelText();
go.Input.mouseDown = true;
// This is kinda neat: By setting "contentEditable = true" we can right-click to paste.
// However, we only want this when the user is actually bringing up the context menu because
// having it enabled slows down screen updates by a non-trivial amount.
if (m.button.middle) {
u.showElement(selectedPastearea);
selectedPastearea.focus();
if (selectedText.length) {
go.Input.handlingPaste = true; // We're emulating a paste so we might as well act like one
// Only preventDefault if text is selected so we don't muck up X11-style middle-click pasting
e.preventDefault();
go.Input.queue(selectedText);
go.Net.sendChars();
setTimeout(function() {
go.Input.handlingPaste = false;
}, 250);
}
} else if (m.button.right) {
if (!selectedText.length) {
// Redisplay the pastearea so we can get a proper context menu in case the user wants to paste
// NOTE: On Firefox this behavior is broken. See: https://bugzilla.mozilla.org/show_bug.cgi?id=785773
u.showElement(selectedPastearea);
selectedPastearea.focus();
} else {
goDiv.focus();
}
} else {
goDiv.focus();
}
}
goDiv.onmouseup = function(e) {
logDebug("goDiv.onmouseup: e.button: " + e.button + ", e.which: " + e.which);
// Once the user is done pasting (or clicking), set it back to false for speed
// goDiv.contentEditable = false; // Having this as false makes screen updates faster
go.Input.mouseDown = false;
var selectedText = u.getSelText();
if (selectedText) {
// Don't show the pastearea as it will prevent the user from right-clicking to copy.
return;
}
if (document.activeElement.tagName == "INPUT" || document.activeElement.tagName == "TEXTAREA" || document.activeElement.tagName == "SELECT" || document.activeElement.tagName == "BUTTON") {
return; // Don't do anything if the user is editing text in an input/textarea or is using a select element (so the up/down arrows work)
}
if (!go.Visual.gridView) {
setTimeout(function() {
if (!u.getSelText()) {
u.showElements('.pastearea');
}
}, 750); // NOTE: For this to work (to allow users to double-click-to-highlight a word) they must double-click before this timer fires.
}
// If the Firefox bug timer hasn't fired by now it wasn't a click-and-drag event
if (go.Input.firefoxBugTimer) {
clearTimeout(go.Input.firefoxBugTimer);
go.Input.firefoxBugTimer = null;
}
goDiv.focus();
}
goDiv.onmousedown = go.Input.onMouseDown;
goDiv.onmouseup = go.Input.onMouseUp;
if (go.Input.overlayTimer) {
clearTimeout(go.Input.overlayTimer);
go.Input.overlayTimer = null;
Expand Down Expand Up @@ -2898,6 +2910,9 @@ GateOne.Base.update(GateOne.Visual, {
}
v.infoTimer = setTimeout(function() {
v.applyStyle(infoContainer, {'opacity': 0});
setTimeout(function() {
u.hideElement(infoContainer);
}, 1000);
}, 1000);
},
displayMessage: function(message, /*opt*/timeout, /*opt*/removeTimeout, /*opt*/id) {
Expand Down Expand Up @@ -4785,24 +4800,55 @@ go.Base.update(GateOne.Terminal, {
pastearea.oncontextmenu = function(e) {
pastearea.focus();
}
pastearea.onmouseover = function(e) {
pastearea.onmousemove = function(e) {
var go = GateOne,
u = go.Utils,
prefix = go.prefs.prefix,
termline = null,
elem = null,
maxRecursion = 10,
count = 0,
X = e.clientX,
Y = e.clientY;
Y = e.clientY,
timeout = 200;
if (pastearea.style.display != 'none') {
u.hideElement(pastearea);
go.Input.pasteareaTemp = pastearea.onmousemove;
pastearea.onmouseover = null;
}
var elementUnder = document.elementFromPoint(X, Y);
while (!termline) {
count += 1;
if (count > maxRecursion) {
break;
}
if (!elem) {
elem = elementUnder;
}
if (typeof(elem.className) == "undefined") {
break;
}
if (elem.className.indexOf('termline') != -1) {
termline = elem;
} else if (elem.className.indexOf('clickable') != -1) {
// Clickable elements mean we shouldn't make the pastearea reappear
if (go.Terminal.pasteAreaTimer) {
clearTimeout(go.Terminal.pasteAreaTimer);
go.Terminal.pasteAreaTimer = null;
}
return;
} else {
elem = elem.parentNode;
}
}
if (go.Terminal.pasteAreaTimer) {
return; // Let it return to visibility on its own
}
go.Terminal.pasteAreaTimer = setTimeout(function() {
if (!u.getSelText()) {
u.showElement(pastearea);
go.Terminal.pasteAreaTimer = null;
}
}, 100);
pastearea.onmousemove = go.Input.pasteareaTemp;
go.Terminal.pasteAreaTimer = null;
u.showElement(pastearea);
}, timeout);
}
pastearea.onmousedown = function(e) {
// When the user left-clicks assume they're trying to highlight text
Expand Down Expand Up @@ -4850,6 +4896,10 @@ go.Base.update(GateOne.Terminal, {
// Browser won't let us execute a paste event... Hope for the best with the pastearea!
;; // Ignore
}
} else if (m.button.right) {
if (u.getSelText()) {
u.hideElement(pastearea);
}
}
}
terminal.appendChild(pastearea);
Expand Down
3 changes: 3 additions & 0 deletions gateone/templates/themes/black.css
Expand Up @@ -338,6 +338,9 @@ hr {
width: 96%; /* For whatever reason Firefox needs the width/height set */
height: 95%; /* Make room at the bottom for playback controls */
}
#{{container}} .pastearea:hover {
cursor: text;
}
/* This is to work around a Chrome/Windows bug where pasting gets disabled if you use JS to set display: none */
#{{container}} .go_none { /* No prefix on this one because of issues with that in the JS code */
/* display: none; */
Expand Down
3 changes: 3 additions & 0 deletions gateone/templates/themes/dark-black.css
Expand Up @@ -339,6 +339,9 @@ hr {
width: 96%; /* For whatever reason Firefox needs the width/height set */
height: 95%;
}
#{{container}} .pastearea:hover {
cursor: text;
}
/* This is to work around a Chrome/Windows bug where pasting gets disabled if you use JS to set display: none */
#{{container}} .go_none { /* No prefix on this one because of issues with that in the JS code */
display: none;
Expand Down
3 changes: 3 additions & 0 deletions gateone/templates/themes/solarized.css
Expand Up @@ -340,6 +340,9 @@ hr {
width: 96%; /* For whatever reason Firefox needs the width/height set */
height: 95%; /* Make room at the bottom for playback controls */
}
#{{container}} .pastearea:hover {
cursor: text;
}
/* This is to work around a Chrome/Windows bug where pasting gets disabled if you use JS to set display: none */
#{{container}} .go_none { /* No prefix on this one because of issues with that in the JS code */
/* display: none; */
Expand Down
3 changes: 3 additions & 0 deletions gateone/templates/themes/white.css
Expand Up @@ -340,6 +340,9 @@ hr {
width: 96%; /* For whatever reason Firefox needs the width/height set */
height: 95%;
}
#{{container}} .pastearea:hover {
cursor: text;
}
/* This is to work around a Chrome/Windows bug where pasting gets disabled if you use JS to set display: none */
#{{container}} .go_none { /* No prefix on this one because of issues with that in the JS code */
display: none;
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Expand Up @@ -54,7 +54,7 @@ def walk_data_files(path, install_path=prefix):
Walks *path* and returns a list suitable for use in data_files.
*install_path* will be used as the base installation path of the output.
NOTE: Ignores .git directories.
NOTE: Ignores .git directories and .pyc/.pyo files.
"""
out = []
for (dirpath, dirs, filenames) in os.walk(path):
Expand All @@ -64,6 +64,8 @@ def walk_data_files(path, install_path=prefix):
shortened_path = dirpath.split(setup_dir)[1][1:]
final_path = os.path.join(install_path, shortened_path)
for fname in filenames:
if fname.endswith('.pyc') or fname.endswith('.pyo'):
continue # Skip it
file_path = os.path.join(dirpath, fname)
thesefiles.append(file_path)
out.append((final_path, thesefiles))
Expand Down

0 comments on commit d108312

Please sign in to comment.