More encapsulation, lots of reformatting and cleanup.

This commit is contained in:
apoorv569
2022-01-24 02:39:57 +05:30
parent 9e0be8f55a
commit 010a798fe5
46 changed files with 3488 additions and 5177 deletions
+35 -13
View File
@@ -1,15 +1,38 @@
/* SampleHive
* Copyright (C) 2021 Apoorv Singh
* A simple, modern audio sample browser/manager for GNU/Linux.
*
* This file is a part of SampleHive
*
* SampleHive is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SampleHive is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GUI/SearchBar.hpp"
#include "GUI/ListCtrl.hpp"
#include "Database/Database.hpp"
#include "Utility/ControlIDs.hpp"
#include "Utility/HiveData.hpp"
#include "Utility/Serialize.hpp"
#include "Utility/Paths.hpp"
#include "Utility/Log.hpp"
cSearchBar::cSearchBar(wxWindow* window, wxDataViewListCtrl& listCtrl)
: wxSearchCtrl(window, BC_Search, _("Search for samples.."),
#include <exception>
cSearchBar::cSearchBar(wxWindow* window)
: wxSearchCtrl(window, SampleHive::ID::BC_Search, _("Search for samples.."),
wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER),
m_pWindow(window), m_ListCtrl(listCtrl)
m_pWindow(window)
{
// Set minimum and maximum size of m_SearchBox
// so it doesn't expand too wide when resizing the main frame.
@@ -19,16 +42,15 @@ cSearchBar::cSearchBar(wxWindow* window, wxDataViewListCtrl& listCtrl)
ShowSearchButton(true);
ShowCancelButton(true);
Bind(wxEVT_TEXT, &cSearchBar::OnDoSearch, this, BC_Search);
Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &cSearchBar::OnDoSearch, this, BC_Search);
Bind(wxEVT_SEARCHCTRL_CANCEL_BTN, &cSearchBar::OnCancelSearch, this, BC_Search);
Bind(wxEVT_TEXT, &cSearchBar::OnDoSearch, this, SampleHive::ID::BC_Search);
Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &cSearchBar::OnDoSearch, this, SampleHive::ID::BC_Search);
Bind(wxEVT_SEARCHCTRL_CANCEL_BTN, &cSearchBar::OnCancelSearch, this, SampleHive::ID::BC_Search);
}
void cSearchBar::OnDoSearch(wxCommandEvent& event)
{
Serializer serializer;
Database db;
// cListCtrl m_ListCtrl(m_pWindow);
SampleHive::cSerializer serializer;
cDatabase db;
const auto search = this->GetValue().ToStdString();
@@ -43,19 +65,19 @@ void cSearchBar::OnDoSearch(wxCommandEvent& event)
}
else
{
m_ListCtrl.DeleteAllItems();
SampleHive::cHiveData::Get().ListCtrlDeleteAllItems();
std::cout << search << std::endl;
for (const auto& data : dataset)
{
m_ListCtrl.AppendItem(data);
SampleHive::cHiveData::Get().ListCtrlAppendItem(data);
}
}
}
catch (...)
catch (std::exception& e)
{
std::cerr << "Error loading data." << std::endl;
SH_LOG_ERROR("Error loading data. {}", e.what());
}
}