mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 04:20:23 +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,55 +34,64 @@ 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 {
|
|
||||||
Window* window = new Window(Window::WithTitleBar, "Errors Console");
|
|
||||||
Grid* grid = new Grid(1, false);
|
|
||||||
View* view = new View();
|
|
||||||
TextBox* textbox = new TextBox("", JI_WORDWRAP);
|
|
||||||
Button* button = new Button("&Cancel");
|
|
||||||
|
|
||||||
if (!grid || !textbox || !button)
|
console_counter++;
|
||||||
return;
|
if (wid_console || console_counter > 1)
|
||||||
|
return;
|
||||||
|
|
||||||
// The "button" closes the console
|
Window* window = new Window(Window::WithTitleBar, "Errors Console");
|
||||||
button->Click.connect(Bind<void>(&Window::closeWindow, window, button));
|
Grid* grid = new Grid(1, false);
|
||||||
|
View* view = new View();
|
||||||
|
TextBox* textbox = new TextBox("", JI_WORDWRAP);
|
||||||
|
Button* button = new Button("&Cancel");
|
||||||
|
|
||||||
view->attachToView(textbox);
|
if (!grid || !textbox || !button)
|
||||||
|
return;
|
||||||
|
|
||||||
button->setMinSize(gfx::Size(60, 0));
|
// The "button" closes the console
|
||||||
|
button->Click.connect(Bind<void>(&Window::closeWindow, window, button));
|
||||||
|
|
||||||
grid->addChildInCell(view, 1, 1, JI_HORIZONTAL | JI_VERTICAL);
|
view->attachToView(textbox);
|
||||||
grid->addChildInCell(button, 1, 1, JI_CENTER);
|
|
||||||
window->addChild(grid);
|
|
||||||
|
|
||||||
view->setVisible(false);
|
button->setMinSize(gfx::Size(60, 0));
|
||||||
button->setFocusMagnet(true);
|
|
||||||
view->setExpansive(true);
|
|
||||||
|
|
||||||
/* force foreground mode */
|
grid->addChildInCell(view, 1, 1, JI_HORIZONTAL | JI_VERTICAL);
|
||||||
/* ji_find_widget(window)->in_foreground = true; */
|
grid->addChildInCell(button, 1, 1, JI_CENTER);
|
||||||
|
window->addChild(grid);
|
||||||
|
|
||||||
wid_console = window;
|
view->setVisible(false);
|
||||||
wid_view = view;
|
button->setFocusMagnet(true);
|
||||||
wid_textbox = textbox;
|
view->setExpansive(true);
|
||||||
wid_cancel = button;
|
|
||||||
console_locked = false;
|
/* force foreground mode */
|
||||||
want_close_flag = false;
|
/* ji_find_widget(window)->in_foreground = true; */
|
||||||
}
|
|
||||||
|
wid_console = window;
|
||||||
|
wid_view = view;
|
||||||
|
wid_textbox = textbox;
|
||||||
|
wid_cancel = button;
|
||||||
|
console_locked = 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,38 +117,38 @@ 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) {
|
||||||
// Open the window
|
|
||||||
if (!wid_console->isVisible()) {
|
|
||||||
wid_console->openWindow();
|
|
||||||
ui::Manager::getDefault()->invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* update the textbox */
|
|
||||||
if (!console_locked) {
|
|
||||||
console_locked = true;
|
|
||||||
|
|
||||||
wid_view->setVisible(true);
|
|
||||||
|
|
||||||
wid_console->remapWindow();
|
|
||||||
wid_console->setBounds(gfx::Rect(0, 0, ui::display_w()*9/10, ui::display_h()*6/10));
|
|
||||||
wid_console->centerWindow();
|
|
||||||
wid_console->invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& text = wid_textbox->getText();
|
|
||||||
|
|
||||||
std::string final;
|
|
||||||
if (!text.empty())
|
|
||||||
final += text;
|
|
||||||
final += buf;
|
|
||||||
|
|
||||||
wid_textbox->setText(final.c_str());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fputs(buf, stdout);
|
fputs(buf, stdout);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Open the window
|
||||||
|
if (!wid_console->isVisible()) {
|
||||||
|
wid_console->openWindow();
|
||||||
|
ui::Manager::getDefault()->invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* update the textbox */
|
||||||
|
if (!console_locked) {
|
||||||
|
console_locked = true;
|
||||||
|
|
||||||
|
wid_view->setVisible(true);
|
||||||
|
|
||||||
|
wid_console->remapWindow();
|
||||||
|
wid_console->setBounds(gfx::Rect(0, 0, ui::display_w()*9/10, ui::display_h()*6/10));
|
||||||
|
wid_console->centerWindow();
|
||||||
|
wid_console->invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& text = wid_textbox->getText();
|
||||||
|
|
||||||
|
std::string final;
|
||||||
|
if (!text.empty())
|
||||||
|
final += text;
|
||||||
|
final += buf;
|
||||||
|
|
||||||
|
wid_textbox->setText(final.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -12,16 +12,20 @@
|
|||||||
#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