Make the log dialog not insane and crashy

Originally committed to SVN as r5958.
This commit is contained in:
Thomas Goyne 2011-12-02 04:36:06 +00:00
parent 95a329a1e2
commit 48d412468e
2 changed files with 57 additions and 114 deletions

View file

@ -34,69 +34,32 @@
/// @ingroup libaegisub
///
////////////
// Includes
#include "config.h"
#include "dialog_log.h"
#ifndef AGI_PRE
#include <ctime>
#include <functional>
#include <string>
#include <wx/button.h>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/statline.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#endif
#include <time.h>
#include "dialog_log.h"
/// @brief Constructor
/// @param parent Parent frame.
LogWindow::LogWindow(wxWindow *parent)
: wxDialog (parent, -1, _("Log window"), wxDefaultPosition, wxSize(700,300), wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER, _("Log window"))
class EmitLog : public agi::log::Emitter {
wxTextCtrl *text_ctrl;
public:
EmitLog(wxTextCtrl *t)
: text_ctrl(t)
{
// Text sizer
wxSizer *sizer_text = new wxBoxSizer(wxVERTICAL);
wxTextCtrl *text_ctrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString ,wxDefaultPosition, wxSize(700,300), wxTE_MULTILINE|wxTE_READONLY);
wxTextAttr attr;
attr.SetFont(wxFont(8, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
text_ctrl->SetDefaultStyle(attr);
sizer_text->Add(text_ctrl, 1, wxEXPAND);
wxSizer *sizer_button = new wxBoxSizer(wxHORIZONTAL);
sizer_button->Add(new wxButton(this, wxID_OK), 0, wxALIGN_RIGHT | wxALL, 2);
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(sizer_text, 1 ,wxEXPAND|wxALL, 0);
sizer->Add(sizer_button, 0 ,wxEXPAND|wxALL, 0);
sizer->SetSizeHints(this);
SetSizer(sizer);
emit_log = new EmitLog(text_ctrl);
emit_log->Enable();
}
/// @brief Destructor
LogWindow::~LogWindow() {
delete emit_log;
}
LogWindow::EmitLog::EmitLog(wxTextCtrl *t): text_ctrl(t) {
const agi::log::Sink *sink = agi::log::log->GetSink();
for (unsigned int i=0; i < sink->size(); i++) {
Write((*sink)[i]);
}
for_each(sink->begin(), sink->end(), bind(&EmitLog::log, this, std::tr1::placeholders::_1));
}
void LogWindow::EmitLog::Write(agi::log::SinkMessage *sm) {
void log(agi::log::SinkMessage *sm) {
#ifndef _WIN32
tm tmtime;
localtime_r(&sm->tv.tv_sec, &tmtime);
@ -123,19 +86,21 @@ void LogWindow::EmitLog::Write(agi::log::SinkMessage *sm) {
#endif
text_ctrl->AppendText(log);
}
};
LogWindow::LogWindow(wxWindow *parent)
: wxDialog (parent, -1, _("Log window"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER)
{
wxTextCtrl *text_ctrl = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxSize(700,300), wxTE_MULTILINE|wxTE_READONLY);
text_ctrl->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, wxFont(8, wxMODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)));
void LogWindow::EmitLog::log(agi::log::SinkMessage *sm) {
delete text_ctrl;
Write(sm);
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(text_ctrl, wxSizerFlags(1).Expand().Border());
sizer->Add(new wxButton(this, wxID_OK), wxSizerFlags(0).Border().Right());
SetSizerAndFit(sizer);
emit_log.reset(new EmitLog(text_ctrl));
emit_log->Enable();
Bind(wxEVT_CLOSE_WINDOW, std::tr1::bind(&wxDialog::Destroy, this));
}
void LogWindow::OnClose(wxCloseEvent &WXUNUSED(event)) {
Destroy();
}
BEGIN_EVENT_TABLE(LogWindow, wxDialog)
EVT_CLOSE(LogWindow::OnClose)
END_EVENT_TABLE()

View file

@ -34,40 +34,18 @@
/// @ingroup libaegisub
///
////////////
// Includes
#ifndef AGI_PRE
#include <wx/dialog.h>
#include <wx/textctrl.h>
#endif
#include <libaegisub/log.h>
/// @class AboutScreen
/// @brief About dialogue.
#include <libaegisub/scoped_ptr.h>
class LogWindow: public wxDialog {
agi::scoped_ptr<agi::log::Emitter> emit_log;
public:
class EmitLog: public agi::log::Emitter {
wxTextCtrl *text_ctrl;
void Write(agi::log::SinkMessage *sm);
public:
EmitLog(wxTextCtrl *t);
void Prime();
void Set(wxTextCtrl *text_ctrl_p) { text_ctrl = text_ctrl_p; }
void log(agi::log::SinkMessage *sm);
};
/// @brief Constructor
/// @param parent Parent frame.
LogWindow(wxWindow *parent);
~LogWindow();
DECLARE_EVENT_TABLE()
private:
void OnClose(wxCloseEvent &event);
EmitLog *emit_log;
};