Skip to content

Commit

Permalink
nemo-action-manager.c: Generate unique names for actions when
Browse files Browse the repository at this point in the history
they're loaded.

The action name is internal, and used by the UI manager only.
When actions are added, they're presented in the order. Updates
to the UI manager only update action existence at a given level,
to prevent needless widget turnover.

The problem occurs when the action layout is modified: If an
action is moved only up or down at its current depth, the UI
manager won't change the order visibly.

By making each generation of actions unique from the previous,
this makes sure the actions are always newly added in the correct
order.
  • Loading branch information
mtwebster committed Jul 20, 2024
1 parent 4bd96b5 commit 1fd3c55
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions libnemo-private/nemo-action-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,20 @@ set_up_actions_directories (NemoActionManager *action_manager)
}

static char *
escape_action_name (const char *action_name,
const char *prefix)
create_action_name (const char *uri)
{
GString *s;
g_autofree gchar *prefix = NULL;

if (action_name == NULL) {
if (uri == NULL) {
return NULL;
}


prefix = g_strdup_printf ("action_%d_", g_random_int_range (0, 9999));
s = g_string_new (prefix);

while (*action_name != 0) {
switch (*action_name) {
while (*uri != 0) {
switch (*uri) {
case '\\':
g_string_append (s, "\\\\");
break;
Expand All @@ -272,10 +273,10 @@ escape_action_name (const char *action_name,
g_string_append (s, "\\q");
break;
default:
g_string_append_c (s, *action_name);
g_string_append_c (s, *uri);
}

action_name ++;
uri++;
}
return g_string_free (s, FALSE);
}
Expand All @@ -300,7 +301,7 @@ add_action_to_action_list (NemoActionManager *action_manager, NemoFile *file)

uri = nemo_file_get_uri (file);

action_name = escape_action_name (uri, "action_");
action_name = create_action_name (uri);
gchar *path = g_filename_from_uri (uri, NULL, NULL);

action = nemo_action_new (action_name, path);
Expand Down

0 comments on commit 1fd3c55

Please sign in to comment.