2323#include " scripting.h"
2424#include " dataview.h"
2525#include " scriptview.h"
26+ #include " logview.h"
2627#include " daotk_app.h"
2728
2829int version_major = 0 ;
@@ -58,56 +59,48 @@ class CustomThemeProvider : public wxMetroThemeProvider
5859};
5960
6061
62+ IMPLEMENT_APP (MyApp)
6163
62- static wxArrayString g_appArgs;
63- class MyApp : public wxApp
64+ static wxArrayString g_appArgs; // any arguments after the applicaton open
65+ void MyApp::OnFatalException ()
6466{
65- public:
66- virtual void OnFatalException ()
67- {
6867#ifdef __WXMSW__
69- wxMSWHandleApplicationFatalException ();
68+ wxMSWHandleApplicationFatalException ();
7069#endif
71- }
70+ }
7271
73- virtual bool OnInit ()
74- {
72+ bool MyApp:: OnInit ()
73+ {
7574
76- bool is64 = (sizeof (void *) == 8 );
75+ bool is64 = (sizeof (void *) == 8 );
7776
7877#ifdef __WXMSW__
79- wxMSWSetupExceptionHandler (" DAOToolkit" ,
80- wxString::Format (" %d.%d.%d (%d bit)" , version_major, version_minor, version_micro, is64 ? 64 : 32 ),
81- 78+ wxMSWSetupExceptionHandler (" DAOToolkit" ,
79+ wxString::Format (" %d.%d.%d (%d bit)" , version_major, version_minor, version_micro, is64 ? 64 : 32 ),
80+ 8281#endif
8382
84- wxEasyCurl::Initialize ();
83+ wxEasyCurl::Initialize ();
8584
86- for (int i = 0 ; i<argc; i++)
87- g_appArgs.Add (argv[i]);
85+ for (int i = 0 ; i<argc; i++)
86+ g_appArgs.Add (argv[i]);
8887
89- wxInitAllImageHandlers ();
88+ wxInitAllImageHandlers ();
9089
91- wxMetroTheme::SetTheme (new CustomThemeProvider);
92- wxLKScriptWindow::SetFactory (new DAOTKScriptWindowFactory);
90+ wxMetroTheme::SetTheme (new CustomThemeProvider);
9391
94- MainWindow *mw = new MainWindow;
95- mw->Show ();
96- // if (g_appArgs.size() > 1)
97- // mw->LoadProject (g_appArgs[1]);
92+ MainWindow *mw = new MainWindow;
93+ mw->Show ();
94+ if (g_appArgs.size () > 1 )
95+ mw->LoadScript (g_appArgs[1 ]);
9896
99- return true ;
100- }
101-
102- virtual int OnExit ()
103- {
104- return wxApp::OnExit ();
105- }
106- };
97+ return true ;
98+ }
10799
108- #ifndef ST_CONSOLE_APP
109- IMPLEMENT_APP (MyApp);
110- #endif
100+ int MyApp::OnExit ()
101+ {
102+ return wxApp::OnExit ();
103+ }
111104
112105enum {
113106 ID_MAIN_MENU = wxID_HIGHEST + 123 , ID_TABS,
@@ -174,6 +167,9 @@ MainWindow::MainWindow()
174167 m_DataViewForm = new DataView (m_notebook);
175168 m_notebook->AddPage (m_DataViewForm, " Data" );
176169
170+ m_tabList->Append (" Log" );
171+ m_LogViewForm = new LogView (m_notebook);
172+ m_notebook->AddPage (m_LogViewForm, " Log" );
177173
178174 UpdateFrameTitle ();
179175}
@@ -193,22 +189,30 @@ MainWindow &MainWindow::Instance()
193189 return *g_mainWindow;
194190}
195191
192+ void MainWindow::Log (const wxString &text, bool wnl)
193+ {
194+ m_LogViewForm->Log (text, wnl);
195+ }
196+
197+ void MainWindow::ClearLog ()
198+ {
199+ m_LogViewForm->ClearLog ();
200+ }
201+
202+ bool MainWindow::LoadScript (const wxString &file)
203+ {
204+ return m_ScriptViewForm->Load (file);
205+ }
196206
197207void MainWindow::OnClose (wxCloseEvent &evt)
198208{
199- if (!DAOTKScriptWindow::CloseAll ())
209+ Raise ();
210+ if (!m_ScriptViewForm->CloseDoc ())
200211 {
201212 evt.Veto ();
202213 return ;
203214 }
204215
205- Raise ();
206- // if (!CloseProject())
207- // {
208- // evt.Veto();
209- // return;
210- // }
211-
212216 // destroy the window
213217#ifndef DAO_CONSOLE_APP
214218 wxGetApp ().ScheduleForDestruction (this );
@@ -223,14 +227,14 @@ void MainWindow::Save()
223227 return ;
224228 }
225229
226- // if (!SaveProject(m_fileName ))
227- // wxMessageBox("Error writing project to disk:\n\n" + m_fileName, "Notice", wxOK, this);
230+ if (!m_ScriptViewForm-> Save ( ))
231+ wxMessageBox (" Error writing project to disk:\n\n " + m_fileName, " Notice" , wxOK, this );
228232}
229233
230234void MainWindow::SaveAs ()
231235{
232- wxFileDialog dlg (this , " Save SolTrace input file as" , wxPathOnly (m_fileName),
233- m_fileName, " SolTrace Project File (*.stinput )|*.stinput " ,
236+ wxFileDialog dlg (this , " Save DAO-Tk script file as" , wxPathOnly (m_fileName),
237+ m_fileName, " DAO-Tk Project File (*.dtk )|*.dtk " ,
234238 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
235239 if (dlg.ShowModal () == wxID_OK)
236240 {
@@ -246,7 +250,7 @@ void MainWindow::OnCommand(wxCommandEvent &evt)
246250 {
247251 case wxID_NEW:
248252 case wxID_CLOSE:
249- // CloseProject ();
253+ m_ScriptViewForm-> CloseDoc ();
250254 break ;
251255 case wxID_SAVEAS:
252256 SaveAs ();
@@ -256,15 +260,9 @@ void MainWindow::OnCommand(wxCommandEvent &evt)
256260 break ;
257261 case wxID_OPEN:
258262 {
259- // if (!CloseProject()) return;
260- // wxFileDialog dlg(this, "Open SolTrace input file", wxEmptyString, wxEmptyString, "SolTrace Input Files (*.stinput)|*.stinput", wxFD_OPEN);
261- // if (dlg.ShowModal() == wxID_OK)
262- // if (!LoadProject(dlg.GetPath(), false))
263- // wxMessageBox("Error loading input file:\n\n"
264- // + dlg.GetPath() + "\n\n" /*+ m_project.GetLastError()*/, "Notice", wxOK, this);
263+ m_ScriptViewForm->Open ();
264+ break ;
265265 }
266- break ;
267-
268266 case ID_MAIN_MENU:
269267 {
270268 wxPoint p = m_mainMenuButton->ClientToScreen (wxPoint (0 , m_mainMenuButton->GetClientSize ().y ));
@@ -292,6 +290,7 @@ void MainWindow::OnCommand(wxCommandEvent &evt)
292290void MainWindow::OnCaseTabChange (wxCommandEvent &evt)
293291{
294292 m_notebook->SetSelection (evt.GetSelection ());
293+ m_LogViewForm->Log (evt.GetString ().ToStdString (), true );
295294}
296295
297296
0 commit comments