mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-01 18:00:26 +00:00
Show errors in UI when we cannot recover a specific file (related to #4291)
Internal: Visible in: https://igarastudio.zendesk.com/agent/tickets/5772 With files from: https://igarastudio.zendesk.com/agent/tickets/5773
This commit is contained in:
parent
799b3e1918
commit
e0a677545e
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2018-2022 Igara Studio S.A.
|
// Copyright (C) 2018-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -19,6 +19,7 @@
|
|||||||
#include "app/ui/status_bar.h"
|
#include "app/ui/status_bar.h"
|
||||||
#include "base/memory.h"
|
#include "base/memory.h"
|
||||||
#include "base/string.h"
|
#include "base/string.h"
|
||||||
|
#include "fmt/format.h"
|
||||||
#include "ui/system.h"
|
#include "ui/system.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
@ -205,16 +206,10 @@ Console::Console(Context* ctx)
|
|||||||
if (!ui::is_ui_thread())
|
if (!ui::is_ui_thread())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (ctx) {
|
if (ctx)
|
||||||
m_withUI = (ctx->isUIAvailable());
|
m_withUI = ctx->isUIAvailable();
|
||||||
}
|
else
|
||||||
else {
|
m_withUI = Console::isUIAvailable();
|
||||||
m_withUI =
|
|
||||||
(App::instance() &&
|
|
||||||
App::instance()->isGui() &&
|
|
||||||
Manager::getDefault() &&
|
|
||||||
Manager::getDefault()->display()->nativeWindow());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_withUI)
|
if (!m_withUI)
|
||||||
return;
|
return;
|
||||||
@ -272,16 +267,28 @@ void Console::printf(const char* format, ...)
|
|||||||
// static
|
// static
|
||||||
void Console::showException(const std::exception& e)
|
void Console::showException(const std::exception& e)
|
||||||
{
|
{
|
||||||
|
std::string text;
|
||||||
|
if (typeid(e) == typeid(std::bad_alloc))
|
||||||
|
text = "There is not enough memory to complete the action.";
|
||||||
|
else
|
||||||
|
text = fmt::format("A problem has occurred.\n\nDetails:\n{}\n", e.what());
|
||||||
|
|
||||||
if (!ui::is_ui_thread()) {
|
if (!ui::is_ui_thread()) {
|
||||||
LOG(ERROR, "A problem has occurred.\n\nDetails:\n%s\n", e.what());
|
LOG(ERROR, text.c_str());
|
||||||
|
|
||||||
|
// Show the error in the UI thread (if the UI is available)
|
||||||
|
if (Console::isUIAvailable()) {
|
||||||
|
ui::execute_from_ui_thread(
|
||||||
|
[text]{
|
||||||
|
Console console;
|
||||||
|
console.printf(text.c_str());
|
||||||
|
});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console console;
|
Console console;
|
||||||
if (typeid(e) == typeid(std::bad_alloc))
|
console.printf(text.c_str());
|
||||||
console.printf("There is not enough memory to complete the action.");
|
|
||||||
else
|
|
||||||
console.printf("A problem has occurred.\n\nDetails:\n%s\n", e.what());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
@ -291,4 +298,13 @@ void Console::notifyNewDisplayConfiguration()
|
|||||||
m_console->centerConsole();
|
m_console->centerConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
bool Console::isUIAvailable()
|
||||||
|
{
|
||||||
|
auto app = App::instance();
|
||||||
|
auto man = Manager::getDefault();
|
||||||
|
return (app && app->isGui() &&
|
||||||
|
man && man->display() && man->display()->nativeWindow());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2018-2022 Igara Studio S.A.
|
// Copyright (C) 2018-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2017 David Capello
|
// Copyright (C) 2001-2017 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -25,9 +25,11 @@ namespace app {
|
|||||||
static void notifyNewDisplayConfiguration();
|
static void notifyNewDisplayConfiguration();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class ConsoleWindow;
|
static bool isUIAvailable();
|
||||||
|
|
||||||
bool m_withUI;
|
bool m_withUI;
|
||||||
|
|
||||||
|
class ConsoleWindow;
|
||||||
static ConsoleWindow* m_console;
|
static ConsoleWindow* m_console;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user