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

window-slot: Import the stop and reload actions

These actions have been living in the window, but they are actually
implemented by the slot, and conceptually they are slot actions.

Import them in preparation to use them also in the FileChooser window.

Part of https://gitlab.gnome.org/GNOME/nautilus/-/work_items/3413
This commit is contained in:
António Fernandes 2024-04-28 00:41:22 +01:00
parent 13e0bba7ff
commit 095f699da1
4 changed files with 45 additions and 68 deletions

View File

@ -1056,7 +1056,7 @@ setup_view_columns (NautilusListView *self)
static void
nautilus_list_view_reload (NautilusListView *self)
{
gtk_widget_activate_action (GTK_WIDGET (self), "win.reload", NULL);
gtk_widget_activate_action (GTK_WIDGET (self), "slot.reload", NULL);
}
static void

View File

@ -1052,6 +1052,26 @@ action_files_view_mode (GSimpleAction *action,
g_simple_action_set_state (action, value);
}
static void
action_reload (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
NautilusWindowSlot *self = NAUTILUS_WINDOW_SLOT (user_data);
nautilus_window_slot_queue_reload (self);
}
static void
action_stop (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
NautilusWindowSlot *self = NAUTILUS_WINDOW_SLOT (user_data);
nautilus_window_slot_stop_loading (self);
}
const GActionEntry slot_entries[] =
{
{
@ -1063,6 +1083,8 @@ const GActionEntry slot_entries[] =
{ .name = "search-visible", .state = "false", .change_state = action_search_visible },
{ .name = "search-global", .state = "false", .change_state = action_search_global },
{ .name = "focus-search", .activate = action_focus_search },
{ .name = "reload", .activate = action_reload },
{ .name = "stop", .activate = action_stop },
};
static void
@ -1147,6 +1169,8 @@ nautilus_window_slot_init (NautilusWindowSlot *self)
"slot",
G_ACTION_GROUP (self->slot_action_group));
#define ACCELS(...) ((const char *[]) { __VA_ARGS__, NULL })
nautilus_application_set_accelerator (app,
"slot.files-view-mode(uint32 " G_STRINGIFY (NAUTILUS_VIEW_LIST_ID) ")",
"<control>1");
@ -1155,6 +1179,10 @@ nautilus_window_slot_init (NautilusWindowSlot *self)
"<control>2");
nautilus_application_set_accelerators (app, "slot.focus-search", search_visible_accels);
nautilus_application_set_accelerator (app, "slot.search-global", "<control><shift>f");
nautilus_application_set_accelerators (app, "slot.reload", ACCELS ("F5", "<ctrl>r", "Refresh", "Reload"));
nautilus_application_set_accelerator (app, "slot.stop", "Stop");
#undef ACCELS
self->fd_holder = nautilus_fd_holder_new ();
self->view_mode_before_network = NAUTILUS_VIEW_INVALID_ID;
@ -3015,12 +3043,16 @@ void
nautilus_window_slot_set_allow_stop (NautilusWindowSlot *self,
gboolean allow)
{
NautilusWindow *window;
g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
self->allow_stop = allow;
window = nautilus_window_slot_get_window (self);
GActionMap *action_map = G_ACTION_MAP (self->slot_action_group);
GAction *stop_action = g_action_map_lookup_action (action_map, "stop");
GAction *reload_action = g_action_map_lookup_action (action_map, "reload");
g_simple_action_set_enabled (G_SIMPLE_ACTION (stop_action), self->allow_stop);
g_simple_action_set_enabled (G_SIMPLE_ACTION (reload_action), !self->allow_stop);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ALLOW_STOP]);
}

View File

@ -82,7 +82,7 @@ static void nautilus_window_back_or_forward (NautilusWindow *window,
gboolean back,
guint distance);
static void nautilus_window_sync_location_widgets (NautilusWindow *window);
static void nautilus_window_sync_allow_stop (NautilusWindow *window);
static void update_cursor (NautilusWindow *window);
/* Sanity check: highest mouse button value I could find was 14. 5 is our
* lower threshold (well-documented to be the one of the button events for the
@ -239,31 +239,6 @@ action_go_starred (GSimpleAction *action,
nautilus_window_open_location_full (window, starred, 0, NULL, NULL);
}
static void
action_reload (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
NautilusWindowSlot *slot;
slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (user_data));
nautilus_window_slot_queue_reload (slot);
}
static void
action_stop (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
NautilusWindow *window;
NautilusWindowSlot *slot;
window = NAUTILUS_WINDOW (user_data);
slot = nautilus_window_get_active_slot (window);
nautilus_window_slot_stop_loading (slot);
}
static void
action_up (GSimpleAction *action,
GVariant *state,
@ -615,7 +590,7 @@ connect_slot (NautilusWindow *window,
NautilusWindowSlot *slot)
{
g_signal_connect_swapped (slot, "notify::allow-stop",
G_CALLBACK (nautilus_window_sync_allow_stop), window);
G_CALLBACK (update_cursor), window);
g_signal_connect (slot, "notify::location",
G_CALLBACK (on_slot_location_changed), window);
g_signal_connect (slot, "notify::search-global",
@ -848,9 +823,12 @@ nautilus_window_new_tab (NautilusWindow *window)
static void
update_cursor (NautilusWindow *window)
{
NautilusWindowSlot *slot;
NautilusWindowSlot *slot = nautilus_window_get_active_slot (window);
slot = nautilus_window_get_active_slot (window);
if (!gtk_widget_get_realized (GTK_WIDGET (window)))
{
return;
}
if (slot != NULL &&
nautilus_window_slot_get_allow_stop (slot))
@ -863,33 +841,6 @@ update_cursor (NautilusWindow *window)
}
}
static void
nautilus_window_sync_allow_stop (NautilusWindow *window)
{
NautilusWindowSlot *slot = nautilus_window_get_active_slot (window);
GAction *stop_action;
GAction *reload_action;
gboolean allow_stop, slot_allow_stop;
stop_action = g_action_map_lookup_action (G_ACTION_MAP (window),
"stop");
reload_action = g_action_map_lookup_action (G_ACTION_MAP (window),
"reload");
allow_stop = g_action_get_enabled (stop_action);
slot_allow_stop = nautilus_window_slot_get_allow_stop (slot);
if (allow_stop != slot_allow_stop)
{
g_simple_action_set_enabled (G_SIMPLE_ACTION (stop_action), slot_allow_stop);
g_simple_action_set_enabled (G_SIMPLE_ACTION (reload_action), !slot_allow_stop);
if (gtk_widget_get_realized (GTK_WIDGET (window)))
{
update_cursor (window);
}
}
}
/* Callback used when the places sidebar changes location; we need to change the displayed folder */
static void
open_location_cb (NautilusWindow *window,
@ -1664,8 +1615,6 @@ const GActionEntry win_entries[] =
{ .name = "down", .activate = action_down },
{ .name = "current-location-menu", .activate = action_show_current_location_menu },
{ .name = "open-location", .activate = action_open_location, .parameter_type = "s" },
{ .name = "reload", .activate = action_reload },
{ .name = "stop", .activate = action_stop },
{ .name = "new-tab", .activate = action_new_tab },
{ .name = "enter-location", .activate = action_enter_location },
{ .name = "bookmark-current-location", .activate = action_bookmark_current_location },
@ -1719,10 +1668,6 @@ nautilus_window_initialize_actions (NautilusWindow *window)
nautilus_application_set_accelerator (app, "win.new-tab", "<control>t");
nautilus_application_set_accelerator (app, "win.close-current-view", "<control>w");
/* Special case reload, since users are used to use two shortcuts instead of one */
nautilus_application_set_accelerators (app, "win.reload", ACCELS ("F5", "<ctrl>r", "Refresh", "Reload"));
nautilus_application_set_accelerator (app, "win.stop", "Stop");
nautilus_application_set_accelerator (app, "win.undo", "<control>z");
nautilus_application_set_accelerator (app, "win.redo", "<shift><control>z");
/* Only accessible by shorcuts */
@ -2005,7 +1950,7 @@ nautilus_window_set_active_slot (NautilusWindow *window,
nautilus_window_slot_set_active (new_slot, TRUE);
on_location_changed (window);
nautilus_window_sync_allow_stop (window);
update_cursor (window);
}
g_object_notify_by_pspec (G_OBJECT (window), properties[PROP_ACTIVE_SLOT]);

View File

@ -37,12 +37,12 @@
<section>
<item>
<attribute name="label" translatable="yes">R_eload</attribute>
<attribute name="action">win.reload</attribute>
<attribute name="action">slot.reload</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
<item>
<attribute name="label" translatable="yes">St_op</attribute>
<attribute name="action">win.stop</attribute>
<attribute name="action">slot.stop</attribute>
<attribute name="hidden-when">action-disabled</attribute>
</item>
<item>