Add `name playlist' command.
authorW. Trevor King <wking@drexel.edu>
Sun, 22 Aug 2010 05:49:02 +0000 (01:49 -0400)
committerW. Trevor King <wking@drexel.edu>
Sun, 22 Aug 2010 05:49:02 +0000 (01:49 -0400)
To avoid collisions if you load the same playlist twice, etc.

doc/tutorial.txt
hooke/plugin/playlist.py

index be41a0dfc6fd503cbc566a65a2d29df7b74880c0..65d288ec7e74eb801cd14d04aed0900b70149889 100644 (file)
@@ -200,6 +200,12 @@ will jump to the 14th curve in the zero-indexed playlist.
 Replace ``curve`` with ``playlist`` in the above commands to navigate
 around through the list of loaded playlists.
 
+Because the playlist name is usually saved in the playlist file
+itself, there is a ``name_playlist`` command that allows you to rename
+playlists on the fly.
+
+    hooke> name_playlist 'my old playlist'
+
 Taking notes
 ------------
 
index 086fa971e5155c42647033cb54da500d0097a156..ed904c640839dab6c78394c252839727a08768b6 100644 (file)
@@ -38,7 +38,7 @@ class PlaylistPlugin (Builtin):
         self._commands = [
             NextCommand(self), PreviousCommand(self), JumpCommand(self),
             GetCommand(self), IndexCommand(self), CurveListCommand(self),
-            SaveCommand(self), LoadCommand(self),
+            NameCommand(self), SaveCommand(self), LoadCommand(self),
             AddCommand(self), AddGlobCommand(self),
             RemoveCommand(self), ApplyCommand(self),
             FilterCommand(self),
@@ -210,6 +210,26 @@ class CurveListCommand (PlaylistCommand):
        outqueue.put(list(self._playlist(hooke, params)))
 
 
+class NameCommand (PlaylistCommand):
+    """(Re)name a playlist.
+    """
+    def __init__(self, plugin):
+        super(NameCommand, self).__init__(
+            name='name playlist',
+            arguments=[
+                Argument(name='name', type='string', optional=False,
+                         help="""
+Name for the playlist.
+""".strip()),
+                ],
+            help=self.__doc__, plugin=plugin)
+
+    def _run(self, hooke, inqueue, outqueue, params):
+       p = self._playlist(hooke, params)
+        p.name = params['name']
+        outqueue.put(p)
+
+
 class SaveCommand (PlaylistCommand):
     """Save a playlist.
     """