From 12fa15af1f59168ccee04bd28b51de1f6832eee7 Mon Sep 17 00:00:00 2001 From: Allen Winter Date: Mon, 5 Mar 2007 22:25:33 +0000 Subject: [PATCH] merge SVN commit 633860 by adridg: When the message is set to a composer with a specific cursor position, (ie. not 0, eg. from a template containing %CURSOR) then don't reset the cursor position when appending the signature. This makes it possible to use %CURSOR to place the cursor anywhere in a template. Useful for reply templates, at any rate. svn path=/branches/KDE/3.5/kdepim/; revision=639750 --- kmcomposewin.cpp | 18 ++++++++++++++++-- kmcomposewin.h | 9 +++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/kmcomposewin.cpp b/kmcomposewin.cpp index f5d4195ce..16b46d493 100644 --- a/kmcomposewin.cpp +++ b/kmcomposewin.cpp @@ -176,7 +176,8 @@ KMComposeWin::KMComposeWin( KMMessage *aMsg, uint id ) mEncryptWithChiasmus( false ), mComposer( 0 ), mLabelWidth( 0 ), - mAutoSaveTimer( 0 ), mLastAutoSaveErrno( 0 ) + mAutoSaveTimer( 0 ), mLastAutoSaveErrno( 0 ), + mPreserveUserCursorPosition( false ) { mClassicalRecipients = GlobalSettings::self()->recipientsEditorType() == GlobalSettings::EnumRecipientsEditorType::Classic; @@ -1973,6 +1974,12 @@ void KMComposeWin::setMsg(KMMessage* newMsg, bool mayAutoSign, // QTimer::singleShot( 200, this, SLOT(slotAppendSignature()) ); } + + if ( mMsg->getCursorPos() > 0 ) { + // The message has a cursor position explicitly set, so avoid + // changing it when appending the signature. + mPreserveUserCursorPosition = true; + } setModified( isModified ); // do this even for new messages @@ -4049,7 +4056,14 @@ void KMComposeWin::slotAppendSignature() mEditor->append(mOldSigText); mEditor->setModified(mod); // mEditor->setContentsPos( 0, 0 ); - mEditor->setCursorPositionFromStart( (unsigned int) mMsg->getCursorPos() ); + if ( mPreserveUserCursorPosition ) { + mEditor->setCursorPositionFromStart( (unsigned int) mMsg->getCursorPos() ); + // Only keep the cursor from the mMsg *once* based on the + // preserve-cursor-position setting; this handles the case where + // the message comes from a template with a specific cursor + // position set and the signature is appended automatically. + mPreserveUserCursorPosition = false; + } mEditor->sync(); } } diff --git a/kmcomposewin.h b/kmcomposewin.h index 5f06f02d6..a40809b47 100644 --- a/kmcomposewin.h +++ b/kmcomposewin.h @@ -838,6 +838,15 @@ private: QPopupMenu *mActNowMenu; QPopupMenu *mActLaterMenu; + + /** If the message in this composer has a cursor position set (for + * instance because it comes from a template containing %CURSOR) + * then we need to preserve that cursor position even when auto- + * appending (or prepending) the signature during composer setup. + * Set to true *once* (and only in setMsg() at that) to avoid + * accidentally moving the cursor. + */ + bool mPreserveUserCursorPosition; }; #endif