summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sfx2/objsh.hxx6
-rw-r--r--sfx2/inc/doc.hrc6
-rw-r--r--sfx2/source/doc/doc.src15
-rw-r--r--sfx2/source/doc/objmisc.cxx20
-rw-r--r--writerfilter/source/ooxml/OOXMLDocumentImpl.cxx10
5 files changed, 53 insertions, 4 deletions
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index bf69c21d58c4..7a2e133c83fa 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -213,6 +213,9 @@ private:
bool bIsInGenerateThumbnail; //optimize thumbnail generate and store procedure to improve odt saving performance, i120030
bool mbAvoidRecentDocs; ///< Avoid adding to the recent documents list, if not necessary.
+ enum TriState {undefined, yes, no};
+ TriState mbContinueImportOnFilterExceptions = undefined; // try to import as much as possible
+
bool CloseInternal();
SAL_DLLPRIVATE void UpdateTime_Impl(const css::uno::Reference<
@@ -458,6 +461,9 @@ public:
/// Don't add to the recent documents - it's an expensive operation, sometimes it is not wanted.
void AvoidRecentDocs(bool bAvoid) { mbAvoidRecentDocs = bAvoid; }
+ /// On first error ask user if import should continue; return saved answer.
+ bool IsContinueImportOnFilterExceptions(const OUString& aErrMessage);
+
// Transfer IFace
bool IsAbortingImport() const;
void FinishedLoading( SfxLoadedFlags nWhich = SfxLoadedFlags::ALL );
diff --git a/sfx2/inc/doc.hrc b/sfx2/inc/doc.hrc
index 388cdf621dbf..29e4f667efa9 100644
--- a/sfx2/inc/doc.hrc
+++ b/sfx2/inc/doc.hrc
@@ -127,8 +127,12 @@
#define STR_MSG_EXPORT_SUCCESS (RID_SFX_DOC_START+170)
#define STR_MSG_QUERY_COPY (RID_SFX_DOC_START+171)
+#define STR_QMSG_ERROR_OPENING_FILE (RID_SFX_DOC_START+180)
+#define STR_QMSG_ERROR_OPENING_FILE_DETAILS (RID_SFX_DOC_START+181)
+#define STR_QMSG_ERROR_OPENING_FILE_CONTINUE (RID_SFX_DOC_START+182)
+
// please update to the last id
-#define ACT_SFX_DOC_END STR_MSG_QUERY_COPY
+#define ACT_SFX_DOC_END STR_QMSG_ERROR_OPENING_FILE_CONTINUE
#if ACT_SFX_DOC_END > RID_SFX_DOC_END
#error resource overflow in #line, #file
#endif
diff --git a/sfx2/source/doc/doc.src b/sfx2/source/doc/doc.src
index 978f5e3c5b72..d607087c16f6 100644
--- a/sfx2/source/doc/doc.src
+++ b/sfx2/source/doc/doc.src
@@ -353,6 +353,21 @@ String STR_QMSG_SEL_TEMPLATE_DELETE
Text [ en-US ] = "Do you want to delete the selected templates?";
};
+String STR_QMSG_ERROR_OPENING_FILE
+{
+ Text [ en-US ] = "An error occured during opening the file. This may be caused by incorrect file contents.\n";
+};
+
+String STR_QMSG_ERROR_OPENING_FILE_DETAILS
+{
+ Text [ en-US ] = "The error details are:\n";
+};
+
+String STR_QMSG_ERROR_OPENING_FILE_CONTINUE
+{
+ Text [ en-US ] = "\nProceeding with import may cause data loss or corruption, and application may become unstable or crash.\n\nDo you want to ignore the error and attempt to continue loading the file?";
+};
+
Image IMG_ACTION_SORT
{
ImageBitmap = Bitmap
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index 806228e86a21..36d8fac7098e 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -1944,4 +1944,24 @@ void SfxObjectShell::StoreLog()
}
}
+bool SfxObjectShell::IsContinueImportOnFilterExceptions(const OUString& aErrMessage)
+{
+ if (mbContinueImportOnFilterExceptions == undefined)
+ {
+ if (Application::GetDialogCancelMode() == Application::DialogCancelMode::Off)
+ {
+ // Ask the user to try to continue or abort loading
+ OUString aMessage = SfxResId(STR_QMSG_ERROR_OPENING_FILE).toString();
+ if (!aErrMessage.isEmpty())
+ aMessage += SfxResId(STR_QMSG_ERROR_OPENING_FILE_DETAILS).toString() + aErrMessage;
+ aMessage += SfxResId(STR_QMSG_ERROR_OPENING_FILE_CONTINUE).toString();
+ ScopedVclPtrInstance< MessageDialog > aBox(nullptr, aMessage, VclMessageType::Question, VclButtonsType::YesNo);
+ mbContinueImportOnFilterExceptions = (aBox->Execute() == RET_YES) ? yes : no;
+ }
+ else
+ mbContinueImportOnFilterExceptions = no;
+ }
+ return mbContinueImportOnFilterExceptions == yes;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
index f836cf85ac42..94f2fbba4c7e 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
@@ -41,6 +41,7 @@
#include <unotools/mediadescriptor.hxx>
#include <iostream>
+#include "sfx2/objsh.hxx"
// this extern variable is declared in OOXMLStreamImpl.hxx
OUString customTarget;
@@ -503,11 +504,14 @@ void OOXMLDocumentImpl::resolve(Stream & rStream)
{
xParser->parseStream(aParserInput);
}
- catch (xml::sax::SAXException const&)
+ catch (xml::sax::SAXException const& rErr)
{
- // don't swallow these - handlers may not have been executed,
+ // don't silently swallow these - handlers may not have been executed,
// and the domain mapper is likely in an inconsistent state
- throw;
+ // In case user chooses to try to continue loading, don't ask again for this file
+ SfxObjectShell* rShell = SfxObjectShell::GetShellFromComponent(mxModel);
+ if (!rShell || !rShell->IsContinueImportOnFilterExceptions("SAXException: " + rErr.Message))
+ throw;
}
catch (uno::RuntimeException const&)
{