@@ -206,7 +206,30 @@ void MainFrameDerived::LoadProjects(const std::string &filter){
206
206
}
207
207
}
208
208
209
- void MainFrameDerived::Filter (wxKeyEvent &){
209
+ void MainFrameDerived::Filter (wxKeyEvent &event){
210
+ // focus on the table
211
+ if (projectsList->GetItemCount () > 0 ){
212
+ if (event.GetKeyCode () == wxKeyCode::WXK_DOWN){
213
+ projectsList->SetFocus ();
214
+ projectsList->SetItemState (0 , wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
215
+ return ;
216
+ }
217
+ if (event.GetKeyCode () == wxKeyCode::WXK_UP){
218
+ projectsList->SetFocus ();
219
+ projectsList->SetItemState (projectsList->GetItemCount () - 1 , wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
220
+ return ;
221
+ }
222
+ // straight up select the open the first project on ENTER
223
+ if (event.GetKeyCode () == wxKeyCode::WXK_RETURN){
224
+ // select first item first
225
+ projectsList->SetFocus ();
226
+ projectsList->SetItemState (0 , wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
227
+
228
+ // open first item
229
+ OpenProject (0 );
230
+ return ;
231
+ }
232
+ }
210
233
projectsList->DeleteAllItems ();
211
234
wxListEvent e;
212
235
OnDeselectProject (e);
@@ -262,7 +285,7 @@ void MainFrameDerived::OnAddProject(wxCommandEvent& event){
262
285
// add it to the projects list
263
286
try {
264
287
project p = LoadProject (path);
265
- AddProject (p," " ,true );
288
+ AddProject (p," " ,true , true );
266
289
}
267
290
catch (runtime_error& e){
268
291
wxMessageBox (e.what ()," Unable to add project" ,wxOK | wxICON_ERROR);
@@ -325,7 +348,7 @@ void MainFrameDerived::OnCreateProject(wxCommandEvent& event){
325
348
if (editors.size () > 0 ){
326
349
DialogCallback d = [&](string str, project p){
327
350
// add the project
328
- this ->AddProject (p," " ,true );
351
+ this ->AddProject (p," " ,true , true );
329
352
330
353
// launch the process
331
354
launch_process (str);
@@ -519,51 +542,41 @@ void MainFrameDerived::SaveEditorVersions(){
519
542
@param p the project struct to add
520
543
@note Ensure all the fields on the struct are initialized
521
544
*/
522
- void MainFrameDerived::AddProject (const project& p, const std::string& filter, bool select){
545
+ void MainFrameDerived::AddProject (const project& p, const std::string& filter, bool select, bool save ){
523
546
// add to the vector backing the UI
524
547
if (std::find_if (projects.begin (),projects.end (),[&](const auto & item){
525
548
return p == item;
526
549
}) != projects.end ()){
527
550
return ;
528
551
}
529
- projects.insert (projects.begin (),p);
530
-
531
- // save to file
532
- if (filter == " " ){
533
- SaveProjects ();
534
- }
535
552
536
- // add (painfully) to the UI
537
553
auto name = p.name ;
538
554
transform (name.begin (), name.end (), name.begin (), ::tolower);
539
555
if (name.find (filter) != std::string::npos){
556
+ projects.push_back (p);
557
+
558
+ // save to file
559
+ if (save){
560
+ SaveProjects ();
561
+ }
562
+
563
+ // add to the UI
540
564
wxListItem i;
541
- i.SetId (0 );
565
+ i.SetId (projectsList-> GetItemCount () );
542
566
i.SetText (p.name );
543
-
544
567
projectsList->InsertItem (i);
545
-
546
- i.SetText (p.version );
547
- i.SetColumn (1 );
548
- projectsList->SetItem (i);
549
-
550
- i.SetText (p.modifiedDate );
551
-
552
- i.SetColumn (2 );
553
- projectsList->SetItem (i);
554
-
555
- i.SetColumn (3 );
556
- i.SetText (p.path .string ());
557
- projectsList->SetItem (i);
568
+ projectsList->SetItem (i, 1 , p.version );
569
+ projectsList->SetItem (i, 2 , p.modifiedDate );
570
+ projectsList->SetItem (i, 3 , p.path .string ());
558
571
559
572
// resize columns
560
573
int cols = projectsList->GetColumnCount ();
561
574
for (int i = 0 ; i < cols; i++){
562
- projectsList->SetColumnWidth (i, wxLIST_AUTOSIZE );
575
+ projectsList->SetColumnWidth (i, wxLIST_AUTOSIZE_USEHEADER );
563
576
}
564
577
565
578
if (select ){
566
- projectsList->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
579
+ projectsList->SetItemState (i, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED , wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED );
567
580
}
568
581
}
569
582
0 commit comments