diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2023-06-16 14:51:13 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> | 2023-06-19 10:51:58 +0200 |
commit | 67232f226438a9e73beab9dec90f1a3739088b57 (patch) | |
tree | d63eb09ad5f81f72e26f53abebbd5fc5050f7eee | |
parent | 71c48fa7be6a526430e81067a1e439207a4a1b39 (diff) |
tdf#146547 sfx2: allow read-only documents to be modified
This is particularly useful for a Writer document that contains a
section that is set to be editable in a read-only document, so that the
user is warned when closing such a document without saving it.
Originally this check was added in commit
27db57efc51487b3976fbf73df1868b8fb78d201 "CWS fwkbugfix05"
"#i39869#: readonly docs should never become modified"
but the actual problem there was that the read-only document was
displayed in a wizard dialog, not in a document view, so let's instead
check that the document is some kind of "internal" document.
Also the dialog's Save button should do something, and since the
document is read-only, a Save As dialog appears appropriate.
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153180
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
(cherry picked from commit aca32a55456aa4e907b216fb490b3c15d26c3d55)
Change-Id: I339cbe92a2c9eb74a1f5061246f921037a47f79c
-rw-r--r-- | sfx2/source/doc/objembed.cxx | 9 | ||||
-rw-r--r-- | sfx2/source/doc/objmisc.cxx | 7 | ||||
-rw-r--r-- | sfx2/source/doc/objxtor.cxx | 8 | ||||
-rw-r--r-- | starmath/qa/cppunit/test_cursor.cxx | 1 | ||||
-rw-r--r-- | starmath/qa/cppunit/test_node.cxx | 1 | ||||
-rw-r--r-- | starmath/qa/cppunit/test_nodetotextvisitors.cxx | 1 | ||||
-rw-r--r-- | starmath/qa/extras/mmlexport-test.cxx | 3 | ||||
-rw-r--r-- | sw/qa/python/check_xmodifiable2.py | 9 |
8 files changed, 31 insertions, 8 deletions
diff --git a/sfx2/source/doc/objembed.cxx b/sfx2/source/doc/objembed.cxx index 7d5cdb5cb21c..2d4b6ef5229e 100644 --- a/sfx2/source/doc/objembed.cxx +++ b/sfx2/source/doc/objembed.cxx @@ -28,6 +28,7 @@ #include <sfx2/app.hxx> #include <objshimp.hxx> #include <sfx2/event.hxx> +#include <sfx2/sfxbasemodel.hxx> #include <comphelper/fileformat.h> #include <svtools/embedtransfer.hxx> @@ -118,8 +119,14 @@ void SfxObjectShell::SetVisArea( const tools::Rectangle & rVisArea ) pImpl->m_aVisArea = rVisArea; if ( GetCreateMode() == SfxObjectCreateMode::EMBEDDED ) { - if ( IsEnableSetModified() ) + if (IsEnableSetModified() + // Base forms use EMBEDDED but they actually live in their own + // frame - resizing that shouldn't set it to modified. + && pImpl->pBaseModel + && pImpl->pBaseModel->getIdentifier() != "com.sun.star.sdb.FormDesign") + { SetModified(); + } SfxGetpApp()->NotifyEvent(SfxEventHint( SfxEventHintId::VisAreaChanged, GlobalEventConfig::GetEventName(GlobalEventId::VISAREACHANGED), this)); } diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index ff31ce956bbc..2b6b361b1231 100644 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -262,7 +262,12 @@ void SfxObjectShell::EnableSetModified( bool bEnable ) bool SfxObjectShell::IsEnableSetModified() const { - return pImpl->m_bEnableSetModified && !IsReadOnly(); + // tdf#146547 read-only does not prevent modified, instead try to prevent + // setting "internal" documents that may be displayed in some dialog but + // which the user didn't load or activate to modified. + return pImpl->m_bEnableSetModified && !IsPreview() + && eCreateMode != SfxObjectCreateMode::ORGANIZER + && eCreateMode != SfxObjectCreateMode::INTERNAL; } diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index 510c35daf59f..29171a3e4e9a 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -589,7 +589,13 @@ bool SfxObjectShell::PrepareClose { // Save by each Dispatcher const SfxPoolItem *pPoolItem; - if ( IsSaveVersionOnClose() ) + if (IsReadOnly()) + { + SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI ); + const SfxPoolItem* ppArgs[] = { &aWarnItem, nullptr }; + pPoolItem = pFrame->GetBindings().ExecuteSynchron(SID_SAVEASDOC, ppArgs); + } + else if (IsSaveVersionOnClose()) { SfxStringItem aItem( SID_DOCINFO_COMMENTS, SfxResId(STR_AUTOMATICVERSION) ); SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI ); diff --git a/starmath/qa/cppunit/test_cursor.cxx b/starmath/qa/cppunit/test_cursor.cxx index 080e7a274c4d..b85b5ceef37a 100644 --- a/starmath/qa/cppunit/test_cursor.cxx +++ b/starmath/qa/cppunit/test_cursor.cxx @@ -57,6 +57,7 @@ void Test::setUp() SmGlobals::ensure(); xDocShRef = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT); + xDocShRef->DoInitNew(); } void Test::tearDown() diff --git a/starmath/qa/cppunit/test_node.cxx b/starmath/qa/cppunit/test_node.cxx index dba0b9ff3c40..570cab00d062 100644 --- a/starmath/qa/cppunit/test_node.cxx +++ b/starmath/qa/cppunit/test_node.cxx @@ -53,6 +53,7 @@ void NodeTest::setUp() mxDocShell = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT | SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS | SfxModelFlags::DISABLE_DOCUMENT_RECOVERY); + mxDocShell->DoInitNew(); } void NodeTest::tearDown() diff --git a/starmath/qa/cppunit/test_nodetotextvisitors.cxx b/starmath/qa/cppunit/test_nodetotextvisitors.cxx index c3172ab60126..e738351a8d23 100644 --- a/starmath/qa/cppunit/test_nodetotextvisitors.cxx +++ b/starmath/qa/cppunit/test_nodetotextvisitors.cxx @@ -90,6 +90,7 @@ void Test::setUp() SmGlobals::ensure(); xDocShRef = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT); + xDocShRef->DoInitNew(); } void Test::tearDown() diff --git a/starmath/qa/extras/mmlexport-test.cxx b/starmath/qa/extras/mmlexport-test.cxx index 737885d5f73e..c3a2fc5afca0 100644 --- a/starmath/qa/extras/mmlexport-test.cxx +++ b/starmath/qa/extras/mmlexport-test.cxx @@ -91,6 +91,7 @@ xmlDocPtr MathMLExportTest::exportAndParse() void MathMLExportTest::testBlank() { + mxDocShell->DoInitNew(); mxDocShell->SetText("x`y~~z"); xmlDocPtr pDoc = exportAndParse(); assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mspace[1]", "width", "0.5em"); @@ -99,6 +100,7 @@ void MathMLExportTest::testBlank() void MathMLExportTest::testTdf97049() { + mxDocShell->DoInitNew(); mxDocShell->SetText("intd {{1 over x} dx}"); xmlDocPtr pDoc = exportAndParse(); assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mo[1]", "stretchy", "true"); @@ -111,6 +113,7 @@ void MathMLExportTest::testTdf101022() { #define CHECK_MATHVARIANT(capital, small) do \ { \ + mxDocShell->DoInitNew(); \ mxDocShell->SetText("%GAMMA %iGAMMA {ital %GAMMA} {nitalic %iGAMMA} " \ "%gamma %igamma {ital %gamma} {nitalic %igamma}"); \ xmlDocPtr pDoc = exportAndParse(); \ diff --git a/sw/qa/python/check_xmodifiable2.py b/sw/qa/python/check_xmodifiable2.py index 53082fc2865e..b860e1f31d0f 100644 --- a/sw/qa/python/check_xmodifiable2.py +++ b/sw/qa/python/check_xmodifiable2.py @@ -173,17 +173,16 @@ class XModifiable2(unittest.TestCase): xDoc = self._uno.openTemplateFromTDOC('WriteProtected.odt') # perform unit test: - # it is unable to set modified flag using text editing - # when modification of the flag was disabled as + # it is able to set modified flag using text editing despite # ODT file was marked to be opened as read-only - self.assertFalse(xDoc.isSetModifiedEnabled()) + self.assertTrue(xDoc.isSetModifiedEnabled()) self.assertFalse(xDoc.isModified()) cursor = xDoc.Text.createTextCursor() xDoc.Text.insertString(cursor, "The first paragraph", 0) - self.assertFalse(xDoc.isSetModifiedEnabled()) - self.assertFalse(xDoc.isModified()) + self.assertTrue(xDoc.isSetModifiedEnabled()) + self.assertTrue(xDoc.isModified()) # clean up xDoc.close(True) |