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