cont'd work to prevent duplicate playlist names
authorRobin Gareus <robin@gareus.org>
Fri, 25 Nov 2016 13:24:15 +0000 (14:24 +0100)
committerRobin Gareus <robin@gareus.org>
Fri, 25 Nov 2016 13:24:29 +0000 (14:24 +0100)
gtk2_ardour/editor.cc
gtk2_ardour/route_time_axis.cc
gtk2_ardour/route_time_axis.h

index 806ec3cd1c1d41508affce5ca62f1a88e555ad02..f23f6b22f47b8c3bb8fd62ec0d094f96ce3d8b97 100644 (file)
@@ -4330,13 +4330,13 @@ Editor::clear_playlists (TimeAxisView* v)
 void
 Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
 {
-       atv.use_new_playlist (sz > 1 ? false : true, playlists);
+       atv.use_new_playlist (sz > 1 ? false : true, playlists, false);
 }
 
 void
 Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector<boost::shared_ptr<ARDOUR::Playlist> > const & playlists)
 {
-       atv.use_copy_playlist (sz > 1 ? false : true, playlists);
+       atv.use_new_playlist (sz > 1 ? false : true, playlists, true);
 }
 
 void
index 7bb41cf8ec78e4df488beb1b1349c3da9ed406e5..24ed6bd556e2fda111f88d69605477271c7389bd 100644 (file)
@@ -1182,7 +1182,7 @@ RouteTimeAxisView::resolve_new_group_playlist_name(std::string &basename, vector
 }
 
 void
-RouteTimeAxisView::use_copy_playlist (bool prompt, vector<boost::shared_ptr<Playlist> > const & playlists_before_op)
+RouteTimeAxisView::use_new_playlist (bool prompt, vector<boost::shared_ptr<Playlist> > const & playlists_before_op, bool copy)
 {
        string name;
 
@@ -1199,91 +1199,54 @@ RouteTimeAxisView::use_copy_playlist (bool prompt, vector<boost::shared_ptr<Play
        name = pl->name();
 
        if (route_group() && route_group()->is_active() && route_group()->enabled_property (ARDOUR::Properties::group_select.property_id)) {
-               name = resolve_new_group_playlist_name(name, playlists_before_op);
+               name = resolve_new_group_playlist_name(name,playlists_before_op);
        }
 
        while (_session->playlists->by_name(name)) {
                name = Playlist::bump_name (name, *_session);
        }
 
-       // TODO: The prompter "new" button should be de-activated if the user
-       // specifies a playlist name which already exists in the session.
-
        if (prompt) {
+               // TODO: The prompter "new" button should be de-activated if the user
+               // specifies a playlist name which already exists in the session.
 
                ArdourPrompter prompter (true);
 
-               prompter.set_title (_("New Copy Playlist"));
-               prompter.set_prompt (_("Name for new playlist:"));
+               if (copy) {
+                       prompter.set_title (_("New Copy Playlist"));
+                       prompter.set_prompt (_("Name for playlist copy:"));
+               } else {
+                       prompter.set_title (_("New Playlist"));
+                       prompter.set_prompt (_("Name for new playlist:"));
+               }
                prompter.set_initial_text (name);
                prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
                prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
                prompter.show_all ();
 
-               switch (prompter.run ()) {
-               case Gtk::RESPONSE_ACCEPT:
+               while (true) {
+                       if (prompter.run () != Gtk::RESPONSE_ACCEPT) {
+                               return;
+                       }
                        prompter.get_result (name);
-                       break;
-
-               default:
-                       return;
+                       if (name.length()) {
+                               if (_session->playlists->by_name (name)) {
+                                       MessageDialog msg (_("Given playlist name is not unique."));
+                                       msg.run ();
+                                       prompter.set_initial_text (Playlist::bump_name (name, *_session));
+                               } else {
+                                       break;
+                               }
+                       }
                }
        }
 
        if (name.length()) {
-               tr->use_copy_playlist ();
-               tr->playlist()->set_name (name);
-       }
-}
-
-void
-RouteTimeAxisView::use_new_playlist (bool prompt, vector<boost::shared_ptr<Playlist> > const & playlists_before_op)
-{
-       string name;
-
-       boost::shared_ptr<Track> tr = track ();
-       if (!tr || tr->destructive()) {
-               return;
-       }
-
-       boost::shared_ptr<const Playlist> pl = tr->playlist();
-       if (!pl) {
-               return;
-       }
-
-       name = pl->name();
-
-       if (route_group() && route_group()->is_active() && route_group()->enabled_property (ARDOUR::Properties::group_select.property_id)) {
-               name = resolve_new_group_playlist_name(name,playlists_before_op);
-       }
-
-       while (_session->playlists->by_name(name)) {
-               name = Playlist::bump_name (name, *_session);
-       }
-
-
-       if (prompt) {
-
-               ArdourPrompter prompter (true);
-
-               prompter.set_title (_("New Playlist"));
-               prompter.set_prompt (_("Name for new playlist:"));
-               prompter.set_initial_text (name);
-               prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
-               prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
-
-               switch (prompter.run ()) {
-               case Gtk::RESPONSE_ACCEPT:
-                       prompter.get_result (name);
-                       break;
-
-               default:
-                       return;
+               if (copy) {
+                       tr->use_new_playlist ();
+               } else {
+                       tr->use_copy_playlist ();
                }
-       }
-
-       if (name.length()) {
-               tr->use_new_playlist ();
                tr->playlist()->set_name (name);
        }
 }
index 825a286360f50c4ccb9c0eda06845e404a4fa283..1a26868b471ae6ed2dcec3251dbf10cb34d59272 100644 (file)
@@ -115,8 +115,7 @@ public:
        void fade_range (TimeSelection&);
 
        /* The editor calls these when mapping an operation across multiple tracks */
-       void use_new_playlist (bool prompt, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
-       void use_copy_playlist (bool prompt, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &);
+       void use_new_playlist (bool prompt, std::vector<boost::shared_ptr<ARDOUR::Playlist> > const &, bool copy);
        void clear_playlist ();
 
        /* group playlist name resolving */