@@ -206,7 +206,32 @@ 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
+ wxListEvent listEvent;
230
+ listEvent.m_itemIndex = 0 ;
231
+ OnOpenProject (listEvent);
232
+ return ;
233
+ }
234
+ }
210
235
projectsList->DeleteAllItems ();
211
236
wxListEvent e;
212
237
OnDeselectProject (e);
@@ -262,7 +287,7 @@ void MainFrameDerived::OnAddProject(wxCommandEvent& event){
262
287
// add it to the projects list
263
288
try {
264
289
project p = LoadProject (path);
265
- AddProject (p," " ,true );
290
+ AddProject (p," " ,true , true );
266
291
}
267
292
catch (runtime_error& e){
268
293
wxMessageBox (e.what ()," Unable to add project" ,wxOK | wxICON_ERROR);
@@ -325,7 +350,7 @@ void MainFrameDerived::OnCreateProject(wxCommandEvent& event){
325
350
if (editors.size () > 0 ){
326
351
DialogCallback d = [&](string str, project p){
327
352
// add the project
328
- this ->AddProject (p," " ,true );
353
+ this ->AddProject (p," " ,true , true );
329
354
330
355
// launch the process
331
356
launch_process (str);
@@ -519,51 +544,41 @@ void MainFrameDerived::SaveEditorVersions(){
519
544
@param p the project struct to add
520
545
@note Ensure all the fields on the struct are initialized
521
546
*/
522
- 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 ){
523
548
// add to the vector backing the UI
524
549
if (std::find_if (projects.begin (),projects.end (),[&](const auto & item){
525
550
return p == item;
526
551
}) != projects.end ()){
527
552
return ;
528
553
}
529
- projects.insert (projects.begin (),p);
530
-
531
- // save to file
532
- if (filter == " " ){
533
- SaveProjects ();
534
- }
535
554
536
555
// add (painfully) to the UI
537
556
auto name = p.name ;
538
557
transform (name.begin (), name.end (), name.begin (), ::tolower);
539
558
if (name.find (filter) != std::string::npos){
559
+ projects.push_back (p);
560
+
561
+ // save to file
562
+ if (save){
563
+ SaveProjects ();
564
+ }
565
+
540
566
wxListItem i;
541
- i.SetId (0 );
567
+ i.SetId (projectsList-> GetItemCount () );
542
568
i.SetText (p.name );
543
-
544
569
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);
570
+ projectsList->SetItem (i, 1 , p.version );
571
+ projectsList->SetItem (i, 2 , p.modifiedDate );
572
+ projectsList->SetItem (i, 3 , p.path .string ());
558
573
559
574
// resize columns
560
575
int cols = projectsList->GetColumnCount ();
561
576
for (int i = 0 ; i < cols; i++){
562
- projectsList->SetColumnWidth (i, wxLIST_AUTOSIZE );
577
+ projectsList->SetColumnWidth (i, wxLIST_AUTOSIZE_USEHEADER );
563
578
}
564
579
565
580
if (select){
566
- 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 );
567
582
}
568
583
}
569
584
0 commit comments