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

Implement checkbox option for individual file in search result panel. #8260

Merged
merged 8 commits into from
Jul 18, 2014
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/htmlContent/search-results.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<tbody>
{{#searchList}}
<tr class="file-section" data-file-index="{{fileIndex}}">
{{#replace}}<td class="checkbox-column"><input type="checkbox" class="check-one-file" {{#isChecked}}checked="true"{{/isChecked}} /></td>{{/replace}}
<td colspan="{{#replace}}3{{/replace}}{{^replace}}2{{/replace}}">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong now and it might be the reason of the misalignment. It should 2 in both cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @TomMalbran. Will push a change soon.

<span class="disclosure-triangle expanded" title="{{Strings.FIND_IN_FILES_EXPAND_COLLAPSE}}"></span>
{{{filename}}}
Expand Down
45 changes: 37 additions & 8 deletions src/search/SearchResultsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,40 @@ define(function (require, exports, module) {
});
});
self._$table.find(".check-one").prop("checked", isChecked);
self._$table.find(".check-one-file").prop("checked", isChecked);
self._allChecked = isChecked;
})
.on("click.searchResults", ".check-one-file", function (e) {
var isChecked = $(this).is(":checked"),
$row = $(e.target).closest("tr"),
item = self._searchList[$row.data("file-index")],
$matchRows = $row.nextUntil(".file-section");

if (item) {
self._model.results[item.fullPath].matches.forEach(function (match) {
match.isChecked = isChecked;
});
}
$matchRows.find(".check-one").prop("checked", isChecked);
e.stopPropagation();
})
.on("click.searchResults", ".check-one", function (e) {
var $row = $(e.target).closest("tr"),
$firstMatch = ($row.data("item-index") === 0) ? $row : $row.prevUntil(".file-section").last(),
$fileRow = $firstMatch.prev(),
$fileCheckbox = $fileRow.find(".check-one-file"),
item = self._searchList[$row.data("file-index")],
match = self._model.results[item.fullPath].matches[$row.data("match-index")],
$checkAll = self._panel.$panel.find(".check-all");

match.isChecked = $(this).is(":checked");
if (!match.isChecked && $checkAll.is(":checked")) {
$checkAll.prop("checked", false);
if (!match.isChecked) {
if ($checkAll.is(":checked")) {
$checkAll.prop("checked", false);
}
if ($fileCheckbox.is(":checked")) {
$fileCheckbox.prop("checked", false);
}
}
e.stopPropagation();
})
Expand Down Expand Up @@ -318,12 +341,13 @@ define(function (require, exports, module) {
*/
SearchResultsView.prototype._render = function () {
var searchItems, match, i, item, multiLine,
count = this._model.countFilesMatches(),
searchFiles = this._model.getSortedFiles(this._initialFilePath),
lastIndex = this._getLastIndex(count.matches),
matchesCounter = 0,
showMatches = false,
self = this;
count = this._model.countFilesMatches(),
searchFiles = this._model.getSortedFiles(this._initialFilePath),
lastIndex = this._getLastIndex(count.matches),
matchesCounter = 0,
showMatches = false,
allInFileChecked = true,
self = this;

this._showSummary();
this._searchList = [];
Expand Down Expand Up @@ -361,6 +385,7 @@ define(function (require, exports, module) {
// Add a row for each match in the file
searchItems = [];

allInFileChecked = true;
// Add matches until we get to the last match of this item, or filling the page
while (i < item.matches.length && matchesCounter < lastIndex) {
match = item.matches[i];
Expand All @@ -378,6 +403,9 @@ define(function (require, exports, module) {
end: match.end,
isChecked: match.isChecked
});
if (!match.isChecked) {
allInFileChecked = false;
}
matchesCounter++;
i++;
}
Expand All @@ -396,6 +424,7 @@ define(function (require, exports, module) {
fileIndex: self._searchList.length,
filename: displayFileName,
fullPath: fullPath,
isChecked: allInFileChecked,
items: searchItems
});
}
Expand Down
6 changes: 5 additions & 1 deletion src/styles/brackets.less
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ a, img {
}

.file-section > td {
padding-left: 5px;
padding-left: 10px;
}

.file-section > .checkbox-column {
padding-left: 15px;
}

.line-number {
Expand Down