sd/qa/unit/data/odp/tdf143603.fodp |   15 +++++++++++++++
 sd/qa/unit/import-tests.cxx        |   13 +++++++++++++
 sd/source/ui/docshell/docshel4.cxx |   12 ++++++++++++
 3 files changed, 40 insertions(+)

New commits:
commit 1b61a0737e3600aadf42f28a15c70aface9ab61e
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Sep 4 22:34:10 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Sep 4 21:59:00 2024 +0200

    tdf#143603: disable undo in DrawDocShell::ImportFrom
    
    Change-Id: I6fbc317d9f72f1bec70ff97e915487ac2b5a2f53
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172872
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/sd/qa/unit/data/odp/tdf143603.fodp 
b/sd/qa/unit/data/odp/tdf143603.fodp
new file mode 100644
index 000000000000..d342d4b3f221
--- /dev/null
+++ b/sd/qa/unit/data/odp/tdf143603.fodp
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" 
office:version="1.3" 
office:mimetype="application/vnd.oasis.opendocument.presentation">
+ <office:body>
+  <office:presentation>
+   <draw:page>
+    <draw:frame svg:width="10cm" svg:height="10cm" svg:x="0cm" svg:y="0cm">
+     <draw:text-box>
+      <text:p>text</text:p>
+     </draw:text-box>
+    </draw:frame>
+   </draw:page>
+  </office:presentation>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 4d9aaa1e6ed8..220bf3e30342 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -58,6 +58,8 @@
 #include <com/sun/star/drawing/RectanglePoint.hpp>
 
 #include <stlpool.hxx>
+#include <undo/undomanager.hxx>
+
 #include <unotools/syslocaleoptions.hxx>
 #include <comphelper/scopeguard.hxx>
 #include <comphelper/sequenceashashmap.hxx>
@@ -2026,6 +2028,17 @@ CPPUNIT_TEST_FIXTURE(SdImportTest, testTdf152070)
         
xBackgroundProps->getPropertyValue(u"FillBitmapPositionOffsetY"_ustr).get<sal_Int32>());
 }
 
+CPPUNIT_TEST_FIXTURE(SdImportTest, testTdf143603)
+{
+    createSdImpressDoc("odp/tdf143603.fodp");
+    SdXImpressDocument* pXImpressDocument = 
dynamic_cast<SdXImpressDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pXImpressDocument);
+    SdDrawDocument* pDoc = pXImpressDocument->GetDoc();
+    CPPUNIT_ASSERT(pDoc);
+    // Loading FODP used to record UNDO entries - this was 2
+    CPPUNIT_ASSERT_EQUAL(size_t(0), 
pDoc->GetUndoManager()->GetUndoActionCount());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/docshell/docshel4.cxx 
b/sd/source/ui/docshell/docshel4.cxx
index 514409ec755b..76562ed093ca 100644
--- a/sd/source/ui/docshell/docshel4.cxx
+++ b/sd/source/ui/docshell/docshel4.cxx
@@ -42,6 +42,7 @@
 #include <sfx2/printer.hxx>
 #include <svtools/ctrltool.hxx>
 #include <comphelper/classids.hxx>
+#include <comphelper/scopeguard.hxx>
 #include <sot/formats.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <vcl/syswin.hxx>
@@ -418,6 +419,17 @@ bool DrawDocShell::ImportFrom(SfxMedium &rMedium,
         mpDoc->SetDefaultTabulator( 2540 );
     }
 
+    comphelper::ScopeGuard undoGuard([this, wasUndo = mpDoc->IsUndoEnabled()]
+                                     { mpDoc->EnableUndo(wasUndo); });
+    if (xInsertPosition) // insert mode
+    {
+        undoGuard.dismiss();
+    }
+    else // initial loading of the document
+    {
+        mpDoc->EnableUndo(false);
+    }
+
     const bool bRet = SfxObjectShell::ImportFrom(rMedium, xInsertPosition);
 
     SfxItemSet& rSet = rMedium.GetItemSet();

Reply via email to