Blame SOURCES/commit-fab91e9

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