diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2019-08-22 09:15:15 -0400 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2019-12-22 22:14:41 +0100 |
commit | 9b3c7c81299590d6d845f7437f6ab16db0219929 (patch) | |
tree | c899c06bb8ed9c26b37e371dea0bae7bfc79f37b /desktop | |
parent | 6ef3027ff9a5ee48e9fe2b8817eeabe444d6ec05 (diff) |
sc: LOK: commit cell edits before saveas
Users typically don't recognize that changes
done to a cell need to be committed (typically
by hitting RETURN) before they are saved to file.
This is especially true on the web.
This patch commits any in-flight changes before
SaveAs. This is currently done only for LOK and
unconditionally at that. This can be controlled
via a flag, if there is such a use-case.
Reviewed-on: https://gerrit.libreoffice.org/78012
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
(cherry picked from commit cc7eb4d345e3fede698a3f255c1938d275305c14)
Reviewed-on: https://gerrit.libreoffice.org/78455
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit e867404fbe7e0ff0d6f2573292c19b3a178a412d)
Change-Id: I2a88b2f1df47be764058f4505561b22830d9d67a
Reviewed-on: https://gerrit.libreoffice.org/82102
Tested-by: Jenkins
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 178d42f335c0..2649c0cb0d40 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); @@ -147,6 +148,7 @@ public: void testDialogPaste(); void testShowHideDialog(); void testDialogInput(); + void testCalcSaveAs(); void testABI(); CPPUNIT_TEST_SUITE(DesktopLOKTest); @@ -204,6 +206,7 @@ public: CPPUNIT_TEST(testDialogPaste); CPPUNIT_TEST(testShowHideDialog); CPPUNIT_TEST(testDialogInput); + CPPUNIT_TEST(testCalcSaveAs); CPPUNIT_TEST(testABI); CPPUNIT_TEST_SUITE_END(); @@ -249,10 +252,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) { @@ -269,7 +270,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); @@ -278,6 +279,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()) @@ -905,7 +913,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(); @@ -1833,6 +1841,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; @@ -1894,6 +1903,11 @@ public: boost::property_tree::read_json(aStream, m_aCallbackWindowResult); } break; + case LOK_CALLBACK_CELL_FORMULA: + { + m_aCellFormula = aPayload; + } + break; } } }; @@ -1903,7 +1917,6 @@ public: void DesktopLOKTest::testPaintPartTile() { // Load an impress doc of 2 slides. - // ViewCallback aView1; // ViewCallback aView2; LibLODocument_Impl* pDocument = loadDoc("2slides.odp"); @@ -2689,6 +2702,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) |