Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
gruehle committed May 9, 2013
1 parent 528f55b commit 4bccf2d
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/search/FindInFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ define(function (require, exports, module) {
currentQuery = "",
currentScope;

// Div holding the search results. Initialized in htmlReady().
var $searchResultsDiv;

function _getQueryRegExp(query) {
// Clear any pending RegEx error message
$(".modal-bar .message").css("display", "inline-block");
Expand Down Expand Up @@ -187,7 +190,13 @@ define(function (require, exports, module) {

return this.result.promise();
};


function _hideSearchResults() {
if ($searchResultsDiv.is(":visible")) {
$searchResultsDiv.hide();
EditorManager.resizeEditor();
}
}

function _getSearchMatches(contents, queryExpr) {
// Quick exit if not found
Expand Down Expand Up @@ -231,8 +240,6 @@ define(function (require, exports, module) {
}

function _showSearchResults(searchResults, query, scope) {
var $searchResultsDiv = $("#search-results");

if (searchResults && searchResults.length) {
var $resultTable = $("<table class='zebra-striped condensed-table' />")
.append("<tbody>");
Expand Down Expand Up @@ -329,13 +336,12 @@ define(function (require, exports, module) {

$("#search-results .close")
.one("click", function () {
$searchResultsDiv.hide();
EditorManager.resizeEditor();
_hideSearchResults();
});

$searchResultsDiv.show();
} else {
$searchResultsDiv.hide();
_hideSearchResults();
}

EditorManager.resizeEditor();
Expand Down Expand Up @@ -441,15 +447,13 @@ define(function (require, exports, module) {
doFindInFiles(selectedEntry);
}


// Initialize items dependent on HTML DOM
AppInit.htmlReady(function () {
var $searchResults = $("#search-results"),
$searchContent = $("#search-results .table-container");
$searchResultsDiv = $("#search-results");
});

function _fileNameChangeHandler(event, oldName, newName) {
if ($("#search-results").is(":visible")) {
if ($searchResultsDiv.is(":visible")) {
// Update the search results
searchResults.forEach(function (item) {
item.fullPath = item.fullPath.replace(oldName, newName);
Expand All @@ -458,17 +462,8 @@ define(function (require, exports, module) {
}
}

function _beforeProjectCloseHandler(event, projectRoot) {
var $searchResultsDiv = $("#search-results");
if ($searchResultsDiv.is(":visible")) {
// Hide the search results
$searchResultsDiv.hide();
EditorManager.resizeEditor();
}
}

$(DocumentManager).on("fileNameChange", _fileNameChangeHandler);
$(ProjectManager).on("beforeProjectClose", _beforeProjectCloseHandler);
$(ProjectManager).on("beforeProjectClose", _hideSearchResults);

CommandManager.register(Strings.CMD_FIND_IN_FILES, Commands.EDIT_FIND_IN_FILES, doFindInFiles);
CommandManager.register(Strings.CMD_FIND_IN_SUBTREE, Commands.EDIT_FIND_IN_SUBTREE, doFindInSubtree);
Expand Down

0 comments on commit 4bccf2d

Please sign in to comment.