[Libreoffice-commits] core.git: sc/qa sc/source sfx2/source

Henry Castro hcastro at collabora.com
Wed Jun 28 18:50:00 UTC 2017


 sc/qa/unit/tiledrendering/tiledrendering.cxx |   67 +++++++++++++++++++++++++++
 sc/source/ui/view/tabvwshb.cxx               |    3 +
 sfx2/source/view/viewfrm.cxx                 |   26 +++++++++-
 3 files changed, 94 insertions(+), 2 deletions(-)

New commits:
commit 0ac92837d31c4065be4a41e2a2541811c9f6be00
Author: Henry Castro <hcastro at collabora.com>
Date:   Wed Jun 28 10:26:21 2017 -0400

    sc lok: disable Undo/Redo state if conflict with other views
    
    Change-Id: I5bc5be2b17925ec3a203f9704f62a8c80ac5fc9d
    Reviewed-on: https://gerrit.libreoffice.org/39363
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Henry Castro <hcastro at collabora.com>

diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index 3778f4be1093..c90032a8c0ca 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -83,6 +83,7 @@ public:
     void testUndoRepairDispatch();
     void testInsertGraphicInvalidations();
     void testDocumentSizeWithTwoViews();
+    void testDisableUndoRepair();
 
     CPPUNIT_TEST_SUITE(ScTiledRenderingTest);
     CPPUNIT_TEST(testRowColumnSelections);
@@ -109,6 +110,7 @@ public:
     CPPUNIT_TEST(testUndoRepairDispatch);
     CPPUNIT_TEST(testInsertGraphicInvalidations);
     CPPUNIT_TEST(testDocumentSizeWithTwoViews);
+    CPPUNIT_TEST(testDisableUndoRepair);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1347,6 +1349,71 @@ void ScTiledRenderingTest::testDocumentSizeWithTwoViews()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void ScTiledRenderingTest::testDisableUndoRepair()
+{
+    comphelper::LibreOfficeKit::setActive();
+    ScModelObj* pModelObj = createDoc("cursor-away.ods");
+    CPPUNIT_ASSERT(pModelObj);
+
+    // view #1
+    int nView1 = SfxLokHelper::getView();
+    SfxViewShell* pView1 = SfxViewShell::Current();
+
+    // view #2
+    SfxLokHelper::createView();
+    int nView2 = SfxLokHelper::getView();
+    SfxViewShell* pView2 = SfxViewShell::Current();
+    CPPUNIT_ASSERT(pView1 != pView2);
+    {
+        SfxItemSet aSet1(pView1->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
+        SfxItemSet aSet2(pView2->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
+        pView1->GetSlotState(SID_UNDO, nullptr, &aSet1);
+        pView2->GetSlotState(SID_UNDO, nullptr, &aSet2);
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::DISABLED, aSet1.GetItemState(SID_UNDO));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::DISABLED, aSet2.GetItemState(SID_UNDO));
+    }
+
+    // text edit a cell in view #1
+    SfxLokHelper::setView(nView1);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'h', 0);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'h', 0);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
+    Scheduler::ProcessEventsToIdle();
+    {
+        SfxItemSet aSet1(pView1->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
+        SfxItemSet aSet2(pView2->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
+        pView1->GetSlotState(SID_UNDO, nullptr, &aSet1);
+        pView2->GetSlotState(SID_UNDO, nullptr, &aSet2);
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet1.GetItemState(SID_UNDO));
+        CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(aSet1.GetItem(SID_UNDO)));
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet2.GetItemState(SID_UNDO));
+        CPPUNIT_ASSERT(dynamic_cast< const SfxUInt32Item* >(aSet2.GetItem(SID_UNDO)));
+        CPPUNIT_ASSERT_EQUAL(static_cast< sal_uInt32 >(SID_REPAIRPACKAGE), dynamic_cast< const SfxUInt32Item* >(aSet2.GetItem(SID_UNDO))->GetValue());
+    }
+
+    // text edit a cell in view #2
+    SfxLokHelper::setView(nView2);
+    pModelObj->setPart(1);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'c', 0);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'c', 0);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
+    Scheduler::ProcessEventsToIdle();
+    Scheduler::ProcessEventsToIdle();
+    {
+        SfxItemSet aSet1(pView1->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
+        SfxItemSet aSet2(pView2->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
+        pView1->GetSlotState(SID_UNDO, nullptr, &aSet1);
+        pView2->GetSlotState(SID_UNDO, nullptr, &aSet2);
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet1.GetItemState(SID_UNDO));
+        CPPUNIT_ASSERT(dynamic_cast< const SfxUInt32Item* >(aSet1.GetItem(SID_UNDO)));
+        CPPUNIT_ASSERT_EQUAL(static_cast< sal_uInt32 >(SID_REPAIRPACKAGE), dynamic_cast< const SfxUInt32Item* >(aSet1.GetItem(SID_UNDO))->GetValue());
+        CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet2.GetItemState(SID_UNDO));
+        CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(aSet2.GetItem(SID_UNDO)));
+    }
+}
+
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(ScTiledRenderingTest);
diff --git a/sc/source/ui/view/tabvwshb.cxx b/sc/source/ui/view/tabvwshb.cxx
index a9a46d5bd50a..1077f9c1aac9 100644
--- a/sc/source/ui/view/tabvwshb.cxx
+++ b/sc/source/ui/view/tabvwshb.cxx
@@ -588,7 +588,10 @@ void ScTabViewShell::ExecuteUndo(SfxRequest& rReq)
                     {
                         ViewShellId nViewShellId = GetViewShellId();
                         if (pAction->GetViewShellId() != nViewShellId)
+                        {
+                            rReq.SetReturnValue(SfxUInt32Item(SID_UNDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
                             return;
+                        }
                     }
                 }
 
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index f1754effcf67..1dbcdf6e52a1 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -904,12 +904,34 @@ void SfxViewFrame::StateHistory_Impl( SfxItemSet &rSet )
         rSet.DisableItem( SID_CLEARHISTORY );
 
     if ( pShUndoMgr && pShUndoMgr->GetUndoActionCount() )
-        rSet.Put( SfxStringItem( SID_UNDO, SvtResId(STR_UNDO)+pShUndoMgr->GetUndoActionComment() ) );
+    {
+        const SfxUndoAction* pAction = pShUndoMgr->GetUndoAction();
+        SfxViewShell *pViewSh = GetViewShell();
+        if (pViewSh && pAction->GetViewShellId() != pViewSh->GetViewShellId())
+        {
+            rSet.Put(SfxUInt32Item(SID_UNDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
+        }
+        else
+        {
+            rSet.Put( SfxStringItem( SID_UNDO, SvtResId(STR_UNDO)+pShUndoMgr->GetUndoActionComment() ) );
+        }
+    }
     else
         rSet.DisableItem( SID_UNDO );
 
     if ( pShUndoMgr && pShUndoMgr->GetRedoActionCount() )
-        rSet.Put( SfxStringItem( SID_REDO, SvtResId(STR_REDO)+pShUndoMgr->GetRedoActionComment() ) );
+    {
+        const SfxUndoAction* pAction = pShUndoMgr->GetRedoAction();
+        SfxViewShell *pViewSh = GetViewShell();
+        if (pViewSh && pAction->GetViewShellId() != pViewSh->GetViewShellId())
+        {
+            rSet.Put(SfxUInt32Item(SID_REDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
+        }
+        else
+        {
+            rSet.Put( SfxStringItem( SID_REDO, SvtResId(STR_REDO)+pShUndoMgr->GetRedoActionComment() ) );
+        }
+    }
     else
         rSet.DisableItem( SID_REDO );
 


More information about the Libreoffice-commits mailing list