From 376afa83cc9d3e6b978d9bb0ce3ab2fd2c6364a7 Mon Sep 17 00:00:00 2001
From: Thomas Brand <tom@trellis.ch>
Date: Thu, 8 Aug 2013 19:48:06 +0200
Subject: [PATCH] add editor action editor-delete-time, cut any regions inside
 range and shift back following regions

---
 gtk2_ardour/ardour.menus.in   |    1 +
 gtk2_ardour/editor.cc         |    3 +++
 gtk2_ardour/editor.h          |    1 +
 gtk2_ardour/editor_actions.cc |    2 ++
 gtk2_ardour/editor_ops.cc     |   34 ++++++++++++++++++++++++++++++++++
 5 files changed, 41 insertions(+)

diff --git a/gtk2_ardour/ardour.menus.in b/gtk2_ardour/ardour.menus.in
index 15f1bde..75c6eb5 100644
--- a/gtk2_ardour/ardour.menus.in
+++ b/gtk2_ardour/ardour.menus.in
@@ -193,6 +193,7 @@
       </menu>	   
       <separator/>
       <menuitem action='editor-delete'/>
+      <menuitem action='editor-delete-time'/>
       <menuitem action='editor-crop'/>
       <menuitem action='split-region'/>
       <menuitem action='split-region-at-transients'/>
diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc
index 300e317..b8768f9 100644
--- a/gtk2_ardour/editor.cc
+++ b/gtk2_ardour/editor.cc
@@ -1897,6 +1897,9 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items)
 	edit_items.push_back (MenuElem (_("Set Punch from Range"), sigc::mem_fun(*this, &Editor::set_punch_from_selection)));
 
 	edit_items.push_back (SeparatorElem());
+	edit_items.push_back (MenuElem (_("Delete Time from Range"), sigc::mem_fun(*this, &Editor::delete_time)));
+
+	edit_items.push_back (SeparatorElem());
 	edit_items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_location_from_selection)));
 
 	edit_items.push_back (SeparatorElem());
diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h
index 033888c..757d1a6 100644
--- a/gtk2_ardour/editor.h
+++ b/gtk2_ardour/editor.h
@@ -1198,6 +1198,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 	void split_region ();
 
 	void delete_ ();
+	void delete_time ();
 	void cut ();
 	void copy ();
 	void paste (float times, bool from_context_menu = false);
diff --git a/gtk2_ardour/editor_actions.cc b/gtk2_ardour/editor_actions.cc
index a5e2e8a..11f7d8e 100644
--- a/gtk2_ardour/editor_actions.cc
+++ b/gtk2_ardour/editor_actions.cc
@@ -309,6 +309,8 @@ Editor::register_actions ()
 	reg_sens (editor_actions, "editor-cut", _("Cut"), sigc::mem_fun(*this, &Editor::cut));
 	reg_sens (editor_actions, "editor-delete", _("Delete"), sigc::mem_fun(*this, &Editor::delete_));
 
+	reg_sens (editor_actions, "editor-delete-time", _("Delete Time"), sigc::mem_fun(*this, &Editor::delete_time));
+
 	reg_sens (editor_actions, "editor-copy", _("Copy"), sigc::mem_fun(*this, &Editor::copy));
 	reg_sens (editor_actions, "editor-paste", _("Paste"), sigc::mem_fun(*this, &Editor::keyboard_paste));
 
diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc
index 93a53dd..57ddca0 100644
--- a/gtk2_ardour/editor_ops.cc
+++ b/gtk2_ardour/editor_ops.cc
@@ -3622,6 +3622,40 @@ Editor::delete_ ()
 	cut_copy (Delete);
 }
 
+/** Delete selected regions, automation points or a time range
+    && remove Time (regions after the selection will be nudged ) */
+void
+Editor::delete_time ()
+{
+	if (_session == 0 || selection->time.empty()) {
+		return;
+	}
+
+	framepos_t start = selection->time.start();
+	framepos_t end = selection->time.end_frame();
+
+	begin_reversible_command (_("delete time"));
+
+	//delete regions in range (split intersected)
+	cut_copy (Delete);
+
+	//remove time in range
+	InsertTimeOption opt = SplitIntersected;
+	insert_time (
+		start,
+		-(end-start), //negative shift
+		opt,
+		false,  //all playlists
+		true,   //move glued regions
+		false,  //move markers
+		false,  //move glued markers
+		false,  //move locked markers
+		false   //move tempo
+	);
+
+	commit_reversible_command ();
+}
+
 /** Cut selected regions, automation points or a time range */
 void
 Editor::cut ()
-- 
1.7.9.5

