summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorKris De Volder2012-02-02 16:21:23 (EST)
committer John Arthorne2012-02-02 16:21:23 (EST)
commite2cb0920ef192e0a3fadf0f3cff938cfefa0aaaf (patch)
tree39936f873849dfe2d72160aa7c33c6c62eee4a80
parentbbc34582e71ebf59846feb3982b02bf58c805692 (diff)
downloadorg.eclipse.orion.client-e2cb0920ef192e0a3fadf0f3cff938cfefa0aaaf.zip
org.eclipse.orion.client-e2cb0920ef192e0a3fadf0f3cff938cfefa0aaaf.tar.gz
org.eclipse.orion.client-e2cb0920ef192e0a3fadf0f3cff938cfefa0aaaf.tar.bz2
Remove presentation related code from searchClient.js and put it in searchRenderer.js
-rw-r--r--bundles/org.eclipse.orion.client.core/web/edit/setup.js7
-rw-r--r--bundles/org.eclipse.orion.client.core/web/orion/searchClient.js144
-rw-r--r--bundles/org.eclipse.orion.client.core/web/orion/searchRenderer.js187
-rw-r--r--bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js8
4 files changed, 217 insertions, 129 deletions
diff --git a/bundles/org.eclipse.orion.client.core/web/edit/setup.js b/bundles/org.eclipse.orion.client.core/web/edit/setup.js
index 385e397..63f52f0 100644
--- a/bundles/org.eclipse.orion.client.core/web/edit/setup.js
+++ b/bundles/org.eclipse.orion.client.core/web/edit/setup.js
@@ -13,14 +13,14 @@
/*global define eclipse:true orion:true dojo dijit window*/
define(['require', 'dojo', 'orion/selection', 'orion/status', 'orion/progress', 'orion/dialogs',
- 'orion/commands', 'orion/util', 'orion/favorites', 'orion/fileClient', 'orion/operationsClient', 'orion/searchClient', 'orion/globalCommands', 'orion/outliner',
+ 'orion/commands', 'orion/util', 'orion/favorites', 'orion/fileClient', 'orion/operationsClient', 'orion/searchClient', 'orion/searchRenderer', 'orion/globalCommands', 'orion/outliner',
'orion/problems', 'orion/editor/contentAssist', 'orion/editorCommands', 'orion/editor/editorFeatures', 'orion/editor/editor', 'orion/syntaxchecker',
'orion/breadcrumbs', 'examples/textview/textStylerOptions', 'orion/textview/textView', 'orion/textview/textModel',
'orion/textview/projectionTextModel', 'orion/textview/keyBinding','orion/searchAndReplace/textSearcher','orion/searchAndReplace/orionTextSearchAdaptor',
'orion/edit/dispatcher', 'orion/contentTypes', 'orion/PageUtil', 'orion/highlight',
'dojo/parser', 'dojo/hash', 'dijit/layout/BorderContainer', 'dijit/layout/ContentPane', 'orion/widgets/eWebBorderContainer' ],
function(require, dojo, mSelection, mStatus, mProgress, mDialogs, mCommands, mUtil, mFavorites,
- mFileClient, mOperationsClient, mSearchClient, mGlobalCommands, mOutliner, mProblems, mContentAssist, mEditorCommands, mEditorFeatures, mEditor,
+ mFileClient, mOperationsClient, mSearchClient, mSearchRenderer, mGlobalCommands, mOutliner, mProblems, mContentAssist, mEditorCommands, mEditorFeatures, mEditor,
mSyntaxchecker, mBreadcrumbs, mTextStylerOptions, mTextView, mTextModel, mProjectionTextModel, mKeyBinding, mSearcher,
mSearchAdaptor, mDispatcher, mContentTypes, PageUtil, Highlight) {
@@ -334,7 +334,8 @@ exports.setUpEditor = function(serviceRegistry, preferences, isReadOnly){
dojo.place(document.createTextNode("\"" + searchPattern + "\"..."), b, "only");
searchFloat.style.display = "block";
var query = searcher.createSearchQuery(searchPattern, null, "Name");
- searcher.search(searchFloat, query, inputManager.getInput(),false,null,false);
+ var renderer = mSearchRenderer.makeRenderFunction(searchFloat, false, null, false);
+ searcher.search(query, inputManager.getInput(), renderer);
}, 0);
return true;
});
diff --git a/bundles/org.eclipse.orion.client.core/web/orion/searchClient.js b/bundles/org.eclipse.orion.client.core/web/orion/searchClient.js
index 5658ecf..3155b44 100644
--- a/bundles/org.eclipse.orion.client.core/web/orion/searchClient.js
+++ b/bundles/org.eclipse.orion.client.core/web/orion/searchClient.js
@@ -13,7 +13,16 @@
/*global define window document */
/*jslint devel:true*/
-define(['require', 'dojo', 'dijit', 'orion/auth', 'orion/util', 'orion/searchUtils', 'dijit/form/Button', 'dijit/layout/BorderContainer', 'dijit/layout/ContentPane' ], function(require, dojo, dijit, mAuth, mUtil, mSearchUtils){
+define(['require', 'dojo', 'dijit', 'orion/auth', 'orion/util', 'orion/searchRenderer', 'orion/searchUtils', 'dijit/form/Button', 'dijit/layout/BorderContainer', 'dijit/layout/ContentPane' ], function(require, dojo, dijit, mAuth, mUtil, mSearchRenderer, mSearchUtils){
+
+// function legacySearch(resultsNode, query, excludeFile, generateHeadingAndSaveLink, onResultReady, hideSummaries) {
+// var renderer = mSearchRenderer.makeRenderFunction(resultsNode, generateHeadingAndSaveLink, onResultReady, hideSummaries);
+// this.searchAndRender(query, excludeFile, renderer);
+// }
+//
+// function legacySearchError() {
+// throw "This method was removed: use 'searchAndRender' instead.";
+// }
/**
* Creates a new search client.
@@ -31,28 +40,22 @@ define(['require', 'dojo', 'dijit', 'orion/auth', 'orion/util', 'orion/searchUti
/**
* Runs a search and displays the results under the given DOM node.
* @public
- * @param {DOMNode} resultsNode Node under which results will be added.
* @param {String} query URI of the query to run.
* @param {String} [excludeFile] URI of a file to exclude from the result listing.
- * @param {Boolean} [generateHeading] generate a heading for the results
- * @param {Function(DOMNode)} [onResultReady] If any results were found, this is called on the resultsNode.
- * @param {Boolean} [hideSummaries] Don't show the summary of what matched beside each result.
- * @param {Boolean} [useSimpleFormat] Use simple format that only shows the file name to show the result, other wise use a complex format with search details.
+ * @param {Function(JSONObject)} Callback function that receives the results of the query.
*/
- search: function(resultsNode, query, excludeFile, generateHeadingAndSaveLink, onResultReady, hideSummaries) {
+ search: function(query, excludeFile, renderer) {
var qObj = mSearchUtils.parseQueryStr(query);
- try{
- this._fileService.search(qObj.location, query).then(
- dojo.hitch(this, function(jsonData) {
- this.showSearchResult(resultsNode, query, excludeFile, generateHeadingAndSaveLink, onResultReady,
- hideSummaries, jsonData);
- })
- );
+ try {
+ this._fileService.search(qObj.location, query).then(function(jsonData) {
+ renderer(jsonData);
+ });
}
catch(error){
this.registry.getService("orion.page.message").setErrorMessage(error);
}
},
+
handleError: function(response, resultsNode) {
console.error(response);
var errorText = document.createTextNode(response);
@@ -125,120 +128,15 @@ define(['require', 'dojo', 'dijit', 'orion/auth', 'orion/util', 'orion/searchUti
}
return output;
},
- /**
- * Creates a div representing the highlight snippet of a search result.
- * @param {String} str The highlight string we got from the server
- * @return {DomNode}
- * @private
- */
+
formatHighlight: function(str) {
- var start = "##match",
- end = "match##",
- array = str.split(/(##match|match##)/),
- div = dojo.create("div"),
- bold;
- for (var i=0; i < array.length; i++) {
- var token = array[i];
- if (token === start) {
- bold = dojo.create("b");
- } else if (token === end) {
- dojo.place(bold, div, "last");
- bold = null;
- } else {
- dojo.place(document.createTextNode(token), (bold || div), "last");
- }
- }
- return div;
+ throw "This method was moved to orion/searchRenderer.js";
},
showSearchResult: function(resultsNode, query, excludeFile, generateHeading, onResultReady, hideSummaries, jsonData) {
-
- //Helper function to append a path String to the end of a search result dom node
- var appendPath = (function() {
-
- //Map to track the names we have already seen. If the name is a key in the map, it means
- //we have seen it already. Optionally, the value associated to the key may be a function'
- //containing some deferred work we need to do if we see the same name again.
- var namesSeenMap = {};
-
- function doAppend(domElement, hit) {
- var path = hit.Path;
- path = path.substring(0, path.length-hit.Name.length-1);
- domElement.appendChild(document.createTextNode(' - ' + path + ' '));
- }
-
- function appendPath(domElement, hit) {
- var name = hit.Name;
- if (namesSeenMap.hasOwnProperty(name)) {
- //Seen the name before
- doAppend(domElement, hit);
- var deferred = namesSeenMap[name];
- if (typeof(deferred)==='function') {
- //We have seen the name before, but prior element left some deferred processing
- namesSeenMap[name] = null;
- deferred();
- }
- } else {
- //Not seen before, so, if we see it again in future we must append the path
- namesSeenMap[name] = function() { doAppend(domElement, hit); };
- }
- }
- return appendPath;
- }()); //End of appendPath function
-
- var foundValidHit = false;
- dojo.empty(resultsNode);
- var token = jsonData.responseHeader.params.q;
- token= token.substring(token.indexOf("}")+1);
- if (jsonData.response.numFound > 0) {
- var table = document.createElement('table');
- for (var i=0; i < jsonData.response.docs.length; i++) {
- var hit = jsonData.response.docs[i];
- // ignore hits in the file that launched the search
- if (!hit.Directory && hit.Location !== excludeFile) {
- var col;
- if (!foundValidHit) {
- foundValidHit = true;
- if (generateHeading) {
- var heading = table.insertRow(0);
- col = heading.insertCell(0);
- col.innerHTML = "<h2>Search Results On</h2>";
- }
- }
- var row = table.insertRow(-1);
- col = row.insertCell(0);
- col.colspan = 2;
- var hitLink = document.createElement('a');
- dojo.place(document.createTextNode(hit.Name), hitLink);
- if (hit.LineNumber) { // FIXME LineNumber === 0
- dojo.place(document.createTextNode(' (Line ' + hit.LineNumber + ')'), hitLink);
- }
- var loc = hit.Location;
- hitLink.setAttribute('href', require.toUrl("edit/edit.html") + "#" + loc);
- col.appendChild(hitLink);
- appendPath(col, hit);
-
- if (!hideSummaries && jsonData.highlighting && jsonData.highlighting[hit.Id] && jsonData.highlighting[hit.Id].Text) {
- var highlightText = jsonData.highlighting[hit.Id].Text[0];
- var highlight = table.insertRow(-1);
- col = highlight.insertCell(0);
- col.colspan = 2;
- dojo.place(this.formatHighlight(highlightText), col, "only");
- }
- }
- }
- dojo.place(table, resultsNode, "last");
- if (typeof(onResultReady) === "function") {
- onResultReady(resultsNode);
- }
- }
- if (!foundValidHit) {
- var div = dojo.place("<div>No matches found for </div>", resultsNode, "only");
- var b = dojo.create("b", null, div, "last");
- dojo.place(document.createTextNode(token), b, "only");
- }
+ throw "This method was moved to orion/searchRenderer.js";
}
-
+
};
Searcher.prototype.constructor = Searcher;
//return module exports
diff --git a/bundles/org.eclipse.orion.client.core/web/orion/searchRenderer.js b/bundles/org.eclipse.orion.client.core/web/orion/searchRenderer.js
new file mode 100644
index 0000000..d8d7f26
--- /dev/null
+++ b/bundles/org.eclipse.orion.client.core/web/orion/searchRenderer.js
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * @license
+ * Copyright (c) 2012 IBM Corporation and others
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0
+ * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
+ * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html).
+ *
+ * Contributors:
+ * Kris De Volder - initial API and implementation
+ *******************************************************************************/
+
+/*global define window document */
+/*jslint devel:true*/
+
+// This module contains presentation related code 'ripped out' from searchClient.js.
+// At this point it has not yet been refactored to make it more generally useful or reusable.
+// The only goal at this point was to separate out presentation related code from the rest
+// of the searchClient code.
+
+define( ['require', 'dojo', 'dijit', 'orion/auth', 'orion/util', 'orion/searchUtils', 'dijit/form/Button', 'dijit/layout/BorderContainer', 'dijit/layout/ContentPane'],
+ function(require, dojo , dijit, mAuth, mUtil, mSearchUtils) {
+
+ /**
+ * Create a renderer to display search results.
+ * @public
+ * @param {DOMNode} resultsNode Node under which results will be added.
+ * @param {Boolean} [generateHeading] generate a heading for the results
+ * @param {Function(DOMNode)} [onResultReady] If any results were found, this is called on the resultsNode.
+ * @param {Boolean} [hideSummaries] Don't show the summary of what matched beside each result.
+ * @returns a render function.
+ */
+ function makeRenderFunction(resultsNode, generateHeading, onResultReady, hideSummaries) {
+
+ /**
+ * Displays search results under the given DOM node.
+ * @param {?} jsonData the results of the search.
+ */
+ function render(jsonData) {
+
+ //Helper function to append a path String to the end of a search result dom node
+ var appendPath = (function() {
+
+ //Map to track the names we have already seen. If the name is a key in the map, it means
+ //we have seen it already. Optionally, the value associated to the key may be a function'
+ //containing some deferred work we need to do if we see the same name again.
+ var namesSeenMap = {};
+
+ function doAppend(domElement, hit) {
+ var path = hit.Path;
+ path = path.substring(0, path.length-hit.Name.length-1);
+ domElement.appendChild(document.createTextNode(' - ' + path + ' '));
+ }
+
+ function appendPath(domElement, hit) {
+ var name = hit.Name;
+ if (namesSeenMap.hasOwnProperty(name)) {
+ //Seen the name before
+ doAppend(domElement, hit);
+ var deferred = namesSeenMap[name];
+ if (typeof(deferred)==='function') {
+ //We have seen the name before, but prior element left some deferred processing
+ namesSeenMap[name] = null;
+ deferred();
+ }
+ } else {
+ //Not seen before, so, if we see it again in future we must append the path
+ namesSeenMap[name] = function() { doAppend(domElement, hit); };
+ }
+ }
+ return appendPath;
+ }()); //End of appendPath function
+
+ var foundValidHit = false;
+ dojo.empty(resultsNode);
+ var token = jsonData.responseHeader.params.q;
+ token= token.substring(token.indexOf("}")+1);
+ if (jsonData.response.numFound > 0) {
+ var table = document.createElement('table');
+ for (var i=0; i < jsonData.response.docs.length; i++) {
+ var hit = jsonData.response.docs[i];
+//TODO: // ignore hits in the file that launched the search
+//TODO: if (!hit.Directory && hit.Location !== excludeFile) {
+ var col;
+ if (!foundValidHit) {
+ foundValidHit = true;
+ if (generateHeading) {
+ var heading = table.insertRow(0);
+ col = heading.insertCell(0);
+ col.innerHTML = "<h2>Search Results On</h2>";
+ }
+ }
+ var row = table.insertRow(-1);
+ col = row.insertCell(0);
+ col.colspan = 2;
+ var hitLink = document.createElement('a');
+ dojo.place(document.createTextNode(hit.Name), hitLink);
+ if (hit.LineNumber) { // FIXME LineNumber === 0
+ dojo.place(document.createTextNode(' (Line ' + hit.LineNumber + ')'), hitLink);
+ }
+ var loc = hit.Location;
+ hitLink.setAttribute('href', require.toUrl("edit/edit.html") + "#" + loc);
+ col.appendChild(hitLink);
+ appendPath(col, hit);
+
+ if (!hideSummaries && jsonData.highlighting && jsonData.highlighting[hit.Id] && jsonData.highlighting[hit.Id].Text) {
+ var highlightText = jsonData.highlighting[hit.Id].Text[0];
+ var highlight = table.insertRow(-1);
+ col = highlight.insertCell(0);
+ col.colspan = 2;
+ dojo.place(this.formatHighlight(highlightText), col, "only");
+ }
+//TODO: }
+ }
+ dojo.place(table, resultsNode, "last");
+ if (typeof(onResultReady) === "function") {
+ onResultReady(resultsNode);
+ }
+ }
+ if (!foundValidHit) {
+ var div = dojo.place("<div>No matches found for </div>", resultsNode, "only");
+ var b = dojo.create("b", null, div, "last");
+ dojo.place(document.createTextNode(token), b, "only");
+ }
+ }
+ return render;
+ }
+// Renderer.prototype = /**@lends orion.searchClient.Searcher.prototype*/ {
+// handleError: function(response, resultsNode) {
+// throw "Is anybody using this?";
+// console.error(response);
+// var errorText = document.createTextNode(response);
+// dojo.place(errorText, resultsNode, "only");
+// return response;
+// },
+// setLocationByMetaData: function(meta){
+// var locationName = "root";
+// if(meta && meta.Directory && meta.Location && meta.Parents){
+// this.setLocationByURL(meta.Location);
+// locationName = meta.Name;
+// }
+// var searchInputDom = dojo.byId("search");
+// if(searchInputDom && searchInputDom.placeholder){
+// if(locationName.length > 13){
+// searchInputDom.placeholder = "Search " + locationName.substring(0, 10) + "...";
+// } else {
+// searchInputDom.placeholder = "Search " + locationName;
+// }
+// }
+// if(searchInputDom && searchInputDom.title){
+// searchInputDom.title = "Type a keyword or wild card to search in " + locationName;
+// }
+// },
+// setLocationByURL: function(locationURL){
+// this.location = locationURL;
+// },
+
+// This doesn't appear to be used at all.
+// /**
+// * Creates a div representing the highlight snippet of a search result.
+// * @param {String} str The highlight string we got from the server
+// * @return {DomNode}
+// * @private
+// */
+// function formatHighlight(str) {
+// var start = "##match",
+// end = "match##",
+// array = str.split(/(##match|match##)/),
+// div = dojo.create("div"),
+// bold;
+// for (var i=0; i < array.length; i++) {
+// var token = array[i];
+// if (token === start) {
+// bold = dojo.create("b");
+// } else if (token === end) {
+// dojo.place(bold, div, "last");
+// bold = null;
+// } else {
+// dojo.place(document.createTextNode(token), (bold || div), "last");
+// }
+// }
+// return div;
+// }
+//
+// };
+ return {makeRenderFunction:makeRenderFunction};
+}); \ No newline at end of file
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 e8fbb16..82e7b23 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,9 @@
/*jslint browser:true*/
/*global define orion window 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) {
+define(['require', 'dojo', 'dijit', "orion/util", 'orion/searchRenderer', 'dijit/Dialog', 'dijit/form/TextBox',
+ 'orion/widgets/_OrionDialogMixin', 'text!orion/widgets/templates/OpenResourceDialog.html'],
+ function(require, dojo, dijit, mUtil, mSearchRenderer) {
/**
* Usage: <code>new widgets.OpenResourceDialog(options).show();</code>
@@ -233,7 +234,8 @@ var OpenResourceDialog = dojo.declare("orion.widgets.OpenResourceDialog", [dijit
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*/);
+ var renderFunction = mSearchRenderer.makeRenderFunction(that.results, false, dojo.hitch(that, that.decorateResult), true);
+ that.searcher.search(query, false, renderFunction);
}, 0);
}
},