Skip to content

Commit

Permalink
Fix handling of actions that are not part of the layout.
Browse files Browse the repository at this point in the history
This mainly includes actions added/removed from spices.

- Reload the layout editor tree (maybe eventually this could be non-
  destructive of existing layout changes)
- Include unused actions in Nemo that haven't been used in the layout.

Fixes linuxmint/mint22-beta#14
  • Loading branch information
mtwebster committed Jun 30, 2024
1 parent 874783b commit 393d979
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
30 changes: 30 additions & 0 deletions action-layout-editor/nemo_action_layout_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import uuid
import gettext
import subprocess
import os

import leconfig

Expand Down Expand Up @@ -248,6 +249,9 @@ def __init__(self, window, builder=None):
self.updating_row_edit_fields = False
self.dnd_autoscroll_timeout_id = 0

self.monitors = []
self.monitor_action_dirs()

self.needs_saved = False
self.reload_model()
self.update_treeview_state()
Expand Down Expand Up @@ -291,6 +295,29 @@ def reload_model(self, flat=False):

self.updating_model = False

def monitor_action_dirs (self):
data_dirs = GLib.get_system_data_dirs() + [GLib.get_user_data_dir()]

for d in data_dirs:
full = os.path.join(d, "nemo", "actions")
file = Gio.File.new_for_path(full)
try:
if not file.query_exists(None):
continue
monitor = file.monitor_directory(Gio.FileMonitorFlags.WATCH_MOVES | Gio.FileMonitorFlags.SEND_MOVED, None)
monitor.connect("changed", self.actions_folder_changed)
self.monitors.append(monitor)
except GLib.Error as e:
print("Error monitoring action directory '%s'" % full)

def actions_folder_changed(self, monitor, file, other, event_type, data=None):
if not file.get_basename().endswith(".nemo_action"):
return

self.reload_model()
self.update_treeview_state()
self.set_needs_saved(False)

def save_model(self):
# Save the modified model back to the JSON file
self.data["toplevel"] = self.serialize_model(None, self.model)
Expand Down Expand Up @@ -1269,6 +1296,9 @@ def quit(self, *args, **kwargs):
self.save_model()
self.save_disabled_list()

for monitor in self.monitors:
monitor.cancel()

return True

class EditorWindow():
Expand Down
16 changes: 16 additions & 0 deletions libnemo-private/nemo-action-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ typedef struct
{
NemoActionManager *action_manager;
JsonReader *reader;
GHashTable *used_uuids;

GError *error;

Expand Down Expand Up @@ -712,6 +713,8 @@ parse_item (ActionsIterData *idata,
idata->user_data);
g_object_unref (action);

g_hash_table_add (idata->used_uuids, action->uuid);

return TRUE;
}
else
Expand Down Expand Up @@ -851,33 +854,46 @@ nemo_action_manager_iterate_actions (NemoActionManager *action_ma
JsonReader *reader = get_layout_reader (action_manager);
gboolean ret = FALSE;

GHashTable *used_uuids = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);

if (reader != NULL) {
ActionsIterData idata;

idata.action_manager = action_manager;
idata.reader = reader;
idata.func = func;
idata.user_data = user_data;
idata.used_uuids = used_uuids;

ret = iter_actions (action_manager, &idata);

g_object_unref (idata.reader);
}

if (!ret) {
g_hash_table_remove_all (used_uuids);
}

if (g_hash_table_size (used_uuids) < g_hash_table_size (priv->actions_by_uuid)) {
NemoAction *action;
GList *node;

for (node = priv->actions; node != NULL; node = node->next) {
action = node->data;

if (g_hash_table_contains (used_uuids, action->uuid)) {
continue;
}

func (action_manager,
GTK_ACTION (action),
GTK_UI_MANAGER_MENUITEM,
NULL,
user_data);
}
}

g_hash_table_destroy (used_uuids);
}

void
Expand Down

0 comments on commit 393d979

Please sign in to comment.