Skip to content

Commit 7212bd4

Browse files
fixed not being able to opening projects with search. added keyboard navigation to project list for when search is focused (#49)
1 parent 82b68ce commit 7212bd4

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

source/interface_derived.cpp

+41-28
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,30 @@ void MainFrameDerived::LoadProjects(const std::string &filter){
206206
}
207207
}
208208

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+
}
210233
projectsList->DeleteAllItems();
211234
wxListEvent e;
212235
OnDeselectProject(e);
@@ -262,7 +285,7 @@ void MainFrameDerived::OnAddProject(wxCommandEvent& event){
262285
//add it to the projects list
263286
try{
264287
project p = LoadProject(path);
265-
AddProject(p,"",true);
288+
AddProject(p,"",true,true);
266289
}
267290
catch(runtime_error& e){
268291
wxMessageBox(e.what(),"Unable to add project",wxOK | wxICON_ERROR);
@@ -325,7 +348,7 @@ void MainFrameDerived::OnCreateProject(wxCommandEvent& event){
325348
if (editors.size() > 0){
326349
DialogCallback d = [&](string str, project p){
327350
//add the project
328-
this->AddProject(p,"",true);
351+
this->AddProject(p,"",true, true);
329352

330353
//launch the process
331354
launch_process(str);
@@ -519,51 +542,41 @@ void MainFrameDerived::SaveEditorVersions(){
519542
@param p the project struct to add
520543
@note Ensure all the fields on the struct are initialized
521544
*/
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){
523546
//add to the vector backing the UI
524547
if (std::find_if(projects.begin(),projects.end(),[&](const auto& item){
525548
return p == item;
526549
}) != projects.end()){
527550
return;
528551
}
529-
projects.insert(projects.begin(),p);
530-
531-
//save to file
532-
if (filter == ""){
533-
SaveProjects();
534-
}
535552

536-
//add (painfully) to the UI
537553
auto name = p.name;
538554
transform(name.begin(), name.end(), name.begin(), ::tolower);
539555
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
540564
wxListItem i;
541-
i.SetId(0);
565+
i.SetId(projectsList->GetItemCount());
542566
i.SetText(p.name);
543-
544567
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());
558571

559572
//resize columns
560573
int cols = projectsList->GetColumnCount();
561574
for (int i = 0; i < cols; i++){
562-
projectsList->SetColumnWidth(i, wxLIST_AUTOSIZE);
575+
projectsList->SetColumnWidth(i, wxLIST_AUTOSIZE_USEHEADER);
563576
}
564577

565578
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);
567580
}
568581
}
569582

source/interface_derived.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class MainFrameDerived : public MainFrame{
4040
static std::string GetPathFromDialog(const std::string& message);
4141

4242
private:
43-
void AddProject(const project& p, const std::string& filter, bool select=false);
43+
void AddProject(const project& p, const std::string& filter, bool select=false, bool save=false);
4444
project LoadProject(const std::filesystem::path& path);
4545
void SaveProjects();
4646
void OpenProject(const long& index);

0 commit comments

Comments
 (0)