From d9d6c7268cf91fb7d2923e85db4cb635549b22c1 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 5 Sep 2022 06:02:24 +0300 Subject: [PATCH 55/55] gtk4: Open help dialog from worklist right-click See osdn #45576 Signed-off-by: Marko Lindqvist --- client/gui-gtk-4.0/wldlg.c | 82 ++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 16 deletions(-) diff --git a/client/gui-gtk-4.0/wldlg.c b/client/gui-gtk-4.0/wldlg.c index c0fed5516b..5e5f24db59 100644 --- a/client/gui-gtk-4.0/wldlg.c +++ b/client/gui-gtk-4.0/wldlg.c @@ -522,6 +522,29 @@ static void popup_add_menu(GtkMenuShell *menu, gpointer data) } #endif /* MENUS_GTK3 */ +/************************************************************************//** + Open help dialog for the cid pointed by iterator. +****************************************************************************/ +static void wl_help_from_iter(GtkTreeModel *model, GtkTreeIter *it) +{ + gint id; + struct universal target; + + gtk_tree_model_get(model, it, 0, &id, -1); + target = cid_decode(id); + + if (VUT_UTYPE == target.kind) { + popup_help_dialog_typed(utype_name_translation(target.value.utype), + HELP_UNIT); + } else if (is_great_wonder(target.value.building)) { + popup_help_dialog_typed(improvement_name_translation(target.value.building), + HELP_WONDER); + } else { + popup_help_dialog_typed(improvement_name_translation(target.value.building), + HELP_IMPROVEMENT); + } +} + /************************************************************************//** Help button clicked ****************************************************************************/ @@ -536,22 +559,7 @@ static void help_callback(GtkWidget *w, gpointer data) selection = ptr->src_selection; if (gtk_tree_selection_get_selected(selection, &model, &it)) { - gint id; - struct universal target; - - gtk_tree_model_get(model, &it, 0, &id, -1); - target = cid_decode(id); - - if (VUT_UTYPE == target.kind) { - popup_help_dialog_typed(utype_name_translation(target.value.utype), - HELP_UNIT); - } else if (is_great_wonder(target.value.building)) { - popup_help_dialog_typed(improvement_name_translation(target.value.building), - HELP_WONDER); - } else { - popup_help_dialog_typed(improvement_name_translation(target.value.building), - HELP_IMPROVEMENT); - } + wl_help_from_iter(model, &it); } else { popup_help_dialog_string(HELP_WORKLIST_EDITOR_ITEM); } @@ -1066,6 +1074,32 @@ static void populate_view(GtkTreeView *view, struct city **ppcity, } } +/************************************************************************//** + Open help dialog for the worklist item. +****************************************************************************/ +static gboolean wl_right_button_up(GtkGestureClick *gesture, + int n_press, + double x, double y) +{ + GtkEventController *controller = GTK_EVENT_CONTROLLER(gesture); + GtkWidget *w = gtk_event_controller_get_widget(controller); + GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(w)); + GtkTreePath *path; + int bx, by; + + gtk_tree_view_convert_widget_to_bin_window_coords(GTK_TREE_VIEW(w), x, y, &bx, &by); + + if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(w), bx, by, &path, NULL, NULL, NULL)) { + GtkTreeIter iter; + + if (gtk_tree_model_get_iter(model, &iter, path)) { + wl_help_from_iter(model, &iter); + } + } + + return TRUE; +} + /************************************************************************//** Worklist editor shell. ****************************************************************************/ @@ -1082,6 +1116,8 @@ GtkWidget *create_worklist(void) GtkListStore *src_store, *dst_store; struct worklist_data *ptr; int editor_row = 0; + GtkEventController *controller; + GtkGesture *gesture; ptr = fc_malloc(sizeof(*ptr)); @@ -1124,6 +1160,13 @@ GtkWidget *create_worklist(void) gtk_widget_set_name(src_view, "small_font"); gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(src_view), 1); + gesture = gtk_gesture_click_new(); + gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 3); + controller = GTK_EVENT_CONTROLLER(gesture); + g_signal_connect(controller, "pressed", + G_CALLBACK(wl_right_button_up), NULL); + gtk_widget_add_controller(src_view, controller); + populate_view(GTK_TREE_VIEW(src_view), &ptr->pcity, &ptr->src_col); gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), src_view); @@ -1216,6 +1259,13 @@ GtkWidget *create_worklist(void) gtk_widget_set_name(dst_view, "small_font"); gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(dst_view), 1); + gesture = gtk_gesture_click_new(); + gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 3); + controller = GTK_EVENT_CONTROLLER(gesture); + g_signal_connect(controller, "pressed", + G_CALLBACK(wl_right_button_up), NULL); + gtk_widget_add_controller(dst_view, controller); + populate_view(GTK_TREE_VIEW(dst_view), &ptr->pcity, &ptr->dst_col); gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(sw), dst_view); -- 2.35.1