diff --git a/sfx2/UIConfig_sfx.mk b/sfx2/UIConfig_sfx.mk index 554bf63785ed..3d182da9c27a 100644 --- a/sfx2/UIConfig_sfx.mk +++ b/sfx2/UIConfig_sfx.mk @@ -20,6 +20,7 @@ $(eval $(call gb_UIConfig_add_uifiles,sfx,\ sfx2/uiconfig/ui/documentfontspage \ sfx2/uiconfig/ui/documentinfopage \ sfx2/uiconfig/ui/documentpropertiesdialog \ + sfx2/uiconfig/ui/editdocumentdialog \ sfx2/uiconfig/ui/editdurationdialog \ sfx2/uiconfig/ui/emojicontrol \ sfx2/uiconfig/ui/errorfindemaildialog \ diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 660e0d5fe0a9..3586a9ac3559 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -154,6 +154,55 @@ void SfxViewFrame::InitInterface_Impl() #endif } +/// Asks the user if editing a read-only document is really wanted. +class SfxEditDocumentDialog : public MessageDialog +{ +private: + VclPtr m_pEditDocument; + VclPtr m_pCancel; + +public: + SfxEditDocumentDialog(vcl::Window* pParent); + ~SfxEditDocumentDialog() override; + void dispose() override; +}; + +SfxEditDocumentDialog::SfxEditDocumentDialog(vcl::Window* pParent) + : MessageDialog(pParent, "EditDocumentDialog", "sfx/ui/editdocumentdialog.ui") +{ + get(m_pEditDocument, "edit"); + get(m_pCancel, "cancel"); +} + +SfxEditDocumentDialog::~SfxEditDocumentDialog() +{ + disposeOnce(); +} + +void SfxEditDocumentDialog::dispose() +{ + m_pEditDocument.clear(); + m_pCancel.clear(); + MessageDialog::dispose(); +} + +/// Is this read-only object shell opened via .uno:SignPDF? +static bool IsSignPDF(SfxObjectShellRef xObjSh) +{ + if (!xObjSh.Is()) + return false; + + SfxMedium* pMedium = xObjSh->GetMedium(); + if (pMedium && !pMedium->IsOriginallyReadOnly()) + { + std::shared_ptr pFilter = pMedium->GetFilter(); + if (pFilter && pFilter->GetName() == "draw_pdf_import") + return true; + } + + return false; +} + static bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const OUString& aPath, const std::shared_ptr& pFilter, sal_uInt32 nPasswordHash, const uno::Sequence< beans::PropertyValue >& aInfo ) { // TODO/LATER: In future the info should replace the direct hash completely @@ -1149,13 +1198,7 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) } else { - bool bSignPDF = false; - SfxMedium* pMedium = m_xObjSh->GetMedium(); - if (pMedium && !pMedium->IsOriginallyReadOnly()) - { - std::shared_ptr pFilter = pMedium->GetFilter(); - bSignPDF = pFilter && pFilter->GetName() == "draw_pdf_import"; - } + bool bSignPDF = IsSignPDF(m_xObjSh); SfxInfoBarWindow* pInfoBar = AppendInfoBar("readonly", SfxResId(bSignPDF ? STR_READONLY_PDF : STR_READONLY_DOCUMENT)); if (pInfoBar) @@ -1267,6 +1310,12 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) IMPL_LINK_NOARG(SfxViewFrame, SwitchReadOnlyHandler, Button*, void) { + if (m_xObjSh.Is() && IsSignPDF(m_xObjSh)) + { + ScopedVclPtrInstance pDialog(nullptr); + if (pDialog->Execute() != RET_OK) + return; + } GetDispatcher()->Execute(SID_EDITDOC); } diff --git a/sfx2/uiconfig/ui/editdocumentdialog.ui b/sfx2/uiconfig/ui/editdocumentdialog.ui new file mode 100644 index 000000000000..bfaccd927322 --- /dev/null +++ b/sfx2/uiconfig/ui/editdocumentdialog.ui @@ -0,0 +1,73 @@ + + + + + + False + 6 + Confirm editing of document + False + True + dialog + True + question + Are you sure you want to edit the document? + The original file can be signed without editing the document. Existing signatures on the document will be lost in case of saving an edited version. + + + False + vertical + 12 + + + False + end + + + Edit Document + True + True + True + True + True + True + + + False + True + 0 + True + + + + + Cancel + True + True + True + True + bottom + + + False + True + 1 + True + + + + + False + True + end + 0 + + + + + + edit + cancel + + +