Re-implemented search as a filter.

This commit is contained in:
Oliver Hamlet
2014-11-14 23:31:49 +00:00
parent 8986f4d6f6
commit 3ca6ed2084
5 changed files with 32 additions and 57 deletions
+3
View File
@@ -66,6 +66,9 @@ paper-item > a {
left: 0;
right: 0;
}
#searchBox {
display: block;
}
#container {
position: fixed;
top: 64px;
+26 -31
View File
@@ -522,6 +522,28 @@ function applyFilters(evt) {
document.getElementById('hiddenPluginNo').textContent = hiddenPluginNo;
});
}
function searchFilter(plugins) {
var search = document.getElementById('searchBox').value.toLowerCase();
if (search.length > 0) {
var hiddenPluginNo = 0;
var hiddenMessageNo = 0;
var filteredPlugins = [];
/* Check each plugin entry to see if the current search string exists in
its name, version, crc, Bash Tag or message strings. */
for (var i = 0; i < plugins.length; ++i) {
if (plugins[i].name.toLowerCase().indexOf(search) != -1
|| plugins[i].getCrcString().toLowerCase().indexOf(search) != -1) {
filteredPlugins.push(plugins[i]);
}
}
return filteredPlugins;
} else {
return plugins;
}
}
function showMessageDialog(title, text, yesNo, closeCallback) {
var dialog = document.createElement('loot-message-dialog');
if (yesNo) {
@@ -982,34 +1004,9 @@ function showSettingsDialog(evt) {
document.getElementById('settingsDialog').showModal();
}
function startSearch(evt) {
var findNext = false;
if (evt.type == 'keyup') {
if (evt.keyCode != 13) {
// Don't do anything for keyboard events that aren't enter - if valid, the input event will handle them.
return;
} else {
findNext = true;
}
}
if (evt.target.inputValue == '') {
loot.query('cancelFind').then(function(result){
evt.target.focus();
}).catch(processCefError);
} else {
var request = JSON.stringify({
name: 'find',
args: [
evt.target.value,
findNext
]
});
loot.query(request).then(function(result){
evt.target.focus();
}).catch(processCefError);
}
function handleSearch(evt) {
document.getElementById('cardsNav').lastElementChild.data = searchFilter(loot.game.plugins);
document.getElementById('main').lastElementChild.data = searchFilter(loot.game.plugins);
}
function focusSearch(evt) {
if (evt.ctrlKey && evt.keyCode == 70) { //'f'
@@ -1229,9 +1226,7 @@ function setupEventHandlers() {
settings.getElementsByClassName('cancel')[0].addEventListener('click', closeSettingsDialog, false);
/* Set up event handlers for content search. */
var searchBox = document.getElementById('searchBox');
searchBox.addEventListener('input', startSearch, false);
searchBox.addEventListener('keyup', startSearch, false);
document.getElementById('searchBox').addEventListener('change', handleSearch, false);
window.addEventListener('keyup', focusSearch, false);
/* Set up handler for opening and closing editors. */
+2 -5
View File
@@ -28,7 +28,6 @@
<link rel="import" href="bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="bower_components/paper-button/paper-button.html">
<link rel="import" href="bower_components/paper-input/paper-input.html">
<link rel="import" href="bower_components/paper-input/paper-input-decorator.html">
<link rel="import" href="bower_components/paper-tabs/paper-tabs.html">
<link rel="import" href="bower_components/paper-checkbox/paper-checkbox.html">
<link rel="import" href="bower_components/paper-dialog/paper-dialog.html">
@@ -139,10 +138,8 @@
</div>
</div>
</core-animated-pages>
<core-tooltip label="Press Enter when searching to select the next match." position="top">
<paper-input-decorator label="Search content...">
<input id="searchBox" is="core-input" type="search">
</paper-input-decorator>
<core-tooltip label="Press Enter or click outside the input to set the filter." position="top">
<paper-input id="searchBox" label="Filter content..."></paper-input>
</core-tooltip>
</div>
<div main id="main">
+1 -20
View File
@@ -196,19 +196,7 @@ namespace loot {
CefRefPtr<Callback> callback) {
const string requestName = request["name"].as<string>();
if (requestName == "find") {
// Has one arg, which is the search string.
try {
Find(browser, request["args"][0].as<string>(), request["args"][1].as<bool>());
callback->Success("");
}
catch (std::exception& e) {
BOOST_LOG_TRIVIAL(error) << "Failed to perform search. Details: " << e.what();
callback->Failure(-1, string("Failed to perform search. Details: ") + e.what());
}
return true;
}
else if (requestName == "changeGame") {
if (requestName == "changeGame") {
try {
// Has one arg, which is the folder name of the new game.
g_app_state.ChangeGame(request["args"][0].as<string>());
@@ -340,13 +328,6 @@ namespace loot {
return false;
}
void Handler::Find(CefRefPtr<CefBrowser> browser, const std::string& search, bool findNext) {
// Only one search at a time is allowed, so give a constant identifier,
// and we want case-insensitive forward searching, with no repeated
// searches.
browser->GetHost()->Find(0, search, true, false, findNext);
}
void Handler::GetConflictingPlugins(const std::string& pluginName, CefRefPtr<CefFrame> frame, CefRefPtr<Callback> callback) {
BOOST_LOG_TRIVIAL(debug) << "Searching for plugins that conflict with " << pluginName;
-1
View File
@@ -66,7 +66,6 @@ namespace loot {
YAML::Node& request,
CefRefPtr<Callback> callback);
void Find(CefRefPtr<CefBrowser> browser, const std::string& search, bool findNext);
void GetConflictingPlugins(const std::string& pluginName, CefRefPtr<CefFrame> frame, CefRefPtr<Callback> callback);
void CopyMetadata(const std::string& pluginName);
std::string ClearPluginMetadata(const std::string& pluginName);