[Libreoffice-commits] core.git: editeng/source include/editeng sw/qa

Miklos Vajna vmiklos at collabora.co.uk
Tue Aug 2 17:33:48 UTC 2016


 editeng/source/editeng/editundo.cxx            |   11 ++++++++
 editeng/source/editeng/impedit.cxx             |    5 ++++
 editeng/source/editeng/impedit.hxx             |    1 
 include/editeng/editund2.hxx                   |    3 ++
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   31 +++++++++++++++++++++++++
 5 files changed, 50 insertions(+), 1 deletion(-)

New commits:
commit b567278c4aa6e3dee331b60c71eb996babcc9d08
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Aug 2 17:52:44 2016 +0200

    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 at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/editeng/source/editeng/editundo.cxx b/editeng/source/editeng/editundo.cxx
index faea53b..62d7e3f 100644
--- a/editeng/source/editeng/editundo.cxx
+++ b/editeng/source/editeng/editundo.cxx
@@ -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),
diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx
index b3cf784..13a53ac 100644
--- a/editeng/source/editeng/impedit.cxx
+++ b/editeng/source/editeng/impedit.cxx
@@ -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
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx
index 4dd3356..cc7362e 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -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();
diff --git a/include/editeng/editund2.hxx b/include/editeng/editund2.hxx
index 449c4ad..c6914d3 100644
--- a/include/editeng/editund2.hxx
+++ b/include/editeng/editund2.hxx
@@ -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;
 };
 
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 79d3e18..cfb1cbe 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -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();


More information about the Libreoffice-commits mailing list