Skip to content

fixed not being able to opening projects with search. added keyboard navigation to project list for when search is focused #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 41 additions & 28 deletions source/interface_derived.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,30 @@ void MainFrameDerived::LoadProjects(const std::string &filter){
}
}

void MainFrameDerived::Filter(wxKeyEvent &){
void MainFrameDerived::Filter(wxKeyEvent &event){
//focus on the table
if (projectsList->GetItemCount() > 0){
if (event.GetKeyCode() == wxKeyCode::WXK_DOWN){
projectsList->SetFocus();
projectsList->SetItemState(0, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
return;
}
if (event.GetKeyCode() == wxKeyCode::WXK_UP){
projectsList->SetFocus();
projectsList->SetItemState(projectsList->GetItemCount() - 1, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
return;
}
//straight up select the open the first project on ENTER
if (event.GetKeyCode() == wxKeyCode::WXK_RETURN){
//select first item first
projectsList->SetFocus();
projectsList->SetItemState(0, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);

//open first item
OpenProject(0);
return;
}
}
projectsList->DeleteAllItems();
wxListEvent e;
OnDeselectProject(e);
Expand Down Expand Up @@ -262,7 +285,7 @@ void MainFrameDerived::OnAddProject(wxCommandEvent& event){
//add it to the projects list
try{
project p = LoadProject(path);
AddProject(p,"",true);
AddProject(p,"",true,true);
}
catch(runtime_error& e){
wxMessageBox(e.what(),"Unable to add project",wxOK | wxICON_ERROR);
Expand Down Expand Up @@ -325,7 +348,7 @@ void MainFrameDerived::OnCreateProject(wxCommandEvent& event){
if (editors.size() > 0){
DialogCallback d = [&](string str, project p){
//add the project
this->AddProject(p,"",true);
this->AddProject(p,"",true, true);

//launch the process
launch_process(str);
Expand Down Expand Up @@ -519,51 +542,41 @@ void MainFrameDerived::SaveEditorVersions(){
@param p the project struct to add
@note Ensure all the fields on the struct are initialized
*/
void MainFrameDerived::AddProject(const project& p, const std::string& filter, bool select){
void MainFrameDerived::AddProject(const project& p, const std::string& filter, bool select, bool save){
//add to the vector backing the UI
if (std::find_if(projects.begin(),projects.end(),[&](const auto& item){
return p == item;
}) != projects.end()){
return;
}
projects.insert(projects.begin(),p);

//save to file
if (filter == ""){
SaveProjects();
}

//add (painfully) to the UI
auto name = p.name;
transform(name.begin(), name.end(), name.begin(), ::tolower);
if (name.find(filter) != std::string::npos){
projects.push_back(p);

//save to file
if (save){
SaveProjects();
}

//add to the UI
wxListItem i;
i.SetId(0);
i.SetId(projectsList->GetItemCount());
i.SetText(p.name);

projectsList->InsertItem(i);

i.SetText(p.version);
i.SetColumn(1);
projectsList->SetItem(i);

i.SetText(p.modifiedDate);

i.SetColumn(2);
projectsList->SetItem(i);

i.SetColumn(3);
i.SetText(p.path.string());
projectsList->SetItem(i);
projectsList->SetItem(i, 1, p.version);
projectsList->SetItem(i, 2, p.modifiedDate);
projectsList->SetItem(i, 3, p.path.string());

//resize columns
int cols = projectsList->GetColumnCount();
for (int i = 0; i < cols; i++){
projectsList->SetColumnWidth(i, wxLIST_AUTOSIZE);
projectsList->SetColumnWidth(i, wxLIST_AUTOSIZE_USEHEADER);
}

if(select){
projectsList->SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
projectsList->SetItemState(i, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/interface_derived.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MainFrameDerived : public MainFrame{
static std::string GetPathFromDialog(const std::string& message);

private:
void AddProject(const project& p, const std::string& filter, bool select=false);
void AddProject(const project& p, const std::string& filter, bool select=false, bool save=false);
project LoadProject(const std::filesystem::path& path);
void SaveProjects();
void OpenProject(const long& index);
Expand Down
Loading