Fix safe save overwrite activation by double-click (by Codex)
This commit is contained in:
1 parent
9c82cb16b5
commit
6f33f9c155
6 files changed
+81
-7
No files matched your search
+2
-1
@@ -2670,7 +2670,8 @@ int main(int argc, char** argv) {
|
||||
file_input.button.button == SDL_BUTTON_RIGHT)) {
|
||||
file_changed |= file_screen.click(file_input.button.x,
|
||||
file_input.button.y,
|
||||
file_input.button.button == SDL_BUTTON_RIGHT);
|
||||
file_input.button.button == SDL_BUTTON_RIGHT,
|
||||
file_input.button.clicks >= 2);
|
||||
} else if (file_input.type == SDL_KEYDOWN && !file_input.key.repeat) {
|
||||
std::string_view key;
|
||||
switch (file_input.key.keysym.sym) {
|
||||
|
||||
+1
-1
@@ -446,7 +446,7 @@ FlowResult StartupFlow::click(int x, int y, bool right, bool double_click) {
|
||||
}
|
||||
if (save_load_) {
|
||||
const auto before = state_json();
|
||||
const bool changed = save_load_->click(x, y, right);
|
||||
const bool changed = save_load_->click(x, y, right, double_click);
|
||||
return finish_file_input(changed || before != state_json());
|
||||
}
|
||||
if (in_preparation_menu()) {
|
||||
|
||||
+2
-1
@@ -185,7 +185,8 @@ int main(int argc, char** argv) {
|
||||
const bool held=event.button.button==SDL_BUTTON_LEFT&&left_press&&
|
||||
event.button.x==left_press->x&&event.button.y==left_press->y&&left_press->screen==screen.screen_name()&&SDL_GetTicks()-left_press->time>=2000;
|
||||
auto result = held ? screen.hold(event.button.x,event.button.y,2000) :
|
||||
screen.click(event.button.x, event.button.y, event.button.button == SDL_BUTTON_RIGHT);
|
||||
screen.click(event.button.x, event.button.y, event.button.button == SDL_BUTTON_RIGHT,
|
||||
event.button.clicks >= 2);
|
||||
auto input=pointer_input(held ? "hold" : event.button.button == SDL_BUTTON_RIGHT ? "right" : "left",event.button.x,event.button.y);
|
||||
if(held){input.pop_back();input+=",\"milliseconds\":"+std::to_string(SDL_GetTicks()-left_press->time)+"}";}
|
||||
left_press.reset();report(screen, result, input);dirty |= result.changed;
|
||||
|
||||
@@ -321,7 +321,7 @@ void SaveLoadScreen::request_action() {
|
||||
file_kind_, origin_item_id_};
|
||||
}
|
||||
|
||||
bool SaveLoadScreen::click(int x, int y, bool right) {
|
||||
bool SaveLoadScreen::click(int x, int y, bool right, bool double_click) {
|
||||
if (info_) { info_.reset(); return true; }
|
||||
if (pending_) return false;
|
||||
// OpenBMH deviates from the original: permits cancelling host file dialogs with the right mouse button.
|
||||
@@ -337,7 +337,11 @@ bool SaveLoadScreen::click(int x, int y, bool right) {
|
||||
}
|
||||
if (x >= 53 && x <= 199 && select_row(y)) {
|
||||
const int row = scroll_ + (y - 40) / 10;
|
||||
if (mode_ == SaveLoadMode::load && row == last_clicked_row_) { request_action(); return true; }
|
||||
// Row selection clears overwrite confirmation before activation. Even a
|
||||
// repeated double-click must ask again; only Enter confirms replacement.
|
||||
if (double_click || (mode_ == SaveLoadMode::load && row == last_clicked_row_)) {
|
||||
request_action(); return true;
|
||||
}
|
||||
last_clicked_row_ = row;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
// InfoPress opens5870f on right DOWN; its popup restores on mouse UP.
|
||||
bool info_press(int x, int y);
|
||||
bool info_open() const { return bool(info_); }
|
||||
bool click(int x, int y, bool right = false);
|
||||
bool click(int x, int y, bool right = false, bool double_click = false);
|
||||
bool key(std::string_view key);
|
||||
bool text(std::string_view value);
|
||||
const std::optional<SaveLoadRequest>& pending() const { return pending_; }
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "ui/save_load.hpp"
|
||||
#include "ui/flow.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace bmh;
|
||||
@@ -30,7 +32,66 @@ int main(int argc, char** argv) {
|
||||
std::pair{SaveLoadFileKind::game, ".FBM"},
|
||||
std::pair{SaveLoadFileKind::settings, ".EIN"},
|
||||
std::pair{SaveLoadFileKind::menu_layout, ".MEN"}}) {
|
||||
std::ofstream(root / (std::string("Existing") + extension)) << "authored filename fixture";
|
||||
const auto existing = root / (std::string("Existing") + extension);
|
||||
const std::string fixture = "authored filename fixture";
|
||||
std::ofstream(existing) << fixture;
|
||||
const auto unchanged = [&] {
|
||||
std::ifstream input(existing);
|
||||
check(std::string(std::istreambuf_iterator<char>(input), {}) == fixture,
|
||||
"picker interactions never write the selected file");
|
||||
};
|
||||
SaveLoadScreen overwrite(argv[1], root, SaveLoadMode::save, 2, 17, backdrop, true, kind, 9);
|
||||
check(overwrite.click(70, 45) && overwrite.click(70, 45) && !overwrite.pending() &&
|
||||
overwrite.state_json().find("EXISTIERT") == std::string::npos,
|
||||
"separate single clicks only select an existing save");
|
||||
check(overwrite.click(70, 45, false, true) && !overwrite.pending() &&
|
||||
overwrite.state_json().find("ENTER ZUM ERSETZEN") != std::string::npos,
|
||||
"a true double-click asks for overwrite confirmation without submitting a write");
|
||||
check(overwrite.click(70, 45, false, true) && !overwrite.pending(),
|
||||
"repeated double-clicks cannot confirm an overwrite");
|
||||
unchanged();
|
||||
check(overwrite.key("ENTER") && overwrite.pending() && overwrite.pending()->overwrite &&
|
||||
overwrite.pending()->path == existing && overwrite.pending()->manager_slot == 2 &&
|
||||
overwrite.pending()->revision == 17 && overwrite.pending()->file_kind == kind &&
|
||||
overwrite.pending()->origin_item_id == 9,
|
||||
"Enter confirms the exact selected file with its manager, revision and file kind");
|
||||
const auto request = *overwrite.pending();
|
||||
check(!overwrite.click(70, 45, false, true) && !overwrite.key("ENTER") &&
|
||||
*overwrite.pending() == request,
|
||||
"queued mouse releases and Enter cannot submit a second pending overwrite");
|
||||
overwrite.acknowledge();
|
||||
check(overwrite.close_requested() && !overwrite.pending(),
|
||||
"acknowledgement closes the picker and clears its one request");
|
||||
unchanged();
|
||||
for (bool right : {false, true}) {
|
||||
SaveLoadScreen cancel(argv[1], root, SaveLoadMode::save, 0, 7, backdrop, true, kind);
|
||||
cancel.click(70, 45, false, true);
|
||||
check((right ? cancel.click(70, 45, true, true) : cancel.key("ESC")) &&
|
||||
cancel.close_requested() && !cancel.pending(),
|
||||
"right-click and Escape cancel an armed overwrite without a write");
|
||||
}
|
||||
const auto second = root / (std::string("Second") + extension);
|
||||
std::ofstream(second) << fixture;
|
||||
SaveLoadScreen change_row(argv[1], root, SaveLoadMode::save, 0, 7, backdrop, true, kind);
|
||||
change_row.click(70, 45, false, true);
|
||||
check(change_row.click(70, 55) && change_row.key("ENTER") && !change_row.pending() &&
|
||||
change_row.key("ENTER") && change_row.pending() && change_row.pending()->path == second,
|
||||
"selecting another row cannot reuse the first file's overwrite confirmation");
|
||||
SaveLoadScreen reset(argv[1], root, SaveLoadMode::save, 0, 7, backdrop, true, kind);
|
||||
reset.click(70, 45, false, true);
|
||||
reset.click(70, 45);
|
||||
check(reset.key("ENTER") && !reset.pending() && reset.key("ENTER") && reset.pending(),
|
||||
"single selection clears confirmation and preserves the existing two-Enter save path");
|
||||
SaveLoadScreen rename(argv[1], root, SaveLoadMode::save, 0, 7, backdrop, true, kind);
|
||||
rename.click(70, 45, false, true);
|
||||
check(rename.text("Other") && rename.key("ENTER") && rename.pending() &&
|
||||
!rename.pending()->overwrite && rename.pending()->path.filename() == std::string("Other") + extension,
|
||||
"editing an armed overwrite starts an independent new-file save");
|
||||
SaveLoadScreen activate_load(argv[1], root, SaveLoadMode::load, 0, 7, backdrop, true, kind);
|
||||
check(activate_load.click(70, 45, false, true) && activate_load.pending() &&
|
||||
activate_load.pending()->action == SaveLoadAction::load && activate_load.pending()->path == existing,
|
||||
"an explicit double-click also activates an existing load entry");
|
||||
unchanged();
|
||||
SaveLoadScreen load(argv[1], root, SaveLoadMode::load, 0, 7, backdrop, true, kind);
|
||||
check(load.click(0, 0, true) && load.close_requested() && !load.pending(),
|
||||
"right-click closes every file picker without submitting a load");
|
||||
@@ -54,6 +115,13 @@ int main(int argc, char** argv) {
|
||||
check(edit.pending() && edit.pending()->path.filename() == std::string("Short") + extension,
|
||||
"editing and UTF-8 deletion preserve the resulting host filename");
|
||||
}
|
||||
StartupFlow flow(argv[1], root);
|
||||
flow.click(214, 215);
|
||||
check(flow.screen_name() == "save_load", "setup opens its save-list picker");
|
||||
const auto load = flow.click(70, 45, false, true);
|
||||
check(load.request == FlowRequest::file_action && load.file_action.action == SaveLoadAction::load &&
|
||||
load.file_action.path.filename() == "Existing.FBM",
|
||||
"startup flow forwards a real double-click to its active file picker");
|
||||
std::cout << "save/load input checks passed\n";
|
||||
return 0;
|
||||
} catch (const std::exception& error) {
|
||||
|
||||
Reference in new issue
Block a user