[nautilus/wip/antoniof/gtk4-preparation-popovers: 29/45] list-view: Use a popover for columns context menu
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/gtk4-preparation-popovers: 29/45] list-view: Use a popover for columns context menu
- Date: Sun, 26 Dec 2021 23:15:37 +0000 (UTC)
commit 0ab905e43ce71e6625ac38d5e39b191b4c516b72
Author: António Fernandes <antoniof gnome org>
Date: Fri Dec 17 13:00:52 2021 +0000
list-view: Use a popover for columns context menu
GtkMenu is gone in GTK 4.
This is a lazy implementation, reusing the old menu code.
src/nautilus-gtk4-helpers.c | 17 +++++++++++++++
src/nautilus-gtk4-helpers.h | 3 +++
src/nautilus-list-view-private.h | 2 ++
src/nautilus-list-view.c | 45 ++++++++++++++++++++++++++--------------
4 files changed, 52 insertions(+), 15 deletions(-)
---
diff --git a/src/nautilus-gtk4-helpers.c b/src/nautilus-gtk4-helpers.c
index 926dca8e3..ad7e9e2ef 100644
--- a/src/nautilus-gtk4-helpers.c
+++ b/src/nautilus-gtk4-helpers.c
@@ -82,6 +82,23 @@ gtk_popover_set_child (GtkPopover *popover,
gtk_container_add (GTK_CONTAINER (popover), child);
}
+void
+gtk_check_button_set_active (GtkCheckButton *button,
+ gboolean setting)
+{
+ g_assert (GTK_IS_CHECK_BUTTON (button));
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), setting);
+}
+
+gboolean
+gtk_check_button_get_active (GtkCheckButton *button)
+{
+ g_assert (GTK_IS_CHECK_BUTTON (button));
+
+ return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+}
+
GtkWidget *
gtk_widget_get_first_child (GtkWidget *widget)
{
diff --git a/src/nautilus-gtk4-helpers.h b/src/nautilus-gtk4-helpers.h
index bea0892be..675416a20 100644
--- a/src/nautilus-gtk4-helpers.h
+++ b/src/nautilus-gtk4-helpers.h
@@ -25,7 +25,10 @@ void gtk_revealer_set_child (GtkRevealer *revealer,
GtkWidget *child);
void gtk_popover_set_child (GtkPopover *popover,
GtkWidget *child);
+void gtk_check_button_set_active (GtkCheckButton *button,
+ gboolean setting);
+gboolean gtk_check_button_get_active (GtkCheckButton *button);
GtkWidget *gtk_widget_get_first_child (GtkWidget *widget);
diff --git a/src/nautilus-list-view-private.h b/src/nautilus-list-view-private.h
index 5ec3b9f5a..5f890e488 100644
--- a/src/nautilus-list-view-private.h
+++ b/src/nautilus-list-view-private.h
@@ -60,6 +60,8 @@ struct NautilusListViewDetails {
GHashTable *columns;
GtkWidget *column_editor;
+ GtkPopover *columns_popover;
+ GtkWidget *columns_popover_box;
char *original_name;
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 488be8b3e..0f207ff7b 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -1307,7 +1307,7 @@ move_copy_items_callback (NautilusTreeViewDragDest *dest,
}
static void
-column_header_menu_toggled (GtkCheckMenuItem *menu_item,
+column_header_menu_toggled (GtkCheckButton *menu_item,
NautilusListView *list_view)
{
NautilusFile *file;
@@ -1328,7 +1328,7 @@ column_header_menu_toggled (GtkCheckMenuItem *menu_item,
list = g_list_prepend (list, visible_columns[i]);
}
- if (gtk_check_menu_item_get_active (menu_item))
+ if (gtk_check_button_get_active (menu_item))
{
list = g_list_prepend (list, g_strdup (column));
}
@@ -1362,7 +1362,7 @@ column_header_menu_toggled (GtkCheckMenuItem *menu_item,
}
static void
-column_header_menu_use_default (GtkMenuItem *menu_item,
+column_header_menu_use_default (GtkButton *menu_item,
NautilusListView *list_view)
{
NautilusFile *file;
@@ -1381,6 +1381,8 @@ column_header_menu_use_default (GtkMenuItem *menu_item,
* updated yet.
*/
apply_columns_settings (list_view, default_order, default_columns);
+ /* Popdown the popover because the checkboxes are not updated. */
+ gtk_popover_popdown (list_view->details->columns_popover);
g_strfreev (default_columns);
g_strfreev (default_order);
@@ -1398,6 +1400,7 @@ popup_column_header_menu (NautilusListView *list_view,
GHashTable *visible_columns_hash;
int i;
GList *l;
+ GtkPopover *popover;
GtkWidget *menu;
GtkWidget *menu_item;
@@ -1426,7 +1429,13 @@ popup_column_header_menu (NautilusListView *list_view,
}
}
- menu = gtk_menu_new ();
+ popover = list_view->details->columns_popover;
+ menu = list_view->details->columns_popover_box;
+ /* Remove all old items before repopulating. */
+ while ((menu_item = gtk_widget_get_first_child (menu)) != NULL)
+ {
+ gtk_box_remove (GTK_BOX (menu), menu_item);
+ }
for (l = all_columns; l != NULL; l = l->next)
{
@@ -1440,8 +1449,8 @@ popup_column_header_menu (NautilusListView *list_view,
NULL);
lowercase = g_ascii_strdown (name, -1);
- menu_item = gtk_check_menu_item_new_with_label (label);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ menu_item = gtk_check_button_new_with_label (label);
+ gtk_box_append (GTK_BOX (menu), menu_item);
g_object_set_data_full (G_OBJECT (menu_item),
"column-name", name, g_free);
@@ -1454,8 +1463,7 @@ popup_column_header_menu (NautilusListView *list_view,
if (g_hash_table_lookup (visible_columns_hash, lowercase) != NULL)
{
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
- TRUE);
+ gtk_check_button_set_active (GTK_CHECK_BUTTON (menu_item), TRUE);
}
g_signal_connect (menu_item,
@@ -1467,19 +1475,17 @@ popup_column_header_menu (NautilusListView *list_view,
g_free (label);
}
- menu_item = gtk_separator_menu_item_new ();
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
-
- menu_item = gtk_menu_item_new_with_label (_("Use Default"));
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ menu_item = gtk_button_new_with_label (_("Use Default"));
+ gtk_box_append (GTK_BOX (menu), menu_item);
g_signal_connect (menu_item,
- "activate",
+ "clicked",
G_CALLBACK (column_header_menu_use_default),
list_view);
gtk_widget_show_all (menu);
- gtk_menu_popup_at_pointer (GTK_MENU (menu), NULL);
+ gtk_popover_set_pointing_to (popover, &(GdkRectangle){x, y, 0, 0});
+ gtk_popover_popup (popover);
g_hash_table_destroy (visible_columns_hash);
nautilus_column_list_free (all_columns);
@@ -4002,6 +4008,15 @@ nautilus_list_view_init (NautilusListView *list_view)
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (list_view)),
"nautilus-list-view");
+ list_view->details->columns_popover = GTK_POPOVER (gtk_popover_new (GTK_WIDGET (list_view)));
+ list_view->details->columns_popover_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+ gtk_widget_set_margin_top (list_view->details->columns_popover_box, 6);
+ gtk_widget_set_margin_bottom (list_view->details->columns_popover_box, 6);
+ gtk_widget_set_margin_start (list_view->details->columns_popover_box, 6);
+ gtk_widget_set_margin_end (list_view->details->columns_popover_box, 6);
+ gtk_popover_set_child (list_view->details->columns_popover,
+ list_view->details->columns_popover_box);
+
g_signal_connect_swapped (nautilus_preferences,
"changed::" NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER,
G_CALLBACK (default_sort_order_changed_callback),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]