<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39878 >

It is very comfortable to get help after right clicking on city
improvement/worklist item/...
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
--- client/gui-gtk-2.0/citydlg.c	(revision 14011)
+++ client/gui-gtk-2.0/citydlg.c	(working copy)
@@ -253,11 +253,18 @@
 static void buy_callback(GtkWidget * w, gpointer data);
 static void change_production_callback(GtkWidget* w, struct city_dialog*);
 
+static void production_help_callback(GtkWidget *widget, GdkEventButton *event, gpointer data){
+	if(event->button == 3){
+		popup_help_dialog_for_item(&((struct city_dialog*)data)->pcity->production);
+	}
+}
+
 static void sell_callback(Impr_type_id id, gpointer data);
 static void sell_callback_response(GtkWidget *w, gint response, gpointer data);
 
 static void impr_callback(GtkTreeView *view, GtkTreePath *path,
 			  GtkTreeViewColumn *col, gpointer data);
+static void impr_help_callback(GtkWidget *widget, GdkEventButton *event, gpointer data);
 static void switch_page_callback(GtkNotebook * notebook,
 				 GtkNotebookPage * page, guint page_num,
 				 gpointer data);
@@ -635,7 +642,7 @@
 {
   GtkWidget *top, *vbox, *page, *align;
   GtkWidget *hbox, *ebox;
-  GtkWidget *frame, *table, *label, *sw, *view, *bar, *production_combo;
+  GtkWidget *frame, *table, *label, *sw, *view, *bar, *barEventBox, *production_combo;
   GtkCellRenderer *rend;
   GtkListStore *store;
   GtkListStore *production_store;
@@ -783,7 +790,7 @@
   g_object_set(rend, "xalign", 1.0, NULL);
   gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, NULL,
       rend, "text", 3, NULL);
-
+  g_signal_connect(view, "button-release-event", G_CALLBACK(impr_help_callback), view);
   g_signal_connect(view, "row_activated",
 		   G_CALLBACK(impr_callback), pdialog);
 
@@ -821,12 +828,14 @@
                                  rend, "text", 1, NULL);
 
   bar = gtk_progress_bar_new();
+  barEventBox = gtk_event_box_new();
   pdialog->overview.production_bar = bar;
-  gtk_container_add(GTK_CONTAINER(production_combo), bar);
+  gtk_container_add(GTK_CONTAINER(barEventBox), bar);  
+  gtk_container_add(GTK_CONTAINER(production_combo), barEventBox);
   gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(production_combo), 3);
   
   gtk_progress_bar_set_text(GTK_PROGRESS_BAR(bar), _("%d/%d %d turns"));
-
+  g_signal_connect(barEventBox, "button-release-event", G_CALLBACK(production_help_callback), pdialog);
   pdialog->overview.buy_command = gtk_stockbutton_new(GTK_STOCK_EXECUTE,
 						      _("_Buy"));
   gtk_box_pack_start(GTK_BOX(hbox), pdialog->overview.buy_command,
@@ -898,7 +907,7 @@
 {
   const char *tab_title = _("Pro_duction");
   GtkWidget *label = gtk_label_new_with_mnemonic(tab_title);
-  GtkWidget *page, *hbox, *editor, *bar;
+  GtkWidget *page, *hbox, *editor, *bar, *barEventBox;
 
   page = gtk_vbox_new(FALSE, 0);
   gtk_container_set_border_width(GTK_CONTAINER(page), 8);
@@ -916,10 +925,13 @@
   gtk_box_pack_start(GTK_BOX(page), hbox, FALSE, FALSE, 2);
 
   bar = gtk_progress_bar_new();
+  barEventBox = gtk_event_box_new();  
   pdialog->production.production_bar = bar;
-  gtk_box_pack_start(GTK_BOX(hbox), bar, TRUE, TRUE, 0);
+  gtk_container_add(GTK_CONTAINER(barEventBox), bar);   
+  gtk_box_pack_start(GTK_BOX(hbox), barEventBox, TRUE, TRUE, 0);
   gtk_progress_bar_set_text(GTK_PROGRESS_BAR(bar), _("%d/%d %d turns"));
-
+  g_signal_connect(barEventBox, "button-release-event", G_CALLBACK(production_help_callback), pdialog);
+  
   add_worklist_dnd_target(bar);
   g_signal_connect(bar, "drag_data_received",
 		   G_CALLBACK(target_drag_data_received), pdialog);
@@ -2570,6 +2582,23 @@
   }
 }
 
