2009-08-31 17:09:50 -06:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
|
|
|
|
#include <wx/wx.h>
|
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/textctrl.h>
|
|
|
|
#include <wx/listbox.h>
|
|
|
|
#include <wx/checklst.h>
|
|
|
|
|
|
|
|
#include "Core.h" // for Core::GetState()
|
|
|
|
#include "LogWindow.h"
|
|
|
|
#include "Console.h"
|
|
|
|
|
2009-08-31 20:41:48 -06:00
|
|
|
// Milliseconds between msgQueue flushes to wxTextCtrl
|
2009-08-31 17:09:50 -06:00
|
|
|
#define UPDATETIME 200
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(CLogWindow, wxDialog)
|
|
|
|
EVT_CLOSE(CLogWindow::OnClose)
|
|
|
|
EVT_TEXT_ENTER(IDM_SUBMITCMD, CLogWindow::OnSubmit)
|
|
|
|
EVT_BUTTON(IDM_CLEARLOG, CLogWindow::OnClear)
|
|
|
|
EVT_BUTTON(IDM_TOGGLEALL, CLogWindow::OnToggleAll)
|
|
|
|
EVT_RADIOBOX(IDM_VERBOSITY, CLogWindow::OnOptionsCheck)
|
2009-09-02 06:09:51 -06:00
|
|
|
EVT_CHOICE(IDM_FONT, CLogWindow::OnOptionsCheck)
|
|
|
|
EVT_CHECKBOX(IDM_WRAPLINE, CLogWindow::OnOptionsCheck)
|
2009-08-31 17:09:50 -06:00
|
|
|
EVT_CHECKBOX(IDM_WRITEFILE, CLogWindow::OnOptionsCheck)
|
|
|
|
EVT_CHECKBOX(IDM_WRITECONSOLE, CLogWindow::OnOptionsCheck)
|
|
|
|
EVT_CHECKBOX(IDM_WRITEWINDOW, CLogWindow::OnOptionsCheck)
|
|
|
|
EVT_CHECKLISTBOX(IDM_LOGCHECKS, CLogWindow::OnLogCheck)
|
|
|
|
EVT_TIMER(IDTM_UPDATELOG, CLogWindow::OnLogTimer)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2009-09-02 06:09:51 -06:00
|
|
|
CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
|
2009-08-31 20:41:48 -06:00
|
|
|
: wxDialog(parent, id, title, position, size, style)
|
2009-09-02 06:09:51 -06:00
|
|
|
, Parent(parent), m_LogSection(1), m_Log(NULL), m_cmdline(NULL)
|
|
|
|
, m_LogAccess(true)
|
2009-08-31 17:09:50 -06:00
|
|
|
{
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager = LogManager::GetInstance();
|
2009-08-31 17:09:50 -06:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, this);
|
|
|
|
m_fileLog = m_LogManager->getFileListener();
|
|
|
|
m_console = m_LogManager->getConsoleListener();
|
2009-08-31 17:09:50 -06:00
|
|
|
|
|
|
|
CreateGUIControls();
|
|
|
|
|
|
|
|
LoadSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::CreateGUIControls()
|
|
|
|
{
|
2009-09-01 01:32:07 -06:00
|
|
|
// Verbosity
|
2009-09-02 06:09:51 -06:00
|
|
|
wxArrayString wxLevels, wxLevelsUse;
|
|
|
|
wxLevels.Add(wxT("Notice"));
|
|
|
|
wxLevels.Add(wxT("Error"));
|
|
|
|
wxLevels.Add(wxT("Warning"));
|
|
|
|
wxLevels.Add(wxT("Info"));
|
|
|
|
wxLevels.Add(wxT("Debug"));
|
|
|
|
for (int i = 0; i < MAX_LOGLEVEL; ++i) wxLevelsUse.Add(wxString::Format(wxT("%s"), wxLevels.Item(i).c_str()));
|
|
|
|
m_verbosity = new wxRadioBox(this, IDM_VERBOSITY, wxT("Verbosity"), wxDefaultPosition, wxDefaultSize, wxLevelsUse, 0, wxRA_SPECIFY_ROWS, wxDefaultValidator);
|
|
|
|
// Don't take up so much space
|
2009-09-03 01:51:18 -06:00
|
|
|
m_verbosity->SetFont(wxFont(7, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
|
2009-09-02 06:09:51 -06:00
|
|
|
|
|
|
|
// Font
|
|
|
|
wxChoice * m_FontChoice = new wxChoice(this, IDM_FONT, wxDefaultPosition, wxDefaultSize, * new wxArrayString(), 0, wxDefaultValidator);
|
|
|
|
m_FontChoice->Append(wxT("Default font"));
|
|
|
|
m_FontChoice->Append(wxT("Modern font"));
|
|
|
|
m_FontChoice->SetSelection(0);
|
|
|
|
|
2009-09-01 01:32:07 -06:00
|
|
|
// Options
|
2009-09-02 06:09:51 -06:00
|
|
|
wxCheckBox * m_WrapLine = new wxCheckBox(this, IDM_WRAPLINE, wxT("Word Wrap"));
|
2009-08-31 17:09:50 -06:00
|
|
|
m_writeFileCB = new wxCheckBox(this, IDM_WRITEFILE, wxT("Write to File"), wxDefaultPosition, wxDefaultSize, 0);
|
|
|
|
m_writeConsoleCB = new wxCheckBox(this, IDM_WRITECONSOLE, wxT("Write to Console"), wxDefaultPosition, wxDefaultSize, 0);
|
|
|
|
m_writeWindowCB = new wxCheckBox(this, IDM_WRITEWINDOW, wxT("Write to Window ->"), wxDefaultPosition, wxDefaultSize, 0);
|
|
|
|
|
|
|
|
m_checks = new wxCheckListBox(this, IDM_LOGCHECKS, wxDefaultPosition, wxDefaultSize);
|
|
|
|
|
2009-09-02 06:09:51 -06:00
|
|
|
// Log viewer and submit row
|
|
|
|
m_Log = CreateTextCtrl(this, IDM_LOG, wxTE_RICH | wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
|
|
|
|
DefaultFont = m_Log->GetFont();
|
2009-08-31 17:09:50 -06:00
|
|
|
m_cmdline = new wxTextCtrl(this, IDM_SUBMITCMD, wxEmptyString, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB);
|
|
|
|
//m_cmdline->SetFont(DebuggerFont);
|
|
|
|
|
2009-09-01 01:32:07 -06:00
|
|
|
// Sizers
|
2009-09-02 06:09:51 -06:00
|
|
|
sUber = new wxBoxSizer(wxHORIZONTAL); // whole plane
|
|
|
|
sLeft = new wxBoxSizer(wxVERTICAL); // left sizer
|
|
|
|
sRight = new wxBoxSizer(wxVERTICAL); // right sizer
|
|
|
|
sRightBottom = new wxBoxSizer(wxHORIZONTAL); // submit row
|
|
|
|
// Left side: buttons (-submit), options, and log type selection
|
|
|
|
wxStaticBoxSizer* sbLeftOptions = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Options"));
|
|
|
|
|
|
|
|
wxBoxSizer* sLogCtrl = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sLogCtrl->Add(new wxButton(this, IDM_TOGGLEALL, wxT("Toggle all"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 1);
|
|
|
|
sLogCtrl->Add(new wxButton(this, IDM_CLEARLOG, wxT("Clear"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 1);
|
|
|
|
|
|
|
|
sbLeftOptions->Add(m_FontChoice, 0, (wxDOWN), 1);
|
|
|
|
sbLeftOptions->Add(m_WrapLine, 0, (wxDOWN), 1);
|
|
|
|
sbLeftOptions->Add(m_writeFileCB, 0, (wxDOWN), 1);
|
|
|
|
sbLeftOptions->Add(m_writeConsoleCB, 0, (wxDOWN), 1);
|
|
|
|
sbLeftOptions->Add(m_writeWindowCB, 0);
|
2009-09-01 01:32:07 -06:00
|
|
|
|
2009-09-02 06:09:51 -06:00
|
|
|
sLeft->Add(m_verbosity, 0, wxEXPAND | (wxLEFT | wxRIGHT), 5);
|
|
|
|
sLeft->Add(sbLeftOptions, 0, wxEXPAND | (wxLEFT | wxRIGHT), 5);
|
2009-09-01 01:32:07 -06:00
|
|
|
sLeft->Add(sLogCtrl, 0, wxEXPAND);
|
|
|
|
sLeft->Add(m_checks, 1, wxEXPAND);
|
|
|
|
|
2009-09-02 06:09:51 -06:00
|
|
|
PopulateRight();
|
|
|
|
|
2009-08-31 17:09:50 -06:00
|
|
|
sUber->Add(sLeft, 0, wxEXPAND);
|
|
|
|
sUber->Add(sRight, 1, wxEXPAND);
|
2009-09-02 06:09:51 -06:00
|
|
|
this->SetSizer(sUber);
|
2009-08-31 17:09:50 -06:00
|
|
|
|
2009-09-02 06:09:51 -06:00
|
|
|
// Settings
|
2009-08-31 17:09:50 -06:00
|
|
|
SetAffirmativeId(IDM_SUBMITCMD);
|
|
|
|
UpdateChecks();
|
|
|
|
m_cmdline->SetFocus();
|
|
|
|
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogTimer = new wxTimer(this, IDTM_UPDATELOG);
|
|
|
|
m_LogTimer->Start(UPDATETIME);
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
CLogWindow::~CLogWindow()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, this);
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogTimer->Stop();
|
|
|
|
delete m_LogTimer;
|
2009-08-31 17:09:50 -06:00
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::OnClose(wxCloseEvent& event)
|
|
|
|
{
|
|
|
|
wxGetApp().GetCFrame()->ToggleLogWindow(false);
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::SaveSettings()
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
ini.Set("LogWindow", "x", GetPosition().x);
|
|
|
|
ini.Set("LogWindow", "y", GetPosition().y);
|
|
|
|
ini.Set("LogWindow", "w", GetSize().GetWidth());
|
|
|
|
ini.Set("LogWindow", "h", GetSize().GetHeight());
|
|
|
|
ini.Set("Options", "Verbosity", m_verbosity->GetSelection() + 1);
|
|
|
|
ini.Set("Options", "WriteToFile", m_writeFile);
|
|
|
|
ini.Set("Options", "WriteToConsole", m_writeConsole);
|
|
|
|
ini.Set("Options", "WriteToWindow", m_writeWindow);
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
2009-09-02 06:09:51 -06:00
|
|
|
ini.Set("Logs", m_LogManager->getShortName((LogTypes::LOG_TYPE)i), m_checks->IsChecked(i));
|
2009-08-31 17:09:50 -06:00
|
|
|
ini.Save(LOGGER_CONFIG_FILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::LoadSettings()
|
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
ini.Load(LOGGER_CONFIG_FILE);
|
|
|
|
int x,y,w,h,verbosity;
|
|
|
|
ini.Get("LogWindow", "x", &x, GetPosition().x);
|
|
|
|
ini.Get("LogWindow", "y", &y, GetPosition().y);
|
|
|
|
ini.Get("LogWindow", "w", &w, GetSize().GetWidth());
|
|
|
|
ini.Get("LogWindow", "h", &h, GetSize().GetHeight());
|
|
|
|
SetSize(x, y, w, h);
|
|
|
|
ini.Get("Options", "Verbosity", &verbosity, 0);
|
|
|
|
if (verbosity < 1) verbosity = 1;
|
2009-09-02 06:09:51 -06:00
|
|
|
if (verbosity > MAX_LOGLEVEL) verbosity = MAX_LOGLEVEL;
|
2009-08-31 17:09:50 -06:00
|
|
|
m_verbosity->SetSelection(verbosity - 1);
|
|
|
|
ini.Get("Options", "WriteToFile", &m_writeFile, true);
|
|
|
|
m_writeFileCB->SetValue(m_writeFile);
|
|
|
|
ini.Get("Options", "WriteToConsole", &m_writeConsole, true);
|
|
|
|
m_writeConsoleCB->SetValue(m_writeConsole);
|
|
|
|
ini.Get("Options", "WriteToWindow", &m_writeWindow, true);
|
|
|
|
m_writeWindowCB->SetValue(m_writeWindow);
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
bool enable;
|
2009-09-02 06:09:51 -06:00
|
|
|
ini.Get("Logs", m_LogManager->getShortName((LogTypes::LOG_TYPE)i), &enable, true);
|
2009-08-31 17:09:50 -06:00
|
|
|
|
|
|
|
if (m_writeWindow && enable)
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, this);
|
2009-08-31 17:09:50 -06:00
|
|
|
else
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, this);
|
2009-08-31 17:09:50 -06:00
|
|
|
|
|
|
|
if (m_writeFile && enable)
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, m_fileLog);
|
2009-08-31 17:09:50 -06:00
|
|
|
else
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, m_fileLog);
|
2009-08-31 17:09:50 -06:00
|
|
|
|
|
|
|
if (m_writeConsole && enable)
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, m_console);
|
2009-08-31 17:09:50 -06:00
|
|
|
else
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, m_console);
|
|
|
|
m_LogManager->setLogLevel((LogTypes::LOG_TYPE)i, (LogTypes::LOG_LEVELS)(verbosity));
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
UpdateChecks();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::OnSubmit(wxCommandEvent& WXUNUSED (event))
|
|
|
|
{
|
2009-09-02 06:09:51 -06:00
|
|
|
if (!m_cmdline) return;
|
2009-08-31 17:09:50 -06:00
|
|
|
Console_Submit(m_cmdline->GetValue().To8BitData());
|
|
|
|
m_cmdline->SetValue(wxEmptyString);
|
|
|
|
NotifyUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::OnClear(wxCommandEvent& WXUNUSED (event))
|
|
|
|
{
|
2009-09-02 06:09:51 -06:00
|
|
|
m_Log->Clear();
|
2009-08-31 17:09:50 -06:00
|
|
|
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogSection.Enter();
|
2009-08-31 17:09:50 -06:00
|
|
|
int msgQueueSize = (int)msgQueue.size();
|
|
|
|
for (int i = 0; i < msgQueueSize; i++)
|
|
|
|
msgQueue.pop();
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogSection.Leave();
|
2009-08-31 17:09:50 -06:00
|
|
|
|
|
|
|
m_console->ClearScreen();
|
|
|
|
NOTICE_LOG(CONSOLE, "Console cleared");
|
|
|
|
NotifyUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable or disable all boxes for the current verbosity level and save the changes.
|
|
|
|
void CLogWindow::OnToggleAll(wxCommandEvent& WXUNUSED (event))
|
|
|
|
{
|
|
|
|
static bool enableAll = false;
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
ToggleLog(i, enableAll);
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
enableAll = !enableAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append checkboxes and update checked groups.
|
|
|
|
void CLogWindow::UpdateChecks()
|
|
|
|
{
|
|
|
|
// This is only run once to append checkboxes to the wxCheckListBox.
|
|
|
|
if (m_checks->GetCount() == 0)
|
|
|
|
{
|
|
|
|
// [F|RES] hide the window while we fill it... wxwidgets gets trouble
|
|
|
|
// if you don't do it (at least the win version)
|
|
|
|
m_checks->Freeze();
|
|
|
|
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
|
|
|
|
{
|
2009-09-02 06:09:51 -06:00
|
|
|
m_checks->Append(wxString::FromAscii(m_LogManager->getFullName( (LogTypes::LOG_TYPE)i )));
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
m_checks->Thaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_checks->Freeze();
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
|
|
|
|
{
|
|
|
|
m_checks->Check(i,
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->isListener((LogTypes::LOG_TYPE)i, this) ||
|
|
|
|
m_LogManager->isListener((LogTypes::LOG_TYPE)i, m_console) ||
|
|
|
|
m_LogManager->isListener((LogTypes::LOG_TYPE)i, m_fileLog));
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
m_checks->Thaw();
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:09:51 -06:00
|
|
|
void CLogWindow::UnPopulateRight()
|
|
|
|
{
|
|
|
|
sRight->Remove(m_Log);
|
|
|
|
sRight->Remove(sRightBottom);
|
|
|
|
// Remove() destroys sizers
|
|
|
|
sRightBottom = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
}
|
|
|
|
void CLogWindow::PopulateRight()
|
|
|
|
{
|
|
|
|
sRightBottom->Add(m_cmdline, 1, wxEXPAND);
|
|
|
|
sRight->Add(m_Log, 1, wxEXPAND | wxSHRINK);
|
|
|
|
sRight->Add(sRightBottom, 0, wxEXPAND);
|
|
|
|
this->Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxTextCtrl* CLogWindow::CreateTextCtrl(wxDialog* parent, wxWindowID id, long Style)
|
|
|
|
{
|
|
|
|
wxTextCtrl* TC = new wxTextCtrl(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, Style);
|
|
|
|
TC->SetBackgroundColour(*wxBLACK);
|
|
|
|
//TC->SetFont(DebuggerFont);
|
|
|
|
return TC;
|
|
|
|
}
|
|
|
|
|
2009-08-31 17:09:50 -06:00
|
|
|
// When an option is changed, save the change
|
|
|
|
void CLogWindow::OnOptionsCheck(wxCommandEvent& event)
|
|
|
|
{
|
2009-09-02 06:09:51 -06:00
|
|
|
wxString Text;
|
|
|
|
|
2009-08-31 17:09:50 -06:00
|
|
|
switch (event.GetId())
|
|
|
|
{
|
|
|
|
case IDM_VERBOSITY:
|
|
|
|
{
|
|
|
|
// get selection
|
|
|
|
int v = m_verbosity->GetSelection() + 1;
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
|
|
|
|
{
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->setLogLevel((LogTypes::LOG_TYPE)i, (LogTypes::LOG_LEVELS)v);
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-09-02 06:09:51 -06:00
|
|
|
|
|
|
|
|
|
|
|
case IDM_WRAPLINE:
|
|
|
|
// SetWindowStyleFlag doesn't fully work, we need to redraw the window
|
|
|
|
//m_Log->SetWindowStyleFlag(m_Log->GetWindowStyleFlag() ^ wxTE_DONTWRAP);
|
|
|
|
/* Notice: To retain the colors when changing word wrapping we need to
|
|
|
|
loop through every letter with GetStyle and then reapply them letter by letter */
|
|
|
|
// Prevent m_Log access while it's being destroyed
|
|
|
|
m_LogAccess = false;
|
|
|
|
UnPopulateRight();
|
|
|
|
Text = m_Log->GetValue();
|
|
|
|
m_Log->Destroy();
|
|
|
|
switch (event.IsChecked())
|
|
|
|
{
|
|
|
|
case 0: m_Log = CreateTextCtrl(this, IDM_LOG, wxTE_RICH | wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP); break;
|
|
|
|
case 1: m_Log = CreateTextCtrl(this, IDM_LOG, wxTE_RICH | wxTE_MULTILINE | wxTE_READONLY | wxTE_WORDWRAP); break;
|
|
|
|
}
|
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(*wxWHITE));
|
|
|
|
m_Log->AppendText(Text);
|
|
|
|
PopulateRight();
|
|
|
|
m_LogAccess = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_FONT:
|
|
|
|
switch (event.GetSelection())
|
|
|
|
{
|
|
|
|
case 0: m_Log->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, DefaultFont)); break;
|
|
|
|
case 1: m_Log->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, DebuggerFont)); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-08-31 17:09:50 -06:00
|
|
|
case IDM_WRITEFILE:
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
m_writeFile = event.IsChecked();
|
|
|
|
if (m_checks->IsChecked(i))
|
|
|
|
{
|
|
|
|
if (m_writeFile)
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, m_fileLog);
|
2009-08-31 17:09:50 -06:00
|
|
|
else
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, m_fileLog);
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_WRITEWINDOW:
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
m_writeWindow = event.IsChecked();
|
|
|
|
if (m_checks->IsChecked(i))
|
|
|
|
{
|
|
|
|
if (m_writeWindow)
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, this);
|
2009-08-31 17:09:50 -06:00
|
|
|
else
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, this);
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDM_WRITECONSOLE:
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
m_writeConsole = event.IsChecked();
|
|
|
|
if (m_checks->IsChecked(i))
|
|
|
|
{
|
|
|
|
if (m_writeConsole)
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, m_console);
|
2009-08-31 17:09:50 -06:00
|
|
|
else
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, m_console);
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
}
|
2009-09-02 07:05:32 -06:00
|
|
|
/*
|
2009-08-31 17:09:50 -06:00
|
|
|
if (m_writeConsole && !m_console->IsOpen())
|
|
|
|
wxGetApp().GetCFrame()->ToggleConsole(true);
|
|
|
|
else if (!m_writeConsole && m_console->IsOpen())
|
|
|
|
wxGetApp().GetCFrame()->ToggleConsole(false);
|
2009-09-02 07:05:32 -06:00
|
|
|
*/
|
2009-08-31 17:09:50 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
// When a checkbox is changed
|
|
|
|
void CLogWindow::OnLogCheck(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
int i = event.GetInt();
|
|
|
|
ToggleLog(i, m_checks->IsChecked(i));
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::ToggleLog(int _logType, bool enable)
|
|
|
|
{
|
|
|
|
LogTypes::LOG_TYPE logType = (LogTypes::LOG_TYPE)_logType;
|
|
|
|
|
|
|
|
m_checks->Check(_logType, enable);
|
|
|
|
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->setEnable(logType, enable);
|
2009-08-31 17:09:50 -06:00
|
|
|
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
if (m_writeWindow)
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->addListener(logType, this);
|
2009-08-31 17:09:50 -06:00
|
|
|
if (m_writeFile)
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->addListener(logType, m_fileLog);
|
2009-08-31 17:09:50 -06:00
|
|
|
if (m_writeConsole)
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->addListener(logType, m_console);
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogManager->removeListener(logType, this);
|
|
|
|
m_LogManager->removeListener(logType, m_fileLog);
|
|
|
|
m_LogManager->removeListener(logType, m_console);
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event))
|
|
|
|
{
|
2009-09-02 06:09:51 -06:00
|
|
|
if (!m_LogAccess) return;
|
|
|
|
|
|
|
|
//m_Log->Freeze();
|
2009-08-31 17:09:50 -06:00
|
|
|
UpdateLog();
|
2009-09-02 06:09:51 -06:00
|
|
|
// Better auto scroll
|
|
|
|
m_Log->ScrollLines(1);
|
|
|
|
m_Log->ShowPosition( m_Log->GetLastPosition() );
|
|
|
|
//m_Log->Thaw();
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::NotifyUpdate()
|
|
|
|
{
|
|
|
|
UpdateChecks();
|
|
|
|
//UpdateLog();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::UpdateLog()
|
|
|
|
{
|
2009-09-02 06:09:51 -06:00
|
|
|
if (!m_LogAccess) return;
|
|
|
|
if (!m_Log) return;
|
|
|
|
|
|
|
|
m_LogTimer->Stop();
|
2009-08-31 17:09:50 -06:00
|
|
|
wxString collected_text;
|
|
|
|
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogSection.Enter();
|
|
|
|
// Rough estimate
|
2009-08-31 17:09:50 -06:00
|
|
|
collected_text.reserve(100 * msgQueue.size());
|
|
|
|
int msgQueueSize = (int)msgQueue.size();
|
|
|
|
for (int i = 0; i < msgQueueSize; i++)
|
|
|
|
{
|
|
|
|
switch (msgQueue.front().first)
|
|
|
|
{
|
|
|
|
// red
|
|
|
|
case ERROR_LEVEL:
|
2009-09-02 06:09:51 -06:00
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(*wxRED));
|
2009-08-31 17:09:50 -06:00
|
|
|
break;
|
|
|
|
// yellow
|
|
|
|
case WARNING_LEVEL:
|
2009-09-02 06:09:51 -06:00
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(wxColour(255, 255, 0)));
|
2009-08-31 17:09:50 -06:00
|
|
|
break;
|
|
|
|
// green
|
|
|
|
case NOTICE_LEVEL:
|
2009-09-02 06:09:51 -06:00
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(*wxGREEN));
|
2009-08-31 17:09:50 -06:00
|
|
|
break;
|
|
|
|
// cyan
|
|
|
|
case INFO_LEVEL:
|
2009-09-02 06:09:51 -06:00
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(*wxCYAN));
|
2009-08-31 17:09:50 -06:00
|
|
|
break;
|
|
|
|
// light gray
|
|
|
|
case DEBUG_LEVEL:
|
2009-09-02 06:09:51 -06:00
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(wxColour(211, 211, 211)));
|
2009-08-31 17:09:50 -06:00
|
|
|
break;
|
|
|
|
// white
|
|
|
|
default:
|
2009-09-02 06:09:51 -06:00
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(*wxWHITE));
|
2009-08-31 17:09:50 -06:00
|
|
|
break;
|
|
|
|
}
|
2009-09-02 06:09:51 -06:00
|
|
|
if (msgQueue.front().second.size())
|
|
|
|
{
|
|
|
|
int j = m_Log->GetLastPosition();
|
|
|
|
m_Log->AppendText(msgQueue.front().second);
|
|
|
|
// White timestamp
|
|
|
|
m_Log->SetStyle(j, j + 9, wxTextAttr(*wxWHITE));
|
|
|
|
}
|
2009-08-31 17:09:50 -06:00
|
|
|
collected_text.Append(msgQueue.front().second);
|
2009-09-02 06:09:51 -06:00
|
|
|
msgQueue.pop();
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogSection.Leave();
|
|
|
|
// Write all text at once, needs multiple SetStyle, may not be better
|
|
|
|
//if (collected_text.size()) m_Log->AppendText(collected_text);
|
|
|
|
// Return in 0.2 seconds
|
|
|
|
m_LogTimer->Start(UPDATETIME);
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text)
|
|
|
|
{
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogSection.Enter();
|
2009-08-31 17:09:50 -06:00
|
|
|
if (msgQueue.size() >= 100)
|
|
|
|
msgQueue.pop();
|
|
|
|
msgQueue.push(std::pair<u8, wxString>((u8)level, wxString::FromAscii(text)));
|
2009-09-02 06:09:51 -06:00
|
|
|
m_LogSection.Leave();
|
2009-08-31 17:09:50 -06:00
|
|
|
}
|