Add ability to show/hide file extension.
This commit is contained in:
parent
bde89394f3
commit
862b797920
|
|
@ -6,6 +6,6 @@
|
|||
|
||||
(projectile-project-name . "SampleHive")
|
||||
|
||||
(projectile-project-run-cmd . "~/repos/sample-hive/run.sh")
|
||||
(projectile-project-run-cmd . "~/repos/sample-hive/build/SampleHive")
|
||||
|
||||
(projectile-project-test-cmd . "./test.sh"))))
|
||||
|
|
|
|||
|
|
@ -409,8 +409,16 @@ wxString TagLibTowx(const TagLib::String& in)
|
|||
|
||||
void Browser::AddSamples(wxString file)
|
||||
{
|
||||
Settings settings(this, configFilepath, databaseFilepath);
|
||||
|
||||
std::string path = file.ToStdString();
|
||||
std::string filename = file.AfterLast('/').BeforeLast('.').ToStdString();
|
||||
|
||||
std::string filename_with_extension = file.AfterLast('/').ToStdString();
|
||||
std::string filename_without_extension = file.AfterLast('/').BeforeLast('.').ToStdString();
|
||||
std::string extension = file.AfterLast('.').ToStdString();
|
||||
|
||||
std::string filename = settings.IsShowFileExtension() ?
|
||||
filename_with_extension : filename_without_extension;
|
||||
|
||||
Tags tags(path);
|
||||
|
||||
|
|
@ -435,12 +443,14 @@ void Browser::AddSamples(wxString file)
|
|||
data.push_back(wxString::Format("%d", sample_rate));
|
||||
data.push_back(wxString::Format("%d", bitrate));
|
||||
|
||||
if (!db.HasSample(filename))
|
||||
wxLogDebug("Adding file: %s :: Extension: %s", filename, extension);
|
||||
|
||||
if (!db.HasSample(filename_without_extension))
|
||||
{
|
||||
m_SampleListView->AppendItem(data);
|
||||
|
||||
db.InsertSample(0, filename, artist, "", channels, length,
|
||||
sample_rate, bitrate, path, 0);
|
||||
db.InsertSample(0, filename_without_extension, extension, artist, "", channels,
|
||||
length, sample_rate, bitrate, path, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -705,6 +715,8 @@ void Browser::OnSlideVolume(wxScrollEvent& event)
|
|||
|
||||
void Browser::OnClickSampleView(wxDataViewEvent& event)
|
||||
{
|
||||
Settings settings(this, configFilepath, databaseFilepath);
|
||||
|
||||
int selected_row = m_SampleListView->ItemToRow(event.GetItem());
|
||||
|
||||
if (selected_row < 0)
|
||||
|
|
@ -712,11 +724,16 @@ void Browser::OnClickSampleView(wxDataViewEvent& event)
|
|||
return;
|
||||
}
|
||||
|
||||
std::string selection = m_SampleListView->GetTextValue(selected_row, 1).ToStdString();
|
||||
std::string sample = db.GetSamplePathByFilename(selection);
|
||||
wxString selection = m_SampleListView->GetTextValue(selected_row, 1);
|
||||
wxString sample_with_extension = db.GetSamplePathByFilename(selection.BeforeLast('.').ToStdString());
|
||||
wxString sample_without_extension = db.GetSamplePathByFilename(selection.ToStdString());
|
||||
|
||||
wxLogInfo("Selected: %s", selection);
|
||||
wxLogInfo("Sample path: %s", sample);
|
||||
wxString sample = selection.Contains('.') ? sample_with_extension : sample_without_extension;
|
||||
|
||||
wxLogDebug("Selected: %s", selection);
|
||||
wxLogDebug("Sample path: %s", sample);
|
||||
wxLogDebug("Sample with ext: %s", sample_with_extension);
|
||||
wxLogDebug("Sample without ext: %s", sample_without_extension);
|
||||
|
||||
m_MediaCtrl->Load(sample);
|
||||
|
||||
|
|
@ -854,11 +871,13 @@ void Browser::OnShowSampleListViewContextMenu(wxDataViewEvent& event)
|
|||
|
||||
void Browser::RestoreDatabase()
|
||||
{
|
||||
Settings settings(this, configFilepath, databaseFilepath);
|
||||
|
||||
try
|
||||
{
|
||||
wxVector<wxVector<wxVariant>> dataset;
|
||||
|
||||
if (db.LoadDatabase(dataset, *m_CollectionView, rootNode, *m_TrashedItems, trash_root_node).empty())
|
||||
if (db.LoadDatabase(dataset, *m_CollectionView, rootNode, *m_TrashedItems, trash_root_node, settings.IsShowFileExtension()).empty())
|
||||
{
|
||||
wxLogDebug("Error! Database is empty.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ enum ControlIDs
|
|||
SD_BrowseConfigDir,
|
||||
SD_BrowseDatabaseDir,
|
||||
SD_AutoImport,
|
||||
SD_ShowFileExtension,
|
||||
SD_BrowseAutoImportDir,
|
||||
SD_FontType,
|
||||
SD_FontSize,
|
||||
|
|
|
|||
121
src/Database.cpp
121
src/Database.cpp
|
|
@ -5,6 +5,7 @@
|
|||
#include <wx/string.h>
|
||||
|
||||
#include "Database.hpp"
|
||||
#include "SettingsDialog.hpp"
|
||||
|
||||
Database::Database(wxInfoBar& infoBar)
|
||||
: m_InfoBar(infoBar)
|
||||
|
|
@ -13,6 +14,7 @@ Database::Database(wxInfoBar& infoBar)
|
|||
std::string sample = "CREATE TABLE IF NOT EXISTS SAMPLES("
|
||||
"FAVORITE INT NOT NULL,"
|
||||
"FILENAME TEXT NOT NULL,"
|
||||
"EXTENSION TEXT NOT NULL,"
|
||||
"SAMPLEPACK TEXT NOT NULL,"
|
||||
"TYPE TEXT NOT NULL,"
|
||||
"CHANNELS INT NOT NULL,"
|
||||
|
|
@ -52,31 +54,33 @@ Database::~Database()
|
|||
}
|
||||
|
||||
void Database::InsertSample(int favorite, std::string filename,
|
||||
std::string samplePack, std::string type,
|
||||
int channels, int length, int sampleRate,
|
||||
int bitrate, std::string path, int trashed)
|
||||
std::string fileExtension, std::string samplePack,
|
||||
std::string type, int channels, int length,
|
||||
int sampleRate, int bitrate, std::string path,
|
||||
int trashed)
|
||||
{
|
||||
try
|
||||
{
|
||||
rc = sqlite3_open("Samples.db", &m_Database);
|
||||
|
||||
std::string insert = "INSERT INTO SAMPLES (FAVORITE, FILENAME, \
|
||||
SAMPLEPACK, TYPE, CHANNELS, LENGTH, SAMPLERATE, \
|
||||
BITRATE, PATH, TRASHED) \
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
|
||||
EXTENSION, SAMPLEPACK, TYPE, CHANNELS, LENGTH, \
|
||||
SAMPLERATE, BITRATE, PATH, TRASHED) \
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
|
||||
|
||||
rc = sqlite3_prepare_v2(m_Database, insert.c_str(), insert.size(), &m_Stmt, NULL);
|
||||
|
||||
rc = sqlite3_bind_int(m_Stmt, 1, favorite);
|
||||
rc = sqlite3_bind_text(m_Stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC);
|
||||
rc = sqlite3_bind_text(m_Stmt, 3, samplePack.c_str(), samplePack.size(), SQLITE_STATIC);
|
||||
rc = sqlite3_bind_text(m_Stmt, 4, type.c_str(), type.size(), SQLITE_STATIC);
|
||||
rc = sqlite3_bind_int(m_Stmt, 5, channels);
|
||||
rc = sqlite3_bind_int(m_Stmt, 6, length);
|
||||
rc = sqlite3_bind_int(m_Stmt, 7, sampleRate);
|
||||
rc = sqlite3_bind_int(m_Stmt, 8, bitrate);
|
||||
rc = sqlite3_bind_text(m_Stmt, 9, path.c_str(), path.size(), SQLITE_STATIC);
|
||||
rc = sqlite3_bind_int(m_Stmt, 10, trashed);
|
||||
rc = sqlite3_bind_text(m_Stmt, 3, fileExtension.c_str(), fileExtension.size(), SQLITE_STATIC);
|
||||
rc = sqlite3_bind_text(m_Stmt, 4, samplePack.c_str(), samplePack.size(), SQLITE_STATIC);
|
||||
rc = sqlite3_bind_text(m_Stmt, 5, type.c_str(), type.size(), SQLITE_STATIC);
|
||||
rc = sqlite3_bind_int(m_Stmt, 6, channels);
|
||||
rc = sqlite3_bind_int(m_Stmt, 7, length);
|
||||
rc = sqlite3_bind_int(m_Stmt, 8, sampleRate);
|
||||
rc = sqlite3_bind_int(m_Stmt, 9, bitrate);
|
||||
rc = sqlite3_bind_text(m_Stmt, 10, path.c_str(), path.size(), SQLITE_STATIC);
|
||||
rc = sqlite3_bind_int(m_Stmt, 11, trashed);
|
||||
|
||||
if (sqlite3_step(m_Stmt) != SQLITE_DONE)
|
||||
{
|
||||
|
|
@ -429,7 +433,54 @@ std::string Database::GetSamplePathByFilename(std::string filename)
|
|||
return path;
|
||||
}
|
||||
|
||||
wxVector<wxVector<wxVariant>> Database::LoadDatabase(wxVector<wxVector<wxVariant>>& vecSet, wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item, wxTreeCtrl& trash_tree, wxTreeItemId& trash_item)
|
||||
std::string Database::GetSampleFileExtension(std::string filename)
|
||||
{
|
||||
std::string extension;
|
||||
|
||||
try
|
||||
{
|
||||
rc = sqlite3_open("Samples.db", &m_Database);
|
||||
|
||||
std::string select = "SELECT EXTENSION FROM SAMPLES WHERE FILENAME = ?;";
|
||||
|
||||
rc = sqlite3_prepare_v2(m_Database, select.c_str(), select.size(), &m_Stmt, NULL);
|
||||
|
||||
rc = sqlite3_bind_text(m_Stmt, 1, filename.c_str(), filename.size(), SQLITE_STATIC);
|
||||
|
||||
if (sqlite3_step(m_Stmt) == SQLITE_ROW)
|
||||
{
|
||||
wxLogInfo("Record found, fetching..");
|
||||
extension = std::string(reinterpret_cast< const char* >(sqlite3_column_text(m_Stmt, 0)));
|
||||
}
|
||||
|
||||
rc = sqlite3_finalize(m_Stmt);
|
||||
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
wxMessageDialog* msgDialog = new wxMessageDialog(NULL, "Error! Cannot select sample path from table.", "Error", wxOK | wxICON_ERROR);
|
||||
msgDialog->ShowModal();
|
||||
sqlite3_free(m_ErrMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogInfo("Selected data from table successfully.");
|
||||
}
|
||||
|
||||
sqlite3_close(m_Database);
|
||||
}
|
||||
catch (const std::exception &exception)
|
||||
{
|
||||
wxLogDebug(exception.what());
|
||||
}
|
||||
|
||||
return extension;
|
||||
}
|
||||
|
||||
wxVector<wxVector<wxVariant>>
|
||||
Database::LoadDatabase(wxVector<wxVector<wxVariant>>& vecSet,
|
||||
wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item,
|
||||
wxTreeCtrl& trash_tree, wxTreeItemId& trash_item,
|
||||
bool show_extension)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -439,9 +490,9 @@ wxVector<wxVector<wxVariant>> Database::LoadDatabase(wxVector<wxVector<wxVariant
|
|||
throw sqlite3_errmsg(m_Database);
|
||||
}
|
||||
|
||||
std::string load = "SELECT FAVORITE, FILENAME, SAMPLEPACK, TYPE, \
|
||||
CHANNELS, LENGTH, SAMPLERATE, BITRATE, TRASHED \
|
||||
FROM SAMPLES;";
|
||||
std::string load = "SELECT FAVORITE, FILENAME, EXTENSION, SAMPLEPACK, \
|
||||
TYPE, CHANNELS, LENGTH, SAMPLERATE, BITRATE, PATH, \
|
||||
TRASHED FROM SAMPLES;";
|
||||
|
||||
rc = sqlite3_prepare_v2(m_Database, load.c_str(), load.size(), &m_Stmt, NULL);
|
||||
|
||||
|
|
@ -454,14 +505,16 @@ wxVector<wxVector<wxVariant>> Database::LoadDatabase(wxVector<wxVector<wxVariant
|
|||
wxLogDebug("Record found, fetching..");
|
||||
|
||||
int favorite = sqlite3_column_int(m_Stmt, 0);
|
||||
wxString filename = wxString(std::string(reinterpret_cast< const char* >(sqlite3_column_text(m_Stmt, 1))));
|
||||
wxString sample_pack = wxString(std::string(reinterpret_cast< const char* >(sqlite3_column_text(m_Stmt, 2))));
|
||||
wxString sample_type = std::string(reinterpret_cast<const char *>(sqlite3_column_text(m_Stmt, 3)));
|
||||
int channels = sqlite3_column_int(m_Stmt, 4);
|
||||
int length = sqlite3_column_int(m_Stmt, 5);
|
||||
int sample_rate = sqlite3_column_int(m_Stmt, 6);
|
||||
int bitrate = sqlite3_column_int(m_Stmt, 7);
|
||||
int trashed = sqlite3_column_int(m_Stmt, 8);
|
||||
wxString filename = std::string(reinterpret_cast<const char*>(sqlite3_column_text(m_Stmt, 1)));
|
||||
wxString file_extension = std::string(reinterpret_cast<const char*>(sqlite3_column_text(m_Stmt, 2)));
|
||||
wxString sample_pack = std::string(reinterpret_cast<const char*>(sqlite3_column_text(m_Stmt, 3)));
|
||||
wxString sample_type = std::string(reinterpret_cast<const char *>(sqlite3_column_text(m_Stmt, 4)));
|
||||
int channels = sqlite3_column_int(m_Stmt, 5);
|
||||
int length = sqlite3_column_int(m_Stmt, 6);
|
||||
int sample_rate = sqlite3_column_int(m_Stmt, 7);
|
||||
int bitrate = sqlite3_column_int(m_Stmt, 8);
|
||||
wxString path = std::string(reinterpret_cast<const char*>(sqlite3_column_text(m_Stmt, 9)));
|
||||
int trashed = sqlite3_column_int(m_Stmt, 10);
|
||||
|
||||
wxVector<wxVariant> vec;
|
||||
|
||||
|
|
@ -478,7 +531,17 @@ wxVector<wxVector<wxVariant>> Database::LoadDatabase(wxVector<wxVector<wxVariant
|
|||
else
|
||||
vec.push_back(false);
|
||||
|
||||
vec.push_back(filename);
|
||||
if (show_extension)
|
||||
{
|
||||
vec.push_back(path.AfterLast('/'));
|
||||
wxLogDebug("With extension..");
|
||||
}
|
||||
else
|
||||
{
|
||||
vec.push_back(path.AfterLast('/').BeforeLast('.'));
|
||||
wxLogDebug("Without extension..");
|
||||
}
|
||||
|
||||
vec.push_back(sample_pack);
|
||||
vec.push_back(sample_type);
|
||||
vec.push_back(wxString::Format("%d", channels));
|
||||
|
|
@ -522,8 +585,8 @@ wxVector<wxVector<wxVariant>> Database::FilterDatabaseBySampleName(wxVector<wxVe
|
|||
}
|
||||
|
||||
std::string filter = "SELECT FAVORITE, FILENAME, SAMPLEPACK, TYPE, \
|
||||
CHANNELS, LENGTH, SAMPLERATE, BITRATE \
|
||||
FROM SAMPLES WHERE FILENAME LIKE '%' || ? || '%';";
|
||||
CHANNELS, LENGTH, SAMPLERATE, BITRATE \
|
||||
FROM SAMPLES WHERE FILENAME LIKE '%' || ? || '%';";
|
||||
|
||||
rc = sqlite3_prepare_v2(m_Database, filter.c_str(), filter.size(), &m_Stmt, NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,9 +29,10 @@ class Database
|
|||
// -------------------------------------------------------------------
|
||||
// Insert into database
|
||||
void InsertSample(int favorite, std::string filename,
|
||||
std::string samplePack, std::string type,
|
||||
int channels, int length, int sampleRate, int bitrate,
|
||||
std::string path, int trashed);
|
||||
std::string fileExtension, std::string samplePack,
|
||||
std::string type, int channels, int length,
|
||||
int sampleRate, int bitrate, std::string path,
|
||||
int trashed);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Update database
|
||||
|
|
@ -47,6 +48,7 @@ class Database
|
|||
std::string GetSampleType(std::string filename);
|
||||
int GetFavoriteColumnValueByFilename(std::string filename);
|
||||
std::string GetSamplePathByFilename(std::string filename);
|
||||
std::string GetSampleFileExtension(std::string filename);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Check database
|
||||
|
|
@ -61,7 +63,7 @@ class Database
|
|||
wxVector<wxVector<wxVariant>>
|
||||
LoadDatabase(wxVector<wxVector<wxVariant>> &vecSet,
|
||||
wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item,
|
||||
wxTreeCtrl& trash_tree, wxTreeItemId& trash_item);
|
||||
wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, bool show_extension);
|
||||
wxVector<wxVector<wxVariant>>
|
||||
FilterDatabaseBySampleName(wxVector<wxVector<wxVariant>> &sampleVec,
|
||||
std::string sampleName);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ MainFrame::MainFrame(): wxFrame(NULL, wxID_ANY, "Sample Hive", wxDefaultPosition
|
|||
width = serializer.DeserializeWinSize("Width", width);
|
||||
|
||||
this->SetSize(width, height);
|
||||
this->Center(wxBOTH);
|
||||
this->CenterOnScreen(wxBOTH);
|
||||
this->SetIcon(wxIcon("../assets/icons/icon-hive_24x24.png", wxICON_DEFAULT_TYPE, -1, -1));
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
#include <wx/log.h>
|
||||
#include <wx/stdpaths.h>
|
||||
|
||||
#include <yaml-cpp/emittermanip.h>
|
||||
#include <yaml-cpp/node/parse.h>
|
||||
|
||||
#include "Serialize.hpp"
|
||||
|
||||
Serializer::Serializer(const std::string& filepath)
|
||||
|
|
@ -19,12 +22,9 @@ Serializer::Serializer(const std::string& filepath)
|
|||
|
||||
if (!ifstrm)
|
||||
{
|
||||
m_Emitter << YAML::Comment("Hello");
|
||||
m_Emitter << YAML::BeginDoc;
|
||||
m_Emitter << "This is the configuration file for the Sample Browser,"
|
||||
<< YAML::Newline;
|
||||
m_Emitter << "feel free to edit this file as needed";
|
||||
m_Emitter << YAML::EndDoc;
|
||||
m_Emitter << YAML::Comment("This is the configuration file for the Sample Browser,"
|
||||
"feel free to edit this file as needed");
|
||||
m_Emitter << YAML::Newline;
|
||||
|
||||
m_Emitter << YAML::BeginMap;
|
||||
|
||||
|
|
@ -50,10 +50,11 @@ Serializer::Serializer(const std::string& filepath)
|
|||
m_Emitter << YAML::EndMap;
|
||||
m_Emitter << YAML::EndMap << YAML::Newline;
|
||||
|
||||
m_Emitter << YAML::Newline << YAML::Key << "Import_dir";
|
||||
m_Emitter << YAML::Newline << YAML::Key << "Collection";
|
||||
m_Emitter << YAML::BeginMap;
|
||||
m_Emitter << YAML::Key << "AutoImport" << YAML::Value << false;
|
||||
m_Emitter << YAML::Key << "Directory" << YAML::Value << dir;
|
||||
m_Emitter << YAML::Key << "ShowFileExtension" << YAML::Value << true;
|
||||
m_Emitter << YAML::EndMap << YAML::Newline;
|
||||
|
||||
m_Emitter << YAML::EndMap;
|
||||
|
|
@ -78,7 +79,7 @@ int Serializer::DeserializeWinSize(std::string key, int size) const
|
|||
|
||||
try
|
||||
{
|
||||
YAML::Node data = YAML::LoadAllFromFile(m_Filepath)[1];
|
||||
YAML::Node data = YAML::LoadFile(m_Filepath);
|
||||
|
||||
if (!data["Window"])
|
||||
{
|
||||
|
|
@ -116,7 +117,7 @@ bool Serializer::DeserializeBrowserControls(std::string key, bool control) const
|
|||
|
||||
try
|
||||
{
|
||||
YAML::Node config = YAML::LoadAllFromFile(m_Filepath)[1];
|
||||
YAML::Node config = YAML::LoadFile(m_Filepath);
|
||||
|
||||
if (auto media = config["Media"])
|
||||
{
|
||||
|
|
@ -162,11 +163,10 @@ void Serializer::SerializeDisplaySettings(wxFont& font)
|
|||
|
||||
try
|
||||
{
|
||||
auto docs = YAML::LoadAllFromFile(m_Filepath);
|
||||
out << YAML::Comment("Hello") << YAML::BeginDoc << docs[0] << YAML::EndDoc;
|
||||
// auto docs = YAML::LoadFile(m_Filepath);
|
||||
// out << YAML::Comment("Hello") << YAML::BeginDoc << docs[0] << YAML::EndDoc;
|
||||
|
||||
YAML::Node config = docs[1];
|
||||
// YAML::Node config = YAML::LoadAllFromFile(m_Filepath)[1];
|
||||
YAML::Node config = YAML::LoadFile(m_Filepath);
|
||||
|
||||
auto display = config["Display"];
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ FontType Serializer::DeserializeDisplaySettings() const
|
|||
|
||||
try
|
||||
{
|
||||
YAML::Node config = YAML::LoadAllFromFile(m_Filepath)[1];
|
||||
YAML::Node config = YAML::LoadFile(m_Filepath);
|
||||
|
||||
auto display = config["Display"];
|
||||
|
||||
|
|
@ -224,7 +224,8 @@ FontType Serializer::DeserializeDisplaySettings() const
|
|||
return { face, size };
|
||||
}
|
||||
|
||||
void Serializer::SerializeAutoImportSettings(wxTextCtrl& textCtrl, wxCheckBox& checkBox)
|
||||
void Serializer::SerializeAutoImportSettings(wxTextCtrl& textCtrl,
|
||||
wxCheckBox& checkBox)
|
||||
{
|
||||
YAML::Emitter out;
|
||||
|
||||
|
|
@ -233,16 +234,15 @@ void Serializer::SerializeAutoImportSettings(wxTextCtrl& textCtrl, wxCheckBox& c
|
|||
|
||||
try
|
||||
{
|
||||
auto docs = YAML::LoadAllFromFile(m_Filepath);
|
||||
out << YAML::Comment("Hello") << YAML::BeginDoc << docs[0] << YAML::EndDoc;
|
||||
// auto docs = ;
|
||||
// out << YAML::Comment("Hello") << YAML::BeginDoc << docs[0] << YAML::EndDoc;
|
||||
|
||||
YAML::Node config = docs[1];
|
||||
// YAML::Node config = YAML::LoadAllFromFile(m_Filepath)[1];
|
||||
YAML::Node config = YAML::LoadFile(m_Filepath);
|
||||
|
||||
if (auto importInfo = config["Import_dir"])
|
||||
if (auto autoImportInfo = config["Collection"])
|
||||
{
|
||||
importInfo["AutoImport"] = auto_import;
|
||||
importInfo["Directory"] = import_dir;
|
||||
autoImportInfo["AutoImport"] = auto_import;
|
||||
autoImportInfo["Directory"] = import_dir;
|
||||
|
||||
out << config;
|
||||
|
||||
|
|
@ -267,12 +267,12 @@ ImportDirInfo Serializer::DeserializeAutoImportSettings() const
|
|||
|
||||
try
|
||||
{
|
||||
YAML::Node config = YAML::LoadAllFromFile(m_Filepath)[1];
|
||||
YAML::Node config = YAML::LoadFile(m_Filepath);
|
||||
|
||||
if (auto importInfo = config["Import_dir"])
|
||||
if (auto autoImportInfo = config["Collection"])
|
||||
{
|
||||
auto_import = importInfo["AutoImport"].as<bool>();
|
||||
dir = importInfo["Directory"].as<std::string>();
|
||||
auto_import = autoImportInfo["AutoImport"].as<bool>();
|
||||
dir = autoImportInfo["Directory"].as<std::string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -284,7 +284,65 @@ ImportDirInfo Serializer::DeserializeAutoImportSettings() const
|
|||
std::cout << ex.what() << std::endl;
|
||||
}
|
||||
|
||||
return { auto_import, dir };
|
||||
return { auto_import, dir};
|
||||
}
|
||||
|
||||
void Serializer::SerializeShowFileExtensionSetting(wxCheckBox& checkBox)
|
||||
{
|
||||
YAML::Emitter out;
|
||||
|
||||
bool show_extension = checkBox.GetValue();
|
||||
|
||||
try
|
||||
{
|
||||
YAML::Node config = YAML::LoadFile(m_Filepath);
|
||||
|
||||
if (auto fileExtensionInfo = config["Collection"])
|
||||
{
|
||||
fileExtensionInfo["ShowFileExtension"] = show_extension;
|
||||
|
||||
out << config;
|
||||
|
||||
wxLogDebug("Changin show file extension value.");
|
||||
|
||||
std::ofstream ofstrm(m_Filepath);
|
||||
ofstrm << out.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogDebug("Error! Cannot store import dir values.");
|
||||
}
|
||||
}
|
||||
catch(const YAML::ParserException& ex)
|
||||
{
|
||||
std::cout << ex.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Serializer::DeserializeShowFileExtensionSetting() const
|
||||
{
|
||||
bool show_extension = false;
|
||||
|
||||
try
|
||||
{
|
||||
YAML::Node config = YAML::LoadFile(m_Filepath);
|
||||
|
||||
if (auto fileExtensionInfo = config["Collection"])
|
||||
{
|
||||
show_extension = fileExtensionInfo["ShowFileExtension"].as<bool>();
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogDebug("Error! Cannot fetch import dir values.");
|
||||
}
|
||||
}
|
||||
catch(const YAML::ParserException& ex)
|
||||
{
|
||||
std::cout << ex.what() << std::endl;
|
||||
}
|
||||
|
||||
return show_extension;
|
||||
}
|
||||
|
||||
void Serializer::SerializeDataViewTreeCtrlItems(wxTreeCtrl& tree, wxTreeItemId& item)
|
||||
|
|
|
|||
|
|
@ -62,6 +62,11 @@ class Serializer
|
|||
void SerializeAutoImportSettings(wxTextCtrl& textCtrl, wxCheckBox& checkBox);
|
||||
ImportDirInfo DeserializeAutoImportSettings() const;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Show file extension
|
||||
void SerializeShowFileExtensionSetting(wxCheckBox& checkBox);
|
||||
bool DeserializeShowFileExtensionSetting() const;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Favorite samples
|
||||
void SerializeDataViewTreeCtrlItems(wxTreeCtrl& tree, wxTreeItemId& item);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ Settings::Settings(wxWindow* window, std::string& configFilepath, std::string& d
|
|||
m_CollectionSettingPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||
|
||||
m_CollectionTopSizer = new wxBoxSizer(wxVERTICAL);
|
||||
m_CollectionImportDirSizer = new wxBoxSizer(wxVERTICAL);
|
||||
m_CollectionImportDirSizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
m_ShowFileExtensionSizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
wxString defaultDir = wxStandardPaths::Get().GetDocumentsDir();
|
||||
|
||||
|
|
@ -48,6 +49,7 @@ Settings::Settings(wxWindow* window, std::string& configFilepath, std::string& d
|
|||
m_ImportDirLocation->Disable();
|
||||
m_BrowseAutoImportDirButton = new wxButton(m_CollectionSettingPanel, SD_BrowseAutoImportDir, "Browse", wxDefaultPosition, wxDefaultSize, 0);
|
||||
m_BrowseAutoImportDirButton->Disable();
|
||||
m_ShowFileExtensionCheck = new wxCheckBox(m_CollectionSettingPanel, SD_ShowFileExtension, "Show file extension", wxDefaultPosition, wxDefaultSize, 0);
|
||||
|
||||
m_ConfigurationSettingPanel = new wxPanel(m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||
|
||||
|
|
@ -74,6 +76,7 @@ Settings::Settings(wxWindow* window, std::string& configFilepath, std::string& d
|
|||
|
||||
// Bind events
|
||||
Bind(wxEVT_CHECKBOX, &Settings::OnCheckAutoImport, this, SD_AutoImport);
|
||||
Bind(wxEVT_CHECKBOX, &Settings::OnCheckShowFileExtension, this, SD_ShowFileExtension);
|
||||
Bind(wxEVT_SPINCTRL, &Settings::OnChangeFontSize, this, SD_FontSize);
|
||||
Bind(wxEVT_BUTTON, &Settings::OnSelectFont, this, SD_FontBrowseButton);
|
||||
Bind(wxEVT_BUTTON, &Settings::OnClickBrowseAutoImportDir, this, SD_BrowseAutoImportDir);
|
||||
|
|
@ -98,11 +101,14 @@ Settings::Settings(wxWindow* window, std::string& configFilepath, std::string& d
|
|||
|
||||
m_DisplayTopSizer->Add(m_DisplayFontSizer, 1, wxALL | wxEXPAND, 2);
|
||||
|
||||
m_CollectionImportDirSizer->Add(m_AutoImportCheck, 0, wxALL, 2);
|
||||
m_CollectionImportDirSizer->Add(m_ImportDirLocation, 0, wxALL | wxEXPAND, 2);
|
||||
m_CollectionImportDirSizer->Add(m_BrowseAutoImportDirButton, 0, wxALL, 2);
|
||||
m_CollectionImportDirSizer->Add(m_AutoImportCheck, 0, wxALL | wxALIGN_LEFT, 2);
|
||||
m_CollectionImportDirSizer->Add(m_ImportDirLocation, 1, wxALL, 2);
|
||||
m_CollectionImportDirSizer->Add(m_BrowseAutoImportDirButton, 0, wxALL | wxALIGN_RIGHT, 2);
|
||||
|
||||
m_CollectionTopSizer->Add(m_CollectionImportDirSizer, 1, wxALL | wxEXPAND, 2);
|
||||
m_ShowFileExtensionSizer->Add(m_ShowFileExtensionCheck, 0, wxALL | wxALIGN_LEFT, 2);
|
||||
|
||||
m_CollectionTopSizer->Add(m_CollectionImportDirSizer, 0, wxALL | wxEXPAND, 2);
|
||||
m_CollectionTopSizer->Add(m_ShowFileExtensionSizer, 0, wxALL | wxEXPAND, 2);
|
||||
|
||||
m_ButtonSizer->Add(m_OkButton, 0, wxALL | wxALIGN_BOTTOM, 2);
|
||||
m_ButtonSizer->Add(m_CancelButton, 0, wxALL | wxALIGN_BOTTOM, 2);
|
||||
|
|
@ -203,6 +209,22 @@ void Settings::OnCheckAutoImport(wxCommandEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void Settings::OnCheckShowFileExtension(wxCommandEvent& event)
|
||||
{
|
||||
Serializer serialize(m_ConfigFilepath);
|
||||
|
||||
if (!m_ShowFileExtensionCheck->GetValue())
|
||||
{
|
||||
bShowExtension = false;
|
||||
serialize.SerializeShowFileExtensionSetting(*m_ShowFileExtensionCheck);
|
||||
}
|
||||
else
|
||||
{
|
||||
bShowExtension = true;
|
||||
serialize.SerializeShowFileExtensionSetting(*m_ShowFileExtensionCheck);
|
||||
}
|
||||
}
|
||||
|
||||
void Settings::OnClickBrowseAutoImportDir(wxCommandEvent& event)
|
||||
{
|
||||
Serializer serializer(m_ConfigFilepath);
|
||||
|
|
@ -318,13 +340,15 @@ void Settings::LoadDefaultConfig()
|
|||
m_FontSize->SetValue(font_size);
|
||||
SetCustomFont();
|
||||
|
||||
bool import_check = serializer.DeserializeAutoImportSettings().auto_import;
|
||||
bAutoImport = serializer.DeserializeAutoImportSettings().auto_import;
|
||||
wxString location = serializer.DeserializeAutoImportSettings().import_dir;
|
||||
bShowExtension = serializer.DeserializeShowFileExtensionSetting();
|
||||
|
||||
m_AutoImportCheck->SetValue(import_check);
|
||||
m_AutoImportCheck->SetValue(bAutoImport);
|
||||
m_ImportDirLocation->SetValue(location);
|
||||
m_ShowFileExtensionCheck->SetValue(bShowExtension);
|
||||
|
||||
if (import_check)
|
||||
if (bAutoImport)
|
||||
{
|
||||
m_ImportDirLocation->Enable();
|
||||
m_BrowseAutoImportDirButton->Enable();
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ class Settings : public wxDialog
|
|||
{
|
||||
public:
|
||||
Settings(wxWindow* window, std::string& configFilepath, std::string& databaseFilepath);
|
||||
Settings();
|
||||
|
||||
~Settings();
|
||||
|
||||
private:
|
||||
|
|
@ -67,7 +69,9 @@ class Settings : public wxDialog
|
|||
// Collection page
|
||||
wxBoxSizer* m_CollectionTopSizer;
|
||||
wxBoxSizer* m_CollectionImportDirSizer;
|
||||
wxBoxSizer* m_ShowFileExtensionSizer;
|
||||
wxCheckBox* m_AutoImportCheck;
|
||||
wxCheckBox* m_ShowFileExtensionCheck;
|
||||
wxTextCtrl* m_ImportDirLocation;
|
||||
wxButton* m_BrowseAutoImportDirButton;
|
||||
wxDirDialog* m_DirDialog;
|
||||
|
|
@ -94,12 +98,14 @@ class Settings : public wxDialog
|
|||
private:
|
||||
// -------------------------------------------------------------------
|
||||
bool bAutoImport = false;
|
||||
bool bShowExtension = true;
|
||||
|
||||
private:
|
||||
// -------------------------------------------------------------------
|
||||
void OnClickConfigBrowse(wxCommandEvent& event);
|
||||
void OnClickDatabaseBrowse(wxCommandEvent& event);
|
||||
void OnCheckAutoImport(wxCommandEvent& event);
|
||||
void OnCheckShowFileExtension(wxCommandEvent& event);
|
||||
void OnClickBrowseAutoImportDir(wxCommandEvent& event);
|
||||
void OnChangeFontSize(wxSpinEvent& event);
|
||||
void OnSelectFont(wxCommandEvent& event);
|
||||
|
|
@ -118,4 +124,5 @@ class Settings : public wxDialog
|
|||
|
||||
inline wxFont GetFontType() { return m_Font; };
|
||||
inline bool IsAutoImport() { return bAutoImport; };
|
||||
inline bool IsShowFileExtension() { return bShowExtension; };
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue