Icon-O-Matic: Improve saving-related error messages
Improves the errors that are given to the user when exporting to an HVIF file failed. Examples of errors improved include errors related to having too many shapes, too many paths, or too many points in a path. Also changes the icon shown in the alert box from an info icon to an error icon. Fixes #13978 Change-Id: I12a08e9857a95bd4d41da029320fa6f8182c3aa5 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6837 Reviewed-by: Adrien Destugues <[email protected]> Reviewed-by: waddlesplash <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
@@ -319,6 +319,7 @@ DoCatalogs Icon-O-Matic :
|
||||
SVGExporter.cpp
|
||||
SVGImporter.cpp
|
||||
Exporter.cpp
|
||||
FlatIconExporter.cpp
|
||||
AddPathsCommand.cpp
|
||||
AddPointCommand.cpp
|
||||
AddShapesCommand.cpp
|
||||
|
||||
@@ -110,11 +110,11 @@ Exporter::_ExportThread()
|
||||
if (ret < B_OK) {
|
||||
// inform user of failure at this point
|
||||
BString helper(B_TRANSLATE("Saving your document failed!"));
|
||||
helper << "\n\n" << B_TRANSLATE("Error: ") << strerror(ret);
|
||||
helper << "\n\n" << ErrorCodeToString(ret);
|
||||
BAlert* alert = new BAlert(B_TRANSLATE_CONTEXT("Bad news", "Title of error alert"),
|
||||
helper.String(),
|
||||
B_TRANSLATE_COMMENT("Bleep!", "Exporter - Continue in error dialog"),
|
||||
NULL, NULL);
|
||||
NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
||||
// launch alert asynchronously
|
||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||
alert->Go(NULL);
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#define EXPORTER_H
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <Entry.h>
|
||||
#include <OS.h>
|
||||
|
||||
@@ -38,7 +40,9 @@ class Exporter {
|
||||
|
||||
virtual status_t Export(const Icon* icon,
|
||||
BPositionIO* stream) = 0;
|
||||
|
||||
/*! Turns the status_t error code returned by \c Export into a string. */
|
||||
virtual const char* ErrorCodeToString(status_t code)
|
||||
{ return strerror(code); }
|
||||
virtual const char* MIMEType() = 0;
|
||||
|
||||
/*! If \a selfDestroy is true, class deletes itself when export thread is
|
||||
|
||||
@@ -13,7 +13,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Archivable.h>
|
||||
#include <Catalog.h>
|
||||
#include <DataIO.h>
|
||||
#include <Locale.h>
|
||||
#include <Message.h>
|
||||
#include <Node.h>
|
||||
|
||||
@@ -33,6 +35,9 @@
|
||||
#include "Style.h"
|
||||
#include "VectorPath.h"
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
#define B_TRANSLATION_CONTEXT "Icon-O-Matic-FlatIconExporter"
|
||||
|
||||
using std::nothrow;
|
||||
|
||||
|
||||
@@ -92,6 +97,37 @@ FlatIconExporter::Export(const Icon* icon, BPositionIO* stream)
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
FlatIconExporter::ErrorCodeToString(status_t code)
|
||||
{
|
||||
switch (code) {
|
||||
case E_TOO_MANY_PATHS:
|
||||
return B_TRANSLATE("There are too many paths. "
|
||||
"The HVIF format supports a maximum of 255.");
|
||||
case E_PATH_TOO_MANY_POINTS:
|
||||
return B_TRANSLATE("One or more of the paths have too many vertices. "
|
||||
"The HVIF format supports a maximum of 255 vertices per path.");
|
||||
case E_TOO_MANY_SHAPES:
|
||||
return B_TRANSLATE("There are too many shapes. "
|
||||
"The HVIF format supports a maximum of 255.");
|
||||
case E_SHAPE_TOO_MANY_PATHS:
|
||||
return B_TRANSLATE("One or more of the shapes has too many paths. "
|
||||
"The HVIF format supports a maximum of 255 paths per shape.");
|
||||
case E_SHAPE_TOO_MANY_TRANSFORMERS:
|
||||
return B_TRANSLATE("One or more of the shapes have too many transformers. "
|
||||
"The HVIF format supports a maximum of 255 transformers per shape.");
|
||||
case E_TOO_MANY_STYLES:
|
||||
return B_TRANSLATE("There are too many styles. "
|
||||
"The HVIF format supports a maximum of 255.");
|
||||
default:
|
||||
return Exporter::ErrorCodeToString(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
status_t
|
||||
FlatIconExporter::Export(const Icon* icon, BNode* node,
|
||||
const char* attrName)
|
||||
@@ -206,7 +242,7 @@ status_t
|
||||
FlatIconExporter::_WriteStyles(LittleEndianBuffer& buffer, const Container<Style>* styles)
|
||||
{
|
||||
if (styles->CountItems() > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
return E_TOO_MANY_STYLES;
|
||||
uint8 styleCount = min_c(255, styles->CountItems());
|
||||
if (!buffer.Write(styleCount))
|
||||
return B_NO_MEMORY;
|
||||
@@ -362,7 +398,7 @@ status_t
|
||||
FlatIconExporter::_WritePaths(LittleEndianBuffer& buffer, const Container<VectorPath>* paths)
|
||||
{
|
||||
if (paths->CountItems() > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
return E_TOO_MANY_PATHS;
|
||||
uint8 pathCount = min_c(255, paths->CountItems());
|
||||
if (!buffer.Write(pathCount))
|
||||
return B_NO_MEMORY;
|
||||
@@ -374,7 +410,7 @@ FlatIconExporter::_WritePaths(LittleEndianBuffer& buffer, const Container<Vector
|
||||
pathFlags |= PATH_FLAG_CLOSED;
|
||||
|
||||
if (path->CountPoints() > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
return E_PATH_TOO_MANY_POINTS;
|
||||
uint8 pointCount = min_c(255, path->CountPoints());
|
||||
|
||||
// see if writing segments with commands is more efficient
|
||||
@@ -487,7 +523,7 @@ _WritePathSourceShape(LittleEndianBuffer& buffer, PathSourceShape* shape,
|
||||
return false;
|
||||
|
||||
if (shape->Paths()->CountItems() > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
return E_SHAPE_TOO_MANY_PATHS;
|
||||
uint8 pathCount = min_c(255, shape->Paths()->CountItems());
|
||||
|
||||
// write shape type and style index
|
||||
@@ -508,7 +544,7 @@ _WritePathSourceShape(LittleEndianBuffer& buffer, PathSourceShape* shape,
|
||||
}
|
||||
|
||||
if (shape->Transformers()->CountItems() > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
return E_SHAPE_TOO_MANY_TRANSFORMERS;
|
||||
uint8 transformerCount = min_c(255, shape->Transformers()->CountItems());
|
||||
|
||||
// shape flags
|
||||
@@ -582,7 +618,7 @@ FlatIconExporter::_WriteShapes(LittleEndianBuffer& buffer, const Container<Style
|
||||
|
||||
// Write number of exportable shapes
|
||||
if (pathShapeCount > 255)
|
||||
return B_RESULT_NOT_REPRESENTABLE;
|
||||
return E_TOO_MANY_SHAPES;
|
||||
if (!buffer.Write((uint8) pathShapeCount))
|
||||
return B_NO_MEMORY;
|
||||
|
||||
|
||||
@@ -26,6 +26,15 @@ _BEGIN_ICON_NAMESPACE
|
||||
_END_ICON_NAMESPACE
|
||||
|
||||
|
||||
#define HVIF_EXPORTER_ERRORS_BASE (B_ERRORS_END + 1)
|
||||
#define E_TOO_MANY_PATHS (HVIF_EXPORTER_ERRORS_BASE + 0)
|
||||
#define E_PATH_TOO_MANY_POINTS (HVIF_EXPORTER_ERRORS_BASE + 1)
|
||||
#define E_TOO_MANY_SHAPES (HVIF_EXPORTER_ERRORS_BASE + 2)
|
||||
#define E_SHAPE_TOO_MANY_PATHS (HVIF_EXPORTER_ERRORS_BASE + 3)
|
||||
#define E_SHAPE_TOO_MANY_TRANSFORMERS (HVIF_EXPORTER_ERRORS_BASE + 4)
|
||||
#define E_TOO_MANY_STYLES (HVIF_EXPORTER_ERRORS_BASE + 5)
|
||||
|
||||
|
||||
#define PRINT_STATISTICS 0
|
||||
|
||||
#if PRINT_STATISTICS
|
||||
@@ -56,9 +65,10 @@ class FlatIconExporter : public Exporter {
|
||||
// Exporter interface
|
||||
virtual status_t Export(const Icon* icon,
|
||||
BPositionIO* stream);
|
||||
|
||||
virtual const char* ErrorCodeToString(status_t code);
|
||||
virtual const char* MIMEType() { return NULL; }
|
||||
|
||||
// FlatIconExporter
|
||||
/*! Export to file attribute */
|
||||
status_t Export(const Icon* icon, BNode* node,
|
||||
const char* attrName);
|
||||
|
||||
Reference in New Issue
Block a user