Handle overlap of warnings (information loss and write-only warnings)

This commit is contained in:
Isaiah Odhner 2023-06-28 21:34:09 -04:00
parent f194583760
commit 4750c1212d

View File

@ -2811,16 +2811,21 @@ class PaintApp(App[None]):
# This could be considered part of the text information, but could be mentioned. # This could be considered part of the text information, but could be mentioned.
# Also, it could be confusing if a file uses a lot of full block characters (█). # Also, it could be confusing if a file uses a lot of full block characters (█).
# TODO: is this all the formats that can't be opened? # TODO: is this all the formats that can't be opened?
# TODO: consider overlap between non-openable format and information loss warnings non_openable = format_id in ("HTML", "RICH_CONSOLE_MARKUP") or (format_id in Image.SAVE and not format_id in Image.OPEN)
non_openable = (format_id in ("HTML", "RICH_CONSOLE_MARKUP")) or (format_id in Image.SAVE and not format_id in Image.OPEN) supports_text_and_color = format_id in ("ANSI", "SVG", "HTML", "RICH_CONSOLE_MARKUP")
if non_openable: if format_id == "PLAINTEXT":
# The callback argument is whether there's information loss.
# If True, it will try to load the file to show the loss, and it would error in this case.
self.confirm_save_non_openable_file(lambda: callback(False))
elif format_id in ("ANSI", "SVG", "HTML", "RICH_CONSOLE_MARKUP"):
callback(False)
elif format_id == "PLAINTEXT":
self.confirm_lose_color_information(lambda: callback(True)) self.confirm_lose_color_information(lambda: callback(True))
elif supports_text_and_color:
# This is handled before Pillow's image formats, so that bespoke format support overrides Pillow.
if non_openable:
self.confirm_save_non_openable_file(lambda: callback(False))
else:
callback(False)
else:
# Image formats
assert format_id in Image.SAVE, f"Unknown format ID: {format_id!r}"
if non_openable:
self.confirm_save_non_openable_file(lambda: self.confirm_lose_text_information(lambda: callback(False)))
else: else:
self.confirm_lose_text_information(lambda: callback(True)) self.confirm_lose_text_information(lambda: callback(True))