enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / insert_remove_time_dialog.cc
1 /*
2     Copyright (C) 2000-2010 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <gtkmm/table.h>
21 #include <gtkmm/comboboxtext.h>
22 #include <gtkmm/stock.h>
23 #include <gtkmm/alignment.h>
24 #include "insert_remove_time_dialog.h"
25 #include "audio_clock.h"
26 #include "pbd/i18n.h"
27
28 using namespace Gtk;
29 using namespace Editing;
30
31 InsertRemoveTimeDialog::InsertRemoveTimeDialog (PublicEditor& e, bool remove)
32         : ArdourDialog (remove ? _("Remove Time") : _("Insert Time"))
33         , _editor (e)
34         , _clock ("insertTimeClock", true, "",
35                         true,   // editable
36                         false,  // follows_playhead
37                         true,   // duration
38                         false,  // with_info
39                         true    // accept_on_focus_out
40                 )
41 {
42         set_session (_editor.session ());
43
44         framepos_t const pos = _editor.get_preferred_edit_position (EDIT_IGNORE_MOUSE);
45
46         get_vbox()->set_border_width (12);
47         get_vbox()->set_spacing (4);
48
49         Table* table = manage (new Table (2, 2));
50         table->set_spacings (4);
51
52         Label* time_label = manage (new Label (remove ? _("Time to remove") : _("Time to insert:")));
53         time_label->set_alignment (1, 0.5);
54         table->attach (*time_label, 0, 1, 0, 1, FILL | EXPAND);
55         _clock.set (0);
56         _clock.set_session (_session);
57         _clock.set_bbt_reference (pos);
58         table->attach (_clock, 1, 2, 0, 1);
59
60         if (!remove) {
61                 Label* intersected_label = manage (new Label (_("Intersected regions should:")));
62                 intersected_label->set_alignment (1, 0.5);
63                 table->attach (*intersected_label, 0, 1, 1, 2, FILL | EXPAND);
64                 _intersected_combo.append_text (_("stay in position"));
65                 _intersected_combo.append_text (_("move"));
66                 _intersected_combo.append_text (_("be split"));
67                 _intersected_combo.set_active (0);
68                 table->attach (_intersected_combo, 1, 2, 1, 2);
69         }
70
71         get_vbox()->pack_start (*table);
72
73         _all_playlists.set_label (_("Apply to all the track's playlists"));
74         get_vbox()->pack_start (_all_playlists);
75
76         _move_glued.set_label (_("Move glued regions"));
77         get_vbox()->pack_start (_move_glued);
78         _move_markers.set_label (_("Move markers"));
79         get_vbox()->pack_start (_move_markers);
80         _move_markers.signal_toggled().connect (sigc::mem_fun (*this, &InsertRemoveTimeDialog::move_markers_toggled));
81         _move_glued_markers.set_label (_("Move glued markers"));
82         Alignment* indent = manage (new Alignment);
83         indent->set_padding (0, 0, 12, 0);
84         indent->add (_move_glued_markers);
85         get_vbox()->pack_start (*indent);
86         _move_locked_markers.set_label (_("Move locked markers"));
87         indent = manage (new Alignment);
88         indent->set_padding (0, 0, 12, 0);
89         indent->add (_move_locked_markers);
90         get_vbox()->pack_start (*indent);
91         tempo_label.set_markup (_("Move tempo and meter changes\n<i>(may cause oddities in the tempo map)</i>"));
92         HBox* tempo_box = manage (new HBox);
93         tempo_box->set_spacing (6);
94         tempo_box->pack_start (_move_tempos, false, false);
95         tempo_box->pack_start (tempo_label, false, false);
96         get_vbox()->pack_start (*tempo_box);
97
98         add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
99         Gtk::Button *btn = manage (new Gtk::Button (remove ? _("Remove time") : _("Insert time")));
100         btn->signal_clicked().connect (sigc::mem_fun(*this, &InsertRemoveTimeDialog::doit));
101         get_action_area()->pack_start (*btn);
102         show_all ();
103
104         move_markers_toggled ();
105 }
106
107 InsertTimeOption
108 InsertRemoveTimeDialog::intersected_region_action ()
109 {
110         /* only setting this to keep GCC quiet */
111         InsertTimeOption opt = LeaveIntersected;
112
113         switch (_intersected_combo.get_active_row_number ()) {
114         case 0:
115                 opt = LeaveIntersected;
116                 break;
117         case 1:
118                 opt = MoveIntersected;
119                 break;
120         case 2:
121                 opt = SplitIntersected;
122                 break;
123         }
124
125         return opt;
126 }
127
128 bool
129 InsertRemoveTimeDialog::all_playlists () const
130 {
131         return _all_playlists.get_active ();
132 }
133
134 bool
135 InsertRemoveTimeDialog::move_glued () const
136 {
137         return _move_glued.get_active ();
138 }
139
140 bool
141 InsertRemoveTimeDialog::move_tempos () const
142 {
143         return _move_tempos.get_active ();
144 }
145
146 bool
147 InsertRemoveTimeDialog::move_markers () const
148 {
149         return _move_markers.get_active ();
150 }
151
152 bool
153 InsertRemoveTimeDialog::move_glued_markers () const
154 {
155         return _move_glued_markers.get_active ();
156 }
157
158 bool
159 InsertRemoveTimeDialog::move_locked_markers () const
160 {
161         return _move_locked_markers.get_active ();
162 }
163
164 framepos_t
165 InsertRemoveTimeDialog::distance () const
166 {
167         return _clock.current_duration (_editor.get_preferred_edit_position ());
168 }
169
170 void
171 InsertRemoveTimeDialog::doit ()
172 {
173         if (distance () == 0) {
174                 Gtk::MessageDialog msg (*this, _("Invalid or zero duration entered. Please enter a valid duration"));
175                 msg.run ();
176                 return;
177         }
178         response (RESPONSE_OK);
179 }
180
181 void
182 InsertRemoveTimeDialog::move_markers_toggled ()
183 {
184         _move_glued_markers.set_sensitive (_move_markers.get_active ());
185         _move_locked_markers.set_sensitive (_move_markers.get_active ());
186 }