From c7fb668fe90ad85bad8bfeeea0b387336d72214f Mon Sep 17 00:00:00 2001
From: Colin Fletcher <colin.m.fletcher@googlemail.com>
Date: Sun, 17 Jan 2016 01:55:33 +0000
Subject: Add a simple check for valid duration in 'Insert/Remove Time'


diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc
index cb67f1f..6bdf2fb 100644
--- a/gtk2_ardour/editor_ops.cc
+++ b/gtk2_ardour/editor_ops.cc
@@ -7374,7 +7374,7 @@ Editor::remove_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
 			pl->shift (pos, -frames, true, ignore_music_glue);
 
 			if (!in_command) {
-				begin_reversible_command (_("cut time"));
+				begin_reversible_command (_("remove time"));
 				in_command = true;
 			}
 			XMLNode &after = pl->get_state();
@@ -7386,7 +7386,7 @@ Editor::remove_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
 		RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*x);
 		if (rtav) {
 			if (!in_command) {
-				begin_reversible_command (_("cut time"));
+				begin_reversible_command (_("remove time"));
 				in_command = true;
 			}
 			rtav->route ()->shift (pos, -frames);
@@ -7459,7 +7459,7 @@ Editor::remove_time (framepos_t pos, framecnt_t frames, InsertTimeOption opt,
 
 		if (moved) {
 			if (!in_command) {
-				begin_reversible_command (_("cut time"));
+				begin_reversible_command (_("remove time"));
 				in_command = true;
 			}
 			XMLNode& after (_session->locations()->get_state());
diff --git a/gtk2_ardour/insert_remove_time_dialog.cc b/gtk2_ardour/insert_remove_time_dialog.cc
index 851f57d..8620ba1 100644
--- a/gtk2_ardour/insert_remove_time_dialog.cc
+++ b/gtk2_ardour/insert_remove_time_dialog.cc
@@ -96,7 +96,9 @@ InsertRemoveTimeDialog::InsertRemoveTimeDialog (PublicEditor& e, bool remove)
 	get_vbox()->pack_start (*tempo_box);
 
 	add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
-	add_button (remove ? _("Remove time") : _("Insert time"), Gtk::RESPONSE_OK);
+	Gtk::Button *btn = manage (new Gtk::Button (remove ? _("Remove time") : _("Insert time")));
+	btn->signal_clicked().connect (sigc::mem_fun(*this, &InsertRemoveTimeDialog::doit));
+	get_action_area()->pack_start (*btn);
 	show_all ();
 
 	move_markers_toggled ();
@@ -166,6 +168,17 @@ InsertRemoveTimeDialog::distance () const
 }
 
 void
+InsertRemoveTimeDialog::doit ()
+{
+	if (distance () == 0) {
+		Gtk::MessageDialog msg (*this, _("Invalid or zero duration entered. Please enter a valid duration"));
+		msg.run ();
+		return;
+	}
+	response (RESPONSE_OK);
+}
+
+void
 InsertRemoveTimeDialog::move_markers_toggled ()
 {
 	_move_glued_markers.set_sensitive (_move_markers.get_active ());
diff --git a/gtk2_ardour/insert_remove_time_dialog.h b/gtk2_ardour/insert_remove_time_dialog.h
index 6fbb575..ea3b242 100644
--- a/gtk2_ardour/insert_remove_time_dialog.h
+++ b/gtk2_ardour/insert_remove_time_dialog.h
@@ -38,6 +38,7 @@ public:
 
 private:
 	void move_markers_toggled ();
+	void doit ();
 
 	PublicEditor& _editor;
 	Gtk::ComboBoxText _intersected_combo;
