[nautilus/antonioffix-menus-and-popovers: 2/7] list-view: Share common code for rectangle computation
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/antonioffix-menus-and-popovers: 2/7] list-view: Share common code for rectangle computation
- Date: Tue, 30 Jan 2018 09:20:25 +0000 (UTC)
commit dd672624e7f268320b80416235e3f79f7707944e
Author: António Fernandes <antoniof gnome org>
Date: Sun Jan 28 12:17:13 2018 +0000
list-view: Share common code for rectangle computation
Make internal function for both _reveal_rectangle_for_context_menu()
and _compute_rename_popover_pointing_to() to avoid code duplication.
src/nautilus-list-view.c | 86 ++++++++++++++++++++----------------------------
1 file changed, 36 insertions(+), 50 deletions(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 4f01b567b..0fe51b485 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -3641,21 +3641,13 @@ nautilus_list_view_get_id (NautilusFilesView *view)
}
static GdkRectangle *
-nautilus_list_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
+get_rectangle_for_path (NautilusListView *list_view,
+ GtkTreePath *path)
{
- NautilusListView *list_view;
- GtkTreeView *tree_view;
- GtkTreeSelection *selection;
- GList *list;
- GtkTreePath *path;
+ GtkTreeView *tree_view = list_view->details->tree_view;
GdkRectangle *rect = g_malloc0 (sizeof (GdkRectangle));
int header_height;
- list_view = NAUTILUS_LIST_VIEW (view);
- tree_view = list_view->details->tree_view;
- selection = gtk_tree_view_get_selection (tree_view);
- list = gtk_tree_selection_get_selected_rows (selection, NULL);
- path = list->data;
gtk_tree_view_get_cell_area (tree_view,
path,
list_view->details->file_name_column,
@@ -3664,17 +3656,7 @@ nautilus_list_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
rect->x, rect->y,
&rect->x, &rect->y);
- if (list_view->details->last_event_button_x > 0)
- {
- /* Point to the position in the row where it was clicked. */
- rect->x = list_view->details->last_event_button_x;
- /* Make it zero width to point exactly at rect->x.*/
- rect->width = 0;
- }
-
- g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
-
- /* FIXME Due to smooth scrolling, we get the cell area while the view is
+ /* FIXME Due to smooth scrolling, we may get the cell area while the view is
* still scrolling (and still outside the view), not at the final position
* of the cell after scrolling.
* https://bugzilla.gnome.org/show_bug.cgi?id=746773
@@ -3689,12 +3671,42 @@ nautilus_list_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
rect->y = CLAMP (rect->y,
header_height,
- gtk_widget_get_allocated_height (GTK_WIDGET (view)) - rect->height);
+ gtk_widget_get_allocated_height (GTK_WIDGET (list_view)) - rect->height);
/* End of workaround */
return rect;
}
+static GdkRectangle *
+nautilus_list_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
+{
+ NautilusListView *list_view;
+ GtkTreeView *tree_view;
+ GtkTreeSelection *selection;
+ GList *list;
+ GtkTreePath *path;
+ GdkRectangle *rect;
+
+ list_view = NAUTILUS_LIST_VIEW (view);
+ tree_view = list_view->details->tree_view;
+ selection = gtk_tree_view_get_selection (tree_view);
+ list = gtk_tree_selection_get_selected_rows (selection, NULL);
+ path = list->data;
+ rect = get_rectangle_for_path (list_view, path);
+
+ if (list_view->details->last_event_button_x > 0)
+ {
+ /* Point to the position in the row where it was clicked. */
+ rect->x = list_view->details->last_event_button_x;
+ /* Make it zero width to point exactly at rect->x.*/
+ rect->width = 0;
+ }
+
+ g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
+
+ return rect;
+}
+
static GdkRectangle *
nautilus_list_view_reveal_for_selection_context_menu (NautilusFilesView *view)
{
@@ -3703,7 +3715,6 @@ nautilus_list_view_reveal_for_selection_context_menu (NautilusFilesView *view)
GtkTreeSelection *tree_selection;
GtkTreePath *path;
GdkRectangle *rect;
- int header_height;
g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), NULL);
@@ -3729,32 +3740,7 @@ nautilus_list_view_reveal_for_selection_context_menu (NautilusFilesView *view)
gtk_tree_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
- rect = g_malloc0 (sizeof (GdkRectangle));
- gtk_tree_view_get_cell_area (tree_view,
- path,
- list_view->details->file_name_column,
- rect);
- gtk_tree_view_convert_bin_window_to_widget_coords (tree_view,
- rect->x, rect->y,
- &rect->x, &rect->y);
-
- /* FIXME Due to smooth scrolling, we may get the cell area while the view is
- * still scrolling (and still outside the view), not at the final position
- * of the cell after scrolling.
- * https://bugzilla.gnome.org/show_bug.cgi?id=746773
- * The following workaround guesses the final "y" coordinate by clamping it
- * to the widget edge. Note that the top edge has got columns header, which
- * is private, so first guess the header height from the difference between
- * widget coordinates and bin cooridinates.
- */
- gtk_tree_view_convert_bin_window_to_widget_coords (tree_view,
- 0, 0,
- NULL, &header_height);
-
- rect->y = CLAMP (rect->y,
- header_height,
- gtk_widget_get_allocated_height (GTK_WIDGET (list_view)) - rect->height);
- /* End of workaround */
+ rect = get_rectangle_for_path (list_view, path);
gtk_tree_path_free (path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]