[vlmc-devel] commit: Commands: Avoid an invalid command to be done or undone. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Mon Oct 11 00:07:23 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sun Oct 10 21:29:22 2010 +0200| [7ca710dadb00f4b334eed92c90920f4f1d7f4ea7] | committer: Hugo Beauzée-Luyssen 

Commands: Avoid an invalid command to be done or undone.

Fixes #137

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=7ca710dadb00f4b334eed92c90920f4f1d7f4ea7
---

 src/Commands/Commands.cpp |   51 +++++++++++++++++++++++++++++---------------
 src/Commands/Commands.h   |   42 +++++++++++++++++++-----------------
 2 files changed, 55 insertions(+), 38 deletions(-)

diff --git a/src/Commands/Commands.cpp b/src/Commands/Commands.cpp
index 2738336..dccabd4 100644
--- a/src/Commands/Commands.cpp
+++ b/src/Commands/Commands.cpp
@@ -54,6 +54,7 @@ Commands::Generic::Generic() :
 void
 Commands::Generic::invalidate()
 {
+    setText( tr( "Invalid action" ) );
     m_valid = false;
 }
 
@@ -63,6 +64,20 @@ Commands::Generic::isValid() const
     return m_valid;
 }
 
+void
+Commands::Generic::redo()
+{
+    if ( m_valid == true )
+        internalRedo();
+}
+
+void
+Commands::Generic::undo()
+{
+    if ( m_valid == true )
+        internalUndo();
+}
+
 Commands::Clip::Add::Add( ClipHelper* ch, TrackWorkflow* tw, qint64 pos ) :
         m_clipHelper( ch ),
         m_trackWorkflow( tw ),
@@ -76,12 +91,12 @@ Commands::Clip::Add::~Add()
 {
 }
 
-void Commands::Clip::Add::redo()
+void Commands::Clip::Add::internalRedo()
 {
     m_trackWorkflow->addClip( m_clipHelper, m_pos );
 }
 
-void Commands::Clip::Add::undo()
+void Commands::Clip::Add::internalUndo()
 {
     m_trackWorkflow->removeClip( m_clipHelper->uuid() );
 }
@@ -105,7 +120,7 @@ Commands::Clip::Move::Move( TrackWorkflow *oldTrack, TrackWorkflow *newTrack,
     m_oldPos = oldTrack->getClipPosition( clipHelper->uuid() );
 }
 
-void Commands::Clip::Move::redo()
+void Commands::Clip::Move::internalRedo()
 {
     if ( m_newTrack != m_oldTrack )
     {
@@ -116,7 +131,7 @@ void Commands::Clip::Move::redo()
         m_oldTrack->moveClip( m_clipHelper->uuid(), m_newPos );
 }
 
-void Commands::Clip::Move::undo()
+void Commands::Clip::Move::internalUndo()
 {
     if ( m_newTrack != m_oldTrack )
     {
@@ -135,12 +150,12 @@ Commands::Clip::Remove::Remove( ClipHelper* ch, TrackWorkflow* tw ) :
     m_pos = tw->getClipPosition( ch->uuid() );
 }
 
-void Commands::Clip::Remove::redo()
+void Commands::Clip::Remove::internalRedo()
 {
     m_trackWorkflow->removeClip( m_clipHelper->uuid() );
 }
 
-void Commands::Clip::Remove::undo()
+void Commands::Clip::Remove::internalUndo()
 {
     m_trackWorkflow->addClip( m_clipHelper, m_pos );
 }
@@ -160,7 +175,7 @@ Commands::Clip::Resize::Resize( TrackWorkflow* tw, ClipHelper* ch, qint64 newBeg
     setText( QObject::tr( "Resizing clip" ) );
 }
 
-void Commands::Clip::Resize::redo()
+void Commands::Clip::Resize::internalRedo()
 {
     if ( m_newBegin != m_newEnd )
     {
@@ -169,7 +184,7 @@ void Commands::Clip::Resize::redo()
     m_clipHelper->setBoundaries( m_newBegin, m_newEnd );
 }
 
-void Commands::Clip::Resize::undo()
+void Commands::Clip::Resize::internalUndo()
 {
     if ( m_oldBegin != m_newBegin )
     {
@@ -197,7 +212,7 @@ Commands::Clip::Split::~Split()
     delete m_newClip;
 }
 
-void    Commands::Clip::Split::redo()
+void    Commands::Clip::Split::internalRedo()
 {
     //If we don't remove 1, the clip will end exactly at the starting frame (ie. they will
     //be rendering at the same time)
@@ -205,7 +220,7 @@ void    Commands::Clip::Split::redo()
     m_trackWorkflow->addClip( m_newClip, m_newClipPos );
 }
 
-void    Commands::Clip::Split::undo()
+void    Commands::Clip::Split::internalUndo()
 {
     m_trackWorkflow->removeClip( m_newClip->uuid() );
     m_toSplit->setEnd( m_oldEnd );
@@ -219,13 +234,13 @@ Commands::Effect::Add::Add( EffectHelper *helper, EffectUser *target ) :
 }
 
 void
-Commands::Effect::Add::redo()
+Commands::Effect::Add::internalRedo()
 {
     m_target->addEffect( m_helper );
 }
 
 void
-Commands::Effect::Add::undo()
+Commands::Effect::Add::internalUndo()
 {
     m_target->removeEffect( m_helper );
 }
@@ -244,7 +259,7 @@ Commands::Effect::Move::Move( EffectHelper *helper, EffectUser *old, EffectUser
 }
 
 void
-Commands::Effect::Move::redo()
+Commands::Effect::Move::internalRedo()
 {
     if ( m_old != m_new )
     {
@@ -258,7 +273,7 @@ Commands::Effect::Move::redo()
 }
 
 void
-Commands::Effect::Move::undo()
+Commands::Effect::Move::internalUndo()
 {
     if ( m_old != m_new )
     {
@@ -283,7 +298,7 @@ Commands::Effect::Resize::Resize( EffectUser *target, EffectHelper *helper, qint
 }
 
 void
-Commands::Effect::Resize::redo()
+Commands::Effect::Resize::internalRedo()
 {
     if ( m_newBegin != m_oldBegin )
         m_target->moveEffect( m_helper, m_newBegin );
@@ -291,7 +306,7 @@ Commands::Effect::Resize::redo()
 }
 
 void
-Commands::Effect::Resize::undo()
+Commands::Effect::Resize::internalUndo()
 {
     if ( m_oldBegin != m_newBegin )
         m_target->moveEffect( m_helper, m_oldBegin );
@@ -306,13 +321,13 @@ Commands::Effect::Remove::Remove( EffectHelper *helper, EffectUser *user ) :
 }
 
 void
-Commands::Effect::Remove::redo()
+Commands::Effect::Remove::internalRedo()
 {
     m_user->removeEffect( m_helper );
 }
 
 void
-Commands::Effect::Remove::undo()
+Commands::Effect::Remove::internalUndo()
 {
     m_user->addEffect( m_helper );
 }
diff --git a/src/Commands/Commands.h b/src/Commands/Commands.h
index 983383a..252311f 100644
--- a/src/Commands/Commands.h
+++ b/src/Commands/Commands.h
@@ -51,8 +51,10 @@ namespace Commands
 
         public:
             Generic();
-            virtual void    redo() = 0;
-            virtual void    undo() = 0;
+            virtual void    internalRedo() = 0;
+            virtual void    internalUndo() = 0;
+            void            redo();
+            void            undo();
             bool            isValid() const;
         private:
             bool            m_valid;
@@ -78,8 +80,8 @@ namespace Commands
             public:
                 Add( ClipHelper* ch, TrackWorkflow* tw, qint64 pos );
                 virtual ~Add();
-                virtual void    redo();
-                virtual void    undo();
+                virtual void    internalRedo();
+                virtual void    internalUndo();
             private:
                 ClipHelper                  *m_clipHelper;
                 TrackWorkflow               *m_trackWorkflow;
@@ -91,8 +93,8 @@ namespace Commands
             public:
                 Move( TrackWorkflow *oldTrack, TrackWorkflow *newTrack,
                         ClipHelper *clipHelper, qint64 newPos );
-                virtual void    redo();
-                virtual void    undo();
+                virtual void    internalRedo();
+                virtual void    internalUndo();
 
             private:
                 TrackWorkflow   *m_oldTrack;
@@ -106,8 +108,8 @@ namespace Commands
         {
             public:
                 Remove( ClipHelper* clip, TrackWorkflow* tw );
-                virtual void redo();
-                virtual void undo();
+                virtual void internalRedo();
+                virtual void internalUndo();
 
             private:
                 ClipHelper                  *m_clipHelper;
@@ -127,8 +129,8 @@ namespace Commands
             public:
                 Resize( TrackWorkflow* tw, ClipHelper* clipHelper,
                             qint64 newBegin, qint64 newEnd, qint64 newPos );
-                virtual void    redo();
-                virtual void    undo();
+                virtual void    internalRedo();
+                virtual void    internalUndo();
             private:
                 TrackWorkflow*              m_trackWorkflow;
                 ClipHelper*                 m_clipHelper;
@@ -146,8 +148,8 @@ namespace Commands
                 Split( TrackWorkflow *tw, ClipHelper* toSplit, qint64 newClipPos,
                            qint64 newClipBegin );
                 ~Split();
-                virtual void    redo();
-                virtual void    undo();
+                virtual void    internalRedo();
+                virtual void    internalUndo();
             private:
                 TrackWorkflow               *m_trackWorkflow;
                 ClipHelper*                 m_toSplit;
@@ -163,8 +165,8 @@ namespace Commands
         {
             public:
                 Add( EffectHelper *helper, EffectUser *target );
-                virtual void    redo();
-                virtual void    undo();
+                virtual void    internalRedo();
+                virtual void    internalUndo();
             private:
                 EffectHelper    *m_helper;
                 EffectUser      *m_target;
@@ -174,8 +176,8 @@ namespace Commands
         {
             public:
                 Move( EffectHelper *helper, EffectUser *old, EffectUser *newUser, qint64 pos );
-                virtual void    redo();
-                virtual void    undo();
+                virtual void    internalRedo();
+                virtual void    internalUndo();
             private:
                 EffectHelper    *m_helper;
                 EffectUser      *m_old;
@@ -190,8 +192,8 @@ namespace Commands
         {
             public:
                 Resize( EffectUser *target, EffectHelper *helper, qint64 newBegin, qint64 newEnd );
-                virtual void        redo();
-                virtual void        undo();
+                virtual void        internalRedo();
+                virtual void        internalUndo();
             private:
                 EffectUser          *m_target;
                 EffectHelper        *m_helper;
@@ -205,8 +207,8 @@ namespace Commands
         {
             public:
                 Remove( EffectHelper *helper, EffectUser *user );
-                virtual void    redo();
-                virtual void    undo();
+                virtual void    internalRedo();
+                virtual void    internalUndo();
             private:
                 EffectHelper    *m_helper;
                 EffectUser      *m_user;



More information about the Vlmc-devel mailing list