Skip to content

Commit e8fa262

Browse files
committed
reorganizing, developing basic app functionality
1 parent 58cffd1 commit e8fa262

File tree

9 files changed

+484
-153
lines changed

9 files changed

+484
-153
lines changed

app/daotk_app.cpp

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "scripting.h"
2424
#include "dataview.h"
2525
#include "scriptview.h"
26+
#include "logview.h"
2627
#include "daotk_app.h"
2728

2829
int 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

112105
enum {
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

197207
void 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

230234
void 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)
292290
void MainWindow::OnCaseTabChange(wxCommandEvent &evt)
293291
{
294292
m_notebook->SetSelection(evt.GetSelection());
293+
m_LogViewForm->Log(evt.GetString().ToStdString(), true );
295294
}
296295

297296

app/daotk_app.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ class wxMetroButton;
1111
class wxMetroTabList;
1212
class ScriptView;
1313
class DataView;
14+
class LogView;
15+
16+
17+
class MyApp : public wxApp
18+
{
19+
public:
20+
virtual void OnFatalException();
21+
virtual bool OnInit();
22+
virtual int OnExit();
23+
};
24+
25+
DECLARE_APP(MyApp)
26+
1427

1528
class MainWindow : public wxFrame
1629
{
@@ -20,6 +33,11 @@ class MainWindow : public wxFrame
2033
static MainWindow &Instance();
2134
void UpdateFrameTitle();
2235

36+
void ClearLog();
37+
void Log(const wxString &, bool wnl = true);
38+
39+
bool LoadScript(const wxString &file);
40+
2341
void Save();
2442
void SaveAs();
2543

@@ -35,6 +53,7 @@ class MainWindow : public wxFrame
3553

3654
ScriptView *m_ScriptViewForm;
3755
DataView *m_DataViewForm;
56+
LogView *m_LogViewForm;
3857

3958
wxString m_fileName;
4059

app/logview.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <wx/wx.h>
2+
#include <wx/clipbrd.h>
3+
#include <wex/numeric.h>
4+
5+
#include "logview.h"
6+
7+
enum A {
8+
ID_ELEMENT_LIST = wxID_HIGHEST + 198,
9+
ID_LOG_CLEAR,
10+
ID_LOG_COPY,
11+
ID_NONE
12+
};
13+
14+
BEGIN_EVENT_TABLE(LogView, wxPanel)
15+
EVT_LISTBOX(ID_ELEMENT_LIST, LogView::OnCommand)
16+
EVT_BUTTON(ID_LOG_CLEAR, LogView::OnCommand)
17+
EVT_BUTTON(ID_LOG_COPY, LogView::OnCommand)
18+
END_EVENT_TABLE()
19+
20+
21+
LogView::LogView(wxWindow *parent)
22+
: wxPanel(parent)
23+
{
24+
25+
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
26+
27+
wxBoxSizer *top_sizer = new wxBoxSizer(wxHORIZONTAL);
28+
29+
top_sizer->Add(new wxButton(this, ID_LOG_CLEAR, "Clear log"), 0, wxALL, 5);
30+
top_sizer->Add(new wxButton(this, ID_LOG_COPY, "Copy log"), 0, wxALL, 5);
31+
32+
m_TextLog = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
33+
wxTE_READONLY | wxTE_MULTILINE | wxHSCROLL | wxTE_DONTWRAP | wxBORDER_NONE);
34+
m_TextLog->SetFont(wxFont(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, "consolas"));
35+
m_TextLog->SetForegroundColour(*wxBLUE);
36+
37+
sizer->Add(top_sizer);
38+
sizer->Add(m_TextLog, 1, wxEXPAND | wxALL, 5);
39+
SetSizer(sizer);
40+
}
41+
42+
LogView::~LogView()
43+
{
44+
/* nothing to do */
45+
}
46+
47+
void LogView::OnCommand(wxCommandEvent &evt)
48+
{
49+
switch (evt.GetId())
50+
{
51+
case ID_ELEMENT_LIST:
52+
break;
53+
case ID_LOG_CLEAR:
54+
ClearLog();
55+
break;
56+
case ID_LOG_COPY:
57+
if (wxTheClipboard->Open())
58+
{
59+
// This data objects are held by the clipboard,
60+
// so do not delete them in the app.
61+
wxTheClipboard->SetData(new wxTextDataObject(m_TextLog->GetValue()));
62+
wxTheClipboard->Close();
63+
}
64+
break;
65+
case ID_NONE:
66+
break;
67+
default:
68+
break;
69+
}
70+
}
71+
72+
void LogView::Log(const wxString &text, bool wnl)
73+
{
74+
if (wnl) m_TextLog->AppendText(text + "\n");
75+
else m_TextLog->AppendText(text);
76+
}
77+
78+
void LogView::ClearLog()
79+
{
80+
m_TextLog->Clear();
81+
}
82+

app/logview.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
#ifndef __logview_h
3+
#define __logview_h
4+
5+
#include <wx/wx.h>
6+
7+
class LogView : public wxPanel
8+
{
9+
public:
10+
LogView(wxWindow *parent);
11+
virtual ~LogView();
12+
13+
void Log(const wxString &text, bool wnl);
14+
void ClearLog();
15+
16+
private:
17+
18+
wxTextCtrl * m_TextLog;
19+
20+
void OnCommand(wxCommandEvent &);
21+
22+
DECLARE_EVENT_TABLE();
23+
};
24+
25+
26+
#endif

0 commit comments

Comments
 (0)