@@ -208,7 +208,30 @@ void MainFrameDerived::LoadProjects(const std::string &filter){
208208 }
209209}
210210
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+ }
212235 projectsList->DeleteAllItems ();
213236 wxListEvent e;
214237 OnDeselectProject (e);
@@ -264,7 +287,7 @@ void MainFrameDerived::OnAddProject(wxCommandEvent& event){
264287 // add it to the projects list
265288 try {
266289 project p = LoadProject (path);
267- AddProject (p," " ,true );
290+ AddProject (p," " ,true , true );
268291 }
269292 catch (runtime_error& e){
270293 wxMessageBox (e.what ()," Unable to add project" ,wxOK | wxICON_ERROR);
@@ -327,7 +350,7 @@ void MainFrameDerived::OnCreateProject(wxCommandEvent& event){
327350 if (editors.size () > 0 ){
328351 DialogCallback d = [&](string str, project p){
329352 // add the project
330- this ->AddProject (p," " ,true );
353+ this ->AddProject (p," " ,true , true );
331354
332355 // launch the process
333356 launch_process (str);
@@ -521,51 +544,41 @@ void MainFrameDerived::SaveEditorVersions(){
521544 @param p the project struct to add
522545 @note Ensure all the fields on the struct are initialized
523546 */
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 ){
525548 // add to the vector backing the UI
526549 if (std::find_if (projects.begin (),projects.end (),[&](const auto & item){
527550 return p == item;
528551 }) != projects.end ()){
529552 return ;
530553 }
531- projects.insert (projects.begin (),p);
532-
533- // save to file
534- if (filter == " " ){
535- SaveProjects ();
536- }
537554
538- // add (painfully) to the UI
539555 auto name = p.name ;
540556 transform (name.begin (), name.end (), name.begin (), ::tolower);
541557 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
542566 wxListItem i;
543- i.SetId (0 );
567+ i.SetId (projectsList-> GetItemCount () );
544568 i.SetText (p.name );
545-
546569 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 ());
560573
561574 // resize columns
562575 int cols = projectsList->GetColumnCount ();
563576 for (int i = 0 ; i < cols; i++){
564- projectsList->SetColumnWidth (i, wxLIST_AUTOSIZE );
577+ projectsList->SetColumnWidth (i, wxLIST_AUTOSIZE_USEHEADER );
565578 }
566579
567580 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 );
569582 }
570583 }
571584
0 commit comments