diff options
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 31 | ||||
-rw-r--r-- | sc/source/ui/docshell/externalrefmgr.cxx | 86 | ||||
-rw-r--r-- | sc/source/ui/src/globstr.src | 8 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun2.cxx | 5 |
4 files changed, 116 insertions, 14 deletions
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 9fa5769ee1ff..8f4f3fc68f9f 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -913,11 +913,25 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) if ( !bSuccess ) SetError( ERRCODE_IO_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); // this error code will produce no error message, but will break the further saving process } + + if (pSheetSaveData) pSheetSaveData->SetInSupportedSave(true); } break; case SFX_EVENT_SAVEASDOC: + { + if ( GetDocument()->GetExternalRefManager()->containsUnsavedReferences() ) + { + WarningBox aBox( GetActiveDialogParent(), WinBits( WB_YES_NO ), + ScGlobal::GetRscString( STR_UNSAVED_EXT_REF ) ); + + if( RET_NO == aBox.Execute()) + { + SetError( ERRCODE_IO_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) ); // this error code will produce no error message, but will break the further saving process + } + } + } // fall through case SFX_EVENT_SAVETODOC: // #i108978# If no event is sent before saving, there will also be no "...DONE" event, // and SAVE/SAVEAS can't be distinguished from SAVETO. So stream copying is only enabled @@ -926,21 +940,11 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) pSheetSaveData->SetInSupportedSave(true); break; case SFX_EVENT_SAVEDOCDONE: + case SFX_EVENT_SAVEASDOCDONE: { - if ( IsDocShared() && !SC_MOD()->IsInSharedDocSaving() ) - { - } + // new positions are used after "save" and "save as", but not "save to" UseSheetSaveEntries(); // use positions from saved file for next saving - if (pSheetSaveData) - pSheetSaveData->SetInSupportedSave(false); - } - break; - case SFX_EVENT_SAVEASDOCDONE: - // new positions are used after "save" and "save as", but not "save to" - UseSheetSaveEntries(); // use positions from saved file for next saving - if (pSheetSaveData) - pSheetSaveData->SetInSupportedSave(false); - break; + } // fall through case SFX_EVENT_SAVETODOCDONE: // only reset the flag, don't use the new positions if (pSheetSaveData) @@ -1567,6 +1571,7 @@ sal_Bool ScDocShell::SaveAs( SfxMedium& rMedium ) return false; } + ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() ); PrepareSaveGuard aPrepareGuard( *this); diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx index 6d23ab9fbf2b..83881a5ecd3d 100644 --- a/sc/source/ui/docshell/externalrefmgr.cxx +++ b/sc/source/ui/docshell/externalrefmgr.cxx @@ -44,6 +44,7 @@ #include "viewdata.hxx" #include "tabvwsh.hxx" #include "sc.hrc" +#include "globstr.hrc" #include "sfx2/app.hxx" #include "sfx2/docfilt.hxx" @@ -61,6 +62,7 @@ #include "tools/urlobj.hxx" #include "unotools/ucbhelper.hxx" #include "unotools/localfilehelper.hxx" +#include "vcl/msgbox.hxx" #include <memory> #include <algorithm> @@ -2092,7 +2094,7 @@ const ScDocument* ScExternalRefManager::getInMemorySrcDocument(sal_uInt16 nFileI while (pShell) { SfxMedium* pMedium = pShell->GetMedium(); - if (pMedium) + if (pMedium && pMedium->GetName().Len()) { OUString aName = pMedium->GetName(); // TODO: We should make the case sensitivity platform dependent. @@ -2103,6 +2105,21 @@ const ScDocument* ScExternalRefManager::getInMemorySrcDocument(sal_uInt16 nFileI break; } } + else + { + // handle unsaved documents here + OUString aName = pShell->GetName(); + if (pFileName->equalsIgnoreAsciiCase(aName)) + { + // Found ! + SrcShell aSrcDoc; + aSrcDoc.maShell = pShell; + maUnsavedDocShells.insert(DocShellMap::value_type(nFileId, aSrcDoc)); + StartListening(*pShell); + pSrcDoc = pShell->GetDocument(); + break; + } + } pShell = static_cast<ScDocShell*>(SfxObjectShell::GetNext(*pShell, &aType, false)); } @@ -2127,6 +2144,17 @@ const ScDocument* ScExternalRefManager::getSrcDocument(sal_uInt16 nFileId) return static_cast<ScDocShell*>(p)->GetDocument(); } + itrEnd = maUnsavedDocShells.end(); + itr = maUnsavedDocShells.find(nFileId); + if (itr != itrEnd) + { + //document is unsaved document + + SfxObjectShell* p = itr->second.maShell; + itr->second.maLastAccess = Time( Time::SYSTEM ); + return static_cast<ScDocShell*>(p)->GetDocument(); + } + const OUString* pFile = getExternalFileName(nFileId); if (!pFile) // no file name associated with this ID. @@ -2341,6 +2369,17 @@ bool ScExternalRefManager::isOwnDocument(const OUString& rFile) const void ScExternalRefManager::convertToAbsName(OUString& rFile) const { + // unsaved documents have no AbsName + TypeId aType(TYPE(ScDocShell)); + ScDocShell* pShell = static_cast<ScDocShell*>(SfxObjectShell::GetFirst(&aType, false)); + while (pShell) + { + if (rFile == rtl::OUString(pShell->GetName())) + return; + + pShell = static_cast<ScDocShell*>(SfxObjectShell::GetNext(*pShell, &aType, false)); + } + SfxObjectShell* pDocShell = mpDoc->GetDocumentShell(); rFile = ScGlobal::GetAbsDocName(rFile, pDocShell); } @@ -2644,6 +2683,51 @@ sal_uInt32 ScExternalRefManager::getMappedNumberFormat(sal_uInt16 nFileId, sal_u return nNumFmt; } +void ScExternalRefManager::transformUnsavedRefToSavedRef( SfxObjectShell* pShell ) +{ + DocShellMap::iterator itr = maUnsavedDocShells.begin(); + while( itr != maUnsavedDocShells.end() ) + { + if (&(itr->second.maShell) == pShell) + { + // found that the shell is marked as unsaved + rtl::OUString aFileURL = pShell->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI); + switchSrcFile(itr->first, aFileURL, rtl::OUString()); + EndListening(*pShell); + maUnsavedDocShells.erase(itr++); + } + } +} + +void ScExternalRefManager::Notify( SfxBroadcaster&, const SfxHint& rHint ) +{ + if ( rHint.ISA( SfxEventHint ) ) + { + sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId(); + switch ( nEventId ) + { + case SFX_EVENT_PREPARECLOSEDOC: + { + SfxObjectShell* pObjShell = static_cast<const SfxEventHint&>( rHint ).GetObjShell(); + ScDocShell* pDocShell = static_cast< ScDocShell* >( pObjShell ); + WarningBox aBox( pDocShell->GetActiveDialogParent(), WinBits( WB_OK ), + ScGlobal::GetRscString( STR_CLOSE_WITH_UNSAVED_REFS ) ); + aBox.Execute(); + } + break; + case SFX_EVENT_SAVEDOCDONE: + case SFX_EVENT_SAVEASDOCDONE: + { + SfxObjectShell* pObjShell = static_cast<const SfxEventHint&>( rHint ).GetObjShell(); + transformUnsavedRefToSavedRef(pObjShell); + } + break; + default: + break; + } + } +} + IMPL_LINK(ScExternalRefManager, TimeOutHdl, AutoTimer*, pTimer) { if (pTimer == &maSrcDocTimer) diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src index 464f14119a50..a5a1e6aedac2 100644 --- a/sc/source/ui/src/globstr.src +++ b/sc/source/ui/src/globstr.src @@ -1851,5 +1851,13 @@ Resource RID_GLOBSTR { Text [ en-US ] = "Invalid name. Only use letters, numbers and underscore."; }; + String STR_UNSAVED_EXT_REF + { + Text [ en-US ] = "This Document contains external references to unsaved documents.\n\nDo you want to continue?"; + }; + String STR_CLOSE_WITH_UNSAVED_REFS + { + Text [ en-US ] = "This Document is referenced by another document and not yet saved. Closing it without saving will result in data loss."; + }; }; diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index cfa027e8d54e..e2c950c4d9b9 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -89,6 +89,7 @@ #include "docuno.hxx" #include "charthelper.hxx" #include "tabbgcolor.hxx" +#include "clipparam.hxx" #include <basic/sbstar.hxx> #include <com/sun/star/container/XNameContainer.hpp> @@ -2562,6 +2563,7 @@ void ScViewFunc::MoveTable( if(nDestTab==SC_TAB_APPEND) nDestTab=pDestDoc->GetTableCount(); SCTAB nDestTab1=nDestTab; + ScClipParam aParam; for( sal_uInt16 j=0; j<TheTabs.size(); ++j, ++nDestTab1 ) { // insert sheets first and update all references rtl::OUString aName; @@ -2576,7 +2578,10 @@ void ScViewFunc::MoveTable( nErrVal = 0; // total error break; // for } + ScRange aRange( 0, 0, TheTabs[j], MAXCOL, MAXROW, TheTabs[j] ); + aParam.maRanges.Append(aRange); } + pDoc->SetClipParam(aParam); if ( nErrVal > 0 ) { nDestTab1 = nDestTab; |