mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Implemented search box functionality.
This commit is contained in:
@@ -421,6 +421,40 @@ function hideHoverText(evt) {
|
||||
hoverText.parentElement.removeChild(hoverText);
|
||||
}
|
||||
}
|
||||
function startSearch(evt) {
|
||||
if (evt.target.value == '') {
|
||||
var request_id = window.cefQuery({
|
||||
request: 'cancelFind',
|
||||
persistent: false,
|
||||
onSuccess: function(response) { evt.target.focus(); },
|
||||
onFailure: function(error_code, error_message) {
|
||||
showMessageBox('error', "Error", "Error code: " + error_code + "; " + error_message);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var request = {
|
||||
name: 'find',
|
||||
args: [
|
||||
evt.target.value
|
||||
]
|
||||
};
|
||||
|
||||
var request_id = window.cefQuery({
|
||||
request: JSON.stringify(request),
|
||||
persistent: false,
|
||||
onSuccess: function(response) { evt.target.focus(); },
|
||||
onFailure: function(error_code, error_message) {
|
||||
showMessageBox('error', "Error", "Error code: " + error_code + "; " + error_message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
function focusSearch(evt) {
|
||||
if (evt.ctrlKey && evt.keyCode == 70) { //'f'
|
||||
document.getElementById('searchBox').focus();
|
||||
}
|
||||
}
|
||||
function setupEventHandlers() {
|
||||
var elements;
|
||||
if (isStorageSupported()) { /*Set up filter value and CSS setting storage read/write handlers.*/
|
||||
@@ -479,6 +513,12 @@ function setupEventHandlers() {
|
||||
hoverTargets[i].addEventListener('mouseenter', showHoverText, false);
|
||||
hoverTargets[i].addEventListener('mouseleave', hideHoverText, false);
|
||||
}
|
||||
|
||||
/* Set up event handlers for content search. */
|
||||
var searchBox = document.getElementById('searchBox');
|
||||
searchBox.addEventListener('input', startSearch, false);
|
||||
searchBox.addEventListener('search', startSearch, false);
|
||||
window.addEventListener('keyup', focusSearch, false);
|
||||
}
|
||||
function processCefError(errorCode, errorMessage) {
|
||||
showMessageBox('error', "Error", "Error code: " + error_code + "; " + error_message);
|
||||
|
||||
@@ -120,6 +120,41 @@ namespace loot {
|
||||
callback->Success(GetGameData());
|
||||
return true;
|
||||
}
|
||||
else if (request == "cancelFind") {
|
||||
browser->GetHost()->StopFinding(true);
|
||||
callback->Success("");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// May be a request with arguments.
|
||||
YAML::Node req;
|
||||
try {
|
||||
req = JSON::parse(request.ToString());
|
||||
}
|
||||
catch (exception &e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to parse CEF query request \"" << request << "\": " << e.what();
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string requestName = req["name"].as<string>();
|
||||
|
||||
if (requestName == "find") {
|
||||
// Has one arg, which is the search string.
|
||||
const std::string search = req["args"][0].as<string>();
|
||||
|
||||
// In case there is a search already running, cancel it.
|
||||
browser->GetHost()->StopFinding(true);
|
||||
|
||||
// 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, false);
|
||||
|
||||
callback->Success("");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user