Vkeybd: use ArdourWidgets for all GUI elements
[ardour.git] / gtk2_ardour / save_as_dialog.cc
1 /*
2  * Copyright (C) 2015-2016 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #include <gtkmm/stock.h>
21
22 #include "ardour/session.h"
23
24 #include "gtkmm2ext/utils.h"
25
26 #include "save_as_dialog.h"
27
28 #include "pbd/i18n.h"
29
30 using namespace std;
31 using namespace Gtk;
32 using namespace ARDOUR;
33
34 SaveAsDialog::SaveAsDialog ()
35         : ArdourDialog (_("Save As"))
36         , switch_to_button (_("Switch to newly-saved version"))
37         , copy_media_button (_("Copy media to new session"))
38         , copy_external_button (_("Copy external media into new session"))
39         , no_include_media_button (_("Newly-saved session should be empty"))
40 {
41         VBox* vbox = get_vbox();
42
43         vbox->set_spacing (6);
44
45         HBox* hbox;
46         Label* label;
47
48         hbox = manage (new HBox);
49         hbox->set_spacing (6);
50         label = manage (new Label (_("Save as session name")));
51         hbox->pack_start (*label, false, false);
52         hbox->pack_start (new_name_entry, true, true);
53         vbox->pack_start (*hbox, false, false);
54
55         hbox = manage (new HBox);
56         hbox->set_spacing (6);
57         label = manage (new Label (_("Parent directory/folder")));
58         hbox->pack_start (*label, false, false);
59         hbox->pack_start (new_parent_folder_selector, true, true);
60         vbox->pack_start (*hbox, false, false);
61
62         vbox->pack_start (switch_to_button, false, false);
63
64         VBox* sub_vbox = manage (new VBox);
65         HBox* sub_hbox = manage (new HBox);
66         HBox* empty = manage (new HBox);
67
68         sub_vbox->pack_start (copy_media_button, false, false);
69         sub_vbox->pack_start (copy_external_button, false, false);
70
71         /* indent the two media-related buttons by some amount */
72         sub_hbox->set_spacing (24);
73         sub_hbox->pack_start (*empty, false, false);
74         sub_hbox->pack_start (*sub_vbox, false, false);
75
76         vbox->pack_start (no_include_media_button, false, false);
77         vbox->pack_start (*sub_hbox, false, false);
78
79         switch_to_button.set_active (true);
80         copy_media_button.set_active (true);
81
82         vbox->show_all ();
83
84         add_button (Stock::CANCEL, RESPONSE_CANCEL);
85         add_button (Stock::OK, RESPONSE_OK);
86
87         no_include_media_button.signal_toggled ().connect (sigc::mem_fun (*this, &SaveAsDialog::no_include_toggled));
88
89         Gtkmm2ext::add_volume_shortcuts (new_parent_folder_selector);
90         new_parent_folder_selector.set_action (FILE_CHOOSER_ACTION_SELECT_FOLDER);
91         new_parent_folder_selector.set_current_folder (Config->get_default_session_parent_dir ());
92
93         new_name_entry.signal_changed().connect (sigc::mem_fun (*this, &SaveAsDialog::name_entry_changed));
94         new_parent_folder_selector.signal_current_folder_changed().connect (sigc::mem_fun (*this, &SaveAsDialog::name_entry_changed));
95         new_parent_folder_selector.signal_selection_changed().connect (sigc::mem_fun (*this, &SaveAsDialog::name_entry_changed));
96         set_response_sensitive (RESPONSE_OK, false);
97 }
98
99 void
100 SaveAsDialog::no_include_toggled ()
101 {
102         if (no_include_media_button.get_active()) {
103                 copy_media_button.set_sensitive (false);
104                 copy_external_button.set_sensitive (false);
105         } else {
106                 copy_media_button.set_sensitive (true);
107                 copy_external_button.set_sensitive (true);
108         }
109 }
110
111 void
112 SaveAsDialog::name_entry_changed ()
113 {
114         if (new_name_entry.get_text().empty()) {
115                 set_response_sensitive (RESPONSE_OK, false);
116                 return;
117         }
118
119         std::string dir = Glib::build_filename (new_parent_folder(), new_name_entry.get_text());
120
121         if (Glib::file_test (dir, Glib::FILE_TEST_EXISTS)) {
122                 set_response_sensitive (RESPONSE_OK, false);
123                 return;
124         }
125
126         set_response_sensitive (RESPONSE_OK);
127 }
128
129 string
130 SaveAsDialog::new_parent_folder () const
131 {
132         return new_parent_folder_selector.get_filename ();
133 }
134
135 string
136 SaveAsDialog::new_name () const
137 {
138         return new_name_entry.get_text ();
139 }
140
141 bool
142 SaveAsDialog::switch_to () const
143 {
144         return switch_to_button.get_active ();
145 }
146
147 bool
148 SaveAsDialog::copy_media () const
149 {
150         return copy_media_button.get_active ();
151 }
152
153 bool
154 SaveAsDialog::copy_external () const
155 {
156         return copy_external_button.get_active ();
157 }
158
159 void
160 SaveAsDialog::clear_name ()
161 {
162         new_name_entry.set_text ("");
163         set_response_sensitive (RESPONSE_OK, false);
164 }
165
166 void
167 SaveAsDialog::set_name (std::string name)
168 {
169         new_name_entry.set_text (name);
170         name_entry_changed ();
171 }
172
173 bool
174 SaveAsDialog::include_media () const
175 {
176         return !no_include_media_button.get_active ();
177 }