From 5f8e04457e0e966a3c0da72317f805b6bc670d25 Mon Sep 17 00:00:00 2001 From: Colin Caine Date: Mon, 16 Jun 2025 22:25:54 +0200 Subject: [PATCH] Codechange: Use default OnHotkey handler for focusing editboxes (#14358) --- src/build_vehicle_gui.cpp | 22 +--------------------- src/industry_gui.cpp | 19 +------------------ src/signs_gui.cpp | 22 +--------------------- src/town_gui.cpp | 20 +------------------- 4 files changed, 4 insertions(+), 79 deletions(-) diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 45f8277429..3cba5c4408 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1131,11 +1131,6 @@ void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, Engi } } -/** Enum referring to the Hotkeys in the build vehicle window */ -enum BuildVehicleHotkeys : int32_t { - BVHK_FOCUS_FILTER_BOX, ///< Focus the edit box for editing the filter string -}; - /** GUI for building vehicles. */ struct BuildVehicleWindow : Window { VehicleType vehicle_type = VEH_INVALID; ///< Type of vehicles shown in the window. @@ -1941,23 +1936,8 @@ struct BuildVehicleWindow : Window { } } - EventState OnHotkey(int hotkey) override - { - switch (hotkey) { - case BVHK_FOCUS_FILTER_BOX: - this->SetFocusedWidget(WID_BV_FILTER); - SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused. - return ES_HANDLED; - - default: - return ES_NOT_HANDLED; - } - - return ES_HANDLED; - } - static inline HotkeyList hotkeys{"buildvehicle", { - Hotkey('F', "focus_filter_box", BVHK_FOCUS_FILTER_BOX), + Hotkey('F', "focus_filter_box", WID_BV_FILTER), }}; }; diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index b8af1ad201..980bc54611 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1343,10 +1343,6 @@ static bool CargoFilter(const Industry * const *industry, const std::pairSetFocusedWidget(WID_ID_FILTER); - SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused. - break; - default: - return ES_NOT_HANDLED; - } - return ES_HANDLED; - } - static inline HotkeyList hotkeys {"industrydirectory", { - Hotkey('F', "focus_filter_box", IDHK_FOCUS_FILTER_BOX), + Hotkey('F', "focus_filter_box", WID_ID_FILTER), }}; }; diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index 45f0018b54..a9c448f946 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -132,11 +132,6 @@ struct SignList { bool SignList::match_case = false; std::string SignList::default_name; -/** Enum referring to the Hotkeys in the sign list window */ -enum SignListHotkeys : int32_t { - SLHK_FOCUS_FILTER_BOX, ///< Focus the edit box for editing the filter string -}; - struct SignListWindow : Window, SignList { QueryString filter_editbox; ///< Filter editbox; int text_offset = 0; ///< Offset of the sign text relative to the left edge of the WID_SIL_LIST widget. @@ -277,21 +272,6 @@ struct SignListWindow : Window, SignList { } } - EventState OnHotkey(int hotkey) override - { - switch (hotkey) { - case SLHK_FOCUS_FILTER_BOX: - this->SetFocusedWidget(WID_SIL_FILTER_TEXT); - SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused. - break; - - default: - return ES_NOT_HANDLED; - } - - return ES_HANDLED; - } - void OnEditboxChanged(WidgetID widget) override { if (widget == WID_SIL_FILTER_TEXT) this->SetFilterString(this->filter_editbox.text.GetText()); @@ -345,7 +325,7 @@ struct SignListWindow : Window, SignList { } static inline HotkeyList hotkeys{"signlist", { - Hotkey('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX), + Hotkey('F', "focus_filter_box", WID_SIL_FILTER_TEXT), }, SignListGlobalHotkeys}; }; diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 141872f7bb..95f009e45f 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -701,11 +701,6 @@ static constexpr NWidgetPart _nested_town_directory_widgets[] = { EndContainer(), }; -/** Enum referring to the Hotkeys in the town directory window */ -enum TownDirectoryHotkeys : int32_t { - TDHK_FOCUS_FILTER_BOX, ///< Focus the filter box -}; - /** Town directory window class. */ struct TownDirectoryWindow : public Window { private: @@ -1019,21 +1014,8 @@ public: } } - EventState OnHotkey(int hotkey) override - { - switch (hotkey) { - case TDHK_FOCUS_FILTER_BOX: - this->SetFocusedWidget(WID_TD_FILTER); - SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused. - break; - default: - return ES_NOT_HANDLED; - } - return ES_HANDLED; - } - static inline HotkeyList hotkeys {"towndirectory", { - Hotkey('F', "focus_filter_box", TDHK_FOCUS_FILTER_BOX), + Hotkey('F', "focus_filter_box", WID_TD_FILTER), }}; };