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