[planner: 24/61] util: Move menu_position_on_current_cell to a util function
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [planner: 24/61] util: Move menu_position_on_current_cell to a util function
- Date: Sat, 12 Jun 2021 17:30:24 +0000 (UTC)
commit b72ab2128ec3576c32f9a71108bd0e03ece2bbed
Author: Mart Raudsepp <leio gentoo org>
Date: Sat Dec 26 00:39:33 2020 +0200
util: Move menu_position_on_current_cell to a util function
There are 3 different places that use the same kind of code to position
a context menu on top of the currently selected GtkTreeView cell. Move
the helper from the first port away from GtkItemFactory to planner-util
to be ready for the other 2 same menu positioning usages without keeping
the copy-paste approach that popup_menu with gtk_item_factory_popup had
before.
src/planner-task-tree.c | 42 ++----------------------------------------
src/planner-util.c | 39 +++++++++++++++++++++++++++++++++++++++
src/planner-util.h | 7 +++++++
3 files changed, 48 insertions(+), 40 deletions(-)
---
diff --git a/src/planner-task-tree.c b/src/planner-task-tree.c
index 60626ea4..b3c81f7f 100644
--- a/src/planner-task-tree.c
+++ b/src/planner-task-tree.c
@@ -39,6 +39,7 @@
#include "planner-task-tree.h"
#include "planner-gantt-model.h"
#include "planner-task-popup.h"
+#include "planner-util.h"
#define WARN_TASK_DIALOGS 10
@@ -1205,45 +1206,6 @@ task_tree_task_removed_cb (PlannerGanttModel *model,
g_object_unref (task);
}
-static void
-task_tree_menu_position_on_current_cell (GtkMenu *menu,
- gint *x,
- gint *y,
- gboolean *push_in,
- gpointer user_data)
-{
- PlannerTaskTree *tree;
- GtkTreePath *path;
- GtkTreeViewColumn *column;
- GdkRectangle rect;
- gint pos_x, pos_y;
-
- tree = PLANNER_TASK_TREE (user_data);
- gtk_tree_view_get_cursor (GTK_TREE_VIEW (tree), &path, &column);
- gtk_tree_view_get_cell_area (GTK_TREE_VIEW (tree),
- path,
- column,
- &rect);
-
- pos_x = rect.x;
- pos_y = rect.y;
-
- /* Note: this is not perfect, but good enough for now. */
- gdk_window_get_root_origin (GTK_WIDGET (tree)->window, &pos_x, &pos_y);
- rect.x += pos_x;
- rect.y += pos_y;
-
- gtk_widget_translate_coordinates (GTK_WIDGET (tree),
- gtk_widget_get_toplevel (GTK_WIDGET (tree)),
- rect.x, rect.y,
- &pos_x, &pos_y);
-
- /* Offset so it's not overlapping the cell. */
- *x = pos_x + 20;
- *y = pos_y + 20;
- *push_in = TRUE;
-}
-
static void
task_tree_tree_view_popup_menu (GtkWidget *widget,
PlannerTaskTree *tree)
@@ -1256,7 +1218,7 @@ task_tree_tree_view_popup_menu (GtkWidget *widget,
gtk_menu_popup (GTK_MENU (gtk_ui_manager_get_widget (tree->priv->popup_ui_manager, "/TaskPopup")),
NULL, NULL,
- task_tree_menu_position_on_current_cell, tree,
+ planner_util_menu_position_on_current_cell, tree,
0, gtk_get_current_event_time ());
}
diff --git a/src/planner-util.c b/src/planner-util.c
index e78589f2..8c99f959 100644
--- a/src/planner-util.c
+++ b/src/planner-util.c
@@ -65,3 +65,42 @@ planner_util_new_builder (const gchar *resource_path)
g_bytes_unref (res_bytes);
return builder;
}
+
+void
+planner_util_menu_position_on_current_cell (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ gpointer user_data)
+{
+ GtkTreeView *tree;
+ GtkTreePath *path;
+ GtkTreeViewColumn *column;
+ GdkRectangle rect;
+ gint pos_x, pos_y;
+
+ tree = GTK_TREE_VIEW (user_data);
+ gtk_tree_view_get_cursor (tree, &path, &column);
+ gtk_tree_view_get_cell_area (tree,
+ path,
+ column,
+ &rect);
+
+ pos_x = rect.x;
+ pos_y = rect.y;
+
+ /* Note: this is not perfect, but good enough for now. */
+ gdk_window_get_root_origin (GTK_WIDGET (tree)->window, &pos_x, &pos_y);
+ rect.x += pos_x;
+ rect.y += pos_y;
+
+ gtk_widget_translate_coordinates (GTK_WIDGET (tree),
+ gtk_widget_get_toplevel (GTK_WIDGET (tree)),
+ rect.x, rect.y,
+ &pos_x, &pos_y);
+
+ /* Offset so it's not overlapping the cell. */
+ *x = pos_x + 20;
+ *y = pos_y + 20;
+ *push_in = TRUE;
+}
diff --git a/src/planner-util.h b/src/planner-util.h
index 69c57497..0c224420 100644
--- a/src/planner-util.h
+++ b/src/planner-util.h
@@ -29,5 +29,12 @@ void planner_util_show_url (GtkWindow *parent,
const gchar *url);
GtkBuilder *planner_util_new_builder (const gchar *resource_path);
+
+void planner_util_menu_position_on_current_cell (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ gpointer user_data);
+
#endif /* __PLANNER_UTIL_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]