diff options
-rw-r--r-- | sc/inc/document.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 11 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 38 |
3 files changed, 49 insertions, 1 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index a72f7596cd2d..7573a80c0b24 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -572,6 +572,7 @@ public: void AppendTabOnLoad(const rtl::OUString& rName); void SetTabNameOnLoad(SCTAB nTab, const rtl::OUString& rName); + void InvalidateStreamOnSave(); SC_DLLPUBLIC bool InsertTab( SCTAB nPos, const rtl::OUString& rName, bool bExternalDocument = false ); diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 78ae82355230..a3e5cfa6286e 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -402,6 +402,17 @@ void ScDocument::SetTabNameOnLoad(SCTAB nTab, const rtl::OUString& rName) maTabs[nTab]->SetName(rName); } +void ScDocument::InvalidateStreamOnSave() +{ + TableContainer::iterator it = maTabs.begin(), itEnd = maTabs.end(); + for (; it != itEnd; ++it) + { + ScTable* pTab = *it; + if (pTab) + pTab->SetStreamValid(false); + } +} + bool ScDocument::InsertTab( SCTAB nPos, const rtl::OUString& rName, bool bExternalDocument ) { diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index c8ff10bbbf7c..2c35c018358b 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -34,6 +34,7 @@ #include <sfx2/objface.hxx> #include <svl/documentlockfile.hxx> #include <svl/sharecontrolfile.hxx> +#include "svl/urihelper.hxx" #include "chgtrack.hxx" #include "chgviset.hxx" #include <com/sun/star/awt/Key.hpp> @@ -1528,10 +1529,45 @@ sal_Bool ScDocShell::Save() return bRet; } +namespace { + +/** + * Remove the file name from the full path, to keep only the directory path. + */ +void popFileName(OUString& rPath) +{ + if (!rPath.isEmpty()) + { + INetURLObject aURLObj(rPath); + aURLObj.removeSegment(); + rPath = aURLObj.GetMainURL(INetURLObject::NO_DECODE); + } +} + +} sal_Bool ScDocShell::SaveAs( SfxMedium& rMedium ) { - RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::SaveAs" ); + OUString aCurPath; // empty for new document that hasn't been saved. + const SfxMedium* pCurMedium = GetMedium(); + if (pCurMedium) + { + aCurPath = pCurMedium->GetName(); + popFileName(aCurPath); + } + + if (!aCurPath.isEmpty()) + { + // current document has a path -> not a brand-new document. + OUString aNewPath = rMedium.GetName(); + popFileName(aNewPath); + OUString aRel = URIHelper::simpleNormalizedMakeRelative(aCurPath, aNewPath); + if (!aRel.isEmpty()) + { + // Directory path will change before and after the save. + aDocument.InvalidateStreamOnSave(); + } + } ScTabViewShell* pViewShell = GetBestViewShell(); bool bNeedsRehash = ScPassHashHelper::needsPassHashRegen(aDocument, PASSHASH_SHA1); |