[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - desktop/qa include/sfx2 sc/source sfx2/source
Ashod Nakashian (via logerrit)
logerrit at kemper.freedesktop.org
Sat Aug 24 16:29:08 UTC 2019
desktop/qa/desktop_lib/test_desktop_lib.cxx | 56 ++++++++++++++++++++++++++--
include/sfx2/objsh.hxx | 2 +
sc/source/ui/docshell/docsh.cxx | 6 +++
sc/source/ui/inc/docsh.hxx | 2 +
sfx2/source/doc/objserv.cxx | 1
sfx2/source/doc/objstor.cxx | 7 +++
6 files changed, 69 insertions(+), 5 deletions(-)
New commits:
commit cc7eb4d345e3fede698a3f255c1938d275305c14
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Thu Aug 22 09:15:15 2019 -0400
Commit: Ashod Nakashian <ashnakash at gmail.com>
CommitDate: Sat Aug 24 18:28:15 2019 +0200
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.
Change-Id: I2a88b2f1df47be764058f4505561b22830d9d67a
Reviewed-on: https://gerrit.libreoffice.org/78012
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 99b6c9f7806f..927fdd1ede10 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -84,6 +84,7 @@ public:
UnoApiTest::tearDown();
};
+ 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);
@@ -137,6 +138,7 @@ public:
void testSignDocument_PEM_PDF();
void testTextSelectionHandles();
void testDialogPaste();
+ void testCalcSaveAs();
void testABI();
CPPUNIT_TEST_SUITE(DesktopLOKTest);
@@ -190,6 +192,7 @@ public:
#endif
CPPUNIT_TEST(testTextSelectionHandles);
CPPUNIT_TEST(testDialogPaste);
+ CPPUNIT_TEST(testCalcSaveAs);
CPPUNIT_TEST(testABI);
CPPUNIT_TEST_SUITE_END();
@@ -235,10 +238,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)
{
@@ -255,7 +256,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);
@@ -264,6 +265,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())
@@ -1799,6 +1807,7 @@ void DesktopLOKTest::testRedlineCalc()
class ViewCallback
{
public:
+ OString m_aCellFormula;
bool m_bTilesInvalidated;
tools::Rectangle m_aOwnCursor;
boost::property_tree::ptree m_aCommentCallbackResult;
@@ -1843,6 +1852,11 @@ public:
m_aCommentCallbackResult = m_aCommentCallbackResult.get_child("comment");
}
break;
+ case LOK_CALLBACK_CELL_FORMULA:
+ {
+ m_aCellFormula = aPayload;
+ }
+ break;
}
}
};
@@ -2591,6 +2605,40 @@ void DesktopLOKTest::testDialogPaste()
Scheduler::ProcessEventsToIdle();
}
+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->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 {
size_t documentClassOffset(int i)
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index fd4056f02f2a..429b4b1e9e2f 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -316,6 +316,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 a2c6a5a69eb3..39f4770ef8c8 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1766,6 +1766,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 90c5292c828b..349dc278c3b3 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -210,6 +210,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 517d32e1b232..08e34ae5d787 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -282,7 +282,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 1b04019c95c3..5fa3d10a96f4 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2672,6 +2672,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() )
{
@@ -2818,6 +2819,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 = pMergedParams->GetItem<SfxBoolItem>(SID_SAVETO, false);
bool bCopyTo = GetCreateMode() == SfxObjectCreateMode::EMBEDDED || (pSaveToItem && pSaveToItem->GetValue());
More information about the Libreoffice-commits
mailing list