diff options
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 61 | ||||
-rw-r--r-- | include/sfx2/objsh.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 6 | ||||
-rw-r--r-- | sc/source/ui/inc/docsh.hxx | 2 | ||||
-rw-r--r-- | sfx2/source/doc/objserv.cxx | 1 | ||||
-rw-r--r-- | sfx2/source/doc/objstor.cxx | 7 |
6 files changed, 71 insertions, 8 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 1bb185dd5b9e..d1b7ee66efe7 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -75,7 +75,6 @@ public: comphelper::LibreOfficeKit::setActive(true); UnoApiTest::setUp(); - mxDesktop.set(frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); SfxApplication::GetOrCreate(); }; @@ -85,11 +84,13 @@ public: if (m_pDocument) m_pDocument->pClass->registerCallback(m_pDocument.get(), nullptr, nullptr); closeDoc(); + UnoApiTest::tearDown(); comphelper::LibreOfficeKit::setActive(false); }; + LibLODocument_Impl* loadDocUrl(const OUString& rFileURL, LibreOfficeKitDocumentType eType); LibLODocument_Impl* loadDoc(const char* pName, LibreOfficeKitDocumentType eType = LOK_DOCTYPE_TEXT); void closeDoc(); static void callback(int nType, const char* pPayload, void* pData); @@ -146,6 +147,7 @@ public: void testComplexSelection(); void testDialogPaste(); void testShowHideDialog(); + void testCalcSaveAs(); void testABI(); CPPUNIT_TEST_SUITE(DesktopLOKTest); @@ -202,6 +204,7 @@ public: CPPUNIT_TEST(testComplexSelection); CPPUNIT_TEST(testDialogPaste); CPPUNIT_TEST(testShowHideDialog); + CPPUNIT_TEST(testCalcSaveAs); CPPUNIT_TEST(testABI); CPPUNIT_TEST_SUITE_END(); @@ -247,10 +250,8 @@ static Control* GetFocusControl(vcl::Window const * pParent) return nullptr; } -LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType) +LibLODocument_Impl* DesktopLOKTest::loadDocUrl(const OUString& rFileURL, LibreOfficeKitDocumentType eType) { - OUString aFileURL; - createFileURL(OUString::createFromAscii(pName), aFileURL); OUString aService; switch (eType) { @@ -267,7 +268,7 @@ LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDoc CPPUNIT_ASSERT(false); break; } - mxComponent = loadFromDesktop(aFileURL, aService); + mxComponent = loadFromDesktop(rFileURL, aService); if (!mxComponent.is()) { CPPUNIT_ASSERT(false); @@ -276,6 +277,13 @@ LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDoc return m_pDocument.get(); } +LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType) +{ + OUString aFileURL; + createFileURL(OUString::createFromAscii(pName), aFileURL); + return loadDocUrl(aFileURL, eType); +} + void DesktopLOKTest::closeDoc() { if (mxComponent.is()) @@ -903,7 +911,7 @@ void DesktopLOKTest::testTrackChanges() pDocument->pClass->registerCallback(pDocument, &DesktopLOKTest::callback, this); Scheduler::ProcessEventsToIdle(); - // Enable track changes and assert that both views get notified. + // Enable trak changes and assert that both views get notified. m_nTrackChanges = 0; pDocument->pClass->postUnoCommand(pDocument, ".uno:TrackChanges", nullptr, false); Scheduler::ProcessEventsToIdle(); @@ -1799,6 +1807,7 @@ class ViewCallback LibLODocument_Impl* mpDocument; int mnView; public: + OString m_aCellFormula; bool m_bTilesInvalidated; tools::Rectangle m_aOwnCursor; boost::property_tree::ptree m_aCommentCallbackResult; @@ -1860,6 +1869,11 @@ public: boost::property_tree::read_json(aStream, m_aCallbackWindowResult); } break; + case LOK_CALLBACK_CELL_FORMULA: + { + m_aCellFormula = aPayload; + } + break; } } }; @@ -1867,7 +1881,6 @@ public: void DesktopLOKTest::testPaintPartTile() { // Load an impress doc of 2 slides. - // ViewCallback aView1; // ViewCallback aView2; LibLODocument_Impl* pDocument = loadDoc("2slides.odp"); @@ -2653,6 +2666,40 @@ void DesktopLOKTest::testComplexSelection() CPPUNIT_ASSERT_EQUAL(static_cast<int>(LOK_SELTYPE_COMPLEX), pDocument->pClass->getSelectionType(pDocument)); } +void DesktopLOKTest::testCalcSaveAs() +{ + comphelper::LibreOfficeKit::setActive(); + + LibLODocument_Impl* pDocument = loadDoc("sheets.ods"); + CPPUNIT_ASSERT(pDocument); + + // Enter some text, but don't commit. + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 'X', 0); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 'X', 0); + Scheduler::ProcessEventsToIdle(); + + // Save as a new file. + OUString aNewFileUrl = "file:///tmp/saveas.ods"; + pDocument->pClass->saveAs(pDocument, aNewFileUrl.toUtf8().getStr(), nullptr, nullptr); + closeDoc(); + + // Load the new document and verify that the in-flight changes are saved. + pDocument = loadDocUrl(aNewFileUrl, LOK_DOCTYPE_SPREADSHEET); + CPPUNIT_ASSERT(pDocument); + + ViewCallback aView(pDocument); + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + pDocument->m_pDocumentClass->registerCallback(pDocument, &ViewCallback::callback, &aView); + + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 0, KEY_RIGHT); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 0, KEY_LEFT); + pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 0, KEY_LEFT); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(OString("X"), aView.m_aCellFormula); +} + namespace { constexpr size_t classOffset(int i) diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index 2a56ebe88e07..b5b626c6c713 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -299,6 +299,8 @@ public: // TODO/LATER: currently only overridden in Calc, should be made non-virtual virtual bool DoSaveCompleted( SfxMedium* pNewStor=nullptr, bool bRegisterRecent=true ); + /// Terminate any in-flight editing. Used before saving, primarily by Calc to commit cell changes. + virtual void TerminateEditing() {} bool LoadOwnFormat( SfxMedium& pMedium ); virtual bool SaveAsOwnFormat( SfxMedium& pMedium ); diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index bd7402231333..2bf345635645 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -1764,6 +1764,12 @@ void popFileName(OUString& rPath) } +void ScDocShell::TerminateEditing() +{ + // Commit any cell changes before saving. + SC_MOD()->InputEnterHandler(); +} + bool ScDocShell::SaveAs( SfxMedium& rMedium ) { OUString aCurPath; // empty for new document that hasn't been saved. diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx index a519f4c87d04..bfde244fad3d 100644 --- a/sc/source/ui/inc/docsh.hxx +++ b/sc/source/ui/inc/docsh.hxx @@ -203,6 +203,8 @@ public: virtual void SetVisArea( const tools::Rectangle & rVisArea ) override; + virtual void TerminateEditing() override; + using SfxObjectShell::GetVisArea; virtual tools::Rectangle GetVisArea( sal_uInt16 nAspect ) const override; diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 51276917bd5e..ba76289818aa 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -286,7 +286,6 @@ bool SfxObjectShell::APISaveAs_Impl(const OUString& aFileName, SfxItemSet& rItem { bool bOk = false; - if ( GetMedium() ) { OUString aFilterName; diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 6d7b3f99ee69..8f86d559226c 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -2667,6 +2667,7 @@ bool SfxObjectShell::CommonSaveAs_Impl(const INetURLObject& aURL, const OUString return false; } + const SfxBoolItem* pCopyStreamItem = rItemSet.GetItem<SfxBoolItem>(SID_COPY_STREAM_IF_POSSIBLE, false); if ( bSaveTo && pCopyStreamItem && pCopyStreamItem->GetValue() && !IsModified() ) { @@ -2824,6 +2825,12 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString& return false; } + if (comphelper::LibreOfficeKit::isActive()) + { + // Before saving, commit in-flight changes. + TerminateEditing(); + } + // check if a "SaveTo" is wanted, no "SaveAs" const SfxBoolItem* pSaveToItem = pMergedParamsTmp->GetItem<SfxBoolItem>(SID_SAVETO, false); bool bCopyTo = GetCreateMode() == SfxObjectCreateMode::EMBEDDED || (pSaveToItem && pSaveToItem->GetValue()); |