From 49414bd6a73d6418d28aac11913cabb79de7929e Mon Sep 17 00:00:00 2001 From: apoorv569 Date: Fri, 14 May 2021 14:26:26 +0530 Subject: [PATCH] Add experimental keybind support. --- src/App.cpp | 64 ++++++++++++++++++++++++++++++++-- src/MainFrame.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++ src/MainFrame.hpp | 2 ++ 3 files changed, 151 insertions(+), 2 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 9bb7378..9244382 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -59,11 +59,56 @@ int App::FilterEvent(wxEvent& event) wxLogDebug("Focused window: %s", className); // if SearchCtrl or TreeCtrl has focus, let all keys through - if(className == wxT("wxSearchCtrl")) + if(className == wxT("wxDialog")) + { + wxLogDebug("Dialog focused skipping key filtering"); + return wxEventFilter::Event_Skip; + } + else if(className == wxT("wxSearchCtrl")) { wxLogDebug("SearchCtrl focused skipping key filtering"); return wxEventFilter::Event_Skip; } + else if(className == wxT("wxTextCtrl")) + { + wxLogDebug("TextCtrl focused skipping key filtering"); + return wxEventFilter::Event_Skip; + } + else if(className == wxT("wxChoice")) + { + wxLogDebug("Choice focused skipping key filtering"); + return wxEventFilter::Event_Skip; + } + else if(className == wxT("wxCheckBox")) + { + wxLogDebug("CheckBox focused skipping key filtering"); + return wxEventFilter::Event_Skip; + } + else if(className == wxT("wxSlider")) + { + wxLogDebug("Slider focused skipping key filtering"); + return wxEventFilter::Event_Skip; + } + else if(className == wxT("wxDirCtrl")) + { + wxLogDebug("DirCtrl focused skipping key filtering"); + return wxEventFilter::Event_Skip; + } + else if(className == wxT("wxTreeCtrl")) + { + wxLogDebug("TreeCtrl focused skipping key filtering"); + return wxEventFilter::Event_Skip; + } + else if(className == wxT("wxNotebook")) + { + wxLogDebug("Notebook focused skipping key filtering"); + return wxEventFilter::Event_Skip; + } + else if(className == wxT("wxSpinCtrl")) + { + wxLogDebug("SpinCtrl focused skipping key filtering"); + return wxEventFilter::Event_Skip; + } else if(className == wxT("wxTreeCtrl")) { wxLogDebug("TreeCtrl focused skipping key filtering"); @@ -95,8 +140,8 @@ int App::FilterEvent(wxEvent& event) case 'A': { wxCommandEvent autoplayEvent(wxEVT_CHECKBOX); - autoplayEvent.SetId(BC_Autoplay); + autoplayEvent.SetId(BC_Autoplay); autoplayEvent.SetEventObject(m_Frame->m_AutoPlayCheck); if (m_Frame->m_AutoPlayCheck->GetValue()) @@ -112,6 +157,21 @@ int App::FilterEvent(wxEvent& event) break; } + case 'D': + { + wxMenuEvent deleteEvent(wxEVT_COMMAND_MENU_SELECTED); + + deleteEvent.SetId(MN_DeleteSample); + // deleteEvent.SetEventObject(m_Frame->m_AutoPlayCheck); + + m_Frame->OnSelectDeleteFromMenu(deleteEvent); + + wxLogDebug("A pressed"); + + return wxEventFilter::Event_Processed; + + break; + } case 'L': { wxCommandEvent loopEvent(wxEVT_TOGGLEBUTTON); diff --git a/src/MainFrame.cpp b/src/MainFrame.cpp index c2d00cc..2ce739e 100644 --- a/src/MainFrame.cpp +++ b/src/MainFrame.cpp @@ -224,6 +224,8 @@ MainFrame::MainFrame() Bind(wxEVT_BUTTON, &MainFrame::OnClickCollectionAdd, this, BC_CollectionViewAdd); Bind(wxEVT_BUTTON, &MainFrame::OnClickCollectionRemove, this, BC_CollectionViewRemove); + Bind(wxEVT_MENU_OPEN, &MainFrame::OnSelectDeleteFromMenu, this, MN_DeleteSample); + // // Setting up keybindings // wxAcceleratorEntry entries[5]; // entries[0].Set(wxACCEL_NORMAL, (int) 'P', BC_Play); @@ -975,6 +977,91 @@ void MainFrame::OnShowSampleListViewContextMenu(wxDataViewEvent& event) wxLogDebug(msg); } +void MainFrame::OnSelectDeleteFromMenu(wxMenuEvent& event) +{ + Database db(*m_InfoBar); + + wxString msg; + + int selected_row = m_SampleListView->GetSelectedRow(); + + wxString selection = m_SampleListView->GetTextValue(selected_row, 1); + + wxString sample_path = GetFileNamePathAndExtension(selection).Path; + std::string filename = GetFileNamePathAndExtension(selection).Filename; + std::string extension = GetFileNamePathAndExtension(selection).Extension; + + wxDataViewItemArray items; + int rows = m_SampleListView->GetSelections(items); + + wxMessageDialog singleMsgDialog(this, wxString::Format( + "Are you sure you want to delete " + "%s from database? " + "Warning this change is " + "permanent, and cannot be " + "undone.", sample_path.AfterLast('/')), + wxMessageBoxCaptionStr, + wxYES_NO | wxNO_DEFAULT | + wxICON_QUESTION | wxSTAY_ON_TOP | + wxCENTER); + + wxMessageDialog multipleMsgDialog(this, wxString::Format( + "Are you sure you want to delete " + "%d selected samples from database? " + "Warning this change is " + "permanent, and cannot be " + "undone.", rows), + wxMessageBoxCaptionStr, + wxYES_NO | wxNO_DEFAULT | + wxICON_QUESTION | wxSTAY_ON_TOP | + wxCENTER); + + if (m_SampleListView->GetSelectedItemsCount() <= 1) + { + switch (singleMsgDialog.ShowModal()) + { + case wxID_YES: + { + msg = wxString::Format("Selected row: %d :: Sample: %s", selected_row, filename); + db.RemoveSampleFromDatabase(filename); + m_SampleListView->DeleteItem(selected_row); + } + break; + case wxID_NO: + msg = "Cancel delete"; + break; + default: + msg = "Unexpected wxMessageDialog return code!"; + } + } + else + { + switch (multipleMsgDialog.ShowModal()) + { + case wxID_YES: + { + for (int i = 0; i < rows; i++) + { + int row = m_SampleListView->ItemToRow(items[i]); + + wxString text_value = m_SampleListView->GetTextValue(row, 1); + std::string multi_selection = text_value.Contains(wxString::Format(".%s", extension)) ? + text_value.BeforeLast('.').ToStdString() : text_value.ToStdString() ; + + db.RemoveSampleFromDatabase(multi_selection); + m_SampleListView->DeleteItem(row); + } + } + break; + case wxID_NO: + msg = "Cancel delete"; + break; + default: + msg = "Unexpected wxMessageDialog return code!"; + } + } +} + void MainFrame::LoadDatabase() { Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath); diff --git a/src/MainFrame.hpp b/src/MainFrame.hpp index a7d96a7..51cd287 100644 --- a/src/MainFrame.hpp +++ b/src/MainFrame.hpp @@ -203,5 +203,7 @@ class MainFrame : public wxFrame // wxString TagLibTowx(const TagLib::String& in); + void OnSelectDeleteFromMenu(wxMenuEvent& event); + friend class App; };