Don't show clipboard error when we're trying to show the File > New dialog

The error is confusing because the user doesn't know that we're trying
to access the clipboard info only to fill Width/Height fields
automatically on File > New. Some errors (like "invalid image format")
should be displayed only when we use Edit > Paste explicitly.
This commit is contained in:
David Capello 2022-03-10 15:28:52 -03:00
parent e5b0d9de8d
commit 8064179dfc
2 changed files with 22 additions and 2 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2021 Igara Studio S.A.
// Copyright (C) 2021-2022 Igara Studio S.A.
// Copyright (C) 2016-2018 David Capello
//
// This program is distributed under the terms of
@ -36,12 +36,28 @@ using namespace base::serialization::little_endian;
namespace {
clip::format custom_image_format = 0;
bool show_clip_errors = true;
class InhibitClipErrors {
bool m_saved;
public:
InhibitClipErrors() {
m_saved = show_clip_errors;
show_clip_errors = false;
}
~InhibitClipErrors() {
show_clip_errors = m_saved;
}
};
void* native_display_handle() {
return os::instance()->defaultWindow()->nativeHandle();
}
void custom_error_handler(clip::ErrorCode code) {
if (!show_clip_errors)
return;
switch (code) {
case clip::ErrorCode::CannotLock:
ui::Alert::show(Strings::alerts_clipboard_access_locked());
@ -289,6 +305,10 @@ bool get_native_clipboard_bitmap(doc::Image** image,
bool get_native_clipboard_bitmap_size(gfx::Size* size)
{
// Don't show errors when we are trying to get the size of the image
// only. (E.g. don't show "invalid image format error")
InhibitClipErrors inhibitErrors;
clip::image_spec spec;
if (clip::get_image_spec(spec)) {
size->w = spec.width;

@ -1 +1 @@
Subproject commit c46c49141f72dd753b260eea4e6d7b37413f0ff6
Subproject commit 2ada8b17b39bf41a669248a2be5c6e4be4c27f14