editeng: implement SfxUndoAction::GetViewShellId() interface in EditUndo
With this, e.g. inserting a character in a Writer shape text remembers its view shell. Change-Id: Ic82a3f45a66cf622496e3131390d365440dffb3b Reviewed-on: https://gerrit.libreoffice.org/27796 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
This commit is contained in:
@@ -118,8 +118,12 @@ bool EditUndoManager::Redo()
|
||||
}
|
||||
|
||||
EditUndo::EditUndo(sal_uInt16 nI, EditEngine* pEE) :
|
||||
nId(nI), mpEditEngine(pEE)
|
||||
nId(nI), mnViewShellId(-1), mpEditEngine(pEE)
|
||||
{
|
||||
const EditView* pEditView = mpEditEngine ? mpEditEngine->GetActiveView() : nullptr;
|
||||
const OutlinerViewShell* pViewShell = pEditView ? pEditView->GetImpEditView()->GetViewShell() : nullptr;
|
||||
if (pViewShell)
|
||||
mnViewShellId = pViewShell->GetViewShellId();
|
||||
}
|
||||
|
||||
EditUndo::~EditUndo()
|
||||
@@ -147,6 +151,11 @@ OUString EditUndo::GetComment() const
|
||||
return aComment;
|
||||
}
|
||||
|
||||
sal_Int32 EditUndo::GetViewShellId() const
|
||||
{
|
||||
return mnViewShellId;
|
||||
}
|
||||
|
||||
EditUndoDelContent::EditUndoDelContent(
|
||||
EditEngine* pEE, ContentNode* pNode, sal_Int32 nPortion) :
|
||||
EditUndo(EDITUNDO_DELCONTENT, pEE),
|
||||
|
@@ -122,6 +122,11 @@ void ImpEditView::RegisterViewShell(OutlinerViewShell* pViewShell)
|
||||
mpViewShell = pViewShell;
|
||||
}
|
||||
|
||||
const OutlinerViewShell* ImpEditView::GetViewShell() const
|
||||
{
|
||||
return mpViewShell;
|
||||
}
|
||||
|
||||
void ImpEditView::SetEditSelection( const EditSelection& rEditSelection )
|
||||
{
|
||||
// set state before notification
|
||||
|
@@ -369,6 +369,7 @@ public:
|
||||
|
||||
/// Informs this edit view about which view shell contains it.
|
||||
void RegisterViewShell(OutlinerViewShell* pViewShell);
|
||||
const OutlinerViewShell* GetViewShell() const;
|
||||
|
||||
bool IsWrongSpelledWord( const EditPaM& rPaM, bool bMarkIfWrong );
|
||||
OUString SpellIgnoreWord();
|
||||
|
@@ -47,6 +47,7 @@ class EDITENG_DLLPUBLIC EditUndo : public SfxUndoAction
|
||||
{
|
||||
private:
|
||||
sal_uInt16 nId;
|
||||
sal_Int32 mnViewShellId;
|
||||
EditEngine* mpEditEngine;
|
||||
|
||||
public:
|
||||
@@ -60,6 +61,8 @@ public:
|
||||
|
||||
virtual bool CanRepeat(SfxRepeatTarget&) const override;
|
||||
virtual OUString GetComment() const override;
|
||||
/// See SfxUndoAction::GetViewShellId().
|
||||
sal_Int32 GetViewShellId() const override;
|
||||
virtual sal_uInt16 GetId() const override;
|
||||
};
|
||||
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include <ndtxt.hxx>
|
||||
#include <wrtsh.hxx>
|
||||
#include <view.hxx>
|
||||
#include <UndoManager.hxx>
|
||||
#include <sfx2/viewsh.hxx>
|
||||
#include <sfx2/lokhelper.hxx>
|
||||
|
||||
@@ -59,6 +60,7 @@ public:
|
||||
void testViewLock();
|
||||
void testTextEditViewInvalidations();
|
||||
void testUndoInvalidations();
|
||||
void testShapeTextUndoShells();
|
||||
|
||||
CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
|
||||
CPPUNIT_TEST(testRegisterCallback);
|
||||
@@ -84,6 +86,7 @@ public:
|
||||
CPPUNIT_TEST(testViewLock);
|
||||
CPPUNIT_TEST(testTextEditViewInvalidations);
|
||||
CPPUNIT_TEST(testUndoInvalidations);
|
||||
CPPUNIT_TEST(testShapeTextUndoShells);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
@@ -890,6 +893,34 @@ void SwTiledRenderingTest::testUndoInvalidations()
|
||||
comphelper::LibreOfficeKit::setActive(false);
|
||||
}
|
||||
|
||||
void SwTiledRenderingTest::testShapeTextUndoShells()
|
||||
{
|
||||
// Load a document and create a view.
|
||||
comphelper::LibreOfficeKit::setActive();
|
||||
SwXTextDocument* pXTextDocument = createDoc("shape.fodt");
|
||||
sal_Int32 nView1 = SfxLokHelper::getView();
|
||||
|
||||
// Begin text edit.
|
||||
SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
|
||||
SdrPage* pPage = pWrtShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
|
||||
SdrObject* pObject = pPage->GetObj(0);
|
||||
SdrView* pView = pWrtShell->GetDrawView();
|
||||
pWrtShell->GetView().BeginTextEdit(pObject, pView->GetSdrPageView(), pWrtShell->GetWin());
|
||||
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
|
||||
pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
|
||||
|
||||
// Make sure that the undo item remembers who created it.
|
||||
SwDoc* pDoc = pXTextDocument->GetDocShell()->GetDoc();
|
||||
sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rUndoManager.GetUndoActionCount());
|
||||
// This was -1: the view shell id for the undo action wasn't known.
|
||||
CPPUNIT_ASSERT_EQUAL(nView1, rUndoManager.GetUndoAction()->GetViewShellId());
|
||||
|
||||
mxComponent->dispose();
|
||||
mxComponent.clear();
|
||||
comphelper::LibreOfficeKit::setActive(false);
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
Reference in New Issue
Block a user