2013-09-11 06:15:04 +00:00
|
|
|
define([
|
2013-12-04 17:24:04 +00:00
|
|
|
"sessions",
|
|
|
|
"command",
|
|
|
|
"editor",
|
|
|
|
"settings!menus,user",
|
|
|
|
"ui/statusbar",
|
2013-12-10 22:46:28 +00:00
|
|
|
"ui/projectManager",
|
2014-01-22 06:47:02 +00:00
|
|
|
"util/template!templates/paletteItem.html",
|
2013-12-04 17:24:04 +00:00
|
|
|
"util/dom2"
|
2014-01-22 06:47:02 +00:00
|
|
|
], function(sessions, command, editor, Settings, status, project, inflate) {
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-10-15 00:00:13 +00:00
|
|
|
var TokenIterator = ace.require("ace/token_iterator").TokenIterator;
|
2013-10-17 20:56:27 +00:00
|
|
|
var refTest = /identifier|variable|function/;
|
2013-10-17 22:39:54 +00:00
|
|
|
var jsRefTest = /entity\.name\.function/;
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-12-16 16:10:08 +00:00
|
|
|
//build a regex that finds special regex characters for sanitization
|
2013-12-16 16:01:46 +00:00
|
|
|
var antiregex = new RegExp("(\\\\|\\" + "?.*+[](){}|^$".split("").join("|\\") + ")", "g");
|
2013-10-15 00:00:13 +00:00
|
|
|
var sanitize = function(text) {
|
2013-12-16 16:10:08 +00:00
|
|
|
//turn HTML into escaped text for presentation
|
2013-10-15 00:00:13 +00:00
|
|
|
return text.replace(/\</g, "<").replace(/\>/g, ">").trim();
|
|
|
|
};
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-10 16:19:14 +00:00
|
|
|
var re = {
|
|
|
|
file: /^([^:#@]*)/,
|
|
|
|
line: /:(\d*)/,
|
|
|
|
reference: /@([^:#]*)/,
|
|
|
|
search: /#([^:@]*)/
|
|
|
|
};
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-10 16:19:14 +00:00
|
|
|
var prefixes = {
|
|
|
|
":": "line",
|
|
|
|
"@": "reference",
|
|
|
|
"#": "search"
|
|
|
|
};
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-10 16:19:14 +00:00
|
|
|
var modes = {
|
|
|
|
"line": ":",
|
|
|
|
"search": "#",
|
|
|
|
"reference": "@"
|
|
|
|
};
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2014-03-20 02:24:13 +00:00
|
|
|
var DEBOUNCE = 50;
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
var Palette = function() {
|
2013-10-17 22:39:54 +00:00
|
|
|
this.homeTab = null;
|
2013-09-11 06:15:04 +00:00
|
|
|
this.results = [];
|
2013-10-15 00:00:13 +00:00
|
|
|
this.cache = {};
|
2014-03-08 05:06:08 +00:00
|
|
|
this.allFiles = [];
|
|
|
|
this.files = [];
|
|
|
|
this.pending = null;
|
2013-09-11 06:15:04 +00:00
|
|
|
this.selected = 0;
|
|
|
|
this.element = document.find(".palette");
|
|
|
|
this.input = this.element.find("input");
|
|
|
|
this.resultList = this.element.find(".results");
|
|
|
|
this.commandMode = false;
|
2013-10-15 05:17:58 +00:00
|
|
|
this.searchAll = false;
|
2013-09-11 06:15:04 +00:00
|
|
|
this.bindInput();
|
|
|
|
};
|
|
|
|
Palette.prototype = {
|
|
|
|
bindInput: function() {
|
|
|
|
var input = this.input;
|
|
|
|
var self = this;
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
input.on("blur", function() {
|
|
|
|
self.deactivate();
|
|
|
|
});
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
input.on("keydown", function(e) {
|
2014-03-08 05:06:08 +00:00
|
|
|
//escape
|
2013-09-11 06:15:04 +00:00
|
|
|
if (e.keyCode == 27) {
|
|
|
|
sessions.restoreLocation();
|
2013-10-15 05:17:58 +00:00
|
|
|
editor.clearSelection();
|
2013-09-11 06:15:04 +00:00
|
|
|
return input.blur();
|
|
|
|
}
|
2014-03-08 05:06:08 +00:00
|
|
|
//enter
|
2013-09-11 06:15:04 +00:00
|
|
|
if (e.keyCode == 13) {
|
|
|
|
e.stopImmediatePropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
self.executeCurrent();
|
|
|
|
return;
|
|
|
|
}
|
2014-03-08 05:06:08 +00:00
|
|
|
//up/down
|
2013-09-11 06:15:04 +00:00
|
|
|
if (e.keyCode == 38 || e.keyCode == 40) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopImmediatePropagation();
|
|
|
|
self.navigateList(e.keyCode == 38 ? -1 : 1);
|
|
|
|
self.render();
|
2013-09-20 15:57:43 +00:00
|
|
|
return;
|
2013-09-11 06:15:04 +00:00
|
|
|
}
|
2014-03-08 05:06:08 +00:00
|
|
|
//backspace -- falls through
|
|
|
|
if (e.keyCode == 8) {
|
|
|
|
//clear search progress cache
|
|
|
|
self.files = self.allFiles;
|
|
|
|
}
|
2013-09-20 15:57:43 +00:00
|
|
|
self.selected = 0;
|
2013-09-11 06:15:04 +00:00
|
|
|
});
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
input.on("keyup", function(e) {
|
2014-03-08 06:33:32 +00:00
|
|
|
if (self.pending) {
|
2014-03-08 05:06:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.pending = setTimeout(function() {
|
|
|
|
self.pending = null;
|
|
|
|
self.parse(input.value);
|
|
|
|
}, DEBOUNCE);
|
2013-09-11 06:15:04 +00:00
|
|
|
});
|
|
|
|
},
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
parse: function(query) {
|
|
|
|
var startsWith = query[0];
|
|
|
|
if (startsWith in prefixes) {
|
|
|
|
this.commandMode = false;
|
|
|
|
}
|
|
|
|
if (this.commandMode) {
|
|
|
|
this.findCommands(query);
|
|
|
|
} else {
|
|
|
|
this.findLocations(query);
|
|
|
|
}
|
|
|
|
this.render();
|
|
|
|
},
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
findCommands: function(query) {
|
|
|
|
if (query.length == 0) return this.results = [];
|
2013-12-16 16:01:46 +00:00
|
|
|
var fuzzyCommand = new RegExp(query
|
|
|
|
.split("")
|
|
|
|
.map(function(char) { return char.replace(antiregex, "\\$1")})
|
2014-03-21 11:51:42 +00:00
|
|
|
.join(".*?"),
|
2013-12-16 16:01:46 +00:00
|
|
|
"i");
|
2013-09-11 06:15:04 +00:00
|
|
|
var results = [];
|
2014-03-21 11:51:42 +00:00
|
|
|
//load matches from the menu
|
2013-09-11 06:15:04 +00:00
|
|
|
var menus = Settings.get("menus");
|
|
|
|
var menuWalker = function(menu) {
|
|
|
|
for (var i = 0; i < menu.length; i++) {
|
|
|
|
var item = menu[i];
|
2013-09-20 15:57:43 +00:00
|
|
|
//skip dividers and other special cases
|
|
|
|
if (typeof item == "string") continue;
|
2013-11-01 23:24:57 +00:00
|
|
|
if (item.minVersion && item.minVersion > window.navigator.version) continue;
|
2013-09-20 15:57:43 +00:00
|
|
|
if (item.command && fuzzyCommand.test(item.palette || item.label)) {
|
2013-09-11 06:15:04 +00:00
|
|
|
results.push(item);
|
|
|
|
}
|
|
|
|
if (item.sub) {
|
|
|
|
menuWalker(item.sub);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
menuWalker(menus);
|
2014-03-21 11:51:42 +00:00
|
|
|
//also load from the command list
|
|
|
|
var uniques = {};
|
|
|
|
//do not duplicate results from menu
|
|
|
|
results.forEach(function(r) { uniques[r.command] = true; });
|
|
|
|
for (var i = 0; i < command.list.length; i++) {
|
|
|
|
var c = command.list[i];
|
|
|
|
if (c.command in uniques) continue;
|
|
|
|
if (fuzzyCommand.test(c.label)) {
|
|
|
|
results.push(c);
|
2013-12-16 16:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-21 11:51:42 +00:00
|
|
|
//sort the results into best-match
|
|
|
|
results.sort(function(a, b) {
|
|
|
|
var aMatch = fuzzyCommand.exec(a.palette || a.label);
|
|
|
|
var bMatch = fuzzyCommand.exec(b.palette || b.label);
|
|
|
|
var aScore = aMatch.index + aMatch[0].length;
|
|
|
|
var bScore = bMatch.index + bMatch[0].length;
|
2014-03-22 13:09:28 +00:00
|
|
|
if (aScore == bScore) return ((a.palette || a.label) < (b.palette || b.label) ? -1 : 1);
|
2014-03-21 11:51:42 +00:00
|
|
|
return aScore - bScore;
|
|
|
|
});
|
|
|
|
this.results = results.slice(0, 10);
|
2013-09-11 06:15:04 +00:00
|
|
|
},
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-10-15 05:17:58 +00:00
|
|
|
getTabValues: function(tab) {
|
|
|
|
var name = tab.fileName;
|
|
|
|
if (!this.cache[name]) {
|
|
|
|
return this.cacheTab(tab);
|
|
|
|
}
|
|
|
|
var cache = this.cache[name];
|
|
|
|
for (var i = 0; i < cache.length; i++) {
|
|
|
|
if (cache[i].tab == tab) {
|
|
|
|
return cache[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.cacheTab(tab);
|
|
|
|
},
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-10-15 05:17:58 +00:00
|
|
|
cacheTab: function(tab) {
|
|
|
|
//create cache entry
|
|
|
|
var entry = {
|
|
|
|
tab: tab,
|
|
|
|
refs: [],
|
|
|
|
text: tab.getValue()
|
|
|
|
};
|
|
|
|
//create token iterator, search for all references
|
|
|
|
var ti = new TokenIterator(tab, 0);
|
|
|
|
var token;
|
|
|
|
while (token = ti.stepForward()) {
|
2013-10-17 22:39:54 +00:00
|
|
|
if (tab.syntaxMode == "javascript" ? jsRefTest.test(token.type) : refTest.test(token.type)) {
|
2013-10-15 05:17:58 +00:00
|
|
|
//this is a match, let's store it as a valid result object
|
|
|
|
var row = ti.getCurrentTokenRow();
|
|
|
|
var col = ti.getCurrentTokenColumn();
|
|
|
|
var line = sanitize(tab.getLine(row));
|
|
|
|
entry.refs.push({
|
|
|
|
tab: tab,
|
|
|
|
line: row,
|
|
|
|
value: token.value,
|
|
|
|
label: tab.fileName + ":" + row,
|
|
|
|
sublabel: line,
|
|
|
|
column: col
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var name = tab.fileName;
|
|
|
|
if (!this.cache[name]) {
|
|
|
|
this.cache[name] = [ entry ];
|
|
|
|
} else {
|
|
|
|
this.cache[name].push(entry);
|
|
|
|
}
|
|
|
|
return entry;
|
|
|
|
},
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2014-03-20 02:24:13 +00:00
|
|
|
//note: this function is WAY TOO LONG
|
2013-09-11 06:15:04 +00:00
|
|
|
findLocations: function(query) {
|
2013-09-11 03:34:28 +00:00
|
|
|
var file = re.file.test(query) && re.file.exec(query)[1];
|
2013-09-11 04:52:50 +00:00
|
|
|
var line = re.line.test(query) && Number(re.line.exec(query)[1]) - 1;
|
2013-09-11 03:34:28 +00:00
|
|
|
var search = re.search.test(query) && re.search.exec(query)[1];
|
|
|
|
var reference = re.reference.test(query) && re.reference.exec(query)[1];
|
2013-09-11 06:15:04 +00:00
|
|
|
var results = [];
|
2013-10-15 00:00:13 +00:00
|
|
|
var self = this;
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-12-10 22:46:28 +00:00
|
|
|
var tabs, projectFiles = [];
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 03:34:28 +00:00
|
|
|
if (file) {
|
2014-03-20 02:24:13 +00:00
|
|
|
//search through open files by name
|
2013-12-16 16:01:46 +00:00
|
|
|
var fuzzyFile = new RegExp(file
|
2014-02-27 02:56:05 +00:00
|
|
|
.replace(/ /g, "")
|
2014-02-27 06:02:33 +00:00
|
|
|
.split("")
|
2013-12-16 16:01:46 +00:00
|
|
|
.map(function(char) { return char.replace(antiregex, "\\$1") })
|
2014-03-20 02:24:13 +00:00
|
|
|
.join(".*?"),
|
2013-12-16 16:01:46 +00:00
|
|
|
"i");
|
2013-09-21 19:21:25 +00:00
|
|
|
tabs = sessions.getAllTabs().filter(function(tab) {
|
|
|
|
return fuzzyFile.test(tab.fileName);
|
2013-09-11 03:34:28 +00:00
|
|
|
});
|
2013-12-10 22:46:28 +00:00
|
|
|
//check the project for matches as well
|
2014-03-20 02:24:13 +00:00
|
|
|
this.files = this.files.filter(function(path) { return fuzzyFile.test(path) });
|
|
|
|
|
|
|
|
//sort files by relevance
|
|
|
|
this.files.sort(function(a, b) {
|
|
|
|
//first check the filename for each
|
|
|
|
var aFile = a.split(/[\/\\]/).pop();
|
|
|
|
var bFile = b.split(/[\/\\]/).pop();
|
|
|
|
var aMatch = fuzzyFile.exec(aFile);
|
|
|
|
var bMatch = fuzzyFile.exec(bFile);
|
|
|
|
//if either file matches...
|
|
|
|
if (aMatch || bMatch) {
|
|
|
|
//and if one doesn't, the match wins
|
|
|
|
if (!aMatch) {
|
|
|
|
return 1;
|
|
|
|
} else if (!bMatch) {
|
|
|
|
return -1
|
|
|
|
} else {
|
|
|
|
var aScore = aMatch.pop().length + aMatch.index;
|
|
|
|
var bScore = bMatch.pop().length + bMatch.index;
|
|
|
|
var comparison = aScore - bScore;
|
|
|
|
//identical scores? sort on path
|
|
|
|
if (comparison == 0) {
|
|
|
|
return a < b ? -1 : 1;
|
|
|
|
}
|
|
|
|
return comparison;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//otherwise, sort shorter full-path match sequences higher
|
|
|
|
var aResult = fuzzyFile.exec(a).pop();
|
|
|
|
var bResult = fuzzyFile.exec(b).pop();
|
|
|
|
var len = aResult.length - bResult.length;
|
|
|
|
//identical lengths, sort on path
|
|
|
|
if (len == 0) {
|
|
|
|
return a < b ? -1 : 1;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
});
|
|
|
|
|
|
|
|
//transform into result objects
|
2014-03-08 05:06:08 +00:00
|
|
|
projectFiles = this.files.map(function(path) {
|
2013-12-10 22:46:28 +00:00
|
|
|
return {
|
|
|
|
label: path.substr(path.search(/[^\/\\]+$/)),
|
2013-12-10 22:57:20 +00:00
|
|
|
sublabel: path,
|
2013-12-10 22:46:28 +00:00
|
|
|
command: "project:open-file",
|
|
|
|
argument: path
|
2014-02-27 06:34:02 +00:00
|
|
|
};
|
2013-12-10 22:46:28 +00:00
|
|
|
});
|
2013-09-11 03:34:28 +00:00
|
|
|
} else {
|
2014-03-20 02:24:13 +00:00
|
|
|
//the search domain is the current tab
|
2014-03-05 23:47:47 +00:00
|
|
|
var current = this.homeTab;
|
2013-10-17 20:53:21 +00:00
|
|
|
tabs = [ current ];
|
2013-10-15 05:17:58 +00:00
|
|
|
if (this.searchAll) {
|
2013-10-17 20:53:21 +00:00
|
|
|
tabs.push.apply(tabs, sessions.getAllTabs().filter(function(t) { return t !== current }));
|
2013-10-15 05:17:58 +00:00
|
|
|
}
|
2013-09-11 03:34:28 +00:00
|
|
|
}
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-10-04 03:59:46 +00:00
|
|
|
tabs = tabs.map(function(t) {
|
|
|
|
return {
|
|
|
|
tab: t,
|
|
|
|
line: line
|
2014-02-27 06:02:33 +00:00
|
|
|
};
|
2013-10-04 03:59:46 +00:00
|
|
|
});
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 03:34:28 +00:00
|
|
|
if (search) {
|
2014-03-20 02:24:13 +00:00
|
|
|
//find text in open tab(s)
|
2013-10-04 04:33:04 +00:00
|
|
|
try {
|
2013-12-16 16:01:46 +00:00
|
|
|
var crawl = new RegExp(search.replace(antiregex, "\\$1"), "gi");
|
2013-10-04 04:33:04 +00:00
|
|
|
} catch (e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var results = [];
|
|
|
|
tabs.forEach(function(t) {
|
|
|
|
if (results.length >= 10) return;
|
|
|
|
var found;
|
|
|
|
var lines = [];
|
2013-10-15 00:00:13 +00:00
|
|
|
var text = self.getTabValues(t.tab).text;
|
2013-10-04 04:33:04 +00:00
|
|
|
while (found = crawl.exec(text)) {
|
|
|
|
var position = t.tab.doc.indexToPosition(found.index);
|
|
|
|
if (lines.indexOf(position.row) > -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lines.push(position.row);
|
|
|
|
var result = {
|
|
|
|
tab: t.tab
|
2014-02-27 06:34:02 +00:00
|
|
|
};
|
2013-10-04 04:33:04 +00:00
|
|
|
result.label = result.tab.fileName;
|
2013-10-15 00:00:13 +00:00
|
|
|
result.sublabel = sanitize(result.tab.getLine(position.row));
|
2013-10-04 04:33:04 +00:00
|
|
|
result.line = position.row;
|
|
|
|
results.push(result);
|
|
|
|
if (results.length >= 10) return;
|
2013-10-04 03:59:46 +00:00
|
|
|
}
|
2013-10-04 04:33:04 +00:00
|
|
|
});
|
|
|
|
tabs = results;
|
2013-10-17 22:39:54 +00:00
|
|
|
} else if (reference !== false) {
|
2014-03-20 02:24:13 +00:00
|
|
|
//search by symbol reference
|
2013-10-15 00:00:13 +00:00
|
|
|
try {
|
2013-12-16 16:01:46 +00:00
|
|
|
var crawl = new RegExp(reference.replace(antiregex, "\\$1"), "i");
|
2013-10-15 00:00:13 +00:00
|
|
|
} catch (e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var results = [];
|
|
|
|
tabs.forEach(function(t) {
|
|
|
|
if (results.length >= 10) return;
|
|
|
|
var refs = self.getTabValues(t.tab).refs;
|
|
|
|
for (var i = 0; i < refs.length; i++) {
|
2013-10-15 05:17:58 +00:00
|
|
|
if (crawl.test(refs[i].value)) {
|
2013-10-15 00:00:13 +00:00
|
|
|
var len = results.push(refs[i]);
|
2013-10-15 21:23:28 +00:00
|
|
|
if (len >= 10) return;
|
2013-10-15 00:00:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
tabs = results;
|
2013-09-11 03:34:28 +00:00
|
|
|
}
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2014-03-05 23:47:47 +00:00
|
|
|
this.results = tabs.concat(projectFiles).slice(0, 10);
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-21 19:21:25 +00:00
|
|
|
if (this.results.length) {
|
2013-10-04 03:59:46 +00:00
|
|
|
var current = this.results[this.selected];
|
2013-12-10 22:46:28 +00:00
|
|
|
if (!current.tab) return;
|
2013-10-08 16:27:28 +00:00
|
|
|
sessions.raiseBlurred(current.tab);
|
2013-10-04 03:59:46 +00:00
|
|
|
if (current.line) {
|
2013-09-11 06:15:04 +00:00
|
|
|
editor.clearSelection();
|
2013-10-15 05:17:58 +00:00
|
|
|
editor.moveCursorTo(current.line, current.column || 0);
|
|
|
|
if (current.column) {
|
|
|
|
editor.execCommand("selectwordright");
|
|
|
|
}
|
2013-09-11 06:15:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
executeCurrent: function() {
|
|
|
|
var current = this.results[this.selected];
|
|
|
|
if (!current) return;
|
2013-12-10 22:46:28 +00:00
|
|
|
if (current.command) {
|
2013-09-20 15:57:43 +00:00
|
|
|
status.toast("Executing: " + current.label + "...");
|
2014-02-20 17:00:29 +00:00
|
|
|
command.fire(current.command, current.argument);
|
2013-09-21 00:44:25 +00:00
|
|
|
} else {
|
2013-12-10 22:46:28 +00:00
|
|
|
//must be the file search
|
2013-09-21 00:44:25 +00:00
|
|
|
command.fire("session:check-file");
|
2013-09-11 06:15:04 +00:00
|
|
|
}
|
|
|
|
this.deactivate();
|
2013-10-08 18:15:52 +00:00
|
|
|
if (!current.retainFocus) editor.focus();
|
2013-09-11 06:15:04 +00:00
|
|
|
},
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
activate: function(mode) {
|
2013-10-17 22:39:54 +00:00
|
|
|
this.homeTab = sessions.getCurrent();
|
2013-09-11 06:15:04 +00:00
|
|
|
this.results = [];
|
2013-10-15 05:17:58 +00:00
|
|
|
this.cache = {};
|
2014-03-08 05:06:08 +00:00
|
|
|
this.allFiles = this.files = project.getPaths();
|
2014-03-25 01:44:07 +00:00
|
|
|
this.pending = null;
|
2013-09-11 06:15:04 +00:00
|
|
|
this.selected = 0;
|
2013-10-15 05:17:58 +00:00
|
|
|
this.searchAll = Settings.get("user").searchAllFiles;
|
2013-09-20 06:45:04 +00:00
|
|
|
this.commandMode = mode == "command";
|
|
|
|
this.input.value = modes[mode] || "";
|
2013-09-11 06:15:04 +00:00
|
|
|
this.render();
|
2013-11-04 16:41:22 +00:00
|
|
|
this.element.addClass("active");
|
2013-09-11 06:15:04 +00:00
|
|
|
this.input.focus();
|
2014-05-14 05:46:49 +00:00
|
|
|
//trigger animation
|
|
|
|
var self = this;
|
|
|
|
this.element.addClass("enter");
|
|
|
|
setTimeout(function() {
|
|
|
|
self.element.removeClass("enter");
|
|
|
|
});
|
2013-09-11 06:15:04 +00:00
|
|
|
},
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
deactivate: function() {
|
2013-11-04 16:41:22 +00:00
|
|
|
this.element.removeClass("active");
|
2014-03-08 05:06:08 +00:00
|
|
|
if (this.pending) clearTimeout(this.pending);
|
2013-09-11 06:15:04 +00:00
|
|
|
},
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
navigateList: function(interval) {
|
|
|
|
this.selected = (this.selected + interval) % this.results.length;
|
|
|
|
if (this.selected < 0) {
|
|
|
|
this.selected = this.results.length + this.selected;
|
2013-09-11 04:52:50 +00:00
|
|
|
}
|
2013-09-11 06:15:04 +00:00
|
|
|
var current = this.results[this.selected];
|
2013-10-08 16:27:28 +00:00
|
|
|
if (current && current.tab) {
|
|
|
|
sessions.raiseBlurred(current.tab);
|
2013-09-11 06:15:04 +00:00
|
|
|
}
|
|
|
|
this.render();
|
|
|
|
},
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
render: function() {
|
|
|
|
var self = this;
|
|
|
|
this.element.find(".mode").innerHTML = this.commandMode ? "Command:" : "Go To:";
|
|
|
|
this.resultList.innerHTML = "";
|
|
|
|
this.results.slice(0, 10).forEach(function(r, i) {
|
2014-01-22 06:47:02 +00:00
|
|
|
var element = inflate.get("templates/paletteItem.html", {
|
|
|
|
label: r.palette || r.label || (r.tab ? r.tab.fileName : ""),
|
|
|
|
sublabel: r.sublabel,
|
|
|
|
isCurrent: i == self.selected
|
|
|
|
});
|
2013-11-04 16:41:22 +00:00
|
|
|
self.resultList.append(element);
|
2013-09-11 06:15:04 +00:00
|
|
|
});
|
2013-09-11 03:34:28 +00:00
|
|
|
}
|
2013-09-10 16:19:14 +00:00
|
|
|
};
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
var palette = new Palette();
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-10 16:19:14 +00:00
|
|
|
command.on("palette:open", function(mode) {
|
2013-09-11 03:34:28 +00:00
|
|
|
sessions.saveLocation();
|
2013-09-11 06:15:04 +00:00
|
|
|
palette.activate(mode);
|
2013-09-10 16:19:14 +00:00
|
|
|
});
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-11 06:15:04 +00:00
|
|
|
return palette;
|
2014-03-08 05:06:08 +00:00
|
|
|
|
2013-09-10 16:19:14 +00:00
|
|
|
});
|