| author | Andrew Eisenberg | 2012-01-27 15:37:33 (EST) |
|---|---|---|
| committer | John Arthorne | 2012-01-27 15:37:33 (EST) |
| commit | 99dac855adb3329ac80027770a2ac83af71fe461 (patch) (side-by-side diff) | |
| tree | 4c625a4c3211786bc4c8e2a838a511c2431a826b | |
| parent | 8fff33828f9c3fb9e3cf7ffc3a8917b9d88d8465 (diff) | |
| download | org.eclipse.orion.client-99dac855adb3329ac80027770a2ac83af71fe461.zip org.eclipse.orion.client-99dac855adb3329ac80027770a2ac83af71fe461.tar.gz org.eclipse.orion.client-99dac855adb3329ac80027770a2ac83af71fe461.tar.bz2 | |
Initial commit for Bug 347058
4 files changed, 145 insertions, 15 deletions
diff --git a/bundles/org.eclipse.orion.client.core/web/orion/favorites.js b/bundles/org.eclipse.orion.client.core/web/orion/favorites.js index a516dc2..5734205 100644 --- a/bundles/org.eclipse.orion.client.core/web/orion/favorites.js +++ b/bundles/org.eclipse.orion.client.core/web/orion/favorites.js @@ -120,6 +120,61 @@ define(['require', 'dojo', 'orion/util'], function(require, dojo, mUtil){ } return false; }, + + /** @private special characters in regex */ + _SPECIAL_CHARS : "^$\\+[]().", + + + /** + * Queries the favorites using s pseudo-regular expression. + * The format of the regex is the same as that recognized by + * the open resources dialog: * represents any text, ? is a + * single character. And there is an implicit * at the end of + * the queryText. + * + * Empty queryText matches all favorites + * + * @param queryText the name of the favorites to look for. + * @return a possibly empty array of favorites that matches + * the queryText + */ + queryFavorites: function(queryText) { + var i; + if (!queryText) { + // matches all + return this._favorites; + } + + // convert query string + // * --> .* + // ? --> .? + // $ --> \$ (and any other special chars + var convertedQuery = ""; + for (i = 0; i < queryText.length; i++) { + var char = queryText.charAt(i); + if (char === "*") { + convertedQuery += ".*"; + } else if (char === "?") { + convertedQuery += ".?"; + } else if (this._SPECIAL_CHARS.indexOf(char) >= 0) { + convertedQuery += ("\\" + char); + } else { + convertedQuery += char; + } + } + convertedQuery += ".*"; + var regex = new RegExp(convertedQuery); + + // for now, just search the beginning, but we need to support + // the regex that is available in open resources dialog + var result = []; + for (i in this._favorites) { + if (this._favorites[i].name.search(regex) === 0) { + result.push(this._favorites[i]); + } + } + return result; + }, removeSearch: function(query) { for (var i in this._searches) { diff --git a/bundles/org.eclipse.orion.client.core/web/orion/globalCommands.js b/bundles/org.eclipse.orion.client.core/web/orion/globalCommands.js index 20683aa..aba23a4 100644 --- a/bundles/org.eclipse.orion.client.core/web/orion/globalCommands.js +++ b/bundles/org.eclipse.orion.client.core/web/orion/globalCommands.js @@ -555,8 +555,8 @@ define(['require', 'dojo', 'dijit', 'orion/commands', 'orion/util', 'orion/textv dojo.place(text, title, "last"); } - var openResourceDialog = function(searcher, /* optional */ editor) { - var dialog = new orion.widgets.OpenResourceDialog({searcher: searcher}); + var openResourceDialog = function(searcher, serviceRegistry, /* optional */ editor) { + var dialog = new orion.widgets.OpenResourceDialog({searcher: searcher, serviceRegistry:serviceRegistry}); if (editor) { dojo.connect(dialog, "onHide", function() { editor.getTextView().focus(); // Focus editor after dialog close, Dojo's doesn't work @@ -570,14 +570,14 @@ define(['require', 'dojo', 'dijit', 'orion/commands', 'orion/util', 'orion/textv tooltip: "Choose a file by name and open an editor on it", id: "eclipse.openResource", callback: function(data) { - openResourceDialog(searcher, editor); + openResourceDialog(searcher, serviceRegistry, editor); }}); // We need a mod key binding in the editor, for now use the old one (ctrl-shift-r) if (editor) { editor.getTextView().setKeyBinding(new mKeyBinding.KeyBinding("r", true, true, false), "Find File Named..."); editor.getTextView().setAction("Find File Named...", function() { - openResourceDialog(searcher, editor); + openResourceDialog(searcher, serviceRegistry, editor); return true; }); } diff --git a/bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js b/bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js index 086813a..287b42b 100644 --- a/bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js +++ b/bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js @@ -13,8 +13,8 @@ /*jslint browser:true*/ /*global define orion window dojo dijit*/ -define(['dojo', 'dijit', 'dijit/Dialog', 'dijit/form/TextBox', - 'orion/widgets/_OrionDialogMixin', 'text!orion/widgets/templates/OpenResourceDialog.html'], function(dojo, dijit) { +define(['require', 'dojo', 'dijit', "orion/util", 'dijit/Dialog', 'dijit/form/TextBox', + 'orion/widgets/_OrionDialogMixin', 'text!orion/widgets/templates/OpenResourceDialog.html'], function(require, dojo, dijit, mUtil) { /** * Usage: <code>new widgets.OpenResourceDialog(options).show();</code> @@ -34,6 +34,7 @@ var OpenResourceDialog = dojo.declare("orion.widgets.OpenResourceDialog", [dijit time: null, options: null, searcher: null, + favService: null, /** @private */ constructor : function() { @@ -45,6 +46,11 @@ var OpenResourceDialog = dojo.declare("orion.widgets.OpenResourceDialog", [dijit if (!this.searcher) { throw new Error("Missing required argument: searcher"); } + var serviceRegistry = this.options.serviceRegistry; + if (!serviceRegistry) { + throw new Error("Missing required argument: serviceRegistry"); + } + this.favService = serviceRegistry.getService("orion.core.favorite"); }, /** @private */ @@ -76,8 +82,66 @@ var OpenResourceDialog = dojo.declare("orion.widgets.OpenResourceDialog", [dijit // WebKit focuses <body> after link is clicked; override that e.target.focus(); }); + this.populateFavorites(); + }, + + /** @private kick off initial population of favorites */ + populateFavorites: function() { + dojo.place("<div>Populating favorites…</div>", this.favresults, "only"); + + + // initially, show all favorites + this.favService.getFavorites().then(this.showFavorites()); + // need to add the listener since favorites may not + // have been initialized after first getting the favorites + this.favService.addEventListener("favoritesChanged", this.showFavorites()); }, + /** + * @private + * render the favorites that we have found, if any. + * this function wraps another function that does the actual work + * we need this so we can have access to the proper scope. + */ + showFavorites: function() { + var that = this; + + return function(favs) { + if (favs.navigator) { + favs = favs.navigator; + } + if (favs.length > 0) { + var table = document.createElement('table'); + for (var i=0; i < favs.length; i++) { + var fav = favs[i]; + var col; + var row = table.insertRow(-1); + col = row.insertCell(0); + col.colspan = 2; + var favLink = document.createElement('a'); + dojo.place(document.createTextNode(fav.name), favLink); + var loc; + if (fav.isExternalResource) { + // should open link in new tab, but for now, follow the behavior of navoutliner.js + loc = fav.path; + } else { + loc = fav.directory ? require.toUrl("navigate/table.html") + "#" + fav.path : require.toUrl("edit/edit.html") + "#" + fav.path; + if (loc === "#") { + loc = ""; + } + } + favLink.setAttribute('href', loc); + col.appendChild(favLink); + } + dojo.place(table, that.favresults, "only"); + } else { + dojo.place("<div>No favorites</div>", that.favresults, "only"); + } + that.decorateResult(that.favresults); + }; + }, + + /** @private */ checkSearch: function() { clearTimeout(this.timeoutId); @@ -93,16 +157,23 @@ var OpenResourceDialog = dojo.declare("orion.widgets.OpenResourceDialog", [dijit /** @private */ doSearch: function() { var text = this.resourceName && this.resourceName.get("value"); - if (!text) { - return; + + var showFavs = this.showFavorites(); + // update favorites + this.favService.queryFavorites(text).then(function(favs) { + showFavs(favs); + }); + + // don't do a server-side query for an empty text box + if (text) { + dojo.place("<div>Searching…</div>", this.results, "only"); + // Gives Webkit a chance to show the "Searching" message + var that = this; + setTimeout(function() { + var query = that.searcher.createSearchQuery(null, text, "Name"); + that.searcher.search(that.results, query, false, false, dojo.hitch(that, that.decorateResult), true /*no highlight*/); + }, 0); } - dojo.place("<div>Searching…</div>", this.results, "only"); - // Gives Webkit a chance to show the "Searching" message - var that = this; - setTimeout(function() { - var query = that.searcher.createSearchQuery(null, text, "Name"); - that.searcher.search(that.results, query, false, false, dojo.hitch(that, that.decorateResult), true /*no highlight*/); - }, 0); }, /** @private */ diff --git a/bundles/org.eclipse.orion.client.core/web/orion/widgets/templates/OpenResourceDialog.html b/bundles/org.eclipse.orion.client.core/web/orion/widgets/templates/OpenResourceDialog.html index 79c67e4..12f67a3 100644 --- a/bundles/org.eclipse.orion.client.core/web/orion/widgets/templates/OpenResourceDialog.html +++ b/bundles/org.eclipse.orion.client.core/web/orion/widgets/templates/OpenResourceDialog.html @@ -20,6 +20,10 @@ </div> </div> <div style="display:table-row"> + <div dojoAttachPoint="favresults" style="max-height:400px; height:auto; overflow-y:auto;"></div> + </div> + <hr /> + <div style="display:table-row"> <div dojoAttachPoint="results" style="max-height:400px; height:auto; overflow-y:auto;"></div> </div> <div style="display:table-row"> |

