Note modes: note, percussion.
[ardour.git] / gtk2_ardour / new_session_dialog.cc
index 4875ff835a2aa1a3763b6a487a49166bc1e2dfbd..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>
 #include <gtkmm/stock.h>
 #include <gdkmm/cursor.h>
 
+#include <gtkmm2ext/window_title.h>
+
+using namespace Gtkmm2ext;
+using namespace ARDOUR;
+using namespace PBD;
+
 #include "opts.h"
 
 NewSessionDialog::NewSessionDialog()
        : ArdourDialog ("session control")
 {
-        session_name_label = Gtk::manage(new class Gtk::Label(_("Name :")));
+       session_name_label = Gtk::manage(new class Gtk::Label(_("Name :")));
        m_name = Gtk::manage(new class Gtk::Entry());
        m_name->set_text(GTK_ARDOUR::session_name);
 
@@ -338,7 +345,11 @@ NewSessionDialog::NewSessionDialog()
        get_vbox()->set_homogeneous(false);
        get_vbox()->set_spacing(0);
        get_vbox()->pack_start(*m_notebook, Gtk::PACK_SHRINK, 0);
-       set_title(_("ardour: session control"));
+
+       WindowTitle title(Glib::get_application_name());
+       title += _("Session Control");
+       set_title(title.get_string());
+
        //set_modal(false);
        //property_window_position().set_value(Gtk::WIN_POS_NONE);
        set_resizable(false);
@@ -355,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"));
@@ -396,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();
@@ -419,7 +419,7 @@ NewSessionDialog::NewSessionDialog()
        m_limit_output_ports->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::limit_outputs_clicked));
        m_create_master_bus->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::master_bus_button_clicked));
        m_create_control_bus->signal_clicked().connect (mem_fun (*this, &NewSessionDialog::monitor_bus_button_clicked));
-       m_name->signal_key_release_event().connect(mem_fun (*this, &NewSessionDialog::entry_key_release));
+       m_name->signal_changed().connect(mem_fun (*this, &NewSessionDialog::on_new_session_name_entry_changed));
        m_notebook->signal_switch_page().connect (mem_fun (*this, &NewSessionDialog::notebook_page_changed));
        m_treeview->get_selection()->signal_changed().connect (mem_fun (*this, &NewSessionDialog::treeview_selection_changed));
        m_treeview->signal_row_activated().connect (mem_fun (*this, &NewSessionDialog::recent_row_activated));
@@ -437,7 +437,7 @@ NewSessionDialog::set_session_name(const Glib::ustring& name)
 std::string
 NewSessionDialog::session_name() const
 {
-        std::string str = Glib::filename_from_utf8(m_open_filechooser->get_filename());
+       std::string str = Glib::filename_from_utf8(m_open_filechooser->get_filename());
        std::string::size_type position = str.find_last_of ('/');
        str = str.substr (position+1);
        position = str.find_last_of ('.');
@@ -452,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) {
@@ -466,12 +466,12 @@ NewSessionDialog::session_name() const
 std::string
 NewSessionDialog::session_folder() const
 {
-        if (m_notebook->get_current_page() == 0) {
-               return Glib::filename_from_utf8(m_folder->get_current_folder());
+       if (on_new_session_page ()) {
+               return Glib::filename_from_utf8(m_folder->get_current_folder());
        } else {
               
                if (m_treeview->get_selection()->count_selected_rows() == 0) {
-                       return Glib::filename_from_utf8(m_open_filechooser->get_current_folder());
+                       return Glib::filename_from_utf8(m_open_filechooser->get_current_folder());
                }
                Gtk::TreeModel::iterator i = m_treeview->get_selection()->get_selected();
                return (*i)[recent_columns.fullpath];
@@ -481,7 +481,7 @@ NewSessionDialog::session_folder() const
 bool
 NewSessionDialog::use_session_template() const
 {
-        if(m_template->get_filename().empty() && (m_notebook->get_current_page() == 0)) return false;
+       if(m_template->get_filename().empty() && (m_notebook->get_current_page() == 0)) return false;
        return true;
 }
 
@@ -563,11 +563,16 @@ 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
+NewSessionDialog::set_current_page(int page)
+{
+       return m_notebook->set_current_page (page);
 }
 
 void
@@ -575,11 +580,10 @@ NewSessionDialog::reset_name()
 {
        m_name->set_text("");
        set_response_sensitive (Gtk::RESPONSE_OK, false);
-       
 }
 
-bool
-NewSessionDialog::entry_key_release (GdkEventKey* ev)
+void
+NewSessionDialog::on_new_session_name_entry_changed ()
 {
        if (m_name->get_text() != "") {
                set_response_sensitive (Gtk::RESPONSE_OK, true);
@@ -587,14 +591,12 @@ NewSessionDialog::entry_key_release (GdkEventKey* ev)
        } else {
                set_response_sensitive (Gtk::RESPONSE_OK, false);
        }
-       return true;
 }
 
 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)));
@@ -604,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);
                }
@@ -635,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();
 
@@ -662,61 +663,61 @@ NewSessionDialog::template_chosen ()
 void
 NewSessionDialog::recent_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col)
 {
-        response (Gtk::RESPONSE_YES);
+       response (Gtk::RESPONSE_YES);
 }
 
 void
 NewSessionDialog::connect_inputs_clicked ()
 {
-        m_limit_input_ports->set_sensitive(m_connect_inputs->get_active());
+       m_limit_input_ports->set_sensitive(m_connect_inputs->get_active());
 
-               if (m_connect_inputs->get_active() && m_limit_input_ports->get_active()) {
-               m_input_limit_count->set_sensitive(true);
-               } else {
-               m_input_limit_count->set_sensitive(false);
-               }
+       if (m_connect_inputs->get_active() && m_limit_input_ports->get_active()) {
+               m_input_limit_count->set_sensitive(true);
+       } else {
+               m_input_limit_count->set_sensitive(false);
+       }
 }
 
 void
 NewSessionDialog::connect_outputs_clicked ()
 {
-        m_limit_output_ports->set_sensitive(m_connect_outputs->get_active());
+       m_limit_output_ports->set_sensitive(m_connect_outputs->get_active());
 
-               if (m_connect_outputs->get_active() && m_limit_output_ports->get_active()) {
-               m_output_limit_count->set_sensitive(true);
-               } else {
-               m_output_limit_count->set_sensitive(false);
-               }
+       if (m_connect_outputs->get_active() && m_limit_output_ports->get_active()) {
+               m_output_limit_count->set_sensitive(true);
+       } else {
+               m_output_limit_count->set_sensitive(false);
+       }
 }
 
 void
 NewSessionDialog::limit_inputs_clicked ()
 {
-        m_input_limit_count->set_sensitive(m_limit_input_ports->get_active());
+       m_input_limit_count->set_sensitive(m_limit_input_ports->get_active());
 }
 
 void
 NewSessionDialog::limit_outputs_clicked ()
 {
-        m_output_limit_count->set_sensitive(m_limit_output_ports->get_active());
+       m_output_limit_count->set_sensitive(m_limit_output_ports->get_active());
 }
 
 void
 NewSessionDialog::master_bus_button_clicked ()
 {
-        m_master_bus_channel_count->set_sensitive(m_create_master_bus->get_active());
+       m_master_bus_channel_count->set_sensitive(m_create_master_bus->get_active());
 }
 
 void
 NewSessionDialog::monitor_bus_button_clicked ()
 {
-        m_control_bus_channel_count->set_sensitive(m_create_control_bus->get_active());
+       m_control_bus_channel_count->set_sensitive(m_create_control_bus->get_active());
 }
 
 void
 NewSessionDialog::reset_template()
 {
-        m_template->set_filename("");
+       m_template->set_filename("");
 }
 
 void
@@ -749,14 +750,14 @@ NewSessionDialog::reset_recent()
                /* remove any trailing / */
                
                if (fullpath[fullpath.length()-1] == '/') {
-                       fullpath = fullpath.substr (0, fullpath.length()-1);
+                       fullpath = fullpath.substr (0, fullpath.length()-1);
                }
            
                /* now get available states for this session */
                  
                if ((states = ARDOUR::Session::possible_states (fullpath)) == 0) {
-                       /* no state file? */
-                       continue;
+                       /* no state file? */
+                       continue;
                }
            
                Gtk::TreeModel::Row row = *(recent_model->append());
@@ -765,16 +766,16 @@ NewSessionDialog::reset_recent()
                row[recent_columns.fullpath] = fullpath;
                
                if (states->size()) {
-                   
-                       /* add the children */
-                   
-                       for (std::vector<std::string*>::iterator i2 = states->begin(); i2 != states->end(); ++i2) {
 
-                               Gtk::TreeModel::Row child_row = *(recent_model->append (row.children()));
-                               
+                       /* add the children */
+
+                       for (std::vector<std::string*>::iterator i2 = states->begin(); i2 != states->end(); ++i2) {
+
+                               Gtk::TreeModel::Row child_row = *(recent_model->append (row.children()));
+
                                child_row[recent_columns.visible_name] = **i2;
                                child_row[recent_columns.fullpath] = fullpath;
-                               
+
                                delete *i2;
                        }
                }