26 #include "undostack.h"
28 #include "kmmainwin.h"
30 #include "kmmsgdict.h"
32 #include <tdemessagebox.h>
33 #include <tdelocale.h>
38 UndoStack::UndoStack(
int size)
39 : TQObject(0,
"undostack"), mSize(size), mLastId(0),
42 mStack.setAutoDelete(
true);
45 void UndoStack::clear()
52 UndoInfo *info =
new UndoInfo;
54 info->srcFolder = srcFolder;
55 info->destFolder = destFolder;
56 if ((
int) mStack.count() == mSize)
58 mStack.prepend( info );
59 emit undoStackChanged();
63 void UndoStack::addMsgToAction(
int undoId, ulong serNum )
65 if ( !mCachedInfo || mCachedInfo->id != undoId ) {
66 TQPtrListIterator<UndoInfo> itr( mStack );
67 while ( itr.current() ) {
68 if ( itr.current()->id == undoId ) {
69 mCachedInfo = itr.current();
76 Q_ASSERT( mCachedInfo );
77 mCachedInfo->serNums.append( serNum );
80 void UndoStack::undo()
86 if ( mStack.count() > 0 )
88 UndoInfo *info = mStack.
take(0);
89 emit undoStackChanged();
90 TQValueList<ulong>::iterator itr;
92 for( itr = info->serNums.begin(); itr != info->serNums.end(); ++itr ) {
95 if ( idx == -1 || curFolder != info->destFolder ) {
96 kdDebug(5006)<<
"Serious undo error!"<<endl;
100 msg = curFolder->
getMsg( idx );
101 info->srcFolder->moveMsg( msg );
102 if ( info->srcFolder->count() > 1 )
103 info->srcFolder->unGetMsg( info->srcFolder->count() - 1 );
110 KMessageBox::sorry( kmkernel->mainWin(), i18n(
"There is nothing to undo."));
115 UndoStack::pushSingleAction(ulong serNum,
KMFolder *folder,
KMFolder *destFolder)
117 int id = newUndoAction( folder, destFolder );
118 addMsgToAction(
id, serNum );
122 UndoStack::msgDestroyed( KMMsgBase* )
139 UndoStack::folderDestroyed(
KMFolder *folder)
141 for( UndoInfo *info = mStack.first(); info; )
143 if ( (info->srcFolder == folder) ||
144 (info->destFolder == folder) )
146 mStack.removeRef( info );
147 info = mStack.current();
150 info = mStack.next();
152 emit undoStackChanged();
157 #include "undostack.moc"
RAII for KMFolder::open() / close().
KMMessage * take(int idx)
Detach message from this folder.
KMMessage * getMsg(int idx)
Read message at given index.
void getLocation(unsigned long key, KMFolder **retFolder, int *retIndex) const
Returns the folder the message represented by the serial number key is in and the index in that folde...
static const KMMsgDict * instance()
Access the globally unique MessageDict.