+/**
+ * Improvement right click callback shows help dialog
+ */ 
+static void impr_help_callback(GtkWidget *widget, GdkEventButton *event, gpointer data){
+	if(event->button == 3){	
+		GtkTreeView *view = data;
+		GtkTreeModel *model = gtk_tree_view_get_model(view);
+		GtkTreeSelection* selection = gtk_tree_view_get_selection(view);
+		GtkTreeIter it;
+		gtk_tree_selection_get_selected(selection, &model, &it);
+		struct universal target;
+		target.kind = HELP_IMPROVEMENT;
+		gtk_tree_model_get(model, &it, 0, &target.value, -1);
+		popup_help_dialog_for_item(&target);
+	}
+}
+
 /****************************************************************
  If switching away from worklist, we commit it.
 *****************************************************************/
Index: client/gui-gtk-2.0/helpdlg.c
===================================================================
--- client/gui-gtk-2.0/helpdlg.c	(revision 14011)
+++ client/gui-gtk-2.0/helpdlg.c	(working copy)
@@ -168,6 +168,26 @@
   popup_help_dialog_typed(_(item), HELP_ANY);
 }
 
+/**
+ * Popups help dialog for item - improvement or unit
+ *
+ * target - item for which help dialog will be shown
+ */ 
+void popup_help_dialog_for_item(struct universal* target){
+	int type = HELP_IMPROVEMENT;
+	const char *name = 0;
+	if (VUT_UTYPE == target->kind) {
+		type = HELP_UNIT;
+		name = utype_name_translation(target->value.utype);
+	} else{
+		if (is_great_wonder(target->value.building)) {
+			type = HELP_WONDER;
+		}
+		name = improvement_name_translation(target->value.building);
+	}
+	popup_help_dialog_typed(name, type);
+}
+
 /**************************************************************************
 Called by help_update_tech and itself
 Creates a node in the given tree for the given tech, and creates child
Index: client/gui-gtk-2.0/wldlg.c
===================================================================
--- client/gui-gtk-2.0/wldlg.c	(revision 14011)
+++ client/gui-gtk-2.0/wldlg.c	(working copy)
@@ -1061,6 +1061,22 @@
   }
 }
 
+static void plist_help_callback(GtkWidget *widget, GdkEventButton *event, gpointer data){	
+	if(event->button == 3){
+		GtkTreeView* view = data;
+		GtkTreeModel *model = gtk_tree_view_get_model(view);
+		GtkTreeIter it;
+		GtkTreePath *path;
+		gtk_tree_view_get_path_at_pos(view, event->x, event->y, &path, NULL, NULL, NULL);
+		if(gtk_tree_model_get_iter(model, &it, path)){
+			gint cid;
+			gtk_tree_model_get(model, &it, 0, &cid, -1);
+			struct universal target = cid_decode(cid);
+			popup_help_dialog_for_item(&target);
+		}
+	}
+}
+
 /****************************************************************
   Worklist editor shell.
 *****************************************************************/
@@ -1279,6 +1295,8 @@
       		   G_CALLBACK(src_selection_callback), ptr);
   g_signal_connect(ptr->dst_selection, "changed",
       		   G_CALLBACK(dst_selection_callback), ptr);
+	g_signal_connect_after(src_view, "button-release-event", G_CALLBACK(plist_help_callback), src_view);
+	g_signal_connect_after(dst_view, "button-release-event", G_CALLBACK(plist_help_callback), dst_view);
 
 
   gtk_widget_show_all(table);
Index: client/include/helpdlg_g.h
===================================================================
--- client/include/helpdlg_g.h	(revision 14011)
+++ client/include/helpdlg_g.h	(working copy)
@@ -19,6 +19,7 @@
 
 void popup_help_dialog_string(const char *item);
 void popup_help_dialog_typed(const char *item, enum help_page_type);
+void popup_help_dialog_for_item(struct universal* target);
 void popdown_help_dialog(void);
 
 #define HELP_PLAYING_ITEM "Strategy and tactics"
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to