[Debian-live-changes] r2218 - in dists/trunk/live-magic/livemagic: controllers model views

lamby-guest at alioth.debian.org lamby-guest at alioth.debian.org
Wed Jun 20 01:11:25 UTC 2007


Author: lamby-guest
Date: 2007-06-20 01:11:25 +0000 (Wed, 20 Jun 2007)
New Revision: 2218

Modified:
   dists/trunk/live-magic/livemagic/controllers/hooks.py
   dists/trunk/live-magic/livemagic/model/folder_of_files.py
   dists/trunk/live-magic/livemagic/views/hooks.py
Log:
Renaming of hooks

Modified: dists/trunk/live-magic/livemagic/controllers/hooks.py
===================================================================
--- dists/trunk/live-magic/livemagic/controllers/hooks.py	2007-06-20 00:47:22 UTC (rev 2217)
+++ dists/trunk/live-magic/livemagic/controllers/hooks.py	2007-06-20 01:11:25 UTC (rev 2218)
@@ -41,7 +41,7 @@
                 self.view.do_set_selected_hook(hook_name)
                 self.view.do_set_selected_hook_contents(self.model.hooks[hook_name])
             else:
-                self.view.do_show_new_hook_invalid_name()
+                self.view.do_show_error("The name you specified is invalid")
 
     def on_button_hook_import_clicked(self, *_):
         filename = self.view.do_show_hook_import_dialog()
@@ -52,8 +52,19 @@
             self.view.set_save_enabled(True)
 
     def on_button_hook_rename_clicked(self, *_):
-        print "rename called for", self.view.get_selected_hook()
+        hook_name = self.view.get_selected_hook()
+        new_hook_name = self.view.do_show_rename_hook_window(hook_name)
 
+        if new_hook_name is None:
+            return
+
+        try:
+            self.model.hooks.rename(hook_name, new_hook_name)
+            self.notify_load_hooks()
+            self.view.do_set_selected_hook(new_hook_name)
+        except ValueError:
+            self.view.do_show_error("The name already exists")
+
     def on_button_hook_delete_clicked(self, *_):
         print "delete called for", self.view.get_selected_hook()
 

Modified: dists/trunk/live-magic/livemagic/model/folder_of_files.py
===================================================================
--- dists/trunk/live-magic/livemagic/model/folder_of_files.py	2007-06-20 00:47:22 UTC (rev 2217)
+++ dists/trunk/live-magic/livemagic/model/folder_of_files.py	2007-06-20 01:11:25 UTC (rev 2218)
@@ -89,6 +89,8 @@
             raise ValueError
         if self._config_exists(orig):
             os.rename(join(self.dir, orig), join(self.dir, new))
+        if orig in self._stale:
+            self._stale.remove(orig)
         self[new] = self[orig]
         del self[orig]
 

Modified: dists/trunk/live-magic/livemagic/views/hooks.py
===================================================================
--- dists/trunk/live-magic/livemagic/views/hooks.py	2007-06-20 00:47:22 UTC (rev 2217)
+++ dists/trunk/live-magic/livemagic/views/hooks.py	2007-06-20 01:11:25 UTC (rev 2218)
@@ -54,6 +54,27 @@
         else:
             return None
 
+    def do_show_rename_hook_window(self, old_hook_name):
+        dialog = gtk.Dialog(
+            "Choose new name for %s" % old_hook_name,
+            self['window_main'],
+            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+            (   gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
+                gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT))
+
+        entry = gtk.Entry(256)
+        entry.connect("activate", lambda _: dialog.action_area.get_children()[1].clicked())
+
+        dialog.vbox.pack_start(entry, padding=10)
+        dialog.vbox.show_all()
+        res = dialog.run()
+        dialog.destroy()
+
+        if res == gtk.RESPONSE_ACCEPT:
+            return entry.get_text().strip()
+        else:
+            return None
+
     def do_show_hook_import_dialog(self):
         dialog = gtk.FileChooserDialog(
             "Choose hook to import",
@@ -74,13 +95,13 @@
         else:
             return None
 
-    def do_show_new_hook_invalid_name(self):
+    def do_show_error(self, title):
         dialog = gtk.MessageDialog(
             self['window_main'],
             gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
             gtk.MESSAGE_ERROR,
             gtk.BUTTONS_CLOSE,
-            "Invalid name for hook"
+            title,
             )
         dialog.run()
         dialog.destroy()




More information about the Debian-live-changes mailing list