record and replay text field input
This commit is contained in:
@@ -543,6 +543,10 @@ void cDialog::handle_events() {
|
||||
if(info["id"].empty()) continue;
|
||||
eKeyMod mods = static_cast<eKeyMod>(std::stoi(info["mods"]));
|
||||
controls[info["id"]]->triggerClickHandler(*this, info["id"], mods);
|
||||
}else if(replaying && has_next_action() && next_action_type() == "field_input"){
|
||||
Element& next_action = pop_next_action();
|
||||
cKey key = key_from_action(next_action);
|
||||
dynamic_cast<cTextField&>(getControl(currentFocus)).handleInput(key);
|
||||
}else{
|
||||
while(win.pollEvent(currentEvent)) handle_one_event(currentEvent, fps_limiter);
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include "tools/keymods.hpp"
|
||||
#include "tools/winutil.hpp"
|
||||
#include "tools/cursors.hpp"
|
||||
#include "replay.hpp"
|
||||
|
||||
bool cTextField::callHandler(event_fcn<EVT_DEFOCUS>::type onFocus, cDialog& me, std::string id) {
|
||||
if(field_type != FLD_TEXT) {
|
||||
@@ -396,6 +397,9 @@ static cKey divineFunction(cKey key) {
|
||||
}
|
||||
|
||||
void cTextField::handleInput(cKey key) {
|
||||
if(recording){
|
||||
record_field_input(key);
|
||||
}
|
||||
changeMade = true;
|
||||
bool select = mod_contains(key.mod, mod_shift);
|
||||
bool haveSelection = insertionPoint != selectionPoint;
|
||||
|
@@ -11,6 +11,10 @@
|
||||
#include <boost/optional.hpp>
|
||||
#include <cppcodec/base64_rfc4648.hpp>
|
||||
#include "tools/framerate_limiter.hpp"
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
#include <string>
|
||||
|
||||
using base64 = cppcodec::base64_rfc4648;
|
||||
|
||||
bool recording = false;
|
||||
@@ -89,6 +93,32 @@ void record_action(std::string action_type, std::map<std::string,std::string> in
|
||||
log_document.SaveFile(log_file);
|
||||
}
|
||||
|
||||
void record_field_input(cKey key) {
|
||||
std::map<std::string,std::string> info;
|
||||
std::ostringstream sstr;
|
||||
|
||||
sstr << key.spec;
|
||||
info["spec"] = sstr.str();
|
||||
|
||||
sstr.str("");
|
||||
if(key.spec){
|
||||
sstr << key.k;
|
||||
info["k"] = sstr.str();
|
||||
}else{
|
||||
std::wostringstream wstr;
|
||||
wstr << key.c;
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::string c = converter.to_bytes(wstr.str());
|
||||
info["c"] = c;
|
||||
}
|
||||
|
||||
sstr.str("");
|
||||
sstr << key.mod;
|
||||
info["mod"] = sstr.str();
|
||||
|
||||
record_action("field_input", info);
|
||||
}
|
||||
|
||||
bool has_next_action() {
|
||||
return next_action != nullptr;
|
||||
}
|
||||
@@ -162,3 +192,29 @@ short short_from_action(Element& action) {
|
||||
sstr >> s;
|
||||
return s;
|
||||
}
|
||||
|
||||
cKey key_from_action(Element& action) {
|
||||
auto info = info_from_action(action);
|
||||
cKey key;
|
||||
int enum_v;
|
||||
|
||||
std::istringstream sstr(info["spec"]);
|
||||
sstr >> key.spec;
|
||||
|
||||
if(key.spec){
|
||||
sstr.str(info["k"]);
|
||||
sstr >> enum_v;
|
||||
key.k = static_cast<eSpecKey>(enum_v);
|
||||
}else{
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::wstring wstr = converter.from_bytes(info["c"]);
|
||||
std::wistringstream wsstr(wstr);
|
||||
wsstr >> key.c;
|
||||
}
|
||||
|
||||
sstr.str(info["mod"]);
|
||||
sstr >> enum_v;
|
||||
key.mod = static_cast<eKeyMod>(enum_v);
|
||||
|
||||
return key;
|
||||
}
|
@@ -6,6 +6,7 @@
|
||||
#include <map>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "location.hpp"
|
||||
#include "keycodes.hpp"
|
||||
|
||||
// Input recording system
|
||||
namespace ticpp { class Element; }
|
||||
@@ -17,6 +18,7 @@ extern bool replaying;
|
||||
extern bool init_action_log(std::string command, std::string file);
|
||||
extern void record_action(std::string action_type, std::string inner_text, bool cdata = false);
|
||||
extern void record_action(std::string action_type, std::map<std::string,std::string> info);
|
||||
extern void record_field_input(cKey key);
|
||||
extern bool has_next_action();
|
||||
extern std::string next_action_type();
|
||||
extern Element& pop_next_action(std::string expected_action_type="");
|
||||
@@ -25,5 +27,6 @@ extern std::string encode_file(fs::path file);
|
||||
extern void decode_file(std::string data, fs::path file);
|
||||
extern location location_from_action(Element& action);
|
||||
extern short short_from_action(Element& action);
|
||||
extern cKey key_from_action(Element& action);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user