Consolidate code: use libardour API to sort scripts
[ardour.git] / gtk2_ardour / session_dialog.cc
index b73514c1aab4910cc0976938d6b0c0b923281e4f..11b01d8948bb6c60d85913b145b8f3f55a917bb9 100644 (file)
@@ -265,6 +265,11 @@ SessionDialog::master_channel_count ()
 bool
 SessionDialog::use_session_template () const
 {
+       if (!back_button->sensitive () && !new_only) {
+               /* open session -- not create a new one */
+               return false;
+       }
+
        if (!load_template_override.empty()) {
                return true;
        }
@@ -369,7 +374,11 @@ SessionDialog::setup_recent_sessions ()
        recent_session_display.set_model (recent_session_model);
        recent_session_display.append_column (_("Session Name"), recent_session_columns.visible_name);
        recent_session_display.append_column (_("Sample Rate"), recent_session_columns.sample_rate);
+#ifdef MIXBUS
+       recent_session_display.append_column (_("Modified With"), recent_session_columns.modified_with);
+#else
        recent_session_display.append_column (_("File Resolution"), recent_session_columns.disk_format);
+#endif
        recent_session_display.append_column (_("Last Modified"), recent_session_columns.time_formatted);
        recent_session_display.set_headers_visible (true);
        recent_session_display.get_selection()->set_mode (SELECTION_SINGLE);
@@ -472,7 +481,7 @@ SessionDialog::setup_initial_choice_box ()
        existing_session_chooser.add_filter (session_filter);
 
        FileFilter archive_filter;
-       archive_filter.add_pattern (X_("*.tar.xz"));
+       archive_filter.add_pattern (string_compose(X_("*%1"), ARDOUR::session_archive_suffix));
        archive_filter.set_name (_("Session Archives"));
        existing_session_chooser.add_filter (archive_filter);
 
@@ -564,32 +573,28 @@ SessionDialog::populate_session_templates ()
 
        template_model->clear ();
 
-       /* Add Lua Scripts dedicated to session-setup */
-       LuaScriptList& ms (LuaScripting::instance ().scripts (LuaScriptInfo::SessionInit));
-       for (LuaScriptList::const_iterator s = ms.begin(); s != ms.end(); ++s) {
-               TreeModel::Row row = *(template_model->append ());
-               row[session_template_columns.name] = (*s)->name;
-               row[session_template_columns.path] = "urn:ardour:" + (*s)->path;
-               row[session_template_columns.description] = (*s)->description;
-               row[session_template_columns.created_with_short] = _("{Factory Template}");
-               row[session_template_columns.created_with_long] = _("{Factory Template}");
-       }
+       /* Get Lua Scripts dedicated to session-setup */
+       LuaScriptList scripts (LuaScripting::instance ().scripts (LuaScriptInfo::SessionInit));
 
        /* Add Lua Action Scripts which can also be used for session-setup */
        LuaScriptList& as (LuaScripting::instance ().scripts (LuaScriptInfo::EditorAction));
        for (LuaScriptList::const_iterator s = as.begin(); s != as.end(); ++s) {
-               if (!((*s)->subtype & LuaScriptInfo::SessionSetup)) {
-                       continue;
+               if ((*s)->subtype & LuaScriptInfo::SessionSetup) {
+                       scripts.push_back (*s);
                }
+       }
+
+       std::sort (scripts.begin(), scripts.end(), LuaScripting::Sorter());
+
+       for (LuaScriptList::const_iterator s = scripts.begin(); s != scripts.end(); ++s) {
                TreeModel::Row row = *(template_model->append ());
                row[session_template_columns.name] = (*s)->name;
                row[session_template_columns.path] = "urn:ardour:" + (*s)->path;
                row[session_template_columns.description] = (*s)->description;
-               row[session_template_columns.created_with_short] = _("{Factory Template}");
-               row[session_template_columns.created_with_long] = _("{Factory Template}");
+               row[session_template_columns.modified_with_short] = _("{Factory Template}");
+               row[session_template_columns.modified_with_long] = _("{Factory Template}");
        }
 
-
        //Add any "template sessions" found in the user's preferences folder
        for (vector<TemplateInfo>::iterator x = templates.begin(); x != templates.end(); ++x) {
                TreeModel::Row row;
@@ -599,17 +604,17 @@ SessionDialog::populate_session_templates ()
                row[session_template_columns.name] = (*x).name;
                row[session_template_columns.path] = (*x).path;
                row[session_template_columns.description] = (*x).description;
-               row[session_template_columns.created_with_long] = (*x).created_with;
-               row[session_template_columns.created_with_short] = (*x).created_with.substr(0, (*x).created_with.find(" "));
+               row[session_template_columns.modified_with_long] = (*x).modified_with;
+               row[session_template_columns.modified_with_short] = (*x).modified_with.substr(0, (*x).modified_with.find(" "));
        }
 
        //Add an explicit 'Empty Template' item
        TreeModel::Row row = *template_model->prepend ();
        row[session_template_columns.name] = (_("Empty Template"));
        row[session_template_columns.path] = string();
-       row[session_template_columns.description] = _("An empty session with factory default settings.");
-       row[session_template_columns.created_with_short] = _("");
-       row[session_template_columns.created_with_long] = _("");
+       row[session_template_columns.description] = _("An empty session with factory default settings.\n\nSelect this option if you are importing files to mix.");
+       row[session_template_columns.modified_with_short] = _("");
+       row[session_template_columns.modified_with_long] = _("");
 
        //auto-select the first item in the list
        Gtk::TreeModel::Row first = template_model->children()[0];
@@ -652,7 +657,7 @@ SessionDialog::setup_new_session_page ()
        //determine the text in the new folder selector
        if (!ARDOUR_COMMAND_LINE::session_name.empty()) {
                new_folder_chooser.set_current_folder (poor_mans_glob (Glib::path_get_dirname (ARDOUR_COMMAND_LINE::session_name)));
-       } else if (ARDOUR_UI::instance()->session_loaded) {
+       } else if (ARDOUR_UI::instance()->the_session ()) {
                // point the new session file chooser at the parent directory of the current session
                string session_parent_dir = Glib::path_get_dirname(ARDOUR_UI::instance()->the_session()->path());
                new_folder_chooser.set_current_folder (session_parent_dir);
@@ -706,13 +711,15 @@ SessionDialog::setup_new_session_page ()
        template_chooser.set_model (template_model);
        template_chooser.append_column (_("Template"), session_template_columns.name);
 #ifdef MIXBUS
-       template_chooser.append_column (_("Created With"), session_template_columns.created_with_short);
+       template_chooser.append_column (_("Modified With"), session_template_columns.modified_with_short);
 #endif
-       template_chooser.set_tooltip_column(4); // created_with_long
        template_chooser.set_headers_visible (true);
        template_chooser.get_selection()->set_mode (SELECTION_SINGLE);
        template_chooser.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &SessionDialog::template_row_selected));
        template_chooser.set_sensitive (true);
+       if (UIConfiguration::instance().get_use_tooltips()) {
+               template_chooser.set_tooltip_column(4); // modified_with_long
+       }
 
        session_new_vbox.pack_start (*template_hbox, true, true);
        session_new_vbox.pack_start (*folder_box, false, true);
@@ -858,6 +865,7 @@ SessionDialog::redisplay_recent_sessions ()
                        row[recent_session_columns.tip] = Gtkmm2ext::markup_escape_text (dirname);
                } else {
                        row[recent_session_columns.tip] = Gtkmm2ext::markup_escape_text (dirname + "\n" + string_compose (_("Last modified with: %1"), program_version));
+                       row[recent_session_columns.modified_with] = program_version;
                }
 
                ++session_snapshot_count;
@@ -937,7 +945,9 @@ SessionDialog::redisplay_recent_sessions ()
                row[recent_session_columns.time_formatted] = gdt.format ("%F %H:%M");
        }
 
-       recent_session_display.set_tooltip_column(1); // recent_session_columns.tip
+       if (UIConfiguration::instance().get_use_tooltips()) {
+               recent_session_display.set_tooltip_column(1); // recent_session_columns.tip
+       }
        recent_session_display.set_model (recent_session_model);
 
        // custom sort
@@ -1043,7 +1053,7 @@ SessionDialog::recent_context_mennu (GdkEventButton *ev)
        Gtk::TreeModel::Path tpath = recent_session_model->get_path(iter);
        const bool is_child = tpath.up () && tpath.up ();
 
-       Gtk::Menu* m = manage (new Menu);
+       Gtk::Menu* m = ARDOUR_UI::instance()->shared_popup_menu ();
        MenuList& items = m->items ();
        items.push_back (MenuElem (s, sigc::bind (sigc::hide_return (sigc::ptr_fun (&PBD::open_folder)), s)));
        if (!is_child) {