diff --git a/files/usr/share/cinnamon/cinnamon-desktop-editor/cinnamon-desktop-editor.py b/files/usr/share/cinnamon/cinnamon-desktop-editor/cinnamon-desktop-editor.py index ba879b4a2b..e843ce4256 100755 --- a/files/usr/share/cinnamon/cinnamon-desktop-editor/cinnamon-desktop-editor.py +++ b/files/usr/share/cinnamon/cinnamon-desktop-editor/cinnamon-desktop-editor.py @@ -4,6 +4,7 @@ import os import gettext import glob +import json from optparse import OptionParser import shutil import subprocess @@ -415,20 +416,42 @@ def launcher_cb(self, success, dest_path): self.end() def panel_launcher_cb(self, success, dest_path): - if success: - settings = JsonSettingsWidgets.JSONSettingsHandler(self.json_path) - launchers = settings.get_value("launcherList") - if self.desktop_file is None: - launchers.append(os.path.split(dest_path)[1]) - else: - i = launchers.index(self.desktop_file) - if i >= 0: - del launchers[i] - launchers.insert(i, os.path.split(dest_path)[1]) - settings.save_settings() - if self.desktop_file is None: - self.ask_menu_launcher(dest_path) - self.end() + try: + if success: + settings = JsonSettingsWidgets.JSONSettingsHandler(self.json_path) + launchers = settings.get_value("launcherList") + new_name = os.path.split(dest_path)[1] + if self.desktop_file is None: + launchers.append(new_name) + else: + try: + i = launchers.index(self.desktop_file) + except ValueError: + # The entry we were asked to edit is no longer in the + # list (a previous edit may have already replaced it) - + # add the new launcher instead of dropping the edit. + if new_name not in launchers: + launchers.append(new_name) + else: + launchers[i] = new_name + settings.save_settings() + self.notify_cinnamon(launchers) + if self.desktop_file is None: + self.ask_menu_launcher(dest_path) + finally: + self.end() + + def notify_cinnamon(self, launchers): + # Cinnamon does not monitor the settings file for external changes - + # tell it to reload, the same way xlet-settings.py does after saving. + uuid = os.path.basename(os.path.dirname(self.json_path)) + instance_id = os.path.splitext(os.path.basename(self.json_path))[0] + try: + proxy = Gio.DBusProxy.new_for_bus_sync(Gio.BusType.SESSION, Gio.DBusProxyFlags.NONE, None, + "org.Cinnamon", "/org/Cinnamon", "org.Cinnamon", None) + proxy.updateSetting('(ssss)', uuid, instance_id, "launcherList", json.dumps(launchers)) + except GLib.Error as e: + print("Could not notify Cinnamon of launcher list change: %s" % e.message) def nemo_launcher_cb(self, success, dest_path): if success: