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

New commits:
commit a4349c502eb2169b3f83d58e49a7871a341daf76
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 13:27:18 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>

diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index caa2b90d9dc6..bf01afdc0139 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -425,6 +425,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 6c346111cc73..b890ae226eb3 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -81,6 +81,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>
@@ -954,8 +955,14 @@ bool ModelData_Impl::OutputFileDialog( sal_Int16 
nStoreMode,
     SfxFilterFlags nMust = getMustFlags( nStoreMode );
     SfxFilterFlags nDont = getDontFlags( nStoreMode );
     weld::Window* pFrameWin = SfxStoringHelper::GetModelWindow(m_xModel);
-    OUString sPreselectedDir = GetDocProps().getUnpackedValueOrDefault(
-        "ExportDirectory", 
GetDocProps().getUnpackedValueOrDefault("DocumentBaseURL", OUString()));
+    OUString sPreselectedDir
+        = 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 (sPreselectedDir.isEmpty() && pDocShell && 
!pDocShell->IsBasedOnTemplate())
+        sPreselectedDir = 
GetDocProps().getUnpackedValueOrDefault("DocumentBaseURL", OUString());
     INetURLObject aObj(sPreselectedDir);
     aObj.removeSegment(); // remove file name from URL
     sPreselectedDir = aObj.GetMainURL(INetURLObject::DecodeMechanism::NONE);
diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx
index 4b07602fc011..60bcd6d24575 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>
@@ -644,6 +646,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