commit fab91e9c2549bd284dda3cc0f2cffc7ae6c14f0f Author: Stefano Facchini Date: Mon Aug 26 16:37:34 2013 +0200 Do not leave behind stale .desktop files If the user clicked on Cancel in the Editor dialog, we should remove the .desktop file we just copied to ~/.local/share/applications. https://bugzilla.gnome.org/show_bug.cgi?id=706807 diff --git a/Alacarte/ItemEditor.py b/Alacarte/ItemEditor.py index f9d709a..2330de0 100644 --- a/Alacarte/ItemEditor.py +++ b/Alacarte/ItemEditor.py @@ -20,7 +20,7 @@ import gettext import os import gi gi.require_version('Gtk', '3.0') -from gi.repository import GLib, Gtk +from gi.repository import GLib, GObject, Gtk from Alacarte import config, util _ = gettext.gettext @@ -91,10 +91,15 @@ class IconPicker(object): self.image.props.file = chooser.get_filename() chooser.destroy() -class ItemEditor(object): +class ItemEditor(GObject.GObject): ui_file = None + __gsignals__ = { + 'response': (GObject.SIGNAL_RUN_FIRST, None, (bool,)) + } + def __init__(self, parent, item_path): + GObject.GObject.__init__(self) self.builder = Gtk.Builder() self.builder.add_from_file(os.path.join(config.pkgdatadir, self.ui_file)) @@ -158,6 +163,7 @@ class ItemEditor(object): if response == Gtk.ResponseType.OK: self.save() self.dialog.destroy() + self.emit('response', response == Gtk.ResponseType.OK) class LauncherEditor(ItemEditor): ui_file = 'launcher-editor.ui' diff --git a/Alacarte/MainWindow.py b/Alacarte/MainWindow.py index 291949d..40c108d 100644 --- a/Alacarte/MainWindow.py +++ b/Alacarte/MainWindow.py @@ -303,12 +303,19 @@ class MainWindow(object): file_type = 'Menu' Editor = DirectoryEditor + copied = False if not os.path.isfile(file_path): shutil.copy(item.get_desktop_file_path(), file_path) + copied = True editor = Editor(self.main_window, file_path) + editor.connect('response', self.on_editor_response, file_path if copied else None) editor.run() + def on_editor_response(self, editor, modified, file_path): + if not modified and file_path is not None: + os.remove(file_path) + def on_menu_tree_cursor_changed(self, treeview): selection = treeview.get_selection() if selection is None: