Skip to content

Commit 3811b63

Browse files
committed
updates to the script list
1 parent d81f381 commit 3811b63

File tree

8 files changed

+207
-28
lines changed

8 files changed

+207
-28
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
"optional": "cpp",
6262
"ratio": "cpp",
6363
"thread": "cpp",
64-
"cinttypes": "cpp"
64+
"cinttypes": "cpp",
65+
"*.cpng": "cpp",
66+
"bitset": "cpp",
67+
"codecvt": "cpp"
6568
}
6669
}

app/daotk_app.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ MainWindow::MainWindow()
213213

214214
m_tabList->Append("Script");
215215
m_ScriptViewForm = new ScriptView(splitscript);
216-
m_ScriptList = new ScriptList(splitscript);
216+
m_ScriptList = new ScriptList(splitscript, &m_image_dir);
217217
splitscript->SplitVertically(m_ScriptList, m_ScriptViewForm, 180);
218218

219219
m_LogViewForm = new LogView(splitwin);
@@ -428,6 +428,28 @@ void MainWindow::Save()
428428
jv.AddMember("d", jdata, alloc);
429429
D.AddMember((rjs::Value::StringRefType)(v->name.c_str()), jv, alloc);
430430
}
431+
//Add script list info
432+
std::vector<ScriptListObject> *sl = m_ScriptList->GetList();
433+
for(int i=0; i<sl->size(); i++)
434+
{
435+
rjs::Value jv(rjs::kObjectType);
436+
jv.AddMember("sls", rjs::Value((int)sl->at(i).status), alloc);
437+
438+
rjs::Value jdp(rjs::kStringType);
439+
jdp.Set(sl->at(i).path.c_str());
440+
jv.AddMember("slp", jdp, alloc);
441+
442+
rjs::Value jdc(rjs::kStringType);
443+
jdc.SetString( (rjs::Value::StringRefType)sl->at(i).created.FormatISOCombined().c_str() );
444+
jv.AddMember("slc", jdc, alloc);
445+
446+
rjs::Value jdm(rjs::kStringType);
447+
jdm.SetString( (rjs::Value::StringRefType)sl->at(i).modified.FormatISOCombined().c_str() );
448+
jv.AddMember("slm", jdm, alloc);
449+
450+
D.AddMember( (rjs::Value::StringRefType)(wxString::Format("jlo%02d",i).c_str()), jv, alloc);
451+
}
452+
431453

432454
int initsize=2;
433455
while(initsize < cest)
@@ -599,9 +621,32 @@ bool MainWindow::Load(const wxString &file)
599621
}
600622
}
601623
}
602-
}
624+
}
625+
//load script list info
626+
std::vector< ScriptListObject >* slist = m_ScriptList->GetList();
627+
slist->clear();
628+
629+
bool lo_found = true;
630+
int i=0;
631+
while( lo_found )
632+
{
633+
std::string name = wxString::Format("jlo%03d", i);
634+
lo_found = D.HasMember( name.c_str() );
635+
if( lo_found )
636+
{
637+
ScriptListObject slo;
638+
rjs::Value &jv = D[ name.c_str() ];
639+
slo.status = jv["sls"].GetInt();
640+
slo.created.SetFromString( jv["slc"].GetString() );
641+
slo.modified.SetFromString( jv["slm"].GetString() );
642+
643+
slist->push_back( slo );
644+
}
645+
i++;
646+
}
603647

604648
UpdateDataTable();
649+
m_ScriptList->UpdateScriptList();
605650
SetProgress(0, wxString::Format("Successfully loaded \"%s\"", m_fileName.c_str()) );
606651

607652
return true;

app/scriptlist.cpp

Lines changed: 128 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,66 @@
22

33
#include <wx/listctrl.h>
44
#include <wx/imaglist.h>
5+
#include <wx/filename.h>
6+
#include <wx/splitter.h>
7+
58
#include <wex/icons/down_arrow_gray_13.cpng>
69
#include <wex/icons/up_arrow_gray_13.cpng>
710
#include <wex/icons/stock_add_16.cpng>
811
#include <wex/icons/stock_remove_16.cpng>
912
#include <wex/icons/stock_yes_20.cpng>
1013
#include <wex/icons/stock_no_20.cpng>
14+
#include <wex/icons/stock_exec_16.cpng>
15+
#include <wex/icons/qmark.cpng>
16+
17+
#ifdef __WXOSX__
18+
#define FONTSIZE 13
19+
#else
20+
#define FONTSIZE 9
21+
#endif
22+
23+
24+
myDateTime myDateTime::Today()
25+
{
26+
myDateTime D;
27+
D.ParseDateTime( wxDateTime::Today().FormatISOCombined() );
1128

29+
return D;
30+
}
31+
32+
wxString myDateTime::GetDisplayDate()
33+
{
34+
if( this->IsLaterThan( wxDateTime::Today().ResetTime() ) )
35+
return this->FormatTime();
36+
else
37+
return this->FormatDate();
38+
}
1239

13-
ScriptList::ScriptList(wxWindow *parent)
40+
bool myDateTime::SetFromString(const std::string datestr )
41+
{
42+
myDateTime D;
43+
D.ParseDateTime( datestr );
44+
if( D.IsValid() )
45+
(*this) = D;
46+
return D.IsValid();
47+
}
48+
49+
ScriptList::ScriptList(wxSplitterWindow *parent, wxFileName *imagedir)
1450
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
1551
{
1652

17-
wxImageList imlist;
18-
imlist.Add( wxBITMAP_PNG_FROM_DATA(stock_yes_20) );
19-
imlist.Add( wxBITMAP_PNG_FROM_DATA(stock_no_20) );
20-
21-
m_list = new wxListCtrl(this, ID_SCRIPT_LIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SMALL_ICON);
22-
m_list->SetImageList( &imlist, wxIMAGE_LIST_NORMAL);
53+
m_parent = parent;
54+
55+
m_imagelist = new wxImageList(16,16); //create and add image list to listctrl before adding images
56+
57+
m_list = new wxListCtrl(this, ID_SCRIPT_LIST, wxDefaultPosition, wxDefaultSize, wxLC_LIST|wxLC_SINGLE_SEL);
58+
m_list->SetFont( wxFont(FONTSIZE, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL) );
59+
m_list->SetImageList( m_imagelist, wxIMAGE_LIST_SMALL);
60+
61+
m_imagelist->Add( wxIcon( imagedir->GetPath() + "/edit.png", wxBITMAP_TYPE_PNG ) ); //ID_IMG::NONE
62+
m_imagelist->Add( wxIcon( imagedir->GetPath() + "/pass.png", wxBITMAP_TYPE_PNG ) ); //ID_IMG::OK
63+
m_imagelist->Add( wxIcon( imagedir->GetPath() + "/fail.png", wxBITMAP_TYPE_PNG ) ); //ID_IMG::FAILED
64+
m_imagelist->Add( wxIcon( imagedir->GetPath() + "/busy.png", wxBITMAP_TYPE_PNG ) ); //ID_IMG::WORKING
2365

2466
wxBoxSizer *main = new wxBoxSizer(wxVERTICAL);
2567
wxBoxSizer *button = new wxBoxSizer(wxHORIZONTAL);
@@ -38,31 +80,84 @@ ScriptList::ScriptList(wxWindow *parent)
3880

3981
this->SetSizer(main);
4082

41-
42-
m_list->AppendColumn( "File" );
43-
m_list->AppendColumn( "Modified" );
83+
return;
84+
}
85+
86+
void ScriptList::UpdateScriptList()
87+
{
88+
m_list->DeleteAllItems();
4489

45-
// long itemid = m_list->InsertItem(0, 0);
46-
// m_list->SetItem(itemid, 0, "A new file");
47-
// m_list->SetItem(itemid, 1, "89/12");
90+
m_list->SetItemCount((long)m_scripts.size());
4891

49-
// itemid = m_list->InsertItem(1, 1);
50-
// m_list->SetItem(itemid, 0, "An old file");
51-
// m_list->SetItem(itemid, 1, "2587");
92+
wxSize maxextent(-1,-1);
93+
for(int i=0; i<(int)m_scripts.size(); i++)
94+
{
5295

53-
return;
96+
int index = m_list->InsertItem((long)i, (int)( m_scripts.at(i).status) );
97+
98+
wxArrayString spath = wxSplit(m_scripts.at(i).path, '/');
99+
int psize = spath.Last().size();
100+
101+
int pmax=25, dmax=8;
102+
103+
wxString truncpath = m_scripts.at(i).path;
104+
if(psize < pmax-1)
105+
truncpath = ".." + truncpath.SubString(truncpath.length()-(pmax-2), truncpath.length() );
106+
else if( truncpath.length() > pmax )
107+
truncpath = truncpath.SubString(0,pmax-2) + "..";
108+
109+
// "%-20s%-4s%-8s%-2s%-8s",
110+
wxString prettypath = wxString::Format(
111+
wxString::Format("%s-%ds%s-3s%s-%ds%s-2s%s-%ds", "%", pmax, "%", "%", dmax, "%", "%", dmax),
112+
truncpath.c_str(),
113+
"",
114+
m_scripts.at(i).modified.GetDisplayDate().c_str(),
115+
"",
116+
m_scripts.at(i).created.GetDisplayDate().c_str()
117+
);
118+
119+
m_list->SetItemText(index, prettypath);
120+
121+
wxSize thisextent = m_list->GetTextExtent(prettypath);
122+
if(thisextent.GetWidth() > maxextent.GetWidth())
123+
maxextent = thisextent;
124+
}
125+
m_parent->SetSashPosition(maxextent.GetWidth(), true);
54126
}
55127

56-
void ScriptList::Add(const char *scriptpath)
128+
void ScriptList::Add()
57129
{
58130
/*
59131
Adds a new path to the script list
60132
*/
133+
wxFileDialog dlg(this, "Add Script", wxEmptyString, wxEmptyString,
134+
"LK Script Files (*.lk)|*.lk",
135+
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
136+
137+
if (dlg.ShowModal() == wxID_OK)
138+
{
139+
wxStructStat structstat;
140+
wxStat( dlg.GetPath(), &structstat);
141+
142+
143+
ScriptListObject S;
144+
S.path = dlg.GetPath();
145+
S.modified.ParseISOCombined( wxDateTime(structstat.st_mtime).FormatISOCombined() );
146+
S.created.ParseISOCombined( wxDateTime(structstat.st_ctime).FormatISOCombined() );
147+
S.status = ScriptList::ID_IMG::NONE;
148+
149+
m_scripts.push_back( S );
150+
151+
UpdateScriptList();
152+
}
61153
}
62154

63155
void ScriptList::Delete(size_t sel)
64156
{
157+
m_list->DeleteItem( sel );
158+
m_scripts.erase( m_scripts.begin() + sel );
65159

160+
UpdateScriptList();
66161
}
67162

68163
void ScriptList::SortById()
@@ -82,21 +177,33 @@ void ScriptList::OnScriptSelected( wxListEvent &evt )
82177

83178
void ScriptList::OnCommand( wxCommandEvent &evt )
84179
{
180+
int sel=-1;
181+
sel = m_list->GetNextItem(sel, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
182+
if( sel < -1 )
183+
return;
184+
85185
switch( evt.GetId() )
86186
{
87187
case ID_SCRIPT_ADD:
188+
Add();
88189
break;
89190
case ID_SCRIPT_DEL:
90-
break;
191+
Delete(sel);
192+
break;
91193
case ID_SCRIPT_UP:
92-
break;
93194
case ID_SCRIPT_DOWN:
94-
break;
195+
MoveItemInList( sel, evt.GetId() == ID_SCRIPT_UP );
196+
break;
95197
default:
96198
break;
97199
}
98200
}
99201

202+
std::vector< ScriptListObject >* ScriptList::GetList()
203+
{
204+
return &m_scripts;
205+
}
206+
100207
BEGIN_EVENT_TABLE(ScriptList, wxPanel)
101208
EVT_LIST_ITEM_SELECTED(ID_SCRIPT_LIST, ScriptList::OnScriptSelected )
102209
EVT_BUTTON(ID_SCRIPT_ADD, ScriptList::OnCommand )

app/scriptlist.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __scriptlist_h
33

44
#include <wx/wx.h>
5+
#include <wx/datetime.h>
56
#include <lk/absyn.h>
67
#include <lk/env.h>
78

@@ -10,16 +11,31 @@
1011

1112
class wxListCtrl;
1213
class wxListEvent;
14+
class wxImageList;
15+
class wxFileName;
16+
class wxSplitterWindow;
17+
18+
class myDateTime : public wxDateTime
19+
{
20+
public:
21+
bool SetFromString(const std::string datstr);
22+
wxString GetDisplayDate();
23+
static myDateTime Today();
24+
};
1325

1426
struct ScriptListObject
1527
{
1628
std::string path;
17-
int id;
29+
myDateTime modified;
30+
myDateTime created;
31+
unsigned char status; //see ID_INT struct in ScriptList for options
1832

1933
ScriptListObject()
2034
{
2135
path.clear();
22-
id=-1;
36+
modified.SetToCurrent();
37+
created.SetToCurrent();
38+
status = 0;
2339
};
2440
};
2541

@@ -29,18 +45,26 @@ class ScriptList : public wxPanel
2945
{
3046
wxListCtrl *m_list;
3147
std::vector< ScriptListObject > m_scripts;
48+
wxImageList *m_imagelist;
49+
wxSplitterWindow *m_parent;
3250

3351
void OnScriptSelected( wxListEvent &);
3452
void OnCommand( wxCommandEvent &);
3553

3654
public:
3755

38-
ScriptList(wxWindow *parent);
56+
struct ID_IMG { enum A {NONE=0, OK, FAIL, WORKING}; };
57+
58+
ScriptList(wxSplitterWindow *parent, wxFileName *imagedir);
3959

40-
void Add(const char *scriptpath);
60+
void Add();
4161
void Delete(size_t sel);
4262
void SortById();
4363
void MoveItemInList(size_t sel, bool is_up);
64+
void UpdateScriptList();
65+
66+
67+
std::vector< ScriptListObject >* GetList();
4468

4569
DECLARE_EVENT_TABLE()
4670
};

deploy/rs/busy.png

3.48 KB
Loading

deploy/rs/edit.png

1.13 KB
Loading

deploy/rs/fail.png

1.12 KB
Loading

deploy/rs/pass.png

1.16 KB
Loading

0 commit comments

Comments
 (0)