mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-09-29 20:44:17 +00:00
window-slot: Import directory star/unstar actions
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:
parent
84b31ec6c3
commit
3b08536895
|
@ -34,6 +34,7 @@
|
|||
#include "nautilus-mime-actions.h"
|
||||
#include "nautilus-query-editor.h"
|
||||
#include "nautilus-scheme.h"
|
||||
#include "nautilus-tag-manager.h"
|
||||
#include "nautilus-toolbar.h"
|
||||
#include "nautilus-view.h"
|
||||
#include "nautilus-x-content-bar.h"
|
||||
|
@ -1217,6 +1218,28 @@ action_bookmark_current_directory (GSimpleAction *action,
|
|||
nautilus_window_slot_get_bookmark (self));
|
||||
}
|
||||
|
||||
static void
|
||||
action_star_current_directory (GSimpleAction *action,
|
||||
GVariant *state,
|
||||
gpointer user_data)
|
||||
{
|
||||
NautilusWindowSlot *self = NAUTILUS_WINDOW_SLOT (user_data);
|
||||
|
||||
nautilus_tag_manager_star_files (nautilus_tag_manager_get (), G_OBJECT (self),
|
||||
&(GList){ .data = self->viewed_file }, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
action_unstar_current_directory (GSimpleAction *action,
|
||||
GVariant *state,
|
||||
gpointer user_data)
|
||||
{
|
||||
NautilusWindowSlot *self = NAUTILUS_WINDOW_SLOT (user_data);
|
||||
|
||||
nautilus_tag_manager_unstar_files (nautilus_tag_manager_get (), G_OBJECT (self),
|
||||
&(GList){ .data = self->viewed_file }, NULL, NULL);
|
||||
}
|
||||
|
||||
const GActionEntry slot_entries[] =
|
||||
{
|
||||
{ .name = "open-location", .activate = action_open_location, .parameter_type = "s" },
|
||||
|
@ -1238,6 +1261,8 @@ const GActionEntry slot_entries[] =
|
|||
{ .name = "reload", .activate = action_reload },
|
||||
{ .name = "stop", .activate = action_stop },
|
||||
{ .name = "bookmark-current-directory", .activate = action_bookmark_current_directory },
|
||||
{ .name = "star-current-directory", .activate = action_star_current_directory },
|
||||
{ .name = "unstar-current-directory", .activate = action_unstar_current_directory },
|
||||
};
|
||||
|
||||
static void
|
||||
|
@ -1331,6 +1356,34 @@ update_bookmark_action (NautilusWindowSlot *self)
|
|||
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_bookmark);
|
||||
}
|
||||
|
||||
static void
|
||||
update_star_unstar_actions (NautilusWindowSlot *self)
|
||||
{
|
||||
gboolean can_star_location = FALSE;
|
||||
gboolean is_starred = FALSE;
|
||||
GFile *location = nautilus_window_slot_get_location (self);
|
||||
|
||||
if (location != NULL)
|
||||
{
|
||||
NautilusTagManager *tag_manager = nautilus_tag_manager_get ();
|
||||
g_autofree gchar *uri = g_file_get_uri (location);
|
||||
|
||||
can_star_location = nautilus_tag_manager_can_star_location (tag_manager, location);
|
||||
if (uri != NULL)
|
||||
{
|
||||
is_starred = nautilus_tag_manager_file_is_starred (tag_manager, uri);
|
||||
}
|
||||
}
|
||||
|
||||
GAction *star = g_action_map_lookup_action (G_ACTION_MAP (self->slot_action_group),
|
||||
"star-current-directory");
|
||||
GAction *unstar = g_action_map_lookup_action (G_ACTION_MAP (self->slot_action_group),
|
||||
"unstar-current-directory");
|
||||
|
||||
g_simple_action_set_enabled (G_SIMPLE_ACTION (star), !is_starred && can_star_location);
|
||||
g_simple_action_set_enabled (G_SIMPLE_ACTION (unstar), is_starred && can_star_location);
|
||||
}
|
||||
|
||||
static void
|
||||
nautilus_window_slot_init (NautilusWindowSlot *self)
|
||||
{
|
||||
|
@ -1402,6 +1455,11 @@ nautilus_window_slot_init (NautilusWindowSlot *self)
|
|||
G_CALLBACK (update_bookmark_action),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
g_signal_connect_object (nautilus_tag_manager_get (),
|
||||
"starred-changed",
|
||||
G_CALLBACK (update_star_unstar_actions),
|
||||
self,
|
||||
G_CONNECT_SWAPPED);
|
||||
|
||||
self->fd_holder = nautilus_fd_holder_new ();
|
||||
self->view_mode_before_network = NAUTILUS_VIEW_INVALID_ID;
|
||||
|
@ -1636,6 +1694,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);
|
||||
update_star_unstar_actions (self);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOCATION]);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,6 @@
|
|||
#include "nautilus-scheme.h"
|
||||
#include "nautilus-shortcut-manager.h"
|
||||
#include "nautilus-signaller.h"
|
||||
#include "nautilus-tag-manager.h"
|
||||
#include "nautilus-toolbar.h"
|
||||
#include "nautilus-trash-monitor.h"
|
||||
#include "nautilus-ui-utilities.h"
|
||||
|
@ -118,7 +117,6 @@ struct _NautilusWindow
|
|||
GtkWidget *network_address_bar;
|
||||
|
||||
guint sidebar_width_handler_id;
|
||||
gulong starred_id;
|
||||
|
||||
GQueue *tab_data_queue;
|
||||
|
||||
|
@ -210,45 +208,6 @@ action_go_home (GSimpleAction *action,
|
|||
g_object_unref (home);
|
||||
}
|
||||
|
||||
static void
|
||||
star_or_unstar_current_location (NautilusWindow *window)
|
||||
{
|
||||
NautilusWindowSlot *slot = nautilus_window_get_active_slot (window);
|
||||
GFile *location = nautilus_window_slot_get_location (slot);
|
||||
g_autoptr (NautilusFile) file = nautilus_file_get (location);
|
||||
g_autofree gchar *uri = nautilus_file_get_uri (file);
|
||||
|
||||
NautilusTagManager *tag_manager = nautilus_tag_manager_get ();
|
||||
if (nautilus_tag_manager_file_is_starred (tag_manager, uri))
|
||||
{
|
||||
nautilus_tag_manager_unstar_files (tag_manager, G_OBJECT (window),
|
||||
&(GList){ .data = file }, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
nautilus_tag_manager_star_files (tag_manager, G_OBJECT (window),
|
||||
&(GList){ .data = file }, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
action_star_current_location (GSimpleAction *action,
|
||||
GVariant *state,
|
||||
gpointer user_data)
|
||||
{
|
||||
NautilusWindow *window = user_data;
|
||||
star_or_unstar_current_location (window);
|
||||
}
|
||||
|
||||
static void
|
||||
action_unstar_current_location (GSimpleAction *action,
|
||||
GVariant *state,
|
||||
gpointer user_data)
|
||||
{
|
||||
NautilusWindow *window = user_data;
|
||||
star_or_unstar_current_location (window);
|
||||
}
|
||||
|
||||
static void
|
||||
action_new_tab (GSimpleAction *action,
|
||||
GVariant *state,
|
||||
|
@ -746,41 +705,6 @@ nautilus_window_slot_close (NautilusWindow *window,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nautilus_window_sync_starred (NautilusWindow *window)
|
||||
{
|
||||
NautilusWindowSlot *slot = nautilus_window_get_active_slot (window);
|
||||
GFile *location = slot != NULL ? nautilus_window_slot_get_location (slot) : NULL;
|
||||
|
||||
gboolean can_star_location = FALSE;
|
||||
gboolean is_starred = FALSE;
|
||||
|
||||
if (location != NULL)
|
||||
{
|
||||
g_autofree gchar *uri = g_file_get_uri (location);
|
||||
if (uri)
|
||||
{
|
||||
NautilusTagManager *tag_manager = nautilus_tag_manager_get ();
|
||||
can_star_location = nautilus_tag_manager_can_star_location (tag_manager, location);
|
||||
is_starred = nautilus_tag_manager_file_is_starred (tag_manager, uri);
|
||||
}
|
||||
}
|
||||
|
||||
GAction *star_action = g_action_map_lookup_action (G_ACTION_MAP (window), "star-current-location");
|
||||
GAction *unstar_action = g_action_map_lookup_action (G_ACTION_MAP (window), "unstar-current-location");
|
||||
|
||||
if (can_star_location)
|
||||
{
|
||||
g_simple_action_set_enabled (G_SIMPLE_ACTION (star_action), !is_starred);
|
||||
g_simple_action_set_enabled (G_SIMPLE_ACTION (unstar_action), is_starred);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_simple_action_set_enabled (G_SIMPLE_ACTION (star_action), FALSE);
|
||||
g_simple_action_set_enabled (G_SIMPLE_ACTION (unstar_action), FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nautilus_window_sync_location_widgets (NautilusWindow *window)
|
||||
{
|
||||
|
@ -797,8 +721,6 @@ nautilus_window_sync_location_widgets (NautilusWindow *window)
|
|||
gtk_widget_set_visible (window->network_address_bar,
|
||||
g_file_has_uri_scheme (location, SCHEME_NETWORK_VIEW));
|
||||
}
|
||||
|
||||
nautilus_window_sync_starred (window);
|
||||
}
|
||||
|
||||
static gchar *
|
||||
|
@ -1169,8 +1091,6 @@ const GActionEntry win_entries[] =
|
|||
{
|
||||
{ .name = "current-location-menu", .activate = action_show_current_location_menu },
|
||||
{ .name = "new-tab", .activate = action_new_tab },
|
||||
{ .name = "star-current-location", .activate = action_star_current_location },
|
||||
{ .name = "unstar-current-location", .activate = action_unstar_current_location },
|
||||
{ .name = "undo", .activate = action_undo },
|
||||
{ .name = "redo", .activate = action_redo },
|
||||
/* Only accessible by shorcuts */
|
||||
|
@ -1321,22 +1241,15 @@ nautilus_window_constructed (GObject *self)
|
|||
/* Is required that the UI is constructed before initializating the actions, since
|
||||
* some actions trigger UI widgets to show/hide. */
|
||||
nautilus_window_initialize_actions (window);
|
||||
|
||||
window->starred_id = g_signal_connect_object (nautilus_tag_manager_get (),
|
||||
"starred-changed",
|
||||
G_CALLBACK (nautilus_window_sync_starred),
|
||||
window, G_CONNECT_SWAPPED);
|
||||
}
|
||||
|
||||
static void
|
||||
nautilus_window_dispose (GObject *object)
|
||||
{
|
||||
NautilusWindow *window;
|
||||
GtkApplication *application;
|
||||
GList *slots_copy;
|
||||
|
||||
window = NAUTILUS_WINDOW (object);
|
||||
application = gtk_window_get_application (GTK_WINDOW (window));
|
||||
|
||||
g_debug ("Destroying window");
|
||||
|
||||
|
@ -1350,11 +1263,6 @@ nautilus_window_dispose (GObject *object)
|
|||
|
||||
g_clear_weak_pointer (&window->active_slot);
|
||||
|
||||
if (application != NULL)
|
||||
{
|
||||
g_clear_signal_handler (&window->starred_id, nautilus_tag_manager_get ());
|
||||
}
|
||||
|
||||
gtk_widget_dispose_template (GTK_WIDGET (window), NAUTILUS_TYPE_WINDOW);
|
||||
|
||||
G_OBJECT_CLASS (nautilus_window_parent_class)->dispose (object);
|
||||
|
|
|
@ -51,12 +51,12 @@
|
|||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Star Folder</attribute>
|
||||
<attribute name="action">win.star-current-location</attribute>
|
||||
<attribute name="action">slot.star-current-directory</attribute>
|
||||
<attribute name="hidden-when">action-disabled</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Unstar Folder</attribute>
|
||||
<attribute name="action">win.unstar-current-location</attribute>
|
||||
<attribute name="action">slot.unstar-current-directory</attribute>
|
||||
<attribute name="hidden-when">action-disabled</attribute>
|
||||
</item>
|
||||
<item>
|
||||
|
|
Loading…
Reference in a new issue