summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2019-08-22 09:15:15 -0400
committerAndras Timar <andras.timar@collabora.com>2020-05-17 10:28:13 +0200
commitaed9e63f0b6afadae2fad89d4091890d5986c67a (patch)
tree165d67a1dab00d444db0d8c999961745e069aa5c
parent197bf5486348254690b11a98de84946240aa280f (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>
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx61
-rw-r--r--include/sfx2/objsh.hxx2
-rw-r--r--sc/source/ui/docshell/docsh.cxx6
-rw-r--r--sc/source/ui/inc/docsh.hxx2
-rw-r--r--sfx2/source/doc/objserv.cxx1
-rw-r--r--sfx2/source/doc/objstor.cxx7
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());