26#include "karbon_part.h"
30 : m_part( part ), m_undoLimit( 50 ), m_redoLimit( 30 ), m_savedPos( 0 )
32 m_commands.setAutoDelete(
true );
34 m_undo = KStdAction::undo(
this, TQ_SLOT(
undo() ), m_part->actionCollection(),
"koffice_undo" );
35 m_redo = KStdAction::redo(
this, TQ_SLOT(
redo() ), m_part->actionCollection(),
"koffice_redo" );
47 if( m_savedPos !=
int( m_commands.count() - 1 ) )
58 m_undo->setEnabled(
false );
59 m_undo->setText( i18n(
"&Undo" ) );
64 m_redo->setEnabled(
false );
65 m_redo->setText( i18n(
"&Redo" ) );
75 if( !m_commands.isEmpty() )
77 while( m_commands.last() && !m_commands.last()->success() )
79 m_commands.removeLast();
84 m_commands.append( command );
85 kdDebug(38000) <<
"History: new command: " << m_commands.findRef( command ) << endl;
115 int i = m_commands.count() - 1;
120 while( ( i >= 0 ) && !( m_commands.at( i )->success() ) )
140 m_part->repaintAllViews();
146 int i = m_commands.count() - 1;
151 while( ( i >= 0 ) && !( m_commands.at( i )->success() ) )
158 if( i >=
int( m_commands.count() ) )
163 if( ( cmd = m_commands.at( i ) ) == 0L )
173 m_part->repaintAllViews();
179 if( ( m_commands.findRef( command ) == -1 ) || ( !command->
success() ) )
189 m_part->repaintAllViews();
195 if( ( m_commands.findRef( command ) == -1 ) || ( command->
success() ) )
205 m_part->repaintAllViews();
213 if( ( to = m_commands.findRef( command ) ) == -1 )
216 int i = m_commands.count() - 1;
222 cmd = m_commands.at( i-- );
234 m_part->repaintAllViews();
242 if( ( to = m_commands.findRef( command ) ) == -1 )
251 cmd = m_commands.at( i++ );
263 m_part->repaintAllViews();
271 int i = m_commands.count() - 1;
273 while( ( i >= 0 ) && !( m_commands.at( i )->success() ) )
284VCommandHistory::clipCommands()
286 while( m_commands.count() > m_undoLimit )
288 if( m_commands.removeFirst() )
294 int c = m_commands.count();
296 while( ( i < c ) && ( !m_commands.at( c - 1 - i )->success() ) )
303 for(
int j = 0; j < i; j++ )
305 if( m_commands.removeLast() )
311VCommandHistory::updateActions()
313 if( m_commands.count() == 0 )
317 m_undo->setEnabled(
false );
318 m_undo->setText( i18n(
"&Undo" ) );
323 m_redo->setEnabled(
false );
324 m_redo->setText( i18n(
"&Redo" ) );
330 int i = m_commands.count() - 1;
332 while( ( i >= 0 ) && !( m_commands.at( i )->success() ) )
341 m_undo->setEnabled(
false );
342 m_undo->setText( i18n(
"&Undo" ) );
346 m_undo->setEnabled(
true );
347 m_undo->setText( i18n(
"&Undo: " ) + m_commands.at( i )->name() );
353 if( ++i ==
int( m_commands.count() ) )
355 m_redo->setEnabled(
false );
356 m_redo->setText( i18n(
"&Redo" ) );
360 m_redo->setEnabled(
true );
361 m_redo->setText( i18n(
"&Redo: " ) + m_commands.at( i )->name() );
365 if( m_savedPos >= 0 )
367 for( i = 0; i < m_savedPos; i++ )
369 if( !m_commands.at( i )->success() )
373 for( i = m_savedPos; i < int( m_commands.count() ); i++ )
375 if( m_commands.at( i )->success() )
383#include "vcommand.moc"
Keeps track of visual per document properties.
void historyCleared()
This signal is emitted when the command history gets cleared.
VCommandHistory(KarbonPart *part)
Constructs a command history.
void setUndoLimit(unsigned int limit)
Sets a new undo limit.
void documentRestored()
This signal is emitted when the actual document state matches the last saved one.
void clear()
Clears the command history by removing all commands.
void addCommand(VCommand *command, bool execute=true)
Adds a new command to the history.
void undo()
Undoes the last command not already undone.
void redo()
Redoes the last command not already undone.
void setRedoLimit(unsigned int limit)
Sets a new redo limit.
void commandAdded(VCommand *)
This signal is emitted when a command is added to the history.
void lastCommandRemoved()
This signal is emitted when the last (latest) command is removed.
void redoAllTo(VCommand *command)
Redoes all command up to the specified command.
void undoAllTo(VCommand *command)
Undoes all command up to the specified command.
void firstCommandRemoved()
This signal is emitted when the first (oldest) command is removed.
void commandExecuted()
This signal is emitted when a command is executed.
void documentSaved()
Marks the actual document state as saved.
~VCommandHistory()
Destroys the command history.
The base class for all karbon commands.
virtual void unexecute()
Unexecutes the command.
virtual void execute()=0
Executes the command.
bool success() const
Return if the operation was a success or not.