summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2017-06-27 20:42:11 -0400
committerHenry Castro <hcastro@collabora.com>2017-06-28 14:10:49 +0200
commitb6bd337595383b9b9f0524ec4190dc3e1fbbf6e1 (patch)
treefe5d34cea9a3eeff8d18ad60d30220b1439cc12b
parentd7436b75a915f9f018d3722f62301d1f42dc3bcc (diff)
sd lok: disable undo state if conflict with other views
Change-Id: I046d118fca32c95f7734d6e29598da56578c9ec0 Reviewed-on: https://gerrit.libreoffice.org/39333 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Henry Castro <hcastro@collabora.com>
-rw-r--r--sd/qa/unit/tiledrendering/tiledrendering.cxx55
-rw-r--r--sd/source/ui/view/viewshe3.cxx68
2 files changed, 91 insertions, 32 deletions
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 628c72afef30..0ff3e16717c1 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -100,6 +100,7 @@ public:
void testTdf105502();
void testCommentCallbacks();
void testMultiViewInsertDeletePage();
+ void testDisableUndoRepair();
CPPUNIT_TEST_SUITE(SdTiledRenderingTest);
CPPUNIT_TEST(testRegisterCallback);
@@ -136,6 +137,7 @@ public:
CPPUNIT_TEST(testTdf105502);
CPPUNIT_TEST(testCommentCallbacks);
CPPUNIT_TEST(testMultiViewInsertDeletePage);
+ CPPUNIT_TEST(testDisableUndoRepair);
CPPUNIT_TEST_SUITE_END();
@@ -1768,6 +1770,59 @@ void SdTiledRenderingTest::testMultiViewInsertDeletePage()
comphelper::LibreOfficeKit::setActive(false);
}
+void SdTiledRenderingTest::testDisableUndoRepair()
+{
+ // Load the document.
+ comphelper::LibreOfficeKit::setActive();
+ SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp");
+ SfxViewShell* pView1 = SfxViewShell::Current();
+ int nView1 = SfxLokHelper::getView();
+ SfxLokHelper::createView();
+ SfxViewShell* pView2 = SfxViewShell::Current();
+ int nView2 = SfxLokHelper::getView();
+ {
+ std::unique_ptr<SfxPoolItem> pItem1;
+ std::unique_ptr<SfxPoolItem> pItem2;
+ CPPUNIT_ASSERT_EQUAL(SfxItemState::DISABLED, pView1->GetViewFrame()->GetBindings().QueryState(SID_UNDO, pItem1));
+ CPPUNIT_ASSERT_EQUAL(SfxItemState::DISABLED, pView2->GetViewFrame()->GetBindings().QueryState(SID_UNDO, pItem2));
+ }
+
+ // Insert a character in the first view.
+ SfxLokHelper::setView(nView1);
+ pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::TAB);
+ pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::TAB);
+ pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'h', 0);
+ pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'h', 0);
+ Scheduler::ProcessEventsToIdle();
+ {
+ std::unique_ptr<SfxPoolItem> pItem1;
+ std::unique_ptr<SfxPoolItem> pItem2;
+ pView1->GetViewFrame()->GetBindings().QueryState(SID_UNDO, pItem1);
+ pView2->GetViewFrame()->GetBindings().QueryState(SID_UNDO, pItem2);
+ CPPUNIT_ASSERT(!dynamic_cast< const SfxUInt32Item* >(pItem1.get()));
+ CPPUNIT_ASSERT(dynamic_cast< const SfxUInt32Item* >(pItem2.get()));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(SID_REPAIRPACKAGE), dynamic_cast< const SfxUInt32Item * >(pItem2.get())->GetValue());
+ }
+
+ // Insert a character in the second view.
+ SfxLokHelper::setView(nView2);
+ pXImpressDocument->setPart(1);
+ pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::TAB);
+ pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::TAB);
+ pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'c', 0);
+ pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'c', 0);
+ Scheduler::ProcessEventsToIdle();
+ {
+ std::unique_ptr<SfxPoolItem> pItem1;
+ std::unique_ptr<SfxPoolItem> pItem2;
+ pView1->GetViewFrame()->GetBindings().QueryState(SID_UNDO, pItem1);
+ pView2->GetViewFrame()->GetBindings().QueryState(SID_UNDO, pItem2);
+ CPPUNIT_ASSERT(!dynamic_cast< const SfxUInt32Item* >(pItem2.get()));
+ CPPUNIT_ASSERT(dynamic_cast< const SfxUInt32Item* >(pItem1.get()));
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(SID_REPAIRPACKAGE), dynamic_cast< const SfxUInt32Item * >(pItem1.get())->GetValue());
+ }
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sd/source/ui/view/viewshe3.cxx b/sd/source/ui/view/viewshe3.cxx
index 7e744d07f598..5f342906d994 100644
--- a/sd/source/ui/view/viewshe3.cxx
+++ b/sd/source/ui/view/viewshe3.cxx
@@ -126,54 +126,58 @@ void ViewShell::GetMenuState( SfxItemSet &rSet )
if(SfxItemState::DEFAULT == rSet.GetItemState(SID_UNDO))
{
::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
- bool bActivate(false);
-
if(pUndoManager)
{
if(pUndoManager->GetUndoActionCount() != 0)
{
- bActivate = true;
+ // If an other view created the first undo action, prevent redoing it from this view.
+ const SfxUndoAction* pAction = pUndoManager->GetUndoAction();
+ if (pAction->GetViewShellId() != GetViewShellBase().GetViewShellId())
+ {
+ rSet.Put(SfxUInt32Item(SID_UNDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
+ }
+ else
+ {
+ // Set the necessary string like in
+ // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1072 ff.
+ OUString aTmp(SvtResId(STR_UNDO));
+ aTmp += pUndoManager->GetUndoActionComment();
+ rSet.Put(SfxStringItem(SID_UNDO, aTmp));
+ }
+ }
+ else
+ {
+ rSet.DisableItem(SID_UNDO);
}
- }
-
- if(bActivate)
- {
- // Set the necessary string like in
- // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1072 ff.
- OUString aTmp(SvtResId(STR_UNDO));
- aTmp += pUndoManager->GetUndoActionComment();
- rSet.Put(SfxStringItem(SID_UNDO, aTmp));
- }
- else
- {
- rSet.DisableItem(SID_UNDO);
}
}
if(SfxItemState::DEFAULT == rSet.GetItemState(SID_REDO))
{
::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
- bool bActivate(false);
-
if(pUndoManager)
{
if(pUndoManager->GetRedoActionCount() != 0)
{
- bActivate = true;
+ // If an other view created the first undo action, prevent redoing it from this view.
+ const SfxUndoAction* pAction = pUndoManager->GetRedoAction();
+ if (pAction->GetViewShellId() != GetViewShellBase().GetViewShellId())
+ {
+ rSet.Put(SfxUInt32Item(SID_REDO, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
+ }
+ else
+ {
+ // Set the necessary string like in
+ // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1081 ff.
+ OUString aTmp(SvtResId(STR_REDO));
+ aTmp += pUndoManager->GetRedoActionComment();
+ rSet.Put(SfxStringItem(SID_REDO, aTmp));
+ }
+ }
+ else
+ {
+ rSet.DisableItem(SID_REDO);
}
- }
-
- if(bActivate)
- {
- // Set the necessary string like in
- // sfx2/source/view/viewfrm.cxx ver 1.23 ln 1081 ff.
- OUString aTmp(SvtResId(STR_REDO));
- aTmp += pUndoManager->GetRedoActionComment();
- rSet.Put(SfxStringItem(SID_REDO, aTmp));
- }
- else
- {
- rSet.DisableItem(SID_REDO);
}
}
}