Permalink
Browse files

Gnome Shell 3.2 compatibility

  • Loading branch information...
1 parent 83c3b3d commit 13fef4f7bfe69c61c99f57c45cec7d5464171579 @sustmi committed Nov 10, 2011
Showing with 49 additions and 18 deletions.
  1. +48 −17 historymanager-prefix-search/extension.js
  2. +1 −1 historymanager-prefix-search/metadata.json
@@ -1,5 +1,4 @@
const Clutter = imports.gi.Clutter;
-const Mainloop = imports.mainloop;
const History = imports.misc.history;
const Main = imports.ui.main;
@@ -9,16 +8,36 @@ function injectToFunction(parent, name, func) {
let origin = parent[name];
parent[name] = function() {
let ret;
- ret = origin.apply(this, arguments);
- if (ret === undefined)
- ret = func.apply(this, arguments);
+ if (origin !== undefined) {
+ ret = origin.apply(this, arguments);
+ }
+ ret = func.apply(this, arguments);
return ret;
}
+ return origin;
+}
+function removeInjection(object, injection, name) {
+ if (injection[name] === undefined) {
+ delete object[name];
+ } else {
+ object[name] = injection[name];
+ }
}
-function main() {
+let historyManagerInjections;
+
+function resetState() {
+ historyManagerInjections = {};
+}
+
+function enable() {
+ resetState();
+
+ historyManagerInjections['prevItemPrefix'] = undefined;
+ historyManagerInjections['nextItemPrefix'] = undefined;
+ historyManagerInjections['_onEntryKeyPress'] = undefined;
- History.HistoryManager.prototype.prevItemPrefix = function(text, prefix) {
+ historyManagerInjections['prevItemPrefix'] = injectToFunction(History.HistoryManager.prototype, 'prevItemPrefix', function(text, prefix) {
function _hasPrefix(s1, prefix) {
return s1.indexOf(prefix) == 0;
}
@@ -31,9 +50,9 @@ function main() {
}
return text;
- }
+ });
- History.HistoryManager.prototype.nextItemPrefix = function(text, prefix) {
+ historyManagerInjections['nextItemPrefix'] = injectToFunction(History.HistoryManager.prototype, 'nextItemPrefix', function(text, prefix) {
function _hasPrefix(s1, prefix) {
return s1.indexOf(prefix) == 0;
}
@@ -46,17 +65,11 @@ function main() {
}
return text;
- }
+ });
- History.HistoryManager.prototype._onEntryKeyPress = function(entry, event) {
+ historyManagerInjections['_onEntryKeyPress'] = injectToFunction(History.HistoryManager.prototype, '_onEntryKeyPress', function(entry, event) {
let symbol = event.get_key_symbol();
- if (symbol == Clutter.KEY_Up) {
- this.prevItem(entry.get_text());
- return true;
- } else if (symbol == Clutter.KEY_Down) {
- this.nextItem(entry.get_text());
- return true;
- } else if (symbol == Clutter.KEY_Page_Up) {
+ if (symbol == Clutter.KEY_Page_Up) {
let pos = (entry.get_cursor_position() != -1) ? entry.get_cursor_position() : entry.get_text().length;
if (pos > 0) {
this.prevItemPrefix(entry.get_text(), entry.get_text().slice(0, pos));
@@ -77,6 +90,24 @@ function main() {
}
return false;
+ });
+
+}
+
+function disable() {
+ for (i in historyManagerInjections) {
+ removeInjection(History.HistoryManager.prototype, historyManagerInjections, i);
}
+ resetState();
+}
+function init() {
+ // Stateless
}
+
+// 3.0 API backward compatibility
+function main() {
+ init();
+ enable();
+}
+
@@ -1,5 +1,5 @@
{
- "shell-version": ["3.0"],
+ "shell-version": ["3.0", "3.2"],
"uuid": "historymanager-prefix-search@sustmidown.centrum.cz",
"name": "HistoryManager Prefix Search",
"description": "Use PageUp and PageDown to move in HistoryManager (eg. RunCommand, Looking Glass) according to prefix",

0 comments on commit 13fef4f

Please sign in to comment.