diff options
-rw-r--r-- | gtk2_ardour/ardour_ui.cc | 150 | ||||
-rw-r--r-- | gtk2_ardour/ardour_ui.h | 27 | ||||
-rw-r--r-- | gtk2_ardour/session_dialog.cc | 81 | ||||
-rw-r--r-- | gtk2_ardour/session_dialog.h | 2 |
4 files changed, 69 insertions, 191 deletions
diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 0427063222..29cc693d6f 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -257,7 +257,6 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir, UIConfi , error_alert_button ( ArdourButton::just_led_default_elements ) , editor_meter(0) , editor_meter_peak_display() - , session_selector_window (0) , _numpad_locate_happening (false) , _session_is_new (false) , last_key_press_time (0) @@ -1620,170 +1619,39 @@ ARDOUR_UI::update_wall_clock () } void -ARDOUR_UI::redisplay_recent_sessions () -{ - std::vector<std::string> session_directories; - RecentSessionsSorter cmp; - - recent_session_display.set_model (Glib::RefPtr<TreeModel>(0)); - recent_session_model->clear (); - - ARDOUR::RecentSessions rs; - ARDOUR::read_recent_sessions (rs); - - if (rs.empty()) { - recent_session_display.set_model (recent_session_model); - return; - } - - // sort them alphabetically - sort (rs.begin(), rs.end(), cmp); - - for (ARDOUR::RecentSessions::iterator i = rs.begin(); i != rs.end(); ++i) { - session_directories.push_back ((*i).second); - } - - for (vector<std::string>::const_iterator i = session_directories.begin(); - i != session_directories.end(); ++i) - { - std::vector<std::string> state_file_paths; - - // now get available states for this session - - get_state_files_in_directory (*i, state_file_paths); - - vector<string> states; - vector<const gchar*> item; - string fullpath = *i; - - /* remove any trailing / */ - - if (fullpath[fullpath.length() - 1] == '/') { - fullpath = fullpath.substr (0, fullpath.length() - 1); - } - - /* check whether session still exists */ - if (!Glib::file_test(fullpath.c_str(), Glib::FILE_TEST_EXISTS)) { - /* session doesn't exist */ - continue; - } - - /* now get available states for this session */ - states = Session::possible_states (fullpath); - - if (states.empty()) { - /* no state file? */ - continue; - } - - std::vector<string> state_file_names(get_file_names_no_extension (state_file_paths)); - - Gtk::TreeModel::Row row = *(recent_session_model->append()); - - row[recent_session_columns.fullpath] = fullpath; - row[recent_session_columns.tip] = Glib::Markup::escape_text (fullpath); - - if (state_file_names.size() > 1) { - // multiple session files in the session directory - show the directory name. - row[recent_session_columns.visible_name] = Glib::path_get_basename (fullpath); - - // add the children - for (std::vector<std::string>::iterator i2 = state_file_names.begin(); - i2 != state_file_names.end(); ++i2) - { - - Gtk::TreeModel::Row child_row = *(recent_session_model->append (row.children())); - - child_row[recent_session_columns.visible_name] = *i2; - child_row[recent_session_columns.fullpath] = fullpath; - child_row[recent_session_columns.tip] = Glib::Markup::escape_text (fullpath); - } - } else { - // only a single session file in the directory - show its actual name. - row[recent_session_columns.visible_name] = state_file_names.front (); - } - } - - recent_session_display.set_tooltip_column(1); // recent_session_columns.tip - recent_session_display.set_model (recent_session_model); -} - -void -ARDOUR_UI::build_session_selector () -{ - session_selector_window = new ArdourDialog (_("Recent Sessions")); - - Gtk::ScrolledWindow *scroller = manage (new Gtk::ScrolledWindow); - - session_selector_window->add_button (Stock::CANCEL, RESPONSE_CANCEL); - session_selector_window->add_button (Stock::OPEN, RESPONSE_ACCEPT); - session_selector_window->set_default_response (RESPONSE_ACCEPT); - recent_session_model = TreeStore::create (recent_session_columns); - recent_session_display.set_model (recent_session_model); - recent_session_display.append_column (_("Recent Sessions"), recent_session_columns.visible_name); - recent_session_display.set_headers_visible (false); - recent_session_display.get_selection()->set_mode (SELECTION_BROWSE); - recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &ARDOUR_UI::recent_session_row_activated)); - - scroller->add (recent_session_display); - scroller->set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); - - session_selector_window->set_name ("SessionSelectorWindow"); - session_selector_window->set_size_request (200, 400); - session_selector_window->get_vbox()->pack_start (*scroller); - - recent_session_display.show(); - scroller->show(); -} - -void -ARDOUR_UI::recent_session_row_activated (const TreePath& /*path*/, TreeViewColumn* /*col*/) -{ - session_selector_window->response (RESPONSE_ACCEPT); -} - -void ARDOUR_UI::open_recent_session () { bool can_return = (_session != 0); - if (session_selector_window == 0) { - build_session_selector (); - } - - redisplay_recent_sessions (); + SessionDialog recent_session_dialog; while (true) { - ResponseType r = (ResponseType) session_selector_window->run (); + ResponseType r = (ResponseType) recent_session_dialog.run (); switch (r) { case RESPONSE_ACCEPT: break; default: if (can_return) { - session_selector_window->hide(); + recent_session_dialog.hide(); return; } else { exit (1); } } - if (recent_session_display.get_selection()->count_selected_rows() == 0) { - continue; - } + recent_session_dialog.hide(); - session_selector_window->hide(); + bool should_be_new; - Gtk::TreeModel::iterator i = recent_session_display.get_selection()->get_selected(); + std::string path = recent_session_dialog.session_folder(); + std::string state = recent_session_dialog.session_name (should_be_new); - if (i == recent_session_model->children().end()) { - return; + if (should_be_new == true) { + continue; } - std::string path = (*i)[recent_session_columns.fullpath]; - std::string state = (*i)[recent_session_columns.visible_name]; - _session_is_new = false; if (load_session (path, state) == 0) { diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h index e26a8f6f3f..1ae81f54f1 100644 --- a/gtk2_ardour/ardour_ui.h +++ b/gtk2_ardour/ardour_ui.h @@ -502,33 +502,6 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr Gtk::Menu* session_popup_menu; - struct RecentSessionModelColumns : public Gtk::TreeModel::ColumnRecord { - RecentSessionModelColumns() { - add (visible_name); - add (tip); - add (fullpath); - } - Gtk::TreeModelColumn<std::string> visible_name; - Gtk::TreeModelColumn<std::string> tip; - Gtk::TreeModelColumn<std::string> fullpath; - }; - - RecentSessionModelColumns recent_session_columns; - Gtk::TreeView recent_session_display; - Glib::RefPtr<Gtk::TreeStore> recent_session_model; - - ArdourDialog* session_selector_window; - - void build_session_selector(); - void redisplay_recent_sessions(); - void recent_session_row_activated (const Gtk::TreePath& path, Gtk::TreeViewColumn* col); - - struct RecentSessionsSorter { - bool operator() (std::pair<std::string,std::string> a, std::pair<std::string,std::string> b) const { - return ARDOUR::cmp_nocase(a.first, b.first) == -1; - } - }; - /* menu bar and associated stuff */ Gtk::MenuBar* menu_bar; diff --git a/gtk2_ardour/session_dialog.cc b/gtk2_ardour/session_dialog.cc index e47f390eb6..4c71eb8ec2 100644 --- a/gtk2_ardour/session_dialog.cc +++ b/gtk2_ardour/session_dialog.cc @@ -26,6 +26,7 @@ #include <glib.h> #include <glib/gstdio.h> +#include <glibmm.h> #include <gtkmm/filechooser.h> @@ -150,6 +151,37 @@ SessionDialog::SessionDialog (bool require_new, const std::string& session_name, } } +SessionDialog::SessionDialog () + : ArdourDialog (_("Recent Sessions"), true, true) + , new_only (false) + , _provided_session_name ("") + , _provided_session_path ("") + // the following are unused , but have no default ctor + , _output_limit_count_adj (1, 0, 100, 1, 10, 0) + , _input_limit_count_adj (1, 0, 100, 1, 10, 0) + , _master_bus_channel_count_adj (2, 0, 100, 1, 10, 0) + , _existing_session_chooser_used (false) // caller must check should_be_new +{ + get_vbox()->set_spacing (6); + + cancel_button = add_button (Stock::CANCEL, RESPONSE_CANCEL); + open_button = add_button (Stock::OPEN, RESPONSE_ACCEPT); + open_button->set_sensitive (false); + + setup_recent_sessions (); + + get_vbox()->pack_start (recent_scroller, true, true); + get_vbox()->show_all (); + recent_scroller.show(); + + int cnt = redisplay_recent_sessions (); + if (cnt > 4) { + recent_scroller.set_size_request (-1, 300); + } +} + + + SessionDialog::~SessionDialog() { } @@ -253,6 +285,30 @@ SessionDialog::session_folder () } void +SessionDialog::setup_recent_sessions () +{ + recent_session_model = TreeStore::create (recent_session_columns); + recent_session_model->signal_sort_column_changed().connect (sigc::mem_fun (*this, &SessionDialog::recent_session_sort_changed)); + + 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); + recent_session_display.append_column (_("File Resolution"), recent_session_columns.disk_format); + 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); + + recent_session_display.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &SessionDialog::recent_session_row_selected)); + + recent_scroller.add (recent_session_display); + recent_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); + recent_scroller.set_shadow_type (Gtk::SHADOW_IN); + + recent_session_display.show(); + recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &SessionDialog::recent_row_activated)); +} + +void SessionDialog::setup_initial_choice_box () { ic_vbox.set_spacing (6); @@ -314,32 +370,12 @@ SessionDialog::setup_initial_choice_box () } /* recent session scroller */ + setup_recent_sessions (); recent_label.set_no_show_all (true); recent_scroller.set_no_show_all (true); - - recent_label.set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("Recent Sessions"))); - - recent_session_model = TreeStore::create (recent_session_columns); - recent_session_model->signal_sort_column_changed().connect (sigc::mem_fun (*this, &SessionDialog::recent_session_sort_changed)); - - 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); - recent_session_display.append_column (_("File Resolution"), recent_session_columns.disk_format); - 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); - - recent_session_display.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &SessionDialog::recent_session_row_selected)); - - recent_scroller.add (recent_session_display); - recent_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); - recent_scroller.set_shadow_type (Gtk::SHADOW_IN); - - recent_session_display.show(); - recent_session_display.signal_row_activated().connect (sigc::mem_fun (*this, &SessionDialog::recent_row_activated)); + recent_label.set_markup (string_compose ("<span weight=\"bold\" size=\"large\">%1</span>", _("Recent Sessions"))); centering_vbox->pack_start (recent_label, false, false, 12); centering_vbox->pack_start (recent_scroller, true, true); @@ -593,7 +629,6 @@ SessionDialog::redisplay_recent_sessions () recent_session_display.set_model (Glib::RefPtr<TreeModel>(0)); recent_session_model->clear (); - // code below is a near from ARDOUR_UI::redisplay_recent_sessions() ARDOUR::RecentSessions rs; ARDOUR::read_recent_sessions (rs); diff --git a/gtk2_ardour/session_dialog.h b/gtk2_ardour/session_dialog.h index 1a5d1a8386..b2896c6b21 100644 --- a/gtk2_ardour/session_dialog.h +++ b/gtk2_ardour/session_dialog.h @@ -49,6 +49,7 @@ class SessionDialog : public ArdourDialog { public: SessionDialog (bool require_new, const std::string& session_name, const std::string& session_path, const std::string& template_name, bool cancel_not_quit); + SessionDialog (); ~SessionDialog (); void clear_given (); @@ -94,6 +95,7 @@ class SessionDialog : public ArdourDialog { /* initial choice page */ void setup_initial_choice_box (); + void setup_recent_sessions (); Gtk::VBox ic_vbox; Gtk::Button ic_new_session_button; void new_session_button_clicked (); |