forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSearchModel.js
More file actions
1 lines (1 loc) · 3.04 KB
/
SearchModel.js
File metadata and controls
1 lines (1 loc) · 3.04 KB
1
define(function(require,exports,module){var FileUtils=require("file/FileUtils"),EventDispatcher=require("utils/EventDispatcher"),FindUtils=require("search/FindUtils"),MainViewManager=require("view/MainViewManager");function SearchModel(){this.clear()}EventDispatcher.makeEventDispatcher(SearchModel.prototype),SearchModel.MAX_TOTAL_RESULTS=1e5,SearchModel.prototype.results=null,SearchModel.prototype.queryInfo=null,SearchModel.prototype.queryExpr=null,SearchModel.prototype.isReplace=!1,SearchModel.prototype.replaceText=null,SearchModel.prototype.scope=null,SearchModel.prototype.filter=null,SearchModel.prototype.numMatches=0,SearchModel.prototype.foundMaximum=!1,SearchModel.prototype.exceedsMaximum=!1,SearchModel.prototype.clear=function(){var numMatchesBefore=this.numMatches;this.results={},this.queryInfo=null,this.queryExpr=null,this.isReplace=!1,this.replaceText=null,this.scope=null,this.numMatches=0,this.foundMaximum=!1,this.exceedsMaximum=!1,0!==numMatchesBefore&&this.fireChanged()},SearchModel.prototype.setQueryInfo=function(queryInfo){var parsedQuery=FindUtils.parseQueryInfo(queryInfo);return!!parsedQuery.valid&&(this.queryInfo=queryInfo,this.queryExpr=parsedQuery.queryExpr,!0)},SearchModel.prototype.setResults=function(fullpath,resultInfo){this.removeResults(fullpath),!this.foundMaximum&&resultInfo.matches.length&&(resultInfo.collapsed=!!resultInfo.collapsed,!this.results[fullpath]&&this.numFiles>=0&&this.numFiles++,this.results[fullpath]=resultInfo,this.numMatches+=resultInfo.matches.length,this.numMatches>=SearchModel.MAX_TOTAL_RESULTS&&(this.foundMaximum=!0,this.numMatches>SearchModel.MAX_TOTAL_RESULTS&&(this.results[fullpath].matches.pop(),this.numMatches--,this.exceedsMaximum=!0)))},SearchModel.prototype.removeResults=function(fullpath){this.results[fullpath]&&(this.numMatches-=this.results[fullpath].matches.length,this.numFiles&&this.numFiles--,delete this.results[fullpath])},SearchModel.prototype.hasResults=function(){return Object.keys(this.results).length>0},SearchModel.prototype.countFilesMatches=function(){return{files:this.numFiles||Object.keys(this.results).length,matches:this.numMatches}},SearchModel.prototype.prioritizeOpenFile=function(firstFile){var workingSetFiles=MainViewManager.getWorkingSet(MainViewManager.ALL_PANES),workingSetFileFound={},fileSetWithoutWorkingSet=[],startingWorkingFileSet=[],propertyName="",i=0;for(firstFile=firstFile||"",i=0;i<workingSetFiles.length;i++)workingSetFileFound[workingSetFiles[i].fullPath]=!1;for(propertyName in fileSetWithoutWorkingSet=Object.keys(this.results).filter(function(key){return void 0===workingSetFileFound[key]||(workingSetFileFound[key]=!0,!1)}),!0===workingSetFileFound[firstFile]&&(startingWorkingFileSet.push(firstFile),workingSetFileFound[firstFile]=!1),workingSetFileFound)workingSetFileFound.hasOwnProperty(propertyName)&&workingSetFileFound[propertyName]&&startingWorkingFileSet.push(propertyName);return startingWorkingFileSet.concat(fileSetWithoutWorkingSet)},SearchModel.prototype.fireChanged=function(quickChange){this.trigger("change",quickChange)},exports.SearchModel=SearchModel});