diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-01-10 16:21:05 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-01-10 16:23:45 -0500 |
commit | 831d1b6e62e91e67f171bd00305651043731d496 (patch) | |
tree | e5cf9898159d8468ef0486e8a004432849d59c2f | |
parent | 0260f0b256c3675bb6d836c0a2babb7626577b7a (diff) |
fdo#58069: Invalidate sheet stream cache when directory path changes.
To properly regenerate hyperlinks (among other things) which depend on
the full path of the host document.
Change-Id: I44fdd5b0ef0a57bf4fae13f29f1ebacfe1ab19a8
-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); |