include/sfx2/objsh.hxx        |    1 +
 sfx2/source/doc/guisaveas.cxx |    9 +++++++--
 sfx2/source/doc/objcont.cxx   |   10 ++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)

New commits:
commit 8e3c1b26f81b73909b70f0329811dfe85eb66ca2
Author:     Samuel Mehrbrodt <samuel.mehrbr...@collabora.com>
AuthorDate: Thu Aug 7 10:51:48 2025 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@collabora.com>
CommitDate: Thu Aug 7 16:17:07 2025 +0200

    tdf#167845 Don't preselect the template path
    
    When saving a doc which was based on a template,
    don't preselect the path where the template was stored.
    Instead, preselect the last used path from the Save dialog.
    
    Change-Id: I484e5a908cc739618683b6c2e2b4a7fda4a66232
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189053
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@collabora.com>
    (cherry picked from commit a4349c502eb2169b3f83d58e49a7871a341daf76)

diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 20e497b6e4af..1610d8af56ba 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -418,6 +418,7 @@ public:
     void                        SetHeaderAttributesForSourceViewHack();
 
     bool                        IsQueryLoadTemplate() const;
+    bool                        IsBasedOnTemplate() const; // Whether the 
document is based on a template
     bool                        IsUseUserData() const;
     bool                        IsUseThumbnailSave() const;
     bool                        IsLoadReadonly() const;
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index 37560fc72cfb..290f66ad2455 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -73,6 +73,7 @@
 #include <unotools/tempfile.hxx>
 #include <unotools/useroptions.hxx>
 
+#include <sfx2/docfile.hxx>
 #include <sfx2/objsh.hxx>
 #include <sfx2/sfxsids.hrc>
 #include <sfx2/strings.hrc>
@@ -937,8 +938,12 @@ bool ModelData_Impl::OutputFileDialog( sal_Int16 
nStoreMode,
     SfxFilterFlags nDont = getDontFlags( nStoreMode );
     weld::Window* pFrameWin = SfxStoringHelper::GetModelWindow(m_xModel);
 
-    const OUString aBaseUrl = 
GetDocProps().getUnpackedValueOrDefault("DocumentBaseURL", OUString());
-    OUString aExportDir = 
GetDocProps().getUnpackedValueOrDefault("ExportDirectory", aBaseUrl);
+    OUString aExportDir = 
GetDocProps().getUnpackedValueOrDefault("ExportDirectory", OUString());
+    // Fall back to the document base URL - but only if the document is not 
based on a template.
+    // Otherwise the template's directory would be used, which is not what we 
want.
+    SfxObjectShell* pDocShell = SfxViewShell::Current()->GetObjectShell();
+    if (aExportDir.isEmpty() && pDocShell && !pDocShell->IsBasedOnTemplate())
+        aExportDir = 
GetDocProps().getUnpackedValueOrDefault("DocumentBaseURL", OUString());
     INetURLObject aObj( aExportDir );
     aObj.removeSegment();
     aExportDir = aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx
index 156e1aed3217..82363e1831c7 100644
--- a/sfx2/source/doc/objcont.cxx
+++ b/sfx2/source/doc/objcont.cxx
@@ -29,6 +29,8 @@
 #include <svl/style.hxx>
 
 #include <svl/intitem.hxx>
+#include <svl/itemset.hxx>
+#include <svl/eitem.hxx>
 #include <svl/ctloptions.hxx>
 #include <comphelper/processfactory.hxx>
 #include <unotools/securityoptions.hxx>
@@ -621,6 +623,14 @@ bool SfxObjectShell::IsQueryLoadTemplate() const
     return pImpl->bQueryLoadTemplate;
 }
 
+bool SfxObjectShell::IsBasedOnTemplate() const
+{
+    if (!pMedium)
+        return false;
+    const SfxBoolItem* pTemplateItem = 
pMedium->GetItemSet().GetItem(SID_TEMPLATE, false);
+    return pTemplateItem && pTemplateItem->GetValue();
+}
+
 bool SfxObjectShell::IsUseUserData() const
 {
     return pImpl->bUseUserData;

Reply via email to