Codechange: Use default OnHotkey handler for focusing editboxes (#14358)

This commit is contained in:
Colin Caine 2025-06-16 22:25:54 +02:00 committed by GitHub
parent 56bc391763
commit 5f8e04457e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 4 additions and 79 deletions

View File

@ -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. */ /** GUI for building vehicles. */
struct BuildVehicleWindow : Window { struct BuildVehicleWindow : Window {
VehicleType vehicle_type = VEH_INVALID; ///< Type of vehicles shown in the 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", { static inline HotkeyList hotkeys{"buildvehicle", {
Hotkey('F', "focus_filter_box", BVHK_FOCUS_FILTER_BOX), Hotkey('F', "focus_filter_box", WID_BV_FILTER),
}}; }};
}; };

View File

@ -1343,10 +1343,6 @@ static bool CargoFilter(const Industry * const *industry, const std::pair<CargoT
static GUIIndustryList::FilterFunction * const _industry_filter_funcs[] = { &CargoFilter }; static GUIIndustryList::FilterFunction * const _industry_filter_funcs[] = { &CargoFilter };
/** Enum referring to the Hotkeys in the industry directory window */
enum IndustryDirectoryHotkeys : int32_t {
IDHK_FOCUS_FILTER_BOX, ///< Focus the filter box
};
/** /**
* The list of industries. * The list of industries.
*/ */
@ -1921,21 +1917,8 @@ public:
} }
} }
EventState OnHotkey(int hotkey) override
{
switch (hotkey) {
case IDHK_FOCUS_FILTER_BOX:
this->SetFocusedWidget(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", { static inline HotkeyList hotkeys {"industrydirectory", {
Hotkey('F', "focus_filter_box", IDHK_FOCUS_FILTER_BOX), Hotkey('F', "focus_filter_box", WID_ID_FILTER),
}}; }};
}; };

View File

@ -132,11 +132,6 @@ struct SignList {
bool SignList::match_case = false; bool SignList::match_case = false;
std::string SignList::default_name; 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 { struct SignListWindow : Window, SignList {
QueryString filter_editbox; ///< Filter editbox; 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. 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 void OnEditboxChanged(WidgetID widget) override
{ {
if (widget == WID_SIL_FILTER_TEXT) this->SetFilterString(this->filter_editbox.text.GetText()); 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", { static inline HotkeyList hotkeys{"signlist", {
Hotkey('F', "focus_filter_box", SLHK_FOCUS_FILTER_BOX), Hotkey('F', "focus_filter_box", WID_SIL_FILTER_TEXT),
}, SignListGlobalHotkeys}; }, SignListGlobalHotkeys};
}; };

View File

@ -701,11 +701,6 @@ static constexpr NWidgetPart _nested_town_directory_widgets[] = {
EndContainer(), 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. */ /** Town directory window class. */
struct TownDirectoryWindow : public Window { struct TownDirectoryWindow : public Window {
private: 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", { static inline HotkeyList hotkeys {"towndirectory", {
Hotkey('F', "focus_filter_box", TDHK_FOCUS_FILTER_BOX), Hotkey('F', "focus_filter_box", WID_TD_FILTER),
}}; }};
}; };