1
0
mirror of https://gitlab.gnome.org/GNOME/nautilus synced 2024-06-30 23:46:35 +00:00

window-slot: Import directory bookmarking action

To make them reusable in the upcoming FileChooser window.

Part of https://gitlab.gnome.org/GNOME/nautilus/-/work_items/3413
This commit is contained in:
António Fernandes 2024-06-10 16:24:55 +01:00
parent f35402d5e2
commit 84b31ec6c3
3 changed files with 42 additions and 49 deletions

View File

@ -1205,6 +1205,18 @@ action_stop (GSimpleAction *action,
nautilus_window_slot_stop_loading (self);
}
static void
action_bookmark_current_directory (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
NautilusWindowSlot *self = NAUTILUS_WINDOW_SLOT (user_data);
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
nautilus_bookmark_list_append (nautilus_application_get_bookmarks (app),
nautilus_window_slot_get_bookmark (self));
}
const GActionEntry slot_entries[] =
{
{ .name = "open-location", .activate = action_open_location, .parameter_type = "s" },
@ -1225,6 +1237,7 @@ const GActionEntry slot_entries[] =
{ .name = "focus-search", .activate = action_focus_search },
{ .name = "reload", .activate = action_reload },
{ .name = "stop", .activate = action_stop },
{ .name = "bookmark-current-directory", .activate = action_bookmark_current_directory },
};
static void
@ -1298,6 +1311,26 @@ set_back_forward_accelerators (NautilusWindowSlot *self)
#undef ADD_SHORTCUT_FOR_ACTION
}
static void
update_bookmark_action (NautilusWindowSlot *self)
{
gboolean can_bookmark = FALSE;
GFile *location = nautilus_window_slot_get_location (self);
if (location != NULL)
{
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
NautilusBookmarkList *bookmarks = nautilus_application_get_bookmarks (app);
can_bookmark = nautilus_bookmark_list_can_bookmark_location (bookmarks, location);
}
GAction *action = g_action_map_lookup_action (G_ACTION_MAP (self->slot_action_group),
"bookmark-current-directory");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_bookmark);
}
static void
nautilus_window_slot_init (NautilusWindowSlot *self)
{
@ -1351,6 +1384,7 @@ nautilus_window_slot_init (NautilusWindowSlot *self)
ADD_SHORTCUT_FOR_ACTION (self->shortcuts, "slot.stop", "Stop");
ADD_SHORTCUT_FOR_ACTION (self->shortcuts, "slot.up", "<alt>Up");
ADD_SHORTCUT_FOR_ACTION (self->shortcuts, "slot.down", "<alt>Down");
ADD_SHORTCUT_FOR_ACTION (self->shortcuts, "slot.bookmark-current-directory", "<control>d|AddFavorite");
#undef ADD_SHORTCUT_FOR_ACTION
#undef ADD_SHORTCUT_FOR_ACTION_WITH_ARGS
@ -1363,6 +1397,12 @@ nautilus_window_slot_init (NautilusWindowSlot *self)
gtk_pad_controller_set_action_entries (pad_controller, pad_actions, G_N_ELEMENTS (pad_actions));
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (pad_controller));
g_signal_connect_object (nautilus_application_get_bookmarks (NAUTILUS_APPLICATION (g_application_get_default ())),
"changed",
G_CALLBACK (update_bookmark_action),
self,
G_CONNECT_SWAPPED);
self->fd_holder = nautilus_fd_holder_new ();
self->view_mode_before_network = NAUTILUS_VIEW_INVALID_ID;
}
@ -1595,6 +1635,7 @@ nautilus_window_slot_set_location (NautilusWindowSlot *self,
nautilus_fd_holder_set_location (self->fd_holder, self->location);
update_back_forward_actions (self);
update_bookmark_action (self);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOCATION]);
}

View File

@ -118,7 +118,6 @@ struct _NautilusWindow
GtkWidget *network_address_bar;
guint sidebar_width_handler_id;
gulong bookmarks_id;
gulong starred_id;
GQueue *tab_data_queue;
@ -211,20 +210,6 @@ action_go_home (GSimpleAction *action,
g_object_unref (home);
}
static void
action_bookmark_current_location (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
NautilusWindow *window = user_data;
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
NautilusWindowSlot *slot;
slot = nautilus_window_get_active_slot (window);
nautilus_bookmark_list_append (nautilus_application_get_bookmarks (app),
nautilus_window_slot_get_bookmark (slot));
}
static void
star_or_unstar_current_location (NautilusWindow *window)
{
@ -761,29 +746,6 @@ nautilus_window_slot_close (NautilusWindow *window,
}
}
static void
nautilus_window_sync_bookmarks (NautilusWindow *window)
{
gboolean can_bookmark = FALSE;
NautilusWindowSlot *slot;
NautilusBookmarkList *bookmarks;
GAction *action;
GFile *location;
slot = window->active_slot;
location = slot != NULL ? nautilus_window_slot_get_location (slot) : NULL;
if (location != NULL)
{
bookmarks = nautilus_application_get_bookmarks
(NAUTILUS_APPLICATION (gtk_window_get_application (GTK_WINDOW (window))));
can_bookmark = nautilus_bookmark_list_can_bookmark_location (bookmarks, location);
}
action = g_action_map_lookup_action (G_ACTION_MAP (window), "bookmark-current-location");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_bookmark);
}
static void
nautilus_window_sync_starred (NautilusWindow *window)
{
@ -836,7 +798,6 @@ nautilus_window_sync_location_widgets (NautilusWindow *window)
g_file_has_uri_scheme (location, SCHEME_NETWORK_VIEW));
}
nautilus_window_sync_bookmarks (window);
nautilus_window_sync_starred (window);
}
@ -1208,7 +1169,6 @@ const GActionEntry win_entries[] =
{
{ .name = "current-location-menu", .activate = action_show_current_location_menu },
{ .name = "new-tab", .activate = action_new_tab },
{ .name = "bookmark-current-location", .activate = action_bookmark_current_location },
{ .name = "star-current-location", .activate = action_star_current_location },
{ .name = "unstar-current-location", .activate = action_unstar_current_location },
{ .name = "undo", .activate = action_undo },
@ -1247,7 +1207,6 @@ nautilus_window_initialize_actions (NautilusWindow *window)
nautilus_application_set_accelerator (app, "win.undo", "<control>z");
nautilus_application_set_accelerator (app, "win.redo", "<shift><control>z");
/* Only accessible by shorcuts */
nautilus_application_set_accelerators (app, "win.bookmark-current-location", ACCELS ("<control>d", "AddFavorite"));
nautilus_application_set_accelerator (app, "win.tab-move-left", "<shift><control>Page_Up");
nautilus_application_set_accelerator (app, "win.tab-move-right", "<shift><control>Page_Down");
nautilus_application_set_accelerator (app, "win.current-location-menu", "F10");
@ -1363,11 +1322,6 @@ nautilus_window_constructed (GObject *self)
* some actions trigger UI widgets to show/hide. */
nautilus_window_initialize_actions (window);
window->bookmarks_id = g_signal_connect_object (nautilus_application_get_bookmarks (application),
"changed",
G_CALLBACK (nautilus_window_sync_bookmarks),
window, G_CONNECT_SWAPPED);
window->starred_id = g_signal_connect_object (nautilus_tag_manager_get (),
"starred-changed",
G_CALLBACK (nautilus_window_sync_starred),
@ -1398,8 +1352,6 @@ nautilus_window_dispose (GObject *object)
if (application != NULL)
{
g_clear_signal_handler (&window->bookmarks_id,
nautilus_application_get_bookmarks (NAUTILUS_APPLICATION (application)));
g_clear_signal_handler (&window->starred_id, nautilus_tag_manager_get ());
}

View File

@ -47,7 +47,7 @@
</item>
<item>
<attribute name="label" translatable="yes">Add to _Bookmarks</attribute>
<attribute name="action">win.bookmark-current-location</attribute>
<attribute name="action">slot.bookmark-current-directory</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Star Folder</attribute>