make CueEditor be a HistoryOwner and start on undo/redo refactor

This commit is contained in:
Paul Davis
2024-06-27 22:27:29 -06:00
parent b989464914
commit 6081bd5e19
7 changed files with 52 additions and 21 deletions

View File

@@ -1,7 +1,11 @@
#include "cue_editor.h"
#include "editor_drag.h"
#include "pbd/i18n.h"
CueEditor::CueEditor (std::string const & name)
: EditingContext (name)
, HistoryOwner (X_("cue-editor"))
{
}
CueEditor::~CueEditor ()
@@ -214,3 +218,23 @@ CueEditor::end_local_tempo_map (std::shared_ptr<Temporal::TempoMap const> map)
Temporal::TempoMap::set (map);
}
void
CueEditor::do_undo (uint32_t n)
{
if (_drags->active ()) {
_drags->abort ();
}
_history.undo (n);
}
void
CueEditor::do_redo (uint32_t n)
{
if (_drags->active ()) {
_drags->abort ();
}
_history.redo (n);
}

View File

@@ -19,10 +19,12 @@
#ifndef __gtk_ardour_cue_editor_h__
#define __gtk_ardour_cue_editor_h__
#include "pbd/history_owner.h"
#include "editing.h"
#include "editing_context.h"
class CueEditor : public EditingContext
class CueEditor : public EditingContext, public PBD::HistoryOwner
{
public:
CueEditor (std::string const & name);
@@ -97,6 +99,9 @@ class CueEditor : public EditingContext
protected:
void reset_x_origin_to_follow_playhead ();
void do_undo (uint32_t n);
void do_redo (uint32_t n);
};
#endif /* __gtk_ardour_cue_editor_h__ */

View File

@@ -377,6 +377,16 @@ public:
bool on_velocity_scroll_event (GdkEventScroll*);
void pre_render ();
/** Undo some transactions.
* @param n Number of transactions to undo.
*/
void undo (uint32_t n = 1) { do_undo (n); }
/** Redo some transactions.
* @param n Number of transaction to redo.
*/
void redo (uint32_t n = 1) { do_redo (n); }
protected:
std::string _name;
@@ -631,6 +641,9 @@ public:
PBD::ScopedConnection escape_connection;
virtual void escape () {}
virtual void do_undo (uint32_t n) = 0;
virtual void do_redo (uint32_t n) = 0;
private:
static std::stack<EditingContext*> ec_stack;

View File

@@ -180,9 +180,6 @@ public:
}
double trackviews_height () const;
void undo (uint32_t n = 1);
void redo (uint32_t n = 1);
XMLNode& get_state () const;
int set_state (const XMLNode&, int version);
@@ -527,6 +524,9 @@ protected:
RegionSelection region_selection();
void do_undo (uint32_t n);
void do_redo (uint32_t n);
private:
void color_handler ();

View File

@@ -400,11 +400,11 @@ Editor::register_actions ()
reg_sens (editor_actions, "multi-duplicate", _("Multi-Duplicate..."),
sigc::bind (sigc::mem_fun (*this, &Editor::duplicate_range), true));
undo_action = reg_sens (editor_actions, "undo", S_("Command|Undo"), sigc::bind (sigc::mem_fun(*this, &Editor::undo), 1U));
redo_action = reg_sens (editor_actions, "redo", _("Redo"), sigc::bind (sigc::mem_fun(*this, &Editor::redo), 1U));
alternate_redo_action = reg_sens (editor_actions, "alternate-redo", _("Redo"), sigc::bind (sigc::mem_fun(*this, &Editor::redo), 1U));
alternate_alternate_redo_action = reg_sens (editor_actions, "alternate-alternate-redo", _("Redo"), sigc::bind (sigc::mem_fun(*this, &Editor::redo), 1U));
undo_action = reg_sens (editor_actions, "undo", S_("Command|Undo"), []() { current_editing_context()->undo(1U) ; });
redo_action = reg_sens (editor_actions, "redo", _("Redo"), []() { current_editing_context()->redo(1U) ; });
alternate_redo_action = reg_sens (editor_actions, "alternate-redo", _("Redo"), []() { current_editing_context()->redo(1U) ; });
alternate_alternate_redo_action = reg_sens (editor_actions, "alternate-alternate-redo", _("Redo"), []() { current_editing_context()->redo(1U) ; });
selection_undo_action = reg_sens (editor_actions, "undo-last-selection-op", _("Undo Selection Change"), sigc::mem_fun(*this, &Editor::undo_selection_op));
selection_redo_action = reg_sens (editor_actions, "redo-last-selection-op", _("Redo Selection Change"), sigc::mem_fun(*this, &Editor::redo_selection_op));

View File

@@ -145,7 +145,7 @@ using Gtkmm2ext::Keyboard;
***********************************************************************/
void
Editor::undo (uint32_t n)
Editor::do_undo (uint32_t n)
{
if (_session && _session->actively_recording()) {
/* no undo allowed while recording. Session will check also,
@@ -166,7 +166,7 @@ Editor::undo (uint32_t n)
}
void
Editor::redo (uint32_t n)
Editor::do_redo (uint32_t n)
{
if (_session && _session->actively_recording()) {
/* no redo allowed while recording. Session will check also,

View File

@@ -145,17 +145,6 @@ public:
virtual samplepos_t playhead_cursor_sample () const = 0;
/** Undo some transactions.
* @param n Number of transactions to undo.
*/
virtual void undo (uint32_t n = 1) = 0;
/** Redo some transactions.
* @param n Number of transaction to redo.
*/
virtual void redo (uint32_t n = 1) = 0;
/** Possibly start the audition of a region.
*
* If \p r is 0, or not an AudioRegion any current audition is cancelled.