diff options
author | Armin Le Grand <alg@apache.org> | 2012-08-09 08:42:27 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-05-28 15:55:23 +0100 |
commit | 12a4200e8ff7f045efcc7e9d15a24b15b248c437 (patch) | |
tree | 00363aedf07713ec9ff931d933b86a6b35e20267 /svx | |
parent | 64b07d99aa0b31b3d04519afe6afe0cdf36bcd6f (diff) |
Related: #i120498# Enhanced Undo/Redo and user experience...
when editing texts in graphic objects and/or tables
(cherry picked from commit a096725779b210c7a2706e72596fd7c80e049fdd)
Conflicts:
editeng/inc/editeng/editeng.hxx
editeng/inc/editeng/editund2.hxx
editeng/inc/editeng/outliner.hxx
editeng/source/editeng/editundo.cxx
editeng/source/editeng/impedit.hxx
editeng/source/outliner/outliner.cxx
sd/source/core/undo/undomanager.cxx
sd/source/ui/view/drviewse.cxx
svx/Library_svxcore.mk
svx/Package_inc.mk
svx/inc/svx/svdedxv.hxx
svx/source/svdraw/svdedxv.cxx
Change-Id: I40e3ef2dff681f9b6f2f6b5d35507071f8110533
Comment unused variable pNewEditUndoManager to silence the compiler
(cherry picked from commit 568655083af7830e7b9edf56ef862ddf9a99003b)
Change-Id: Ib7179ee6c34ce03a75942978831c3a55968f161f
Removed unused variable
(cherry picked from commit 0bbde4414badfd40234de4a4c9f750194f5d1d5e)
Change-Id: I39e7f25426e8e7d1367102d603b0f6c84d96622f
Diffstat (limited to 'svx')
-rw-r--r-- | svx/Library_svxcore.mk | 1 | ||||
-rw-r--r-- | svx/source/svdraw/sdrundomanager.cxx | 109 | ||||
-rw-r--r-- | svx/source/svdraw/svdedxv.cxx | 83 |
3 files changed, 191 insertions, 2 deletions
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index 94fbf167f8fd..21a03bf47a18 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -254,6 +254,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\ svx/source/svdraw/sdrmasterpagedescriptor \ svx/source/svdraw/sdrpagewindow \ svx/source/svdraw/sdrpaintwindow \ + svx/source/svdraw/sdrundomanager \ svx/source/svdraw/selectioncontroller \ svx/source/svdraw/svdattr \ svx/source/svdraw/svdcrtv \ diff --git a/svx/source/svdraw/sdrundomanager.cxx b/svx/source/svdraw/sdrundomanager.cxx new file mode 100644 index 000000000000..88e0c6c6c5d0 --- /dev/null +++ b/svx/source/svdraw/sdrundomanager.cxx @@ -0,0 +1,109 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <svx/sdrundomanager.hxx> + +////////////////////////////////////////////////////////////////////////////// + +SdrUndoManager::SdrUndoManager(sal_uInt16 nMaxUndoActionCount) +: EditUndoManager(nMaxUndoActionCount), + maEndTextEditHdl(), + mpLastUndoActionBeforeTextEdit(0) +{ +} + +SdrUndoManager::~SdrUndoManager() +{ +} + +sal_Bool SdrUndoManager::Undo() +{ + sal_Bool bRetval(sal_False); + + if(maEndTextEditHdl.IsSet()) + { + // we are in text edit mode + if(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0)) + { + // there is an undo action for text edit, trigger it + bRetval = EditUndoManager::Undo(); + } + else + { + // no more text edit undo, end text edit + maEndTextEditHdl.Call(this); + } + } + + if(!bRetval && GetUndoActionCount()) + { + // no undo triggered up to now, trigger local one + bRetval = SfxUndoManager::Undo(); + } + + return bRetval; +} + +sal_Bool SdrUndoManager::Redo() +{ + sal_Bool bRetval(sal_False); + + if(maEndTextEditHdl.IsSet()) + { + // we are in text edit mode + bRetval = EditUndoManager::Redo(); + } + + if(!bRetval) + { + // no redo triggered up to now, trigger local one + bRetval = SfxUndoManager::Redo(); + } + + return bRetval; +} + +void SdrUndoManager::SetEndTextEditHdl(const Link& rLink) +{ + maEndTextEditHdl = rLink; + + if(maEndTextEditHdl.IsSet()) + { + // text edit start, remember last non-textedit action for later cleanup + mpLastUndoActionBeforeTextEdit = GetUndoActionCount() ? GetUndoAction(0) : 0; + } + else + { + // text edit ends, pop all textedit actions up to the remembered non-textedit action from the start + // to set back the UndoManager to the state before text edit started. If that action is already gone + // (due to being removed from the undo stack in the meantime), all need to be removed anyways + while(GetUndoActionCount() && mpLastUndoActionBeforeTextEdit != GetUndoAction(0)) + { + RemoveLastUndoAction(); + } + + // urgently needed: RemoveLastUndoAction does NOT correct the Redo stack by itself (!) + ClearRedo(); + + // forget marker again + mpLastUndoActionBeforeTextEdit = 0; + } +} + +////////////////////////////////////////////////////////////////////////////// +// eof diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx index 6134278eddb8..6a5e571269bc 100644 --- a/svx/source/svdraw/svdedxv.cxx +++ b/svx/source/svdraw/svdedxv.cxx @@ -63,6 +63,7 @@ #include <svtools/colorcfg.hxx> #include <vcl/svapp.hxx> #include <svx/sdrpaintwindow.hxx> +#include <svx/sdrundomanager.hxx> //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -87,7 +88,8 @@ void SdrObjEditView::ImpClearVars() } SdrObjEditView::SdrObjEditView(SdrModel* pModel1, OutputDevice* pOut): - SdrGlueEditView(pModel1,pOut) + SdrGlueEditView(pModel1,pOut), + mpOldTextEditUndoManager(0) { ImpClearVars(); } @@ -95,8 +97,10 @@ SdrObjEditView::SdrObjEditView(SdrModel* pModel1, OutputDevice* pOut): SdrObjEditView::~SdrObjEditView() { pTextEditWin = NULL; // so there's no ShowCursor in SdrEndTextEdit - if (IsTextEdit()) SdrEndTextEdit(); + if (IsTextEdit()) + SdrEndTextEdit(); delete pTextEditOutliner; + delete mpOldTextEditUndoManager; } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -516,6 +520,12 @@ IMPL_LINK(SdrObjEditView,ImpOutlinerCalcFieldValueHdl,EditFieldInfo*,pFI) return 0; } +IMPL_LINK(SdrObjEditView, EndTextEditHdl, SdrUndoManager*, /*pUndoManager*/) +{ + SdrEndTextEdit(); + return 0; +} + sal_Bool SdrObjEditView::SdrBeginTextEdit( SdrObject* pObj, SdrPageView* pPV, Window* pWin, sal_Bool bIsNewObj, SdrOutliner* pGivenOutliner, @@ -742,6 +752,31 @@ sal_Bool SdrObjEditView::SdrBeginTextEdit( if( mxSelectionController.is() ) mxSelectionController->onSelectionHasChanged(); + if(IsUndoEnabled()) + { + SdrUndoManager* pSdrUndoManager = dynamic_cast< SdrUndoManager* >(GetModel()->GetSdrUndoManager()); + + if(pSdrUndoManager) + { + // we have an outliner, undo manager and it's an EditUndoManager, exchange + // the document undo manager and the default one from the outliner and tell + // it that text edit starts by setting a callback if it needs to end text edit mode. + if(mpOldTextEditUndoManager) + { + // should not happen, delete it + delete mpOldTextEditUndoManager; + mpOldTextEditUndoManager = 0; + } + + mpOldTextEditUndoManager = pTextEditOutliner->SetUndoManager(pSdrUndoManager); + pSdrUndoManager->SetEndTextEditHdl(LINK(this, SdrObjEditView, EndTextEditHdl)); + } + else + { + OSL_ENSURE(false, "The document undo manager is not derived from SdrUndoManager (!)"); + } + } + return sal_True; // ran fine, let TextEdit run now } else @@ -795,6 +830,42 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(sal_Bool bDontDeleteReally) SdrOutliner* pTEOutliner =pTextEditOutliner; OutlinerView* pTEOutlinerView=pTextEditOutlinerView; Cursor* pTECursorMerker=pTextEditCursorMerker; + SdrUndoManager* pExtraUndoEditUndoManager = 0; + + if(IsUndoEnabled() && GetModel() && pTEObj && pTEOutliner) + { + // change back the UndoManager to the remembered original one + ::svl::IUndoManager* pOriginal = pTEOutliner->SetUndoManager(mpOldTextEditUndoManager); + mpOldTextEditUndoManager = 0; + + if(pOriginal) + { + // check if we got back our document undo manager + SdrUndoManager* pSdrUndoManager = dynamic_cast< SdrUndoManager* >(GetModel()->GetSdrUndoManager()); + + if(pSdrUndoManager && dynamic_cast< SdrUndoManager* >(pOriginal) == pSdrUndoManager) + { + // We are ending text edit; execute all redos to create a complete text change + // undo action for the redo buffer. Also mark this state when at least one redo was + // executed; the created TextChange needs to be undone plus the first real undo + // outside the text edit changes + while(pSdrUndoManager->GetRedoActionCount()) + { + pExtraUndoEditUndoManager = pSdrUndoManager; + pSdrUndoManager->Redo(); + } + + // reset the callback link and let the undo manager cleanup all text edit + // undo actions to get the stack back to the form before the text edit + pSdrUndoManager->SetEndTextEditHdl(Link()); + } + else + { + OSL_ENSURE(false, "Got UndoManager back in SdrEndTextEdit which is NOT the expected document UndoManager (!)"); + delete pOriginal; + } + } + } if( GetModel() && mxTextEditObj.is() ) { @@ -988,6 +1059,14 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(sal_Bool bDontDeleteReally) ((SfxBroadcaster*)pTEObj->GetBroadcaster())->Broadcast(aHint); } + if(pExtraUndoEditUndoManager) + { + // undo the text edit action since it was created as part of a EndTextEdit + // callback from undo itself. This needs to be done after the call to + // FmFormView::SdrEndTextEdit since it gets created there + pExtraUndoEditUndoManager->Undo(); + } + return eRet; } |