From f436b1bbf1bb7846e6e000944db0e01a28df9b85 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 14 Oct 2022 21:03:37 +0300 Subject: [PATCH 42/42] gtk4: Enable infra dialog See osdn #45838 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/infradlg.c | 27 +++++++++++++++++---------- client/gui-gtk-4.0/menu.c | 28 ++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/client/gui-gtk-4.0/infradlg.c b/client/gui-gtk-4.0/infradlg.c index 146863b444..25590b6c72 100644 --- a/client/gui-gtk-4.0/infradlg.c +++ b/client/gui-gtk-4.0/infradlg.c @@ -35,7 +35,7 @@ #include "infradlg.h" -static GtkWidget *infra_list_grid = NULL; +static GtkWidget *infra_list_box = NULL; static GtkWidget *instruction_label = NULL; static GtkWidget *points_label = NULL; static int infra_rows = 0; @@ -50,7 +50,7 @@ struct infra_cb_data { ****************************************************************************/ static bool infra_dialog_open(void) { - return infra_list_grid != NULL; + return infra_list_box != NULL; } /************************************************************************//** @@ -58,7 +58,7 @@ static bool infra_dialog_open(void) ****************************************************************************/ static void infra_response_callback(GtkWidget *dlg, gint arg) { - infra_list_grid = NULL; + infra_list_box = NULL; instruction_label = NULL; points_label = NULL; infra_rows = 0; @@ -118,8 +118,8 @@ void infra_dialog_popup(void) sep = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); gtk_grid_attach(GTK_GRID(main_box), sep, 0, grid_row++, 1, 1); - infra_list_grid = gtk_grid_new(); - gtk_grid_attach(GTK_GRID(main_box), infra_list_grid, 0, grid_row++, 1, 1); + infra_list_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + gtk_grid_attach(GTK_GRID(main_box), infra_list_box, 0, grid_row++, 1, 1); gtk_box_append(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))), main_box); @@ -155,7 +155,7 @@ void update_infra_dialog(void) ****************************************************************************/ bool infra_placement_mode(void) { - return infra_list_grid != NULL; + return infra_list_box != NULL; } /************************************************************************//** @@ -163,9 +163,15 @@ bool infra_placement_mode(void) ****************************************************************************/ void infra_placement_set_tile(struct tile *ptile) { - while (infra_rows > 0) { - gtk_grid_remove_row(GTK_GRID(infra_list_grid), --infra_rows); + if (infra_list_box != NULL) { + GtkWidget *child = gtk_widget_get_first_child(infra_list_box); + + while (child != NULL) { + gtk_box_remove(GTK_BOX(infra_list_box), child); + child = gtk_widget_get_first_child(infra_list_box); + } } + infra_rows = 0; if (!client_map_is_known_and_seen(ptile, client.conn.playing, V_MAIN)) { return; @@ -183,7 +189,8 @@ void infra_placement_set_tile(struct tile *ptile) g_signal_connect(but, "clicked", G_CALLBACK(infra_selected_callback), cbdata); - gtk_grid_attach(GTK_GRID(infra_list_grid), but, 1, infra_rows++, 1, 1); + gtk_box_append(GTK_BOX(infra_list_box), but); + infra_rows++; } } extra_type_iterate_end; @@ -195,5 +202,5 @@ void infra_placement_set_tile(struct tile *ptile) _("Select infra for the tile, or another tile.")); } - gtk_widget_show(infra_list_grid); + gtk_widget_show(infra_list_box); } diff --git a/client/gui-gtk-4.0/menu.c b/client/gui-gtk-4.0/menu.c index b20eef03ca..b84bcca5b4 100644 --- a/client/gui-gtk-4.0/menu.c +++ b/client/gui-gtk-4.0/menu.c @@ -281,9 +281,11 @@ static void select_same_type_cont_callback(GtkMenuItem *item, gpointer data); static void select_same_type_callback(GtkMenuItem *item, gpointer data); static void select_dialog_callback(GtkMenuItem *item, gpointer data); static void rally_dialog_callback(GtkMenuItem *item, gpointer data); -static void infra_dialog_callback(GtkMenuItem *item, gpointer data); #endif /* MENUS_GTK3 */ +static void infra_dialog_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data); static void unit_wait_callback(GSimpleAction *action, GVariant *parameter, gpointer data); @@ -377,6 +379,10 @@ static struct menu_entry_info menu_entries[] = { "QUIT", N_("_Quit"), "quit", "q", MGROUP_SAFE }, + /* Edit menu */ + { "INFRA_DLG", N_("Infra dialog"), + "infra_dlg", "i", MGROUP_SAFE }, + /* View menu */ { "CENTER_VIEW", N_("_Center View"), "center_view", "c", MGROUP_PLAYER }, @@ -479,8 +485,7 @@ static struct menu_entry_info menu_entries[] = G_CALLBACK(worklists_callback), MGROUP_SAFE }, { "RALLY_DLG", N_("Rally point dialog"), GDK_KEY_r, GDK_CONTROL_MASK, G_CALLBACK(rally_dialog_callback), MGROUP_SAFE }, - { "INFRA_DLG", N_("Infra dialog"), GDK_KEY_i, GDK_CONTROL_MASK, - G_CALLBACK(infra_dialog_callback), MGROUP_SAFE }, + { "CLIENT_LUA_SCRIPT", N_("Client _Lua Script"), 0, 0, G_CALLBACK(client_lua_script_callback), MGROUP_SAFE }, { "HELP_OVERVIEW", N_("?help:Overview"), 0, 0, @@ -692,6 +697,8 @@ const GActionEntry acts[] = { { "leave", leave_callback }, { "quit", quit_callback }, + { "infra_dlg", infra_dialog_callback }, + { "center_view", center_view_callback }, { "explore", unit_explore_callback }, @@ -1594,15 +1601,17 @@ static void rally_dialog_callback(GtkMenuItem *item, gpointer data) { rally_dialog_popup(); } +#endif /* MENUS_GTK3 */ /************************************************************************//** Open infra placement dialog. ****************************************************************************/ -static void infra_dialog_callback(GtkMenuItem *item, gpointer data) +static void infra_dialog_callback(GSimpleAction *action, + GVariant *parameter, + gpointer data) { infra_dialog_popup(); } -#endif /* MENUS_GTK3 */ /************************************************************************//** Item "UNIT_WAIT" callback. @@ -2260,6 +2269,12 @@ static GMenu *setup_menus(GtkApplication *app) topmenu = g_menu_new(); + menu_entry_init(topmenu, "INFRA_DLG"); + + g_menu_append_submenu(menubar, _("_Edit"), G_MENU_MODEL(topmenu)); + + topmenu = g_menu_new(); + menu_entry_init(topmenu, "CENTER_VIEW"); g_menu_append_submenu(menubar, Q_("?verb:_View"), G_MENU_MODEL(topmenu)); @@ -2821,6 +2836,8 @@ void real_menus_update(void) && can_client_issue_orders() && !editor_is_active()); + menu_entry_set_sensitive(map, "INFRA_DLG", terrain_control.infrapoints); + #ifdef MENUS_GTK3 menu_entry_set_active("EDIT_MODE", game.info.is_edit_mode); @@ -2828,7 +2845,6 @@ void real_menus_update(void) can_conn_enable_editing(&client.conn)); editgui_refresh(); menu_entry_set_sensitive("RALLY_DLG", can_client_issue_orders()); - menu_entry_set_sensitive("INFRA_DLG", terrain_control.infrapoints); { char road_buf[500]; -- 2.35.1