From 4c744617a1f8e932cd8d2f41a885484f773c2ed3 Mon Sep 17 00:00:00 2001 From: Saeed Barari Date: Wed, 22 Jan 2025 14:00:51 +0330 Subject: [PATCH 1/3] fixed not being able to opening projects with search. added keyboard navigation to project list for when search is focused --- source/interface_derived.cpp | 69 ++++++++++++++++++++++-------------- source/interface_derived.hpp | 2 +- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/source/interface_derived.cpp b/source/interface_derived.cpp index 66f19114..3a6e89eb 100644 --- a/source/interface_derived.cpp +++ b/source/interface_derived.cpp @@ -206,7 +206,32 @@ 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 + wxListEvent listEvent; + listEvent.m_itemIndex = 0; + OnOpenProject(listEvent); + return; + } + } projectsList->DeleteAllItems(); wxListEvent e; OnDeselectProject(e); @@ -262,7 +287,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); @@ -325,7 +350,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); @@ -519,51 +544,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(); + } + 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); } } diff --git a/source/interface_derived.hpp b/source/interface_derived.hpp index 6bb32246..e4849102 100644 --- a/source/interface_derived.hpp +++ b/source/interface_derived.hpp @@ -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); From bdeb912f1be5fd3d571b15187509534cc9f724e4 Mon Sep 17 00:00:00 2001 From: Saeed Barari Date: Wed, 22 Jan 2025 14:05:13 +0330 Subject: [PATCH 2/3] minor cleanup --- source/interface_derived.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/interface_derived.cpp b/source/interface_derived.cpp index 3a6e89eb..40e4a7fb 100644 --- a/source/interface_derived.cpp +++ b/source/interface_derived.cpp @@ -226,9 +226,7 @@ void MainFrameDerived::Filter(wxKeyEvent &event){ projectsList->SetItemState(0, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED); //open first item - wxListEvent listEvent; - listEvent.m_itemIndex = 0; - OnOpenProject(listEvent); + OpenProject(0); return; } } @@ -552,7 +550,7 @@ void MainFrameDerived::AddProject(const project& p, const std::string& filter, b return; } - //add (painfully) to the UI + //add to the UI auto name = p.name; transform(name.begin(), name.end(), name.begin(), ::tolower); if (name.find(filter) != std::string::npos){ From bcc492f343e3e078eaac9a60988792e8c97f68dc Mon Sep 17 00:00:00 2001 From: Saeed Barari Date: Wed, 22 Jan 2025 14:06:32 +0330 Subject: [PATCH 3/3] minor commenting --- source/interface_derived.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/interface_derived.cpp b/source/interface_derived.cpp index 40e4a7fb..0e6db963 100644 --- a/source/interface_derived.cpp +++ b/source/interface_derived.cpp @@ -550,7 +550,6 @@ void MainFrameDerived::AddProject(const project& p, const std::string& filter, b return; } - //add to the UI auto name = p.name; transform(name.begin(), name.end(), name.begin(), ::tolower); if (name.find(filter) != std::string::npos){ @@ -561,6 +560,7 @@ void MainFrameDerived::AddProject(const project& p, const std::string& filter, b SaveProjects(); } + //add to the UI wxListItem i; i.SetId(projectsList->GetItemCount()); i.SetText(p.name);