Skip to content
Browse files

Update to latest orion.client

  • Loading branch information...
1 parent d411662 commit bf6e8995633a3fc8618dd97d7e074fd749d0b5c9 @mamacdon committed Dec 12, 2012
Showing with 444 additions and 590 deletions.
  1. +8 −8 lib/orion.client/bundles/org.eclipse.orion.client.core/web/css/editor-theme.css
  2. +20 −1 lib/orion.client/bundles/org.eclipse.orion.client.core/web/css/ide.css
  3. +3 −2 lib/orion.client/bundles/org.eclipse.orion.client.core/web/edit/setup.js
  4. +9 −3 lib/orion.client/bundles/org.eclipse.orion.client.core/web/js-tests/globalSearch/testcase.js
  5. +16 −18 lib/orion.client/bundles/org.eclipse.orion.client.core/web/js-tests/serviceRegistry/testcase.js
  6. +3 −3 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/Deferred.js
  7. +1 −1 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/URL-shim.js
  8. +1 −1 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/commonHTMLFragments.js
  9. +21 −21 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/crawler/searchCrawler.js
  10. +16 −4 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/explorers/explorer-table.js
  11. +12 −4 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js
  12. +0 −7 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/globalCommands.js
  13. +28 −49 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/searchClient.js
  14. +60 −59 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/searchExplorer.js
  15. +11 −12 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/searchResults.js
  16. +106 −258 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/searchUtils.js
  17. +2 −2 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/webui/tooltip.js
  18. +3 −2 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js
  19. +29 −29 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/widgets/themes/editor/ThemeData.js
  20. +60 −14 lib/orion.client/bundles/org.eclipse.orion.client.core/web/plugins/filePlugin/fileImpl.js
  21. +1 −0 lib/orion.client/bundles/org.eclipse.orion.client.core/web/plugins/filePlugin/webdavImpl.js
  22. +28 −51 lib/orion.client/bundles/org.eclipse.orion.client.core/web/search/search.js
  23. +0 −3 lib/orion.client/bundles/org.eclipse.orion.client.editor/web/examples/textview/textStylerOptions.js
  24. +3 −37 lib/orion.client/bundles/org.eclipse.orion.client.editor/web/orion/editor/textMateStyler.js
  25. +3 −1 lib/orion.client/bundles/org.eclipse.orion.client.editor/web/orion/textview/textView.js
View
16 lib/orion.client/bundles/org.eclipse.orion.client.core/web/css/editor-theme.css
@@ -16,7 +16,7 @@
font-size: 10pt;
min-width: 50px;
min-height: 50px;
- color: darkSlateGrey;
+ color: #333;
}
.textviewContent {
@@ -37,15 +37,15 @@
*
*************************************************************************************************/
.comment {
- color: darkSeaGreen;
+ color: #3C802C;
}
.token_multiline_comment {
- color: darkSeaGreen;
+ color: #3C802C;
}
.token_doc_comment {
- color: #AAA;
+ color: #3C802C;
}
a.token_singleline_comment, a.token_multiline_comment, a.token_doc_comment {
@@ -65,15 +65,15 @@ a.token_singleline_comment, a.token_multiline_comment, a.token_doc_comment {
}
.token-string {
- color: cornflowerBlue; /* was blue; */
+ color: #446fbd; /* was blue; */
}
.token_number {
color: blue;
}
.token_keyword {
- color: darkOrange; /* originally darkred; */
+ color: #CC4C07; /* originally darkred; */
font-weight: bold;
}
@@ -179,7 +179,7 @@ a.token_singleline_comment, a.token_multiline_comment, a.token_doc_comment {
/* Hardcoded HTML styles */
.entity-name-tag /*tag name*/ {
- color: darkOrange;
+ color: #CC4C07;
}
.entity-other-attribute-name {
@@ -225,7 +225,7 @@ a.token_singleline_comment, a.token_multiline_comment, a.token_doc_comment {
*************************************************************************************************/
.entity-other-attribute-name {
- color: darkSeaGreen;
+ color: #3C802C;
}
.punctuation-definition-comment {
View
21 lib/orion.client/bundles/org.eclipse.orion.client.core/web/css/ide.css
@@ -158,8 +158,18 @@ h2 {
.parameterPopup {
min-width: 15em;
max-width: 100em;
+ color: #333;
+}
+
+.parameterPopup > label{
+ color: #333;
}
+.parameterPopup > input{
+ color: #333;
+}
+
+
.navTableHeading {
color: #404040;
border-bottom: 1px solid #404040;
@@ -726,7 +736,7 @@ input {
text-indent: none;
text-indent: 0px;
text-shadow: none;
- border: none;
+ border: solid 1px #555;
border-radius: 2px;
color: #333;
font-size: 9pt;
@@ -844,6 +854,15 @@ input {
}
+#folderNameparameterCollector{
+ color:#333;
+}
+
+#urlparameterCollector{
+ color:#333;
+}
+
+
.setting-control {
display: inline-block;
width: 200px;
View
5 lib/orion.client/bundles/org.eclipse.orion.client.core/web/edit/setup.js
@@ -419,9 +419,10 @@ exports.setUpEditor = function(serviceRegistry, preferences, isReadOnly){
var b = dojo.create("b", null, searchFloat, "last"); //$NON-NLS-1$ //$NON-NLS-0$
dojo.place(document.createTextNode("\"" + searchPattern + "\"..."), b, "only"); //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
searchFloat.style.display = "block"; //$NON-NLS-0$
- var query = searcher.createSearchQuery(searchPattern, null, "Name", true); //$NON-NLS-0$
+ var searchParams = searcher.createSearchParams(searchPattern, false, true);
+ searchParams.sort = "Name asc"; //$NON-NLS-0$
var renderer = searcher.defaultRenderer.makeRenderFunction(null, searchFloat, false);
- searcher.search(query, inputManager.getInput(), renderer, true);
+ searcher.search(searchParams, inputManager.getInput(), renderer);
}, 0);
return true;
}, {name: messages["Search Files"]}); //$NON-NLS-0$
View
12 lib/orion.client/bundles/org.eclipse.orion.client.core/web/js-tests/globalSearch/testcase.js
@@ -24,10 +24,16 @@ define(["dojo", "orion/assert", "orion/searchUtils"], function(dojo, assert, mSe
* Search in a file with key word and return the file model node.
*/
function searchInFile(fileContentText, keyword, replacing) {
- var inFileQuery = mSearchUtils.generateInFileQuery(keyword);
+ var searchHelper = mSearchUtils.generateSearchHelper({
+ resource: "Temp",
+ sort: "Path asc",
+ rows: 40,
+ start: 0,
+ keyword: keyword
+ });
var fileModel = makeFileModel();
- mSearchUtils.searchWithinFile(inFileQuery, fileModel, fileContentText, "\n", replacing);
- return {m: fileModel, q:inFileQuery};
+ mSearchUtils.searchWithinFile(searchHelper.inFileQuery, fileModel, fileContentText, "\n", replacing);
+ return {m: fileModel, q:searchHelper.inFileQuery};
}
/**
View
34 ...ion.client/bundles/org.eclipse.orion.client.core/web/js-tests/serviceRegistry/testcase.js
@@ -11,7 +11,7 @@
/*global define console setTimeout*/
-define(["orion/assert", "orion/serviceregistry", "orion/EventTarget"], function(assert, mServiceRegistry, EventTarget) {
+define(["orion/assert", "orion/serviceregistry", "orion/EventTarget", "orion/Deferred"], function(assert, mServiceRegistry, EventTarget, Deferred) {
var tests = {};
tests.testRegisterAndGetService = function() {
var count = 0;
@@ -30,26 +30,24 @@ define(["orion/assert", "orion/serviceregistry", "orion/EventTarget"], function(
assert.equal(count, 0);
var service1 = registry.getService("testRegister");
- service1.test().then(function(newcount) {
+ var service2;
+
+ return service1.test().then(function(newcount) {
count = newcount;
- });
- assert.equal(count, 1);
-
- var service2 = registry.getService(reference);
- service2.test().then(function(newcount) {
+ }).then(function() {
+ assert.equal(count, 1);
+ }).then(function() {
+ service2 = registry.getService(reference);
+ return service2.test();
+ }).then(function(newcount) {
count = newcount;
+ }).then(function() {
+ assert.equal(count, 2);
+ }).then(function() {
+ assert.equal(service1, service2);
+ registration.unregister();
+ assert["throws"](service2.test);
});
- assert.equal(count, 2);
-
- // contrived
- assert.equal(service1, service2);
- registration.unregister();
- assert["throws"](function() {
- service2.test().then(function(newcount) {
- count = newcount;
- });
- });
- assert.equal(count, 2);
};
tests.testRegisterUnregisterMultipleServices = function() {
View
6 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/Deferred.js
@@ -8,7 +8,7 @@
*
* Contributors: IBM Corporation - initial API and implementation
******************************************************************************/
-/*global exports module define*/
+/*global exports module define setTimeout*/
(function(root, factory) { // UMD
if (typeof define === 'function' && define.amd) {
define(factory);
@@ -39,7 +39,7 @@
return;
}
running = true;
- do {
+ setTimeout(function() {
while (fn) {
fn();
if (remainingHead) {
@@ -60,7 +60,7 @@
}
}
running = false;
- } while (running);
+ }, 0);
}
function noReturn(fn) {
View
2 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/URL-shim.js
@@ -415,7 +415,7 @@
}
});
- if (window.URL.createObjectURL) {
+ if (window.URL && window.URL.createObjectURL) {
Object.defineProperty(URL, "createObjectURL", {
value: window.URL.createObjectURL.bind(window.URL),
enumerable: false
View
2 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/commonHTMLFragments.js
@@ -91,7 +91,7 @@ define(['i18n!orion/nls/messages', 'require', 'orion/webui/littlelib'],
'<ul class="layoutLeft commandList pageActions" id="selectionTools"></ul>' + //$NON-NLS-0$
'<img class="layoutRight progressPane" src="'+ require.toUrl("images/none.png") +'" id="progressPane" tabindex="0" role="progressbar" aria-label="Operations - Press spacebar to show current operations"></img>' + //$NON-NLS-4$ //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
'<div class="layoutRight" style="padding-left:7px;padding-right:7px;margin-top:3px;" id="settingsTab" style="visibility:hidden;">' +
- '<div class="layoutRight settings core-sprite-settings" id="settingsAction" role="settings" aria-live="off" style="visibility:hidden;"></div>' + //$NON-NLS-0$
+ '<div class="layoutRight core-sprite-settings" id="settingsAction" role="settings" aria-live="off" style="visibility:hidden;"></div>' + //$NON-NLS-0$
'</div>' +
'<div class="layoutRight status" id="statusPane" role="status" aria-live="off"></div>' + //$NON-NLS-0$
'<ul class="layoutRight commandList pageActions" id="pageNavigationActions"></ul>' + //$NON-NLS-0$
View
42 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/crawler/searchCrawler.js
@@ -21,11 +21,11 @@ define(['i18n!orion/crawler/nls/messages', 'require', 'orion/searchUtils', 'orio
* It basically visits all the children recursively under a given directory location and search on a given keyword, either literal or wild card.
* @param {serviceRegistry} serviceRegistry The service registry.
* @param {fileClient} fileClient The file client that provides fetchChildren and read APIs.
- * @param {String} queryStr The query string. This is temporary for now. The format is "?sort=Path asc&rows=40&start=0&q=keyword+Location:/file/e/bundles/\*"
+ * @param {Object} searchParams The search parameters.
* @param {Object} options Not used yet. For future use.
* @name orion.search.SearchCrawler
*/
- function SearchCrawler( serviceRegistry, fileClient, queryStr, options) {
+ function SearchCrawler( serviceRegistry, fileClient, searchParams, options) {
this.registry= serviceRegistry;
this.fileClient = fileClient;
this.fileLocations = [];
@@ -35,13 +35,13 @@ define(['i18n!orion/crawler/nls/messages', 'require', 'orion/searchUtils', 'orio
this._searchOnName = options && options.searchOnName;
this._buildSkeletonOnly = options && options.buildSkeletonOnly;
this._fetchChildrenCallBack = options && options.fetchChildrenCallBack;
- this.queryObj = (this._searchOnName || this._buildSkeletonOnly) ? null: mSearchUtils.parseQueryStr(queryStr);
+ this.searchHelper = (this._searchOnName || this._buildSkeletonOnly) ? null: mSearchUtils.generateSearchHelper(searchParams);
this._location = options && options.location;
this._childrenLocation = options && options.childrenLocation ? options.childrenLocation : this._location;
}
/**
- * Do search based on this.queryObj.
+ * Do search based on this.searchHelper.
* @param {Function} onComplete The callback function on search complete. The array of hit file locations are passed to the callback.
*/
SearchCrawler.prototype.search = function(onComplete){
@@ -74,9 +74,9 @@ define(['i18n!orion/crawler/nls/messages', 'require', 'orion/searchUtils', 'orio
* @param {String} queryStr The query string. This is temporary for now. The format is "?sort=Path asc&rows=40&start=0&q=keyword+Location:/file/e/bundles/\*"
* @param {Function} onComplete The callback function on search complete. The array of hit file locations are passed to the callback.
*/
- SearchCrawler.prototype.searchName = function(queryStr, onComplete){
- if(queryStr){
- this.queryObj = mSearchUtils.parseQueryStr(queryStr, true);
+ SearchCrawler.prototype.searchName = function(searchParams, onComplete){
+ if(searchParams){
+ this.searchHelper = mSearchUtils.generateSearchHelper(searchParams, true);
}
if(onComplete){
this.onSearchNameComplete = onComplete;
@@ -87,14 +87,14 @@ define(['i18n!orion/crawler/nls/messages', 'require', 'orion/searchUtils', 'orio
for (var i = 0; i < this.fileSkeleton.length ; i++){
var lineString = this.fileSkeleton[i].Name.toLowerCase();
var result;
- if(this.queryObj.inFileQuery.wildCard){
- result = mSearchUtils.searchOnelineRegEx(this.queryObj.inFileQuery, lineString, true);
+ if(this.searchHelper.inFileQuery.wildCard){
+ result = mSearchUtils.searchOnelineRegEx(this.searchHelper.inFileQuery, lineString, true);
} else {
- result = mSearchUtils.searchOnelineLiteral(this.queryObj.inFileQuery, lineString, true);
+ result = mSearchUtils.searchOnelineLiteral(this.searchHelper.inFileQuery, lineString, true);
}
if(result){
results.push(this.fileSkeleton[i]);
- if(results.length >= this.queryObj.rows){
+ if(results.length >= this.searchHelper.params.rows){
break;
}
}
@@ -105,7 +105,7 @@ define(['i18n!orion/crawler/nls/messages', 'require', 'orion/searchUtils', 'orio
};
/**
- * Do search based on this.queryObj.
+ * Do search based on this.searchHelper.
* @param {Function} onComplete The callback function on search complete. The array of hit file locations are passed to the callback.
*/
SearchCrawler.prototype.buildSkeleton = function(onBegin, onComplete){
@@ -118,7 +118,7 @@ define(['i18n!orion/crawler/nls/messages', 'require', 'orion/searchUtils', 'orio
var result = that._visitRecursively(that._childrenLocation).then(function(){ //$NON-NLS-0$
that._buildingSkeleton = false;
onComplete();
- if(that.queryObj && !that._buildSkeletonOnly){
+ if(that.searchHelper && !that._buildSkeletonOnly){
that.searchName();
}
});
@@ -152,11 +152,11 @@ define(['i18n!orion/crawler/nls/messages', 'require', 'orion/searchUtils', 'orio
};
SearchCrawler.prototype._onFileType = function(contentType){
- if(this.queryObj.advOptions && this.queryObj.advOptions.type){
- if(this.queryObj.advOptions.type === mSearchUtils.ALL_FILE_TYPE){
+ if(this.searchHelper.params.fileType){
+ if(this.searchHelper.params.fileType === mSearchUtils.ALL_FILE_TYPE){
return true;
}
- return contentType.extension.indexOf(this.queryObj.advOptions.type) >= 0;
+ return contentType.extension.indexOf(this.searchHelper.params.fileType) >= 0;
}
return true;
};
@@ -192,10 +192,10 @@ define(['i18n!orion/crawler/nls/messages', 'require', 'orion/searchUtils', 'orio
SearchCrawler.prototype._hitOnceWithinFile = function( fileContentText){
var lineString = fileContentText.toLowerCase();
var result;
- if(this.queryObj.inFileQuery.wildCard){
- result = mSearchUtils.searchOnelineRegEx(this.queryObj.inFileQuery, lineString, true);
+ if(this.searchHelper.inFileQuery.wildCard){
+ result = mSearchUtils.searchOnelineRegEx(this.searchHelper.inFileQuery, lineString, true);
} else {
- result = mSearchUtils.searchOnelineLiteral(this.queryObj.inFileQuery, lineString, true);
+ result = mSearchUtils.searchOnelineLiteral(this.searchHelper.inFileQuery, lineString, true);
}
return result;
};
@@ -212,7 +212,7 @@ define(['i18n!orion/crawler/nls/messages', 'require', 'orion/searchUtils', 'orio
SearchCrawler.prototype._sniffSearch = function(fileObj){
this._totalCounter++;
var self = this;
- if(this.queryObj.searchStr === ""){
+ if(this.searchHelper.params.keyword === ""){
this._reportSingleHit(fileObj);
this.registry.getService("orion.page.message").setProgressResult({Message: dojo.string.substitute(messages["${0} files found out of ${1}"], [this._hitCounter, this._totalCounter])});
} else {
@@ -233,7 +233,7 @@ define(['i18n!orion/crawler/nls/messages', 'require', 'orion/searchUtils', 'orio
SearchCrawler.prototype._buildSingleSkeleton = function(fileObj){
this._totalCounter++;
this.fileSkeleton.push(fileObj);
- if(this.queryObj && !this._buildSkeletonOnly && this._totalCounter%100 === 0){
+ if(this.searchHelper && !this._buildSkeletonOnly && this._totalCounter%100 === 0){
this.searchName();
}
//console.log("skeltoned files : "+ this._totalCounter);
View
20 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/explorers/explorer-table.js
@@ -154,14 +154,26 @@ define(['i18n!orion/navigate/nls/messages', 'require', 'dojo', 'orion/fileUtils'
}
} else if (entry.isDirectory) {
var dirReader = entry.createReader();
- fileClient.createFolder(target.Location, entry.name).then(function(subFolder) {
- explorer.changedItem(target, true);
+ var traverseChildren = function(folder) {
dirReader.readEntries(function(entries) {
for (var i=0; i<entries.length; i++) {
- dropFileEntry(entries[i], path + entry.name + "/", subFolder, explorer, performDrop, fileClient); //$NON-NLS-0$
+ dropFileEntry(entries[i], path + entry.name + "/", folder, explorer, performDrop, fileClient); //$NON-NLS-0$
}
});
- });
+ };
+ if (target.Location.indexOf('/workspace') === 0){ //$NON-NLS-0$
+ fileClient.createProject(target.ChildrenLocation, entry.name).then(function(project) {
+ explorer.loadResourceList(explorer.treeRoot.Path, true);
+ fileClient.read(project.ContentLocation, true).then(function(folder) {
+ traverseChildren(folder);
+ });
+ });
+ } else {
+ fileClient.createFolder(target.Location, entry.name).then(function(subFolder) {
+ explorer.changedItem(target, true);
+ traverseChildren(subFolder);
+ });
+ }
}
}
View
16 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js
@@ -431,11 +431,19 @@ define(['i18n!orion/navigate/nls/messages', "orion/Deferred", "orion/i18nUtil"],
},
/**
- * Performs a search with the given query.
- * @param {String} query The search query
+ * Performs a search with the given search parameters.
+ * @param {Object} searchParams The JSON object that describes all the search parameters.
+ * @param {String} searchParams.resource Required. The location where search is performed. Required. Normally a sub folder of the file system. Empty string means the root of the file system.
+ * @param {String} searchParams.keyword The search keyword. Required but can be empty string. If fileType is a specific type and the keyword is empty, then list up all the files of that type. If searchParams.regEx is true then the keyword has to be a valid regular expression.
+ * @param {String} searchParams.sort Required. Defines the order of the return results. Should be either "Path asc" or "Name asc". Extensions are possible but not currently supported.
+ * @param {boolean} searchParams.nameSearch Optional. If true, the search performs only file name search.
+ * @param {String} searchParams.fileType Optional. The file type. If specified, search will be performed under this file type. E.g. "*.*" means all file types. "html" means html files.
+ * @param {Boolean} searchParams.regEx Optional. The option of regular expression search.
+ * @param {integer} searchParams.start Optional. The zero based strat number for the range of the returned hits. E.g if there are 1000 hits in total, then 5 means the 6th hit.
+ * @param {integer} searchParams.rows Optional. The number of hits of the range. E.g if there are 1000 hits in total and start=5 and rows=40, then the return range is 6th-45th.
*/
- search: function(location, query) {
- return _doServiceCall(this._getService(location), "search", arguments); //$NON-NLS-0$
+ search: function(searchParams) {
+ return _doServiceCall(this._getService(searchParams.resource), "search", arguments); //$NON-NLS-0$
}
};//end FileClient prototype
FileClient.prototype.constructor = FileClient;
View
7 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/globalCommands.js
@@ -147,13 +147,6 @@ define(['i18n!orion/nls/messages', 'require', 'dojo', 'dijit', 'orion/commonHTML
}
- function createSearchLink(query, name) {
- var link = document.createElement("a"); //$NON-NLS-0$
- link.href = require.toUrl("search/search.html") + "#" + query; //$NON-NLS-1$ //$NON-NLS-0$
- link.textContent = name;
- return link;
- }
-
function _addAdvancedSearchButton(container) {
var dropDownImage = dojo.create("span", {id: "advancedSearchDropDown"}, "searchOptions", "last"); //$NON-NLS-1$ //$NON-NLS-0$
dropDownImage.tabIndex = 0;
View
77 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/searchClient.js
@@ -35,13 +35,11 @@ function(messages, require, dojo, dijit, mSearchUtils, mSearchCrawler){
/**
* Runs a search and displays the results under the given DOM node.
* @public
- * @param {String} query URI of the query to run.
+ * @param {Object} searchParams The search parameters.
* @param {String} [excludeFile] URI of a file to exclude from the result listing.
* @param {Function(JSONObject)} Callback function that receives the results of the query.
- * @param {Boolean} [keyWordSearch] If true, do keyword search. Otherwise do name search.
*/
- search: function(query, excludeFile, renderer, keyWordSearch) {
- var qObj = mSearchUtils.parseQueryStr(query);
+ search: function(searchParams, excludeFile, renderer) {
var transform = function(jsonData) {
var transformed = [];
for (var i=0; i < jsonData.response.docs.length; i++) {
@@ -54,18 +52,18 @@ function(messages, require, dojo, dijit, mSearchUtils, mSearchCrawler){
}
return transformed;
};
- if(this._crawler && !keyWordSearch){ //$NON-NLS-0$
- this._crawler.searchName(query, function(jsonData){renderer(transform(jsonData), null);});
+ if(this._crawler && searchParams.nameSearch){
+ this._crawler.searchName(searchParams, function(jsonData){renderer(transform(jsonData), null);});
} else {
try {
- this._fileService.search(qObj.location, query).then(function(jsonData) {
+ this._fileService.search(searchParams).then(function(jsonData) {
/**
* transforms the jsonData so that the result conforms to the same
* format as the favourites list. This way renderer implementation can
* be reused for both.
* jsonData.response.docs{ Name, Location, Directory, LineNumber }
*/
- var token = qObj.searchStr;//jsonData.responseHeader.params.q;
+ var token = searchParams.keyword;//jsonData.responseHeader.params.q;
token= token.substring(token.indexOf("}")+1); //$NON-NLS-0$
//remove field name if present
token= token.substring(token.indexOf(":")+1); //$NON-NLS-0$
@@ -76,9 +74,9 @@ function(messages, require, dojo, dijit, mSearchUtils, mSearchCrawler){
}
catch(error){
if(typeof(error) === "string" && error.indexOf("search") > -1 && this._crawler){ //$NON-NLS-0$
- this._crawler.searchName(query, function(jsonData){renderer(transform(jsonData), null);});
- } else if(typeof(error) === "string" && error.indexOf("search") > -1 && keyWordSearch){ //$NON-NLS-0${
- var crawler = new mSearchCrawler.SearchCrawler(this.registry, this._fileService, query, {childrenLocation: this.getChildrenLocation()});
+ this._crawler.searchName(searchParams, function(jsonData){renderer(transform(jsonData), null);});
+ } else if(typeof(error) === "string" && error.indexOf("search") > -1 && !searchParams.nameSearch){ //$NON-NLS-0${
+ var crawler = new mSearchCrawler.SearchCrawler(this.registry, this._fileService, searchParams, {childrenLocation: this.getChildrenLocation()});
crawler.search(function(jsonData){renderer(transform(jsonData), null);});
} else {
this.registry.getService("orion.page.message").setErrorMessage(error); //$NON-NLS-0$
@@ -157,52 +155,33 @@ function(messages, require, dojo, dijit, mSearchUtils, mSearchCrawler){
return this._childrenLocation;
},
/**
- * Returns a query URL for a search.
- * @param {String} query The text to search for, or null when searching purely on file name
- * @param {String} [nameQuery] The name of a file to search for
- * @param {String} [sort] The field to sort search results on. By default results will sort by path
+ * Returns a query object for search. The return value has the propertyies of resource and parameters.
+ * @param {String} keyword The text to search for, or null when searching purely on file name
+ * @param {Boolean} [nameSearch] The name of a file to search for
* @param {Boolean} [useRoot] If true, do not use the location property of the searcher. Use the root url of the file system instead.
*/
- createSearchQuery: function(query, nameQuery, sort, useRoot, searchPrefix, advancedOptions) {
- if (!sort) {
- sort = "Path"; //$NON-NLS-0$
- }
- sort += " asc";//ascending sort order //$NON-NLS-0$
- if (nameQuery) {
+ createSearchParams: function(keyword, nameSearch, useRoot, advancedOptions) {
+ if (nameSearch) {
//assume implicit trailing wildcard if there isn't one already
- var wildcard= (/\*$/.test(nameQuery) ? "" : "*"); //$NON-NLS-0$
- return mSearchUtils.generateSearchQuery({sort: sort,
+ //var wildcard= (/\*$/.test(keyword) ? "" : "*"); //$NON-NLS-0$
+ return {
+ resource: useRoot ? this._searchRootLocation: this._searchLocation,
+ sort: "NameLower asc",
rows: 100,
start: 0,
- location: useRoot ? this._searchRootLocation: this._searchLocation,
- searchStr: searchPrefix + this._luceneEscape(nameQuery, true) + wildcard}); //$NON-NLS-0$
+ nameSearch: true,
+ keyword: keyword
+ };
}
- var useRegularExpresion = advancedOptions ? advancedOptions.regEx : true;
- return mSearchUtils.generateSearchQuery({sort: sort, advOptions: advancedOptions,
+ return {
+ resource: useRoot ? this._searchRootLocation: this._searchLocation,
+ sort: "Path asc",
rows: 40,
start: 0,
- searchStr: (useRegularExpresion ? query : this._luceneEscape(query, true)),
- location: useRoot ? this._searchRootLocation: this._searchLocation});
- },
- /**
- * Escapes all characters in the string that require escaping in Lucene queries.
- * See http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Escaping%20Special%20Characters
- * The following characters need to be escaped in lucene queries: + - && || ! ( ) { } [ ] ^ " ~ * ? : \
- * @param {String} input The string to perform escaping on
- * @param {Boolean} [omitWildcards=false] If true, the * and ? characters will not be escaped.
- * @private
- */
- _luceneEscape: function(input, omitWildcards) {
- var output = "",
- specialChars = "+-&|!(){}[]^\"~:\\" + (!omitWildcards ? "*?" : ""); //$NON-NLS-1$ //$NON-NLS-0$
- for (var i = 0; i < input.length; i++) {
- var c = input.charAt(i);
- if (specialChars.indexOf(c) >= 0) {
- output += '\\'; //$NON-NLS-0$
- }
- output += c;
- }
- return output;
+ regEx: advancedOptions ? advancedOptions.regEx : undefined,
+ fileType: advancedOptions ? advancedOptions.type : undefined,
+ keyword: keyword
+ };
},
//default search renderer until we factor this out completely
View
119 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/searchExplorer.js
@@ -15,7 +15,7 @@
define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/explorers/explorer', 'orion/explorers/explorerNavHandler', 'orion/fileClient', 'orion/commands', 'orion/searchUtils', 'orion/globalSearch/search-features', 'orion/compare/compare-features', 'orion/compare/compare-container', 'orion/explorers/navigationUtils', 'dijit/TooltipDialog'],
function(messages, require, dojo, dijit, mExplorer, mNavHandler, mFileClient, mCommands, mSearchUtils, mSearchFeatures, mCompareFeatures, mCompareContainer, mNavUtils) {
- function SearchResultModel( serviceRegistry, fileClient, resultLocation, queryStr, options) {
+ function SearchResultModel( serviceRegistry, fileClient, resultLocation, searchParams, options) {
this.registry= serviceRegistry;
this.fileClient = fileClient;
this._resultLocation = resultLocation;
@@ -27,12 +27,12 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
this.location2ModelMap = [];
this._lineDelimiter = "\n"; //$NON-NLS-0$
this.onMatchNumberChanged = options.onMatchNumberChanged;
- this.queryObj = mSearchUtils.parseQueryStr(queryStr);
+ this.searchHelper = mSearchUtils.generateSearchHelper(searchParams);
}
SearchResultModel.prototype = new mExplorer.ExplorerModel();
SearchResultModel.prototype.replaceMode = function(){
- return (typeof this.queryObj.replace === "string"); //$NON-NLS-0$
+ return (typeof this.searchHelper.params.replace === "string"); //$NON-NLS-0$
};
SearchResultModel.prototype.sameFile = function(prevSelection, curSelection){
@@ -77,25 +77,25 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
SearchResultModel.prototype.storeStatus = function(currentModel) {
if(currentModel){
var fileItem = this.fileModel(currentModel);
- window.sessionStorage[this.queryObj.queryStr + "_search_result_currentFileLocation"] = fileItem.location; //$NON-NLS-0$
+ window.sessionStorage[this.searchHelper.params.keyword + "_search_result_currentFileLocation"] = fileItem.location; //$NON-NLS-0$
if(currentModel.type === "file"){ //$NON-NLS-0$
- window.sessionStorage[this.queryObj.queryStr + "_search_result_currentDetailIndex"] = "none"; //$NON-NLS-1$ //$NON-NLS-0$
+ window.sessionStorage[this.searchHelper.params.keyword + "_search_result_currentDetailIndex"] = "none"; //$NON-NLS-1$ //$NON-NLS-0$
} else {
- window.sessionStorage[this.queryObj.queryStr + "_search_result_currentDetailIndex"] = JSON.stringify(this.model2Index(currentModel)); //$NON-NLS-0$
+ window.sessionStorage[this.searchHelper.params.keyword + "_search_result_currentDetailIndex"] = JSON.stringify(this.model2Index(currentModel)); //$NON-NLS-0$
}
}
};
SearchResultModel.prototype.restoreGlobalStatus = function() {
- this.defaultReplaceStr = this.queryObj.searchStrTitle;
+ this.defaultReplaceStr = this.searchHelper.displayedSearchTerm;
var defaultReplaceStr = window.sessionStorage["global_search_default_replace_string"]; //$NON-NLS-0$
if (typeof defaultReplaceStr === "string") { //$NON-NLS-0$
if (defaultReplaceStr.length > 0) {
this.defaultReplaceStr= defaultReplaceStr;
}
}
- this.sortByName = (this.queryObj.sort.indexOf("Name") > -1); //$NON-NLS-0$
+ this.sortByName = (this.searchHelper.params.sort.indexOf("Name") > -1); //$NON-NLS-0$
};
SearchResultModel.prototype.getRoot = function(onItem){
@@ -166,7 +166,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
this.getFileContent(model, dojo.hitch(this, function(fileItem){
matchesReplaced = this.matchesReplaced(fileItem);
var newContents = [];
- mSearchUtils.generateNewContents(fileItem.contents, newContents, fileItem, replaceStr, this.queryObj.inFileQuery.searchStrLength);
+ mSearchUtils.generateNewContents(fileItem.contents, newContents, fileItem, replaceStr, this.searchHelper.inFileQuery.searchStrLength);
var contents = newContents.join(this._lineDelimiter);
var etag = fileItem.ETag;
@@ -214,10 +214,10 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
SearchResultModel.prototype.hitOnceWithinFile = function( fileContentText){
var lineString = fileContentText.toLowerCase();
var result;
- if(this.queryObj.inFileQuery.wildCard){
- result = mSearchUtils.searchOnelineRegEx(this.queryObj.inFileQuery, lineString, true);
+ if(this.searchHelper.inFileQuery.wildCard){
+ result = mSearchUtils.searchOnelineRegEx(this.searchHelper.inFileQuery, lineString, true);
} else {
- result = mSearchUtils.searchOnelineLiteral(this.queryObj.inFileQuery, lineString, true);
+ result = mSearchUtils.searchOnelineLiteral(this.searchHelper.inFileQuery, lineString, true);
}
return result;
};
@@ -228,7 +228,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
} else {
this.fileClient.read(fileItem.location).then(
dojo.hitch(this, function(jsonData) {
- mSearchUtils.searchWithinFile(this.queryObj.inFileQuery, fileItem, jsonData, this._lineDelimiter, this.replaceMode());
+ mSearchUtils.searchWithinFile(this.searchHelper.inFileQuery, fileItem, jsonData, this._lineDelimiter, this.replaceMode());
if(this.onMatchNumberChanged && !writing){
this.onMatchNumberChanged(fileItem);
}
@@ -251,12 +251,12 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
} else if (parentItem.type === "detail") { //$NON-NLS-0$
onComplete([]);
} else if (parentItem.type === "file" && parentItem.location) { //$NON-NLS-0$
- if(this.queryObj.searchStr === ""){
+ if(this.searchHelper.params.keyword === ""){
return;
}
this.fileClient.read(parentItem.location).then(
dojo.hitch(this, function(jsonData) {
- mSearchUtils.searchWithinFile(this.queryObj.inFileQuery, parentItem, jsonData, this._lineDelimiter, this.replaceMode());
+ mSearchUtils.searchWithinFile(this.searchHelper.inFileQuery, parentItem, jsonData, this._lineDelimiter, this.replaceMode());
if(this.onMatchNumberChanged){
this.onMatchNumberChanged(parentItem);
}
@@ -307,19 +307,19 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
header = dojo.create("h2", null, title); //$NON-NLS-0$
header.textContent = messages["Results"]; //$NON-NLS-0$
- if( this.explorer.model.queryObj.searchStrTitle){
+ if( this.explorer.model.searchHelper.displayedSearchTerm){
if(this.explorer.numberOnPage > 0){
- var startNumber = this.explorer.model.queryObj.start + 1;
+ var startNumber = this.explorer.model.searchHelper.params.start + 1;
var endNumber = startNumber + this.explorer.numberOnPage - 1;
title.innerHTML = "";
var textBold = dojo.create("h2", null, title, "last"); //$NON-NLS-1$ //$NON-NLS-0$
var displayStr = "";
if(!this.explorer.model.replaceMode()){
displayStr = dojo.string.substitute(messages["Files ${0} of ${1} matching ${2}"],
- [startNumber +"-"+ endNumber, this.explorer.totalNumber, this.explorer.model.queryObj.searchStrTitle]);
+ [startNumber +"-"+ endNumber, this.explorer.totalNumber, this.explorer.model.searchHelper.displayedSearchTerm]);
} else {
displayStr = dojo.string.substitute(messages["Replace ${0} with ${1} for files ${2} of ${3}"],
- [this.explorer.model.queryObj.searchStrTitle,
+ [this.explorer.model.searchHelper.displayedSearchTerm,
this.explorer._replaceStr,
startNumber +"-"+ endNumber, //$NON-NLS-2$
this.explorer.totalNumber
@@ -389,7 +389,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
};
SearchResultRenderer.prototype.renderFileElement = function(item, spanHolder, renderName){
- var link = dojo.create("a", {className: "navlink", id: this.getItemLinkId(item), href: item.linkLocation + mSearchUtils.generateFindURLBinding(this.explorer.model.queryObj.inFileQuery, null, this.explorer._replaceStr)}, spanHolder, "last"); //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
+ var link = dojo.create("a", {className: "navlink", id: this.getItemLinkId(item), href: item.linkLocation + mSearchUtils.generateFindURLBinding(this.explorer.model.searchHelper.inFileQuery, null, this.explorer._replaceStr)}, spanHolder, "last"); //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
dojo.place(document.createTextNode(renderName), link, "only"); //$NON-NLS-0$
mNavUtils.addNavGrid(this.explorer.getNavDict(), item, link);
};
@@ -411,7 +411,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
SearchResultRenderer.prototype.generateDetailHighlight = function(detailModel, parentSpan){
var startIndex = 0;
- var gap = this.explorer.model.queryObj.inFileQuery.searchStrLength;
+ var gap = this.explorer.model.searchHelper.inFileQuery.searchStrLength;
for(var i = 0; i < detailModel.matches.length; i++){
if(startIndex >= detailModel.name.length)
break;
@@ -425,7 +425,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
dojo.place(document.createTextNode(detailModel.name.substring(startIndex, detailModel.matches[i].startIndex)), parentSpan, "last"); //$NON-NLS-0$
}
var matchSegBold = dojo.create("b", null, parentSpan, "last"); //$NON-NLS-1$ //$NON-NLS-0$
- if(this.explorer.model.queryObj.inFileQuery.wildCard){
+ if(this.explorer.model.searchHelper.inFileQuery.wildCard){
gap = detailModel.matches[i].length;
}
dojo.place(document.createTextNode(detailModel.name.substring(detailModel.matches[i].startIndex, detailModel.matches[i].startIndex + gap)), matchSegBold, "only"); //$NON-NLS-0$
@@ -457,7 +457,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
SearchResultRenderer.prototype.getDetailElement = function(item, tableRow, spanHolder){
var that = this;
- var linkLocation = item.parent.linkLocation + mSearchUtils.generateFindURLBinding(this.explorer.model.queryObj.inFileQuery, item.lineNumber, this.explorer._replaceStr);
+ var linkLocation = item.parent.linkLocation + mSearchUtils.generateFindURLBinding(this.explorer.model.searchHelper.inFileQuery, item.lineNumber, this.explorer._replaceStr);
var link = dojo.create("a", {className: "navlink", id: this.getItemLinkId(item), href: linkLocation}, spanHolder, "last"); //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
mNavUtils.addNavGrid(this.explorer.getNavDict(), item, link);
dojo.connect(link, "onclick", link, function() { //$NON-NLS-0$
@@ -498,12 +498,12 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
SearchResultRenderer.prototype.renderLocationElement = function(item, onSpan){
var spanHolder = onSpan ? onSpan: dojo.byId(this.getLocationSpanId(item));
dojo.empty(spanHolder);
- var qParams = mSearchUtils.copyQueryParams(this.explorer.model.queryObj, true);
- qParams.location = item.parentLocation;
+ var qParams = mSearchUtils.copySearchParams(this.explorer.model.searchHelper.params, true);
+ qParams.resource = item.parentLocation;
qParams.start = 0;
var href = mSearchUtils.generateSearchHref(qParams);
var link = dojo.create("a", {className: "navlinkonpage", href: href}, spanHolder, "last"); //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
- link.title = dojo.string.substitute(messages["Search again in this folder with \"${0}\""], [this.explorer.model.queryObj.searchStrTitle]);
+ link.title = dojo.string.substitute(messages["Search again in this folder with \"${0}\""], [this.explorer.model.searchHelper.displayedSearchTerm]);
mNavUtils.addNavGrid(this.explorer.getNavDict(), item, link);
var that = this;
dojo.connect(link, "onclick", link, function() { //$NON-NLS-0$
@@ -528,7 +528,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
if(item.type === "file"){ //$NON-NLS-0$
col.noWrap = true;
span = dojo.create("span", {id: this.getFileIconId(item)}, col, "only"); //$NON-NLS-1$ //$NON-NLS-0$
- if(this.explorer.model.queryObj.searchStr !== ""){
+ if(this.explorer.model.searchHelper.params.keyword !== ""){
this.getExpandImage(tableRow, span, "core-sprite-file"); //$NON-NLS-0$
} else {
var decorateImage = dojo.create("span", null, span, "last"); //$NON-NLS-0$ //$NON-NLS-0$
@@ -690,15 +690,15 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
SearchResultExplorer.prototype.onchange = function(item) {
};
- SearchResultExplorer.prototype.setResult = function(parentNode, resultLocation, queryStr, totalNumber) {
+ SearchResultExplorer.prototype.setResult = function(parentNode, resultLocation, searchParams, totalNumber) {
var that = this;
this.parentNode = parentNode;
- this.queryStr = queryStr;
+ this.searchParams = searchParams;
this.totalNumber = totalNumber;
this.numberOnPage = resultLocation.length;
- this.model = new SearchResultModel(this.registry, this.fileClient, resultLocation, queryStr,
+ this.model = new SearchResultModel(this.registry, this.fileClient, resultLocation, searchParams,
{ onMatchNumberChanged: function(fileItem){that.renderer.replaceFileElement(fileItem);}});
- this._replaceStr = this.model.queryObj.replace;
+ this._replaceStr = this.model.searchHelper.params.replace;
if(this.model.replaceMode()){
this._hasCheckedItems = true;
this.checkbox = true;
@@ -730,7 +730,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
tooltip: messages["Save search query"],
id: "orion.saveSearchResults", //$NON-NLS-0$
callback: function(data) {
- that.saveSearch(that.queryStr);
+ that.saveSearch(that.searchParams);
},
visibleWhen : function(item) {
return !that.model.replaceMode();
@@ -745,7 +745,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
that.preview();
},
visibleWhen : function(item) {
- return !that.model.replaceMode() && that.model.queryObj.searchStr !== "";
+ return !that.model.replaceMode() && that.model.searchHelper.params.keyword !== "";
}
});
@@ -757,7 +757,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
that.replaceAll();
},
visibleWhen : function(item) {
- return that.model.replaceMode() && !that._reporting && that._hasCheckedItems && that.model.queryObj.searchStr !== "";
+ return that.model.replaceMode() && !that._reporting && that._hasCheckedItems && that.model.searchHelper.params.keyword !== "";
}
});
@@ -816,29 +816,29 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
tooltip: messages["Show previous page of search result"],
id : "orion.search.prevPage", //$NON-NLS-0$
hrefCallback : function() {
- var prevPage = that.caculatePrevPage(that.model.queryObj.start, that.model.queryObj.rows, that.totalNumber);
- var qParams = mSearchUtils.copyQueryParams(that.model.queryObj, true);
+ var prevPage = that.caculatePrevPage(that.model.searchHelper.params.start, that.model.searchHelper.params.rows, that.totalNumber);
+ var qParams = mSearchUtils.copySearchParams(that.model.searchHelper.params, true);
qParams.start = prevPage.start;
return mSearchUtils.generateSearchHref(qParams);
},
visibleWhen : function(item) {
- var prevPage = that.caculatePrevPage(that.model.queryObj.start, that.model.queryObj.rows, that.totalNumber);
- return (prevPage.start !== that.model.queryObj.start);
+ var prevPage = that.caculatePrevPage(that.model.searchHelper.params.start, that.model.searchHelper.params.rows, that.totalNumber);
+ return (prevPage.start !== that.model.searchHelper.params.start);
}
});
var nextPage = new mCommands.Command({
name : messages["Next Page >"],
tooltip: messages["Show next page of search result"],
id : "orion.search.nextPage", //$NON-NLS-0$
hrefCallback : function() {
- var nextPage = that.caculateNextPage(that.model.queryObj.start, that.model.queryObj.rows, that.totalNumber);
- var qParams = mSearchUtils.copyQueryParams(that.model.queryObj, true);
+ var nextPage = that.caculateNextPage(that.model.searchHelper.params.start, that.model.searchHelper.params.rows, that.totalNumber);
+ var qParams = mSearchUtils.copySearchParams(that.model.searchHelper.params, true);
qParams.start = nextPage.start;
return mSearchUtils.generateSearchHref(qParams);
},
visibleWhen : function(item) {
- var nextPage = that.caculateNextPage(that.model.queryObj.start, that.model.queryObj.rows, that.totalNumber);
- return (nextPage.start !== that.model.queryObj.start);
+ var nextPage = that.caculateNextPage(that.model.searchHelper.params.start, that.model.searchHelper.params.rows, that.totalNumber);
+ return (nextPage.start !== that.model.searchHelper.params.start);
}
});
var nextResultCommand = new mCommands.Command({
@@ -868,7 +868,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
this._commandService.addCommand(nextResultCommand);
this._commandService.addCommand(prevResultCommand);
mExplorer.createExplorerCommands(this._commandService, function(item){
- return !item._reporting && that.model.queryObj.searchStr !== "";
+ return !item._reporting && that.model.searchHelper.params.keyword !== "";
});
// Register command contributions
this._commandService.registerCommandContribution("pageNavigationActions", "orion.explorer.expandAll", 1); //$NON-NLS-1$ //$NON-NLS-0$
@@ -1007,7 +1007,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
SearchResultExplorer.prototype.doPreview = function(replacingStr, all) {
window.sessionStorage["global_search_default_replace_string"] = replacingStr; //$NON-NLS-0$
- var qParams = mSearchUtils.copyQueryParams(this.model.queryObj, true);
+ var qParams = mSearchUtils.copySearchParams(this.model.searchHelper.params, true);
qParams.replace = replacingStr;
if(all){
qParams.start = 0;
@@ -1018,7 +1018,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
};
SearchResultExplorer.prototype.searchAgain = function() {
- var qParams = mSearchUtils.copyQueryParams(this.model.queryObj, true);
+ var qParams = mSearchUtils.copySearchParams(this.model.searchHelper.params, true);
qParams.replace = null;
if(qParams.rows > this.defaulRows ){
qParams.rows = this.defaulRows;
@@ -1174,7 +1174,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
}
var that = this;
this.model.getFileContent(fileItem, function(fileItem){
- mSearchUtils.generateNewContents(fileItem.contents, that._currentReplacedContents, fileItem, that._replaceStr, that.model.queryObj.inFileQuery.searchStrLength);
+ mSearchUtils.generateNewContents(fileItem.contents, that._currentReplacedContents, fileItem, that._replaceStr, that.model.searchHelper.inFileQuery.searchStrLength);
// Diff operations
var fType = that._getContentType(fileItem);
dojo.when(fType, function(fType) {
@@ -1224,13 +1224,14 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
this.registry.getService("orion.core.savedSearches").addSearch(searchName, query); //$NON-NLS-0$
};
- SearchResultExplorer.prototype.saveSearch = function(query) {
- var queryObj = mSearchUtils.parseQueryStr(query);
+ SearchResultExplorer.prototype.saveSearch = function(searchParams) {
+ var query = mSearchUtils.generateSearchHref(searchParams).split("#")[1];
var qName = query;
- if(queryObj && typeof(queryObj.searchStrTitle) === "string" && typeof(queryObj.location) === "string" ){ //$NON-NLS-1$ //$NON-NLS-0$
- qName = "\'" + queryObj.searchStrTitle + "\' in ";// +queryObj.location; //$NON-NLS-1$ //$NON-NLS-0$
- if(queryObj.location.length > 0){
- this.fileClient.read(queryObj.location, true).then(
+
+ if(typeof(this.model.searchHelper.displayedSearchTerm) === "string" && typeof(searchParams.resource) === "string" ){ //$NON-NLS-1$ //$NON-NLS-0$
+ qName = "\'" + this.model.searchHelper.displayedSearchTerm + "\' in ";// +queryObj.location; //$NON-NLS-1$ //$NON-NLS-0$
+ if(searchParams.resource.length > 0){
+ this.fileClient.read(searchParams.resource, true).then(
dojo.hitch(this, function(meta) {
var parentName = mSearchUtils.fullPathNameByMeta(meta.Parents);
var fullName = parentName.length === 0 ? meta.Name: parentName + "/" + meta.Name; //$NON-NLS-0$
@@ -1272,7 +1273,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
this._commandService.destroy("pageNavigationActions"); //$NON-NLS-0$
this._commandService.renderCommands("pageNavigationActions", "pageNavigationActions", that, that, "button"); //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
- if(this.model.queryObj.searchStr !== ""){
+ if(this.model.searchHelper.params.keyword !== ""){
var newMenu = this._commandService._createDropdownMenu("pageNavigationActions", messages['Options'], false, function() { //$NON-NLS-0$
if(!that.model.replaceMode()){
that._commandService._generateCheckedMenuItem(newMenu.menu, messages["Sort by Name"], that.model.sortByName,
@@ -1421,7 +1422,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
return;
}
this.twoWayCompareContainer.gotoMatch(currentModel.lineNumber-1, currentModel.matches[currentModel.matchNumber-1],
- currentModel.newMatches[currentModel.matchNumber-1], this.model.queryObj.inFileQuery.searchStrLength,
+ currentModel.newMatches[currentModel.matchNumber-1], this.model.searchHelper.inFileQuery.searchStrLength,
function(){window.setTimeout(function(){that.renderer.focus();}, 200);});
window.setTimeout(function(){that.renderer.focus();}, 0);
}
@@ -1474,7 +1475,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
};
SearchResultExplorer.prototype.startUp = function() {
- if(this.model.queryObj.searchStrTitle){
+ if(this.model.searchHelper.displayedSearchTerm){
if (this.numberOnPage > 0) {
var pageTitle = dojo.byId("pageTitle"); //$NON-NLS-0$
if(pageTitle){
@@ -1488,7 +1489,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
this.parentNode.textContent = "";
var textBold = dojo.create("b", null, this.parentNode, "last"); //$NON-NLS-1$ //$NON-NLS-0$
var displayStr = dojo.string.substitute(messages["No matches found for ${0}"],
- [this.model.queryObj.searchStrTitle]);
+ [this.model.searchHelper.displayedSearchTerm]);
dojo.place(document.createTextNode(displayStr), textBold, "only"); //$NON-NLS-0$
return;
}
@@ -1521,10 +1522,10 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
};
SearchResultExplorer.prototype.restoreLocationStatus = function() {
- var currentFileLocation = window.sessionStorage[this.model.queryObj.queryStr + "_search_result_currentFileLocation"]; //$NON-NLS-0$
+ var currentFileLocation = window.sessionStorage[this.model.searchHelper.params.keyword + "_search_result_currentFileLocation"]; //$NON-NLS-0$
var fileModel = this.model.location2Model(currentFileLocation);
var currentDetailIndex = "none"; //$NON-NLS-0$
- var detailIndexCached = window.sessionStorage[this.model.queryObj.queryStr + "_search_result_currentDetailIndex"]; //$NON-NLS-0$
+ var detailIndexCached = window.sessionStorage[this.model.searchHelper.params.keyword + "_search_result_currentDetailIndex"]; //$NON-NLS-0$
if (typeof detailIndexCached === "string") { //$NON-NLS-0$
if (detailIndexCached.length > 0) {
currentDetailIndex = detailIndexCached;
@@ -1565,7 +1566,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'dijit','orion/expl
if(this.model.sortByName === byName){
return;
}
- var qParams = mSearchUtils.copyQueryParams(this.model.queryObj);
+ var qParams = mSearchUtils.copySearchParams(this.model.searchHelper.params);
qParams.sort = byName ? "NameLower asc" : "Path asc"; //$NON-NLS-1$ //$NON-NLS-0$
qParams.start = 0;
var href = mSearchUtils.generateSearchHref(qParams);
View
23 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/searchResults.js
@@ -31,7 +31,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'orion/commands', '
SearchResultsGenerator.prototype = /** @lends orion.searchResults.SearchResultsGenerator.prototype */ {
- _renderSearchResult: function(crawling, resultsNode, query, jsonData, incremental) {
+ _renderSearchResult: function(crawling, resultsNode, searchParams, jsonData, incremental) {
var foundValidHit = false;
var resultLocation = [];
dojo.empty(resultsNode);
@@ -49,7 +49,7 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'orion/commands', '
}
}
this.explorer.setCrawling(crawling);
- this.explorer.setResult(resultsNode, resultLocation, query, jsonData.response.numFound);
+ this.explorer.setResult(resultsNode, resultLocation, searchParams, jsonData.response.numFound);
if(incremental){
this.explorer.incrementalRender();
} else {
@@ -68,32 +68,31 @@ define(['i18n!orion/search/nls/messages', 'require', 'dojo', 'orion/commands', '
* @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.
*/
- _search: function(resultsNode, query) {
+ _search: function(resultsNode, searchParams) {
//For crawling search, temporary
//TODO: we need a better way to render the progress and allow user to be able to cancel hte crawling search
- var qObj = mSearchUtils.parseQueryStr(query);
- this.crawling = (qObj.advOptions ? (qObj.advOptions.regEx/* || qObj.advOptions.type !== mSearchUtils.ALL_FILE_TYPE*/) : false);
+ this.crawling = searchParams.regEx;
var parent = dojo.byId(this.resultsId);
if(this.crawling){
dojo.place(document.createTextNode(""), parent, "only"); //$NON-NLS-1$
var self = this;
- var crawler = new mSearchCrawler.SearchCrawler(this.registry, this.fileService, query, {childrenLocation: this.searcher.getChildrenLocation()});
- crawler.search(function(jsonData, incremental){self._renderSearchResult(true, resultsNode, query, jsonData, incremental);});
+ var crawler = new mSearchCrawler.SearchCrawler(this.registry, this.fileService, searchParams, {childrenLocation: this.searcher.getChildrenLocation()});
+ crawler.search(function(jsonData, incremental){self._renderSearchResult(true, resultsNode, searchParams, jsonData, incremental);});
} else {
- var queryToService = qObj.nonAdvQueryStr;
+ //var queryToService = qObj.nonAdvQueryStr;
dojo.place(document.createTextNode(messages["Searching..."]), parent, "only"); //$NON-NLS-1$
try{
- this.fileService.search(qObj.location, queryToService).then(
+ this.fileService.search(searchParams).then(
dojo.hitch(this, function(jsonData) {
- this._renderSearchResult(false, resultsNode, query, jsonData);
+ this._renderSearchResult(false, resultsNode, searchParams, jsonData);
}));
}
catch(error){
dojo.place(document.createTextNode(""), parent, "only"); //$NON-NLS-1$
if(typeof(error) === "string" && error.indexOf("search") > -1){ //$NON-NLS-0$
var self = this;
- var crawler = new mSearchCrawler.SearchCrawler(this.registry, this.fileService, query, {childrenLocation: this.searcher.getChildrenLocation()});
- crawler.search(function(jsonData, incremental){self._renderSearchResult(true, resultsNode, query, jsonData, incremental);});
+ var crawler = new mSearchCrawler.SearchCrawler(this.registry, this.fileService, searchParams, {childrenLocation: this.searcher.getChildrenLocation()});
+ crawler.search(function(jsonData, incremental){self._renderSearchResult(true, resultsNode, searchParams, jsonData, incremental);});
} else {
this.registry.getService("orion.page.message").setErrorMessage(error); //$NON-NLS-0$
}
View
364 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/searchUtils.js
@@ -10,7 +10,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-define(['i18n!orion/nls/messages', 'require', 'dojo', 'orion/editor/regex', 'orion/commands'], function(messages, require, dojo, mRegex, mCommands) {
+define(['i18n!orion/nls/messages', 'require', 'dojo', 'orion/editor/regex', 'orion/commands', 'orion/PageUtil', 'orion/URITemplate'], function(messages, require, dojo, mRegex, mCommands, PageUtil, URITemplate) {
var exports = exports || {};
@@ -21,258 +21,134 @@ var exports = exports || {};
exports.searchUtils = exports.searchUtils || {};
-/**
- * Parse the search query string from the hash value of a search page.
- * @param {String} queryStr The hash string.
- * @returns {Object} An object having the properties:<ul>
- * <li>{@link Integer} <code>start</code> The start number of search result of current page.</li>
- * <li>{@link Integer} <code>rows</code> The max rows per page.</li>
- * <li>{@link String} <code>sort</code> The sort parameters."Path asc" or "Name asc".</li>
- * <li>{@link Object} <code>inFileQuery</code> The query object for in file search.</li>
- * </ul>
- * @name exports.searchUtils#parseQueryStr
- * @function
- */
-exports.searchUtils.parseQueryStr = function(queryStr, fromStart) {
- var indexOfQMark = queryStr.indexOf("?"); //$NON-NLS-0$
- var indexOfQWqual = queryStr.indexOf("q="); //$NON-NLS-0$
- if(indexOfQMark < indexOfQWqual && indexOfQWqual > 0){
- queryStr = queryStr.substring(indexOfQMark+1);
- }
- var advOptions = exports.searchUtils.parseAdvQueryStr(queryStr);
- var splitQ = advOptions.nonAdvParams;
- var queryObj = {advOptions: advOptions.advOptions, nonAdvQueryStr: advOptions.nonAdvQueryStr, queryStr: advOptions.nonAdvQueryStr, start:0, rows:10, sort:"Path asc", replace: null}; //$NON-NLS-0$
- for(var i=0; i < splitQ.length; i++){
- var qIndex = splitQ[i].indexOf("q="); //$NON-NLS-0$
- var rIndex = splitQ[i].indexOf("replace="); //$NON-NLS-0$
- if(qIndex >= 0){
- (queryObj.advOptions && queryObj.advOptions.regEx) ?
- exports.searchUtils.parseLocationAndSearchStrRegEx(splitQ[i].substring(qIndex+2), queryObj, fromStart):
- exports.searchUtils.parseLocationAndSearchStr(splitQ[i].substring(qIndex+2), queryObj, fromStart);
- } else if(rIndex >= 0){
- queryObj.replace = splitQ[i].substring(rIndex+8);
- } else {
- var splitparameters = splitQ[i].split("="); //$NON-NLS-0$
- if(splitparameters.length === 2){
- if(splitparameters[0] === "rows"){ //$NON-NLS-0$
- queryObj.rows = parseInt(splitparameters[1]);
- } else if(splitparameters[0] === "start"){ //$NON-NLS-0$
- queryObj.start = parseInt(splitparameters[1]);
- } else if(splitparameters[0] === "sort"){ //$NON-NLS-0$
- queryObj.sort = splitparameters[1];
- }
- }
- }
- }
- return queryObj;
-};
-
exports.searchUtils.ALL_FILE_TYPE = "*.*"; //$NON-NLS-0$
-exports.searchUtils.parseAdvQueryStr = function(queryStr) {
- var advOptions = null;
- var indexAdv = queryStr.indexOf("advOptions={");
- var indexAdvEnd = queryStr.indexOf("}&");
- if(indexAdv === 0 && indexAdvEnd > 0){
- advOptions = {};
- var advString = queryStr.substring(12, indexAdvEnd);
- var splitAdv = advString.split("&"); //$NON-NLS-0$
- for(var i=0; i < splitAdv.length; i++){
- var splitparameters = splitAdv[i].split("="); //$NON-NLS-0$
- if(splitparameters.length === 2){
- if(splitparameters[0] === "regEx"){ //$NON-NLS-0$
- advOptions.regEx = (splitparameters[1] === "true" ? true: false);
- } else if(splitparameters[0] === "type"){ //$NON-NLS-0$
- advOptions.type = splitparameters[1];
- }
- }
- }
+function _generateSearchHelperRegEx(inFileQuery, fromStart){
+ var prefix = ""; //$NON-NLS-1$
+ if(fromStart){
+ prefix = "^"; //$NON-NLS-1$
}
- var nonAdvQueryStr = queryStr;
- if(advOptions){
- nonAdvQueryStr = queryStr.substring(indexAdvEnd + 2);
+ var regexp = mRegex.parse("/" + prefix + inFileQuery.searchStr + "/"); //$NON-NLS-1$ //$NON-NLS-0$
+ if (regexp) {
+ var pattern = regexp.pattern;
+ var flags = regexp.flags;
+ flags = flags + (flags.indexOf("i") === -1 ? "i" : ""); //$NON-NLS-1$ //$NON-NLS-0$ //$NON-NLS-0$ //$NON-NLS-0$
+ inFileQuery.regExp = {pattern: pattern, flags: flags};
+ inFileQuery.wildCard = true;
}
- return {advOptions: advOptions, nonAdvQueryStr: "?" + nonAdvQueryStr, nonAdvParams: nonAdvQueryStr.split("&")};
-};
-
-exports.searchUtils.copyQueryParams = function(queryObj, copyReplace) {
- return {
- sort: queryObj.sort,
- advOptions: queryObj.advOptions,
- rows: queryObj.rows,
- start: queryObj.start,
- searchStr: queryObj.searchStr,
- location: queryObj.location,
- replace: copyReplace ? queryObj.replace: null
- };
-};
-
-exports.searchUtils.generateSearchHref = function(options) {
- var base = require.toUrl("search/search.html"); //$NON-NLS-0$
- return base + "#" + exports.searchUtils.generateSearchQuery(options); //$NON-NLS-0$
-};
+}
-exports.searchUtils.generateSearchQuery = function(options) {
- var sort = "Path asc", rows = 40, start = 0 , searchStr = "", loc = "", replace = "", advOptions = ""; //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
- if(options){
- if(options.advOptions){
- advOptions = "advOptions={";
- var andOpt = "";
- if(options.advOptions.regEx){
- advOptions = advOptions + "regEx=true";
- andOpt = "&";
- }
- if(options.advOptions.type){
- advOptions = advOptions + andOpt + "type=" + options.advOptions.type;
- }
- advOptions = advOptions + "}&";
- }
- if(options.sort){
- sort = options.sort;
- }
- if(options.rows){
- rows = options.rows;
- }
- if(options.start){
- start = options.start;
+exports.searchUtils.doSearch = function(searcher, serviceRegistry, searchStr, advOptions){
+ if (searcher) {
+ var newSearchStr = searchStr, commitSearch = true;
+ if(newSearchStr === "*"){
+ newSearchStr = "";
}
- if(options.searchStr){
- searchStr = options.searchStr;
- //searchStr = searchStr.split(" ").join(""); //$NON-NLS-0$
+ if(newSearchStr === ""){
+ commitSearch = advOptions && advOptions.type !== exports.searchUtils.ALL_FILE_TYPE;
}
- if(options.location){
- loc = options.location;
- if(loc.length > 0 && loc[loc.length -1] !== '*'){ //$NON-NLS-0$
- loc = loc + "*"; //$NON-NLS-0$
- }
- if(loc !== ""){
- loc = "+Location:" + loc; //$NON-NLS-0$
+ if (commitSearch) {
+ if(newSearchStr !== ""){
+ exports.searchUtils.addRecentSearch(serviceRegistry, newSearchStr, advOptions ? advOptions.regEx: false);
}
+ var searchParams = searcher.createSearchParams(newSearchStr, false, false, advOptions);
+ var href = exports.searchUtils.generateSearchHref(searchParams);
+ exports.searchUtils.getOpenSearchPref(serviceRegistry, function(openInNewTab){
+ if(openInNewTab){
+ window.open(href);
+ } else {
+ window.location = href;
+ }
+ });
}
- if(options.replace !== null && options.replace !== undefined){
- replace = "&replace=" + options.replace; //$NON-NLS-0$
- }
+ } else {
+ window.alert(messages["Can't search: no search service is available"]);
}
- return "?" + advOptions + "sort=" + sort + "&rows=" + rows + "&start=" + start + "&q=" + searchStr + loc + replace; //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-0$
};
-exports.searchUtils.parseLocationAndSearchStr = function(locAndSearchStr, queryObj, fromStart) {
- var hasLocation = (locAndSearchStr.indexOf("+Location:") > -1); //$NON-NLS-0$
- queryObj.location = "";
- queryObj.searchStr = locAndSearchStr;
- if(hasLocation){
- var splitStr = locAndSearchStr.split("+Location:"); //$NON-NLS-0$
- if(splitStr.length === 2){
- var loc = splitStr[1];
- if(loc.length > 0 && loc[loc.length - 1] === '*'){ //$NON-NLS-0$
- loc = loc.substring(0, loc.length-1);
- }
- queryObj.location = loc;
- queryObj.searchStr = splitStr[0];
- //queryObj.searchStr = splitStr[0].split(" ").join(""); //$NON-NLS-0$
- }
- }
- queryObj.searchStrTitle = queryObj.searchStr.split("\\").join(""); //$NON-NLS-0$
- //If searching on a specific file type, we want to inject the file type into the query string so that it will be passed to the search engine.
- if(queryObj.advOptions && queryObj.advOptions.type && queryObj.advOptions.type !== exports.searchUtils.ALL_FILE_TYPE){
- var newQParam = exports.searchUtils.copyQueryParams(queryObj);
- newQParam.advOptions = null;
- //If the search string is not empty, we just combine the file type.
- if(queryObj.searchStr !== ""){
- var newSearchStr = queryObj.searchStr;
- //If the search string contains white space, we should add double quato at both end.
- if(queryObj.searchStr.indexOf(" ") >= 0){
- newSearchStr = "\"" + newSearchStr + "\"";
- }
- newQParam.searchStr = newSearchStr + "+NameLower:*." + queryObj.advOptions.type;
- } else {//If the search string is empty, we have to simulate a file name search on *.fileType.
- newQParam.searchStr = "NameLower:*." + queryObj.advOptions.type;
- var newSortStr = newQParam.sort.replace("Path", "NameLower");
- newQParam.sort = newSortStr;
- queryObj.searchStrTitle = "*." + queryObj.advOptions.type;
- }
- queryObj.nonAdvQueryStr = exports.searchUtils.generateSearchQuery(newQParam);
- } else if(queryObj.searchStr.indexOf(" ") >= 0){//If the search string contains white space, we should add double quato at both end.
- var newQParam = exports.searchUtils.copyQueryParams(queryObj);
- newQParam.advOptions = null;
- newQParam.searchStr = "\"" + queryObj.searchStr + "\"";
- queryObj.nonAdvQueryStr = exports.searchUtils.generateSearchQuery(newQParam);
+/**
+ * Generate a helper query object used for search result renderer.
+ * @param {Object} searchParams The search parameters.
+ * @param {Boolean} fromStart True if doing file name search, otherwise false.
+ * @returns {Object} An object having the properties:<ul>
+ * <li>{@link Object} <code>searchParams</code> The search parameters.</li>
+ * <li>{@link Object} <code>inFileQuery</code> The query object for in file search.</li>
+ * </ul>
+ * @name exports.searchUtils#generateSearchHelper
+ * @function
+ */
+exports.searchUtils.generateSearchHelper = function(searchParams, fromStart) {
+ var searchStr = searchParams.keyword;
+ var displayedSearchTerm = searchStr;
+ var inFileQuery = {};
+ if(searchParams.fileType && searchParams.fileType !== exports.searchUtils.ALL_FILE_TYPE && searchStr === ""){
+ displayedSearchTerm = "*." + searchParams.fileType;
}
- queryObj.inFileQuery= exports.searchUtils.generateInFileQuery(queryObj.searchStr, fromStart);
-};
-
-exports.searchUtils.parseLocationAndSearchStrRegEx = function(locAndSearchStr, queryObj, fromStart) {
- var hasLocation = (locAndSearchStr.indexOf("+Location:") > -1); //$NON-NLS-0$
- queryObj.location = "";
- queryObj.searchStr = locAndSearchStr;
- if(hasLocation){
- var splitStr = locAndSearchStr.split("+Location:"); //$NON-NLS-0$
- if(splitStr.length === 2){
- var loc = splitStr[1];
- if(loc.length > 0 && loc[loc.length - 1] === '*'){ //$NON-NLS-0$
- loc = loc.substring(0, loc.length-1);
- }
- queryObj.location = loc;
- queryObj.searchStr = splitStr[0];
+ if(!searchParams.regEx){
+ var hasStar = (searchStr.indexOf("*") > -1); //$NON-NLS-0$
+ var hasQMark = (searchStr.indexOf("?") > -1); //$NON-NLS-0$
+ if(hasStar){
+ searchStr = searchStr.split("*").join(".*"); //$NON-NLS-1$ //$NON-NLS-0$
+ }
+ if(hasQMark){
+ searchStr = searchStr.split("?").join("."); //$NON-NLS-1$ //$NON-NLS-0$
+ }
+ if(!hasStar && !hasQMark && !searchParams.nameSearch){
+ inFileQuery.searchStr =searchStr.split("\\").join("").toLowerCase(); //$NON-NLS-0$
+ inFileQuery.wildCard = false;
+ } else {
+ inFileQuery.searchStr =searchStr.toLowerCase();
+ _generateSearchHelperRegEx(inFileQuery, fromStart);
+ inFileQuery.wildCard = true;
}
+ } else {
+ inFileQuery.searchStr =searchStr;
+ _generateSearchHelperRegEx(inFileQuery, fromStart);
}
- queryObj.searchStrTitle = queryObj.searchStr;
- queryObj.inFileQuery= exports.searchUtils.generateInFileQueryRegEx(queryObj.searchStr, fromStart);
+ inFileQuery.searchStrLength = inFileQuery.searchStr.length;
+ return {params: searchParams, inFileQuery: inFileQuery, displayedSearchTerm: displayedSearchTerm};
};
-exports.searchUtils.generateInFileQuery = function(searchStr, fromStart) {
- var inFileQuery = {};
- inFileQuery.originalSearchStr = searchStr;
- var hasStar = (searchStr.indexOf("*") > -1); //$NON-NLS-0$
- var hasQMark = (searchStr.indexOf("?") > -1); //$NON-NLS-0$
- if(hasStar){
- searchStr = searchStr.split("*").join(".*"); //$NON-NLS-1$ //$NON-NLS-0$
+exports.searchUtils.convertSearchParams = function(searchParams) {
+ if(searchParams.rows !== undefined){
+ searchParams.rows = parseInt(searchParams.rows);
}
- if(hasQMark){
- searchStr = searchStr.split("?").join("."); //$NON-NLS-1$ //$NON-NLS-0$
+ if(searchParams.start !== undefined){
+ searchParams.start = parseInt(searchParams.start);
}
- if(!hasStar && !hasQMark){
- inFileQuery.searchStr =searchStr.split("\\").join("").toLowerCase(); //$NON-NLS-0$
- inFileQuery.wildCard = false;
- } else {
- inFileQuery.searchStr =searchStr.toLowerCase();
- var prefix = "";
- if(fromStart){
- prefix = "^";
- }
- var regexp = mRegex.parse("/" + prefix + inFileQuery.searchStr + "/"); //$NON-NLS-1$ //$NON-NLS-0$
- if (regexp) {
- var pattern = regexp.pattern;
- var flags = regexp.flags;
- flags = flags + (flags.indexOf("i") === -1 ? "i" : ""); //$NON-NLS-1$ //$NON-NLS-0$
- inFileQuery.regExp = {pattern: pattern, flags: flags};
- inFileQuery.wildCard = true;
- }
+ if(typeof searchParams.regEx === "string"){
+ searchParams.regEx = (searchParams.regEx.toLowerCase() === "true");
}
- inFileQuery.searchStrLength = inFileQuery.searchStr.length;
- return inFileQuery;
-};
-
-exports.searchUtils.generateInFileQueryRegEx = function(searchStr, fromStart) {
- var inFileQuery = {};
- inFileQuery.originalSearchStr = searchStr;
- inFileQuery.searchStr =searchStr;
- var prefix = "";
- if(fromStart){
- prefix = "^";
+ if(typeof searchParams.nameSearch === "string"){
+ searchParams.nameSearch = (searchParams.nameSearch.toLowerCase() === "true");
}
- var regexp = mRegex.parse("/" + prefix + inFileQuery.searchStr + "/"); //$NON-NLS-1$ //$NON-NLS-0$
- if (regexp) {
- var pattern = regexp.pattern;
- var flags = regexp.flags;
- flags = flags + (flags.indexOf("i") === -1 ? "i" : ""); //$NON-NLS-1$ //$NON-NLS-0$
- inFileQuery.regExp = {pattern: pattern, flags: flags};
- inFileQuery.wildCard = true;
+}
+
+exports.searchUtils.copySearchParams = function(searchParams, copyReplace) {
+ var result = {};
+ for (var prop in searchParams) {
+ if(searchParams[prop] !== undefined && searchParams[prop] !== null){
+ if(!copyReplace && prop === "replace") { //$NON-NLS-2$
+ continue;
+ }
+ result[prop] = searchParams[prop];
+ }
}
- inFileQuery.searchStrLength = inFileQuery.searchStr.length;
- return inFileQuery;
+ return result;
};
-
+
+exports.searchUtils.generateSearchHref = function(options) {
+ var base = require.toUrl("search/search.html"); //$NON-NLS-0$
+ var sParams = exports.searchUtils.copySearchParams(options, true);
+ var searchLocation = sParams.resource;
+ sParams.resource = undefined;
+ var href = new URITemplate(base + "#{,resource,params*}").expand({ //$NON-NLS-0$
+ resource: searchLocation,
+ params: sParams
+ });
+ return href;
+};
+
exports.searchUtils.generateFindURLBinding = function(inFileQuery, lineNumber, replaceStr) {
var binding = ",find="; //$NON-NLS-0$
if (inFileQuery.wildCard) {
@@ -743,33 +619,5 @@ exports.searchUtils.setOpenSearchPref = function(serviceRegistry, openInNewTab){
});
};
-exports.searchUtils.doSearch = function(searcher, serviceRegistry, searchStr, advOptions){
- if (searcher) {
- var newSearchStr = searchStr, commitSearch = true;
- if(newSearchStr === "*"){
- newSearchStr = "";
- }
- if(newSearchStr === ""){
- commitSearch = advOptions && advOptions.type !== exports.searchUtils.ALL_FILE_TYPE;
- }
- if (commitSearch) {
- if(newSearchStr !== ""){
- exports.searchUtils.addRecentSearch(serviceRegistry, newSearchStr, advOptions ? advOptions.regEx: false);
- }
- var query = searcher.createSearchQuery(newSearchStr, null, null, false, null, advOptions);
- exports.searchUtils.getOpenSearchPref(serviceRegistry, function(openInNewTab){
- var href = require.toUrl("search/search.html") + "#" +query; //$NON-NLS-1$ //$NON-NLS-0$
- if(openInNewTab){
- window.open(href);
- } else {
- window.location = href;
- }
- });
- }
- } else {
- window.alert(messages["Can't search: no search service is available"]);
- }
-};
-
return exports.searchUtils;
});
View
4 lib/orion.client/bundles/org.eclipse.orion.client.core/web/orion/webui/tooltip.js
@@ -61,8 +61,6 @@ define(['require', 'orion/webui/littlelib'], function(require, lib) {
lib.stop(event);
}
}, false);
- lib.addAutoDismiss([self._node], function() {self.hide(0);});
-
} else {
this._showDelay = options.showDelay || 1000;
var leave = ["mouseout", "click"]; //$NON-NLS-1$ //$NON-NLS-0$
@@ -96,6 +94,8 @@ define(['require', 'orion/webui/littlelib'], function(require, lib) {
}
this._tip.appendChild(this._tipInner);
document.body.appendChild(this._tip);
+ var self = this;
+ lib.addAutoDismiss([this._tip, this._node], function() {self.hide(0);});
}
return this._tip;
},
View
5 ...rion.client/bundles/org.eclipse.orion.client.core/web/orion/widgets/OpenResourceDialog.js
@@ -242,9 +242,10 @@ var OpenResourceDialog = dojo.declare("orion.widgets.OpenResourceDialog", [dijit
// Gives Webkit a chance to show the "Searching" message
var that = this;
setTimeout(function() {
- var query = that.searcher.createSearchQuery(null, text, that.searcher._crawler ? false : "NameLower", that._searchOnRoot, that.searcher._crawler ? "" : "NameLower:"); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-0$
+ var searchParams = that.searcher.createSearchParams(text, true, that._searchOnRoot);
+ //var query = that.searcher.createSearchQuery(null, text, that.searcher._crawler ? false : "NameLower", that._searchOnRoot, that.searcher._crawler ? "" : "NameLower:"); //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-0$
var renderFunction = that.searchRenderer.makeRenderFunction(that.contentTypeService, that.results, false, dojo.hitch(that, that.decorateResult));
- that.searcher.search(query, false, renderFunction);
+ that.searcher.search(searchParams, false, renderFunction);
}, 0);
}
},
View
58 ...client/bundles/org.eclipse.orion.client.core/web/orion/widgets/themes/editor/ThemeData.js
@@ -42,57 +42,57 @@ define(['i18n!orion/settings/nls/messages', 'require', 'dojo', 'dijit'],
StyleSet.prototype.name = 'prospecto';
StyleSet.prototype.annotationRuler = 'darkSlateGray';
StyleSet.prototype.background = '#EFEFEF';
- StyleSet.prototype.comment = 'darkSlateGray';
- StyleSet.prototype.keyword = '#3087B3';
- StyleSet.prototype.text = 'darkSlateGray';
- StyleSet.prototype.string = 'FEC';
+ StyleSet.prototype.comment = '#3C802C';
+ StyleSet.prototype.keyword = '#CC4C07';
+ StyleSet.prototype.text = '#333';
+ StyleSet.prototype.string = '#446FBD';
StyleSet.prototype.overviewRuler = '#FBFBFB';
StyleSet.prototype.lineNumberOdd = 'white';
StyleSet.prototype.lineNumberEven = 'white';
StyleSet.prototype.lineNumber = 'silver';
- StyleSet.prototype.tag = 'darkorange';
+ StyleSet.prototype.tag = '#CC4C07';
StyleSet.prototype.attribute = 'cadetBlue';
StyleSet.prototypefontSize = '10pt';
function ThemeData() {
this.styles = [];
- var orion = new StyleSet();
-
- orion.name = 'Orion';
- orion.annotationRuler = 'white';
- orion.background = 'white';
- orion.comment = 'green';
- orion.keyword = '#7f0055';
- orion.text = 'darkSlateGray';
- orion.string = 'blue';
- orion.overviewRuler = 'white';
- orion.lineNumberOdd = '#444';
- orion.lineNumberEven = '#444';
- orion.lineNumber = '#444';
- orion.currentLine = '#EAF2FE';
- orion.tag = 'darkorange';
- orion.attribute = 'cadetBlue';
- orion.fontSize = '10pt';
-
- this.styles.push(orion);
+ var eclipse = new StyleSet();
+
+ eclipse.name = 'Eclipse';
+ eclipse.annotationRuler = 'white';
+ eclipse.background = 'white';
+ eclipse.comment = 'green';
+ eclipse.keyword = '#7f0055';
+ eclipse.text = 'darkSlateGray';
+ eclipse.string = 'blue';
+ eclipse.overviewRuler = 'white';
+ eclipse.lineNumberOdd = '#444';
+ eclipse.lineNumberEven = '#444';
+ eclipse.lineNumber = '#444';
+ eclipse.currentLine = '#EAF2FE';
+ eclipse.tag = 'darkorange';
+ eclipse.attribute = 'cadetBlue';
+ eclipse.fontSize = '10pt';
+
+ this.styles.push(eclipse);
var prospecto = new StyleSet();
prospecto.name = 'Prospecto';
prospecto.annotationRuler = 'white';
prospecto.background = 'white';
- prospecto.comment = 'darkSeaGreen';
- prospecto.keyword = 'darkOrange';
- prospecto.text = 'darkSlateGray';
- prospecto.string = 'cornFlowerBlue';
+ prospecto.comment = '#3C802C';
+ prospecto.keyword = '#CC4C07';
+ prospecto.text = '#333';
+ prospecto.string = '#446FBD';
prospecto.overviewRuler = 'white';
prospecto.lineNumberOdd = 'silver';
prospecto.lineNumberEven = 'silver';
prospecto.lineNumber = 'silver';
prospecto.currentLine = '#EAF2FE';
- prospecto.tag = 'darkorange';
+ prospecto.tag = '#CC4C07';
prospecto.attribute = 'cadetBlue';
prospecto.fontSize = '10pt';
View
74 lib/orion.client/bundles/org.eclipse.orion.client.core/web/plugins/filePlugin/fileImpl.js
@@ -449,21 +449,19 @@ define(["orion/Deferred", "orion/xhr", "orion/es5shim"], function(Deferred, xhr)
},
/**
- * Performs a search with the given query.
- * @param {String} query The search query
+ * Performs a search with the given search parameters.
+ * @param {Object} searchParams The JSON object that describes all the search parameters.
+ * @param {String} searchParams.resource Required. The location where search is performed. Required. Normally a sub folder of the file system. Empty string means the root of the file system.
+ * @param {String} searchParams.keyword The search keyword. Required but can be empty string. If fileType is a specific type and the keyword is empty, then list up all the files of that type. If searchParams.regEx is true then the keyword has to be a valid regular expression.
+ * @param {String} searchParams.sort Required. Defines the order of the return results. Should be either "Path asc" or "Name asc". Extensions are possible but not currently supported.
+ * @param {boolean} searchParams.nameSearch Optional. If true, the search performs only file name search.
+ * @param {String} searchParams.fileType Optional. The file type. If specified, search will be performed under this file type. E.g. "*.*" means all file types. "html" means html files.
+ * @param {Boolean} searchParams.regEx Optional. The option of regular expression search.
+ * @param {integer} searchParams.start Optional. The zero based strat number for the range of the returned hits. E.g if there are 1000 hits in total, then 5 means the 6th hit.
+ * @param {integer} searchParams.rows Optional. The number of hits of the range. E.g if there are 1000 hits in total and start=5 and rows=40, then the return range is 6th-45th.
*/
- search: function(location, query) {
- var locationIndex = query.indexOf("+Location:");
- if (locationIndex !== -1) {
- var loc = query.substring(locationIndex + "+Location:".length);
- if (loc.indexOf("://") !== -1) {
- var hostIndex = loc.indexOf("://") + 3;
- var pathIndex = loc.indexOf("/", hostIndex);
- loc = (pathIndex === -1 ) ? "" : loc.substring(pathIndex);
- }
- query = query.substring(0, locationIndex + "+Location:".length) + loc;
- }
-
+ search: function(searchParams) {
+ var query = _generateLuceneQuery(searchParams);
return xhr("GET", "/filesearch" + query, {
headers: {
"Accept": "application/json",
@@ -481,6 +479,54 @@ define(["orion/Deferred", "orion/xhr", "orion/es5shim"], function(Deferred, xhr)
}
};
+ /**
+ * Escapes all characters in the string that require escaping in Lucene queries.
+ * See http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Escaping%20Special%20Characters
+ * The following characters need to be escaped in lucene queries: + - && || ! ( ) { } [ ] ^ " ~ * ? : \
+ * @param {String} input The string to perform escaping on
+ * @param {Boolean} [omitWildcards=false] If true, the * and ? characters will not be escaped.
+ * @private
+ */
+ function _luceneEscape(input, omitWildcards) {
+ var output = "",
+ specialChars = "+-&|!(){}[]^\"~:\\" + (!omitWildcards ? "*?" : ""); //$NON-NLS-1$ //$NON-NLS-0$
+ for (var i = 0; i < input.length; i++) {
+ var c = input.charAt(i);
+ if (specialChars.indexOf(c) >= 0) {
+ output += '\\'; //$NON-NLS-0$
+ }
+ output += c;
+ }
+ return output;
+ }
+
+ function _generateLuceneQuery(searchParams){
+ var newKeyword = _luceneEscape(searchParams.keyword, true);
+ var newSort = searchParams.sort;
+ if(searchParams.nameSearch){ //Search file name only
+ var wildcard= (/\*$/.test(searchParams.keyword) ? "" : "*"); //$NON-NLS-0$
+ newKeyword = "NameLower:" + newKeyword + wildcard;
+ } else {
+ //If searching on a specific file type, we want to inject the file type into the query string so that it will be passed to the search engine.
+ if(searchParams.fileType && searchParams.fileType !== "*.*"){
+ //If the search string is not empty, we just combine the file type.
+ if(newKeyword !== ""){
+ //If the search string contains white space, we should add double quato at both end.
+ if(newKeyword.indexOf(" ") >= 0){
+ newKeyword = "\"" + newKeyword + "\"";
+ }
+ newKeyword = encodeURIComponent(newKeyword) + "+NameLower:*." + searchParams.fileType;
+ } else {//If the search string is empty, we have to simulate a file name search on *.fileType.
+ newKeyword = "NameLower:*." + searchParams.fileType;
+ newSort = newSort.replace("Path", "NameLower");
+ }
+ } else if(newKeyword.indexOf(" ") >= 0){//If the search string contains white space, we should add double quato at both end.
+ newKeyword = encodeURIComponent("\"" + newKeyword + "\"");
+ }
+ }
+ return "?" + "sort=" + newSort + "&rows=" + searchParams.rows + "&start=" + searchParams.start + "&q=" + newKeyword + "+Location:" + searchParams.resource + "*";
+ }
+
function _call2(method, url, headers, body) {
var d = new Deferred(); // create a promise
var xhr = new XMLHttpRequest();
View
1 lib/orion.client/bundles/org.eclipse.orion.client.core/web/plugins/filePlugin/webdavImpl.js
@@ -71,6 +71,7 @@ function parseDAV_response(responseElement) {
propstatElements,
i,
result = {href: []};
+ /* Comment for demo */
if (responsedescriptionElement !==null) {
result.responsedescription = serializeChildren(responsedescriptionElement);
View
79 lib/orion.client/bundles/org.eclipse.orion.client.core/web/search/search.js
@@ -13,62 +13,37 @@
/*browser:true*/