diff options
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 51 | ||||
-rw-r--r-- | uui/inc/strings.hrc | 1 | ||||
-rw-r--r-- | uui/source/iahndl-locking.cxx | 5 | ||||
-rw-r--r-- | uui/source/trylater.cxx | 29 | ||||
-rw-r--r-- | uui/source/trylater.hxx | 2 |
5 files changed, 64 insertions, 24 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index 466372c28bb2..9635f872b210 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -29,6 +29,7 @@ #include <com/sun/star/container/XChild.hpp> #include <com/sun/star/document/XDocumentRevisionListPersistence.hpp> #include <com/sun/star/document/LockedDocumentRequest.hpp> +#include <com/sun/star/document/LockedOnSavingRequest.hpp> #include <com/sun/star/document/OwnLockOnDocumentRequest.hpp> #include <com/sun/star/document/LockFileIgnoreRequest.hpp> #include <com/sun/star/document/LockFileCorruptRequest.hpp> @@ -65,6 +66,7 @@ #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/security/DocumentSignatureInformation.hpp> #include <com/sun/star/security/DocumentDigitalSignatures.hpp> +#include <o3tl/make_unique.hxx> #include <tools/urlobj.hxx> #include <unotools/configmgr.hxx> #include <unotools/tempfile.hxx> @@ -840,7 +842,7 @@ SfxMedium::ShowLockResult SfxMedium::ShowLockedDocumentDialog( const LockFileEnt // show the interaction regarding the document opening uno::Reference< task::XInteractionHandler > xHandler = GetInteractionHandler(); - if ( ::svt::DocumentLockFile::IsInteractionAllowed() && xHandler.is() && ( bIsLoading || bOwnLock ) ) + if ( ::svt::DocumentLockFile::IsInteractionAllowed() && xHandler.is() && ( bIsLoading || !bHandleSysLocked || bOwnLock ) ) { OUString aDocumentURL = GetURLObject().GetLastName(); OUString aInfo; @@ -855,27 +857,32 @@ SfxMedium::ShowLockResult SfxMedium::ShowLockedDocumentDialog( const LockFileEnt xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny( document::OwnLockOnDocumentRequest( OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo, !bIsLoading ) ) ); } - else /*logically therefore bIsLoading is set */ + else { + // Use a fourth continuation in case there's no filesystem lock: + // "Ignore lock file and open/replace the document" + if (!bHandleSysLocked) + nContinuations = 4; + if ( !aData[LockFileComponent::OOOUSERNAME].isEmpty() ) aInfo = aData[LockFileComponent::OOOUSERNAME]; else aInfo = aData[LockFileComponent::SYSUSERNAME]; if ( !aInfo.isEmpty() && !aData[LockFileComponent::EDITTIME].isEmpty() ) + aInfo += " ( " + aData[LockFileComponent::EDITTIME] + " )"; + + if (!bIsLoading) // so, !bHandleSysLocked { - aInfo += " ( " ; - aInfo += aData[LockFileComponent::EDITTIME]; - aInfo += " )"; + xInteractionRequestImpl = new ::ucbhelper::InteractionRequest(uno::makeAny( + document::LockedOnSavingRequest(OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo))); + // Currently, only the last "Retry" continuation (meaning ignore the lock and try overwriting) can be returned. + } + else /*logically therefore bIsLoading is set */ + { + xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny( + document::LockedDocumentRequest( OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) ); } - - xInteractionRequestImpl = new ::ucbhelper::InteractionRequest( uno::makeAny( - document::LockedDocumentRequest( OUString(), uno::Reference< uno::XInterface >(), aDocumentURL, aInfo ) ) ); - - // Use a fourth continuation in case there's no filesystem lock: - // "Ignore lock file and open the document" - if (!bHandleSysLocked) - nContinuations = 4; } uno::Sequence< uno::Reference< task::XInteractionContinuation > > aContinuations(nContinuations); @@ -885,7 +892,7 @@ SfxMedium::ShowLockResult SfxMedium::ShowLockedDocumentDialog( const LockFileEnt if (nContinuations > 3) { // We use InteractionRetry to reflect that user wants to - // ignore the (stale?) alien lock file and open the document + // ignore the (stale?) alien lock file and open/overwrite the document aContinuations[3] = new ::ucbhelper::InteractionRetry(xInteractionRequestImpl.get()); } xInteractionRequestImpl->setContinuations( aContinuations ); @@ -1216,6 +1223,22 @@ SfxMedium::LockFileResult SfxMedium::LockOrigFileOnDemand( bool bLoading, bool b // if system lock is used the writeable stream should be available bool bHandleSysLocked = ( bLoading && bUseSystemLock && !pImpl->xStream.is() && !pImpl->m_pOutStream ); + // The file is attempted to get locked for the duration of lockfile creation on save + std::unique_ptr<osl::File> pFileLock; + if (!bLoading && bUseSystemLock && pImpl->pTempFile) + { + INetURLObject aDest(GetURLObject()); + OUString aDestURL(aDest.GetMainURL(INetURLObject::DecodeMechanism::NONE)); + + if (comphelper::isFileUrl(aDestURL) || !aDest.removeSegment()) + { + pFileLock = o3tl::make_unique<osl::File>(aDestURL); + auto rc = pFileLock->open(osl_File_OpenFlag_Write); + if (rc == osl::FileBase::E_ACCES) + bHandleSysLocked = true; + } + } + do { try diff --git a/uui/inc/strings.hrc b/uui/inc/strings.hrc index 590a582eba06..a47412520bca 100644 --- a/uui/inc/strings.hrc +++ b/uui/inc/strings.hrc @@ -59,6 +59,7 @@ #define STR_TRYLATER_TITLE NC_("STR_TRYLATER_TITLE", "Document in Use") #define STR_TRYLATER_MSG NC_("STR_TRYLATER_MSG", "Document file '$(ARG1)' is locked for editing by:\n\n$(ARG2)\n\nTry again later to save document or save a copy of that document.\n\n") +#define STR_OVERWRITE_IGNORELOCK_MSG NC_("STR_OVERWRITE_IGNORELOCK_MSG", "Document file '$(ARG1)' is locked for editing by:\n\n$(ARG2)\n\nYou may try to ignore the file locking and overwrite the existing document.\n\n") #define STR_TRYLATER_RETRYSAVING_BTN NC_("STR_TRYLATER_RETRYSAVING_BTN", "~Retry Saving") #define STR_TRYLATER_SAVEAS_BTN NC_("STR_TRYLATER_SAVEAS_BTN", "~Save As...") diff --git a/uui/source/iahndl-locking.cxx b/uui/source/iahndl-locking.cxx index 08b5b5c7fd99..ecd49ea55baf 100644 --- a/uui/source/iahndl-locking.cxx +++ b/uui/source/iahndl-locking.cxx @@ -105,11 +105,12 @@ handleLockedDocumentRequest_( ? aInfo : Translate::get( STR_UNKNOWNUSER, aResLocale ) ); - aMessage = Translate::get(STR_TRYLATER_MSG, aResLocale); + aMessage = Translate::get(xRetry.is() ? STR_OVERWRITE_IGNORELOCK_MSG : STR_TRYLATER_MSG, + aResLocale); aMessage = UUIInteractionHelper::replaceMessageWithArguments( aMessage, aArguments ); - ScopedVclPtrInstance< TryLaterQueryBox > xDialog(pParent, aResLocale, aMessage); + ScopedVclPtrInstance< TryLaterQueryBox > xDialog(pParent, aResLocale, aMessage, xRetry.is()); nResult = xDialog->Execute(); } else if ( nMode == UUI_DOC_OWN_LOAD_LOCK || diff --git a/uui/source/trylater.cxx b/uui/source/trylater.cxx index aa9bc08cf603..cacc68bc7d7c 100644 --- a/uui/source/trylater.cxx +++ b/uui/source/trylater.cxx @@ -21,18 +21,33 @@ #include <strings.hrc> #include "trylater.hxx" -TryLaterQueryBox::TryLaterQueryBox(vcl::Window* pParent, const std::locale& rResLocale, const OUString& aMessage) +TryLaterQueryBox::TryLaterQueryBox(vcl::Window* pParent, const std::locale& rResLocale, const OUString& aMessage, bool bEnableOverride) : MessBox(pParent, MessBoxStyle::NONE, 0, Translate::get(STR_TRYLATER_TITLE, rResLocale), aMessage) { SetImage(GetStandardQueryBoxImage()); - AddButton(Translate::get(STR_TRYLATER_RETRYSAVING_BTN, rResLocale), RET_YES, - ButtonDialogFlags::Default | ButtonDialogFlags::OK | ButtonDialogFlags::Focus); - AddButton(Translate::get(STR_TRYLATER_SAVEAS_BTN, rResLocale), RET_NO); - AddButton( StandardButtonType::Cancel, RET_CANCEL, ButtonDialogFlags::Cancel ); + // Currently we don't have the retry/save-as functionality implemented for cases when file is locked. + // So threat them mutually exclusive with overwrite here. TODO/LATER: just add the overwrite option + // as third option when retrying and saving with another name would be possible along with overwriting + if (bEnableOverride) + { + AddButton(Translate::get(STR_FILECHANGED_SAVEANYWAY_BTN, rResLocale), RET_IGNORE, + ButtonDialogFlags::OK); + AddButton(StandardButtonType::Cancel, RET_CANCEL, + ButtonDialogFlags::Default | ButtonDialogFlags::Cancel | ButtonDialogFlags::Focus); - SetButtonHelpText( RET_YES, OUString() ); - SetButtonHelpText( RET_NO, OUString() ); + SetButtonHelpText(RET_IGNORE, OUString()); + } + else + { + AddButton(Translate::get(STR_TRYLATER_RETRYSAVING_BTN, rResLocale), RET_YES, + ButtonDialogFlags::Default | ButtonDialogFlags::OK | ButtonDialogFlags::Focus); + AddButton(Translate::get(STR_TRYLATER_SAVEAS_BTN, rResLocale), RET_NO); + AddButton( StandardButtonType::Cancel, RET_CANCEL, ButtonDialogFlags::Cancel ); + + SetButtonHelpText( RET_YES, OUString() ); + SetButtonHelpText( RET_NO, OUString() ); + } } TryLaterQueryBox::~TryLaterQueryBox() diff --git a/uui/source/trylater.hxx b/uui/source/trylater.hxx index 23d0a0c78841..f03f3cf92187 100644 --- a/uui/source/trylater.hxx +++ b/uui/source/trylater.hxx @@ -24,7 +24,7 @@ class TryLaterQueryBox : public MessBox { public: - TryLaterQueryBox(vcl::Window* pParent, const std::locale& rLocale, const OUString& aMessage); + TryLaterQueryBox(vcl::Window* pParent, const std::locale& rLocale, const OUString& aMessage, bool bEnableOverride); virtual ~TryLaterQueryBox() override; }; |