Skip to content

Commit 4c74461

Browse files
fixed not being able to opening projects with search. added keyboard navigation to project list for when search is focused
1 parent 82b68ce commit 4c74461

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

source/interface_derived.cpp

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,32 @@ 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+
wxListEvent listEvent;
230+
listEvent.m_itemIndex = 0;
231+
OnOpenProject(listEvent);
232+
return;
233+
}
234+
}
210235
projectsList->DeleteAllItems();
211236
wxListEvent e;
212237
OnDeselectProject(e);
@@ -262,7 +287,7 @@ void MainFrameDerived::OnAddProject(wxCommandEvent& event){
262287
//add it to the projects list
263288
try{
264289
project p = LoadProject(path);
265-
AddProject(p,"",true);
290+
AddProject(p,"",true,true);
266291
}
267292
catch(runtime_error& e){
268293
wxMessageBox(e.what(),"Unable to add project",wxOK | wxICON_ERROR);
@@ -325,7 +350,7 @@ void MainFrameDerived::OnCreateProject(wxCommandEvent& event){
325350
if (editors.size() > 0){
326351
DialogCallback d = [&](string str, project p){
327352
//add the project
328-
this->AddProject(p,"",true);
353+
this->AddProject(p,"",true, true);
329354

330355
//launch the process
331356
launch_process(str);
@@ -519,51 +544,41 @@ void MainFrameDerived::SaveEditorVersions(){
519544
@param p the project struct to add
520545
@note Ensure all the fields on the struct are initialized
521546
*/
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){
523548
//add to the vector backing the UI
524549
if (std::find_if(projects.begin(),projects.end(),[&](const auto& item){
525550
return p == item;
526551
}) != projects.end()){
527552
return;
528553
}
529-
projects.insert(projects.begin(),p);
530-
531-
//save to file
532-
if (filter == ""){
533-
SaveProjects();
534-
}
535554

536555
//add (painfully) to the UI
537556
auto name = p.name;
538557
transform(name.begin(), name.end(), name.begin(), ::tolower);
539558
if (name.find(filter) != std::string::npos){
559+
projects.push_back(p);
560+
561+
//save to file
562+
if (save){
563+
SaveProjects();
564+
}
565+
540566
wxListItem i;
541-
i.SetId(0);
567+
i.SetId(projectsList->GetItemCount());
542568
i.SetText(p.name);
543-
544569
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());
558573

559574
//resize columns
560575
int cols = projectsList->GetColumnCount();
561576
for (int i = 0; i < cols; i++){
562-
projectsList->SetColumnWidth(i, wxLIST_AUTOSIZE);
577+
projectsList->SetColumnWidth(i, wxLIST_AUTOSIZE_USEHEADER);
563578
}
564579

565580
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);
567582
}
568583
}
569584

source/interface_derived.hpp

Lines changed: 1 addition & 1 deletion
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)