mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-06-30 23:46:35 +00:00
window: Add Star Folder context menu entries
Add starring and unstarring actions to the pathbar context menu. In order to disallow starring the home directory, add a new function to the tag manager, which checks if a given directory can be starred.
This commit is contained in:
parent
626a04509c
commit
fa7b77fe6c
|
@ -719,6 +719,17 @@ nautilus_tag_manager_can_star_contents (NautilusTagManager *self,
|
|||
return g_file_has_prefix (directory, self->home) || g_file_equal (directory, self->home);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nautilus_tag_manager_can_star_location (NautilusTagManager *self,
|
||||
GFile *directory)
|
||||
{
|
||||
/* We only allow files to be starred inside the home directory for now.
|
||||
* This avoids the starred files database growing too big.
|
||||
* See https://gitlab.gnome.org/GNOME/nautilus/-/merge_requests/553#note_903108
|
||||
*/
|
||||
return g_file_has_prefix (directory, self->home);
|
||||
}
|
||||
|
||||
static void
|
||||
update_moved_uris_callback (GObject *object,
|
||||
GAsyncResult *result,
|
||||
|
|
|
@ -52,6 +52,9 @@ gboolean nautilus_tag_manager_file_is_starred (NautilusTagManager *
|
|||
|
||||
gboolean nautilus_tag_manager_can_star_contents (NautilusTagManager *self,
|
||||
GFile *directory);
|
||||
gboolean nautilus_tag_manager_can_star_location (NautilusTagManager *self,
|
||||
GFile *directory);
|
||||
|
||||
void nautilus_tag_manager_update_moved_uris (NautilusTagManager *tag_manager,
|
||||
GFile *src,
|
||||
GFile *dest);
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
#include "nautilus-progress-indicator.h"
|
||||
#include "nautilus-scheme.h"
|
||||
#include "nautilus-signaller.h"
|
||||
#include "nautilus-tag-manager.h"
|
||||
#include "nautilus-toolbar.h"
|
||||
#include "nautilus-trash-monitor.h"
|
||||
#include "nautilus-ui-utilities.h"
|
||||
|
@ -129,6 +130,7 @@ struct _NautilusWindow
|
|||
|
||||
guint sidebar_width_handler_id;
|
||||
gulong bookmarks_id;
|
||||
gulong starred_id;
|
||||
|
||||
GQueue *tab_data_queue;
|
||||
|
||||
|
@ -337,6 +339,46 @@ action_bookmark_current_location (GSimpleAction *action,
|
|||
nautilus_window_slot_get_bookmark (slot));
|
||||
}
|
||||
|
||||
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);
|
||||
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,
|
||||
|
@ -1130,6 +1172,41 @@ nautilus_window_sync_bookmarks (NautilusWindow *window)
|
|||
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_bookmark);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nautilus_window_sync_location_widgets (NautilusWindow *window)
|
||||
{
|
||||
|
@ -1175,6 +1252,7 @@ nautilus_window_sync_location_widgets (NautilusWindow *window)
|
|||
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
|
||||
|
||||
nautilus_window_sync_bookmarks (window);
|
||||
nautilus_window_sync_starred (window);
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
|
@ -1609,6 +1687,8 @@ const GActionEntry win_entries[] =
|
|||
{ .name = "new-tab", .activate = action_new_tab },
|
||||
{ .name = "enter-location", .activate = action_enter_location },
|
||||
{ .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 },
|
||||
{ .name = "redo", .activate = action_redo },
|
||||
/* Only accessible by shorcuts */
|
||||
|
@ -1793,6 +1873,11 @@ nautilus_window_constructed (GObject *self)
|
|||
"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),
|
||||
window, G_CONNECT_SWAPPED);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1821,6 +1906,7 @@ nautilus_window_dispose (GObject *object)
|
|||
{
|
||||
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 ());
|
||||
}
|
||||
|
||||
nautilus_window_unexport_handle (window);
|
||||
|
|
|
@ -49,6 +49,16 @@
|
|||
<attribute name="label" translatable="yes">Add to _Bookmarks</attribute>
|
||||
<attribute name="action">win.bookmark-current-location</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">_Star Folder</attribute>
|
||||
<attribute name="action">win.star-current-location</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="hidden-when">action-disabled</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="label" translatable="yes">Edit _Location</attribute>
|
||||
<attribute name="action">win.enter-location</attribute>
|
||||
|
|
Loading…
Reference in New Issue
Block a user