show() widgets explicitly, one little file at a time
[ardour.git] / gtk2_ardour / new_session_dialog.cc
index 6046490324b8402760ceffcd78d897b66a139a87..43f98a5271132dc0ce374e8d3ddeabca93bb21ad 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <ardour/recent_sessions.h>
 #include <ardour/session.h>
+#include <ardour/template_utils.h>
 
 #include <gtkmm/entry.h>
 #include <gtkmm/filechooserbutton.h>
@@ -35,6 +36,8 @@
 #include <gtkmm2ext/window_title.h>
 
 using namespace Gtkmm2ext;
+using namespace ARDOUR;
+using namespace PBD;
 
 #include "opts.h"
 
@@ -363,28 +366,18 @@ NewSessionDialog::NewSessionDialog()
        m_treeview->set_headers_visible (false);
        m_treeview->get_selection()->set_mode (Gtk::SELECTION_SINGLE);
 
-       std::string path = ARDOUR::get_user_ardour_path();
-       
-       if (path.empty()) {
-               path = ARDOUR::get_system_data_path();
+       if (is_directory (user_template_directory ()))
+       {
+               m_template->set_current_folder (user_template_directory().to_string());
        }
-
-       const char * const template_dir_name = X_("templates");
-
-       if (!path.empty()) {
-               string user_template_path = path + template_dir_name;
-
-               if (Glib::file_test(user_template_path, Glib::FILE_TEST_IS_DIR))
-               {
-                       m_template->set_current_folder (user_template_path);
-               }
+       else if (is_directory (system_template_directory ()))
+       {
+               m_template->set_current_folder (system_template_directory().to_string());
        }
 
-       const std::string sys_templates_dir = ARDOUR::get_system_data_path() + template_dir_name;
-       
-       if (Glib::file_test(sys_templates_dir, Glib::FILE_TEST_IS_DIR))
+       if (is_directory (system_template_directory ()))
        {
-               m_template->add_shortcut_folder(sys_templates_dir);
+               m_template->add_shortcut_folder (system_template_directory().to_string());
        }
 
        m_template->set_title(_("select template"));
@@ -404,7 +397,6 @@ NewSessionDialog::NewSessionDialog()
        m_folder->set_current_folder(getenv ("HOME"));
        m_folder->set_title(_("select directory"));
 
-       on_new_session_page = true;
        m_notebook->set_current_page(0);
        m_notebook->show();
        m_notebook->show_all_children();
@@ -460,7 +452,7 @@ NewSessionDialog::session_name() const
        }         
        */
 
-       if (m_notebook->get_current_page() == 0) {
+       if (on_new_session_page ()) {
                return Glib::filename_from_utf8(m_name->get_text());
        } else {
                if (m_treeview->get_selection()->count_selected_rows() == 0) {
@@ -474,7 +466,7 @@ NewSessionDialog::session_name() const
 std::string
 NewSessionDialog::session_folder() const
 {
-       if (m_notebook->get_current_page() == 0) {
+       if (on_new_session_page ()) {
                return Glib::filename_from_utf8(m_folder->get_current_folder());
        } else {
               
@@ -571,10 +563,10 @@ NewSessionDialog::connect_outs_to_physical() const
        return m_connect_outputs_to_physical->get_active();
 }
 
-int
-NewSessionDialog::get_current_page()
+bool
+NewSessionDialog::on_new_session_page() const
 {
-       return m_notebook->get_current_page();
+       return (m_notebook->get_current_page() == 0);
 }
 
 void
@@ -604,8 +596,7 @@ NewSessionDialog::on_new_session_name_entry_changed ()
 void
 NewSessionDialog::notebook_page_changed (GtkNotebookPage* np, uint pagenum)
 {
-       if (pagenum == 1) {
-               on_new_session_page = false;
+       if (!on_new_session_page ()) {
                m_okbutton->set_label(_("Open"));
                set_response_sensitive (Gtk::RESPONSE_NONE, false);
                m_okbutton->set_image (*(new Gtk::Image (Gtk::Stock::OPEN, Gtk::ICON_SIZE_BUTTON)));
@@ -615,7 +606,6 @@ NewSessionDialog::notebook_page_changed (GtkNotebookPage* np, uint pagenum)
                        set_response_sensitive (Gtk::RESPONSE_OK, true);
                }
        } else {
-               on_new_session_page = true;
                if (m_name->get_text() != "") {
                        set_response_sensitive (Gtk::RESPONSE_NONE, true);
                }
@@ -646,7 +636,7 @@ NewSessionDialog::treeview_selection_changed ()
 void
 NewSessionDialog::file_chosen ()
 {
-       if (on_new_session_page) return;
+       if (on_new_session_page ()) return;
 
        m_treeview->get_selection()->unselect_all();