summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2019-08-22 09:15:15 -0400
committerAshod Nakashian <ashnakash@gmail.com>2019-12-22 22:14:41 +0100
commit9b3c7c81299590d6d845f7437f6ab16db0219929 (patch)
treec899c06bb8ed9c26b37e371dea0bae7bfc79f37b
parent6ef3027ff9a5ee48e9fe2b8817eeabe444d6ec05 (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 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)
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 843860b053c5..28aae49924e3 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 b15d08f9668a..4a6b32c3811c 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1763,6 +1763,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 1b323aea3b84..6694707d5ee8 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 1559220039f7..231386d479ec 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -294,7 +294,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 438812a2756b..deba40fc9f74 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2669,6 +2669,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() )
{
@@ -2832,6 +2833,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());