From: John L. <jr...@us...> - 2009-09-27 05:35:30
|
Update of /cvsroot/wxlua/wxLua/apps/wxlua/src In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv24103/wxLua/apps/wxlua/src Modified Files: lconsole.cpp lconsole.h wxlua.cpp Log Message: Make the wxLuaConsole a little nicer, fixed width font, toolbar, red error messages. Index: wxlua.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/wxlua.cpp,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** wxlua.cpp 1 Jun 2009 22:28:29 -0000 1.57 --- wxlua.cpp 27 Sep 2009 05:35:20 -0000 1.58 *************** *** 385,389 **** if (m_luaConsoleWrapper.Ok()) ! m_luaConsoleWrapper.GetConsole()->DisplayText(msg); if (m_print_msgdlg) --- 385,389 ---- if (m_luaConsoleWrapper.Ok()) ! m_luaConsoleWrapper.GetConsole()->AppendText(msg); if (m_print_msgdlg) *************** *** 397,402 **** if (m_luaConsoleWrapper.Ok()) { ! m_luaConsoleWrapper.GetConsole()->DisplayText(msg); ! m_luaConsoleWrapper.GetConsole()->SetExitOnError(is_error); if (wxlState.Ok()) m_luaConsoleWrapper.GetConsole()->DisplayStack(wxlState); --- 397,404 ---- if (m_luaConsoleWrapper.Ok()) { ! wxTextAttr attr(*wxRED); ! attr.SetFlags(wxTEXT_ATTR_TEXT_COLOUR); ! m_luaConsoleWrapper.GetConsole()->AppendTextWithAttr(msg, attr); ! m_luaConsoleWrapper.GetConsole()->SetExitWhenClosed(is_error); if (wxlState.Ok()) m_luaConsoleWrapper.GetConsole()->DisplayStack(wxlState); Index: lconsole.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/lconsole.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** lconsole.h 5 Dec 2008 21:15:10 -0000 1.12 --- lconsole.h 27 Sep 2009 05:35:20 -0000 1.13 *************** *** 34,47 **** const wxString& name = wxT("wxLuaConsole")); ! // Display a message in the console ! void DisplayText(const wxString& msg); // Display the stack in a wxListBox, but only if there are any items in it void DisplayStack(const wxLuaState& wxlState); ! // An error has occurred, when this window is closed call wxExit to close ! // the app. ! void SetExitOnError(bool is_error) { m_exit_on_error = m_exit_on_error || is_error; } protected: void OnCloseWindow(wxCloseEvent& event); wxLuaConsoleWrapper *m_wrapper; --- 34,49 ---- const wxString& name = wxT("wxLuaConsole")); ! // Display a message in the console with optional attribute to display it with. ! void AppendText(const wxString& msg); ! void AppendTextWithAttr(const wxString& msg, const wxTextAttr& attr); // Display the stack in a wxListBox, but only if there are any items in it void DisplayStack(const wxLuaState& wxlState); ! // Perhaps an error has occurred, when this window is closed wxExit ! // will be called to close the app. ! void SetExitWhenClosed(bool do_exit) { m_exit_when_closed = m_exit_when_closed || do_exit; } protected: void OnCloseWindow(wxCloseEvent& event); + void OnMenu(wxCommandEvent& event); wxLuaConsoleWrapper *m_wrapper; *************** *** 49,53 **** wxTextCtrl *m_textCtrl; wxListBox *m_debugListBox; ! bool m_exit_on_error; private: --- 51,58 ---- wxTextCtrl *m_textCtrl; wxListBox *m_debugListBox; ! bool m_exit_when_closed; ! ! wxString m_saveFilename; ! wxString m_savePath; private: Index: lconsole.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/lconsole.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** lconsole.cpp 5 Dec 2008 05:57:21 -0000 1.19 --- lconsole.cpp 27 Sep 2009 05:35:20 -0000 1.20 *************** *** 24,31 **** --- 24,37 ---- #include "wx/splitter.h" + #include "wx/toolbar.h" + #include "wx/filename.h" #include "wxlua/include/wxlua.h" #include "lconsole.h" + #include "../../../art/new.xpm" + #include "../../../art/save.xpm" + #include "../../../art/copy.xpm" + // ---------------------------------------------------------------------------- // wxLuaConsole *************** *** 34,37 **** --- 40,44 ---- BEGIN_EVENT_TABLE(wxLuaConsole, wxFrame) EVT_CLOSE(wxLuaConsole::OnCloseWindow) + EVT_MENU(wxID_ANY, wxLuaConsole::OnMenu) END_EVENT_TABLE() *************** *** 41,48 **** long style, const wxString& name) :wxFrame(parent, id, title, pos, size, style, name), ! m_wrapper(consoleWrapper), m_exit_on_error(false) { SetIcon(wxICON(LUA)); m_splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, --- 48,65 ---- long style, const wxString& name) :wxFrame(parent, id, title, pos, size, style, name), ! m_wrapper(consoleWrapper), m_exit_when_closed(false) { + m_savePath = wxGetCwd(); + SetIcon(wxICON(LUA)); + wxToolBar* tb = CreateToolBar(); + + tb->AddTool(wxID_NEW, wxT("Clear window"), wxBitmap(new_xpm), wxT("Clear console window"), wxITEM_NORMAL); + tb->AddTool(wxID_SAVEAS, wxT("Save output"), wxBitmap(save_xpm), wxT("Save contents to file"), wxITEM_NORMAL); + tb->AddTool(wxID_COPY, wxT("Copy text"), wxBitmap(copy_xpm), wxT("Copy contents to clipboard"), wxITEM_NORMAL); + + tb->Realize(); + m_splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, *************** *** 50,54 **** m_textCtrl = new wxTextCtrl(m_splitter, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, ! wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH); m_debugListBox = new wxListBox(m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, --- 67,73 ---- m_textCtrl = new wxTextCtrl(m_splitter, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, ! wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH | wxTE_DONTWRAP); ! m_textCtrl->SetFont(wxFont(10, wxTELETYPE, wxNORMAL, wxNORMAL)); ! m_debugListBox = new wxListBox(m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, *************** *** 69,80 **** Destroy(); ! if (m_exit_on_error) wxExit(); } ! void wxLuaConsole::DisplayText(const wxString& msg) { m_textCtrl->AppendText(msg + wxT("\n")); } void wxLuaConsole::DisplayStack(const wxLuaState& wxlState) --- 88,145 ---- Destroy(); ! if (m_exit_when_closed) wxExit(); } ! void wxLuaConsole::OnMenu(wxCommandEvent& event) ! { ! switch (event.GetId()) ! { ! case wxID_NEW : ! { ! m_textCtrl->Clear(); ! break; ! } ! case wxID_SAVEAS : ! { ! wxString filename = wxFileSelector(wxT("Select file to save output to"), ! m_savePath, ! m_saveFilename, ! wxT("txt"), ! wxT("Text files (*.txt)|*.txt|All files|*.*"), ! wxFD_SAVE|wxFD_OVERWRITE_PROMPT, ! this); ! ! if (!filename.IsEmpty()) ! { ! wxFileName fn(filename); ! m_savePath = fn.GetPath(); ! m_saveFilename = fn.GetFullName(); ! ! m_textCtrl->SaveFile(filename); ! } ! break; ! } ! case wxID_COPY : ! { ! m_textCtrl->Copy(); ! break; ! } ! } ! } ! ! void wxLuaConsole::AppendText(const wxString& msg) { m_textCtrl->AppendText(msg + wxT("\n")); } + void wxLuaConsole::AppendTextWithAttr(const wxString& msg, const wxTextAttr& attr) + { + wxTextAttr oldAttr = m_textCtrl->GetDefaultStyle(); + + m_textCtrl->SetDefaultStyle(attr); + m_textCtrl->AppendText(msg + wxT("\n")); + + m_textCtrl->SetDefaultStyle(oldAttr); + } void wxLuaConsole::DisplayStack(const wxLuaState& wxlState) |