summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEduard Braun <eduard.braun2@gmx.de>2017-12-22 19:17:01 +0000
committerEduard Braun <eduard.braun2@gmx.de>2017-12-22 19:17:01 +0000
commitf589e1fdc71cba2025d940232f132ab0622adda7 (patch)
tree5bff3f1249fa4403bc5077bf4a385650451487a2 /src
parentAllow extensions to throw more fine-grained exceptions (diff)
downloadinkscape-f589e1fdc71cba2025d940232f132ab0622adda7.tar.gz
inkscape-f589e1fdc71cba2025d940232f132ab0622adda7.zip
Show appropriate warning if non-existent export ID is specified
Fixed bug: - https://bugs.launchpad.net/inkscape/+bug/1739497
Diffstat (limited to 'src')
-rw-r--r--src/extension/internal/cairo-ps-out.cpp3
-rw-r--r--src/extension/internal/cairo-renderer-pdf-out.cpp3
-rw-r--r--src/extension/internal/latex-text-renderer.cpp5
-rw-r--r--src/extension/output.h5
-rw-r--r--src/file.cpp7
5 files changed, 22 insertions, 1 deletions
diff --git a/src/extension/internal/cairo-ps-out.cpp b/src/extension/internal/cairo-ps-out.cpp
index e8f47e79e..57169ed45 100644
--- a/src/extension/internal/cairo-ps-out.cpp
+++ b/src/extension/internal/cairo-ps-out.cpp
@@ -76,6 +76,9 @@ ps_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int l
if (exportId && strcmp(exportId, "")) {
// we want to export the given item only
base = SP_ITEM(doc->getObjectById(exportId));
+ if (!base) {
+ throw Inkscape::Extension::Output::export_id_not_found(exportId);
+ }
pageBoundingBox = exportCanvas;
}
else {
diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp
index 5576676b2..865de1a07 100644
--- a/src/extension/internal/cairo-renderer-pdf-out.cpp
+++ b/src/extension/internal/cairo-renderer-pdf-out.cpp
@@ -71,6 +71,9 @@ pdf_render_document_to_file(SPDocument *doc, gchar const *filename, unsigned int
if (exportId && strcmp(exportId, "")) {
// we want to export the given item only
base = SP_ITEM(doc->getObjectById(exportId));
+ if (!base) {
+ throw Inkscape::Extension::Output::export_id_not_found(exportId);
+ }
pageBoundingBox = exportCanvas;
}
else {
diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp
index 7a1cacbf2..960aec7a9 100644
--- a/src/extension/internal/latex-text-renderer.cpp
+++ b/src/extension/internal/latex-text-renderer.cpp
@@ -41,6 +41,7 @@
#include "util/units.h"
+#include "extension/output.h"
#include "extension/system.h"
#include "inkscape-version.h"
@@ -68,7 +69,9 @@ latex_render_document_text_to_file( SPDocument *doc, gchar const *filename,
if (exportId && strcmp(exportId, "")) {
// we want to export the given item only
base = dynamic_cast<SPItem *>(doc->getObjectById(exportId));
- g_assert(base != NULL);
+ if (!base) {
+ throw Inkscape::Extension::Output::export_id_not_found(exportId);
+ }
pageBoundingBox = exportCanvas;
}
else {
diff --git a/src/extension/output.h b/src/extension/output.h
index 44a731ca0..420eb9245 100644
--- a/src/extension/output.h
+++ b/src/extension/output.h
@@ -31,6 +31,11 @@ public:
class save_cancelled {}; /**< Saving was cancelled */
class no_extension_found {}; /**< Failed because we couldn't find an extension to match the filename */
class file_read_only {}; /**< The existing file can not be opened for writing */
+ class export_id_not_found { /**< The object ID requested for export could not be found in the document */
+ public:
+ const gchar * const id;
+ export_id_not_found(const gchar * const id = NULL) : id{id} {};
+ };
Output (Inkscape::XML::Node * in_repr,
Implementation::Implementation * in_imp);
diff --git a/src/file.cpp b/src/file.cpp
index e5caaaca0..9cf0448e1 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -658,6 +658,13 @@ file_save(Gtk::Window &parentWindow, SPDocument *doc, const Glib::ustring &uri,
SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
doc->getReprRoot()->setAttribute("inkscape:version", sp_version_to_string( save ));
return false;
+ } catch (Inkscape::Extension::Output::export_id_not_found &e) {
+ gchar *text = g_strdup_printf(_("File could not be saved:\nNo object with ID '%s' found."), e.id);
+ SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
+ sp_ui_error_dialog(text);
+ g_free(text);
+ doc->getReprRoot()->setAttribute("inkscape:version", sp_version_to_string( save ));
+ return false;
} catch (Inkscape::Extension::Output::no_overwrite &e) {
return sp_file_save_dialog(parentWindow, doc, save_method);
} catch (...) {