mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-01 01:20:25 +00:00
Fix app::Console() to handle a non UI context correctly
This commit is contained in:
parent
f907cd0424
commit
d9259afc04
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "app/app.h"
|
#include "app/app.h"
|
||||||
#include "app/console.h"
|
#include "app/console.h"
|
||||||
|
#include "app/context.h"
|
||||||
#include "app/modules/gui.h"
|
#include "app/modules/gui.h"
|
||||||
#include "app/ui/status_bar.h"
|
#include "app/ui/status_bar.h"
|
||||||
|
|
||||||
@ -33,17 +34,24 @@ static int console_counter = 0;
|
|||||||
static bool console_locked;
|
static bool console_locked;
|
||||||
static bool want_close_flag = false;
|
static bool want_close_flag = false;
|
||||||
|
|
||||||
Console::Console()
|
Console::Console(Context* ctx)
|
||||||
|
: m_withUI(false)
|
||||||
{
|
{
|
||||||
console_counter++;
|
if (ctx)
|
||||||
|
m_withUI = (ctx->isUiAvailable());
|
||||||
|
else
|
||||||
|
m_withUI =
|
||||||
|
(App::instance()->isGui() &&
|
||||||
|
Manager::getDefault() &&
|
||||||
|
Manager::getDefault()->getDisplay());
|
||||||
|
|
||||||
if (!App::instance()->isGui() ||
|
if (!m_withUI)
|
||||||
!Manager::getDefault() ||
|
|
||||||
!Manager::getDefault()->getDisplay() ||
|
|
||||||
wid_console ||
|
|
||||||
console_counter > 1)
|
|
||||||
return;
|
return;
|
||||||
else {
|
|
||||||
|
console_counter++;
|
||||||
|
if (wid_console || console_counter > 1)
|
||||||
|
return;
|
||||||
|
|
||||||
Window* window = new Window(Window::WithTitleBar, "Errors Console");
|
Window* window = new Window(Window::WithTitleBar, "Errors Console");
|
||||||
Grid* grid = new Grid(1, false);
|
Grid* grid = new Grid(1, false);
|
||||||
View* view = new View();
|
View* view = new View();
|
||||||
@ -78,10 +86,12 @@ Console::Console()
|
|||||||
console_locked = false;
|
console_locked = false;
|
||||||
want_close_flag = false;
|
want_close_flag = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Console::~Console()
|
Console::~Console()
|
||||||
{
|
{
|
||||||
|
if (!m_withUI)
|
||||||
|
return;
|
||||||
|
|
||||||
console_counter--;
|
console_counter--;
|
||||||
|
|
||||||
if ((wid_console) && (console_counter == 0)) {
|
if ((wid_console) && (console_counter == 0)) {
|
||||||
@ -107,7 +117,12 @@ void Console::printf(const char* format, ...)
|
|||||||
vsprintf(buf, format, ap);
|
vsprintf(buf, format, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (wid_console) {
|
if (!m_withUI || !wid_console) {
|
||||||
|
fputs(buf, stdout);
|
||||||
|
fflush(stdout);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Open the window
|
// Open the window
|
||||||
if (!wid_console->isVisible()) {
|
if (!wid_console->isVisible()) {
|
||||||
wid_console->openWindow();
|
wid_console->openWindow();
|
||||||
@ -135,11 +150,6 @@ void Console::printf(const char* format, ...)
|
|||||||
|
|
||||||
wid_textbox->setText(final.c_str());
|
wid_textbox->setText(final.c_str());
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
fputs(buf, stdout);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void Console::showException(const std::exception& e)
|
void Console::showException(const std::exception& e)
|
||||||
|
@ -12,15 +12,19 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
class Context;
|
||||||
|
|
||||||
class Console {
|
class Console {
|
||||||
public:
|
public:
|
||||||
Console();
|
Console(Context* ctx = nullptr);
|
||||||
~Console();
|
~Console();
|
||||||
|
|
||||||
void printf(const char *format, ...);
|
void printf(const char *format, ...);
|
||||||
|
|
||||||
static void showException(const std::exception& e);
|
static void showException(const std::exception& e);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_withUI;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
@ -89,7 +89,7 @@ Document* load_document(Context* context, const char* filename)
|
|||||||
fop_post_load(fop);
|
fop_post_load(fop);
|
||||||
|
|
||||||
if (fop->has_error()) {
|
if (fop->has_error()) {
|
||||||
Console console;
|
Console console(context);
|
||||||
console.printf(fop->error.c_str());
|
console.printf(fop->error.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ int save_document(Context* context, doc::Document* document)
|
|||||||
fop_done(fop);
|
fop_done(fop);
|
||||||
|
|
||||||
if (fop->has_error()) {
|
if (fop->has_error()) {
|
||||||
Console console;
|
Console console(context);
|
||||||
console.printf(fop->error.c_str());
|
console.printf(fop->error.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user