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
63155void ScriptList::Delete (size_t sel)
64156{
157+ m_list->DeleteItem ( sel );
158+ m_scripts.erase ( m_scripts.begin () + sel );
65159
160+ UpdateScriptList ();
66161}
67162
68163void ScriptList::SortById ()
@@ -82,21 +177,33 @@ void ScriptList::OnScriptSelected( wxListEvent &evt )
82177
83178void 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+
100207BEGIN_EVENT_TABLE (ScriptList, wxPanel)
101208 EVT_LIST_ITEM_SELECTED(ID_SCRIPT_LIST, ScriptList::OnScriptSelected )
102209 EVT_BUTTON(ID_SCRIPT_ADD, ScriptList::OnCommand )
0 commit comments