Add collection folder feature.
This commit is contained in:
parent
4464da159d
commit
e96fcbff88
|
|
@ -32,7 +32,8 @@ void Database::CreateDatabase()
|
||||||
"SAMPLERATE INT NOT NULL,"
|
"SAMPLERATE INT NOT NULL,"
|
||||||
"BITRATE INT NOT NULL,"
|
"BITRATE INT NOT NULL,"
|
||||||
"PATH TEXT NOT NULL,"
|
"PATH TEXT NOT NULL,"
|
||||||
"TRASHED INT NOT NULL);";
|
"TRASHED INT NOT NULL,"
|
||||||
|
"FOLDER TEXT NOT NULL);";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -90,8 +91,8 @@ void Database::InsertSamples(std::vector<Sample> samples)
|
||||||
|
|
||||||
std::string insert = "INSERT INTO SAMPLES (FAVORITE, FILENAME, \
|
std::string insert = "INSERT INTO SAMPLES (FAVORITE, FILENAME, \
|
||||||
EXTENSION, SAMPLEPACK, TYPE, CHANNELS, LENGTH, \
|
EXTENSION, SAMPLEPACK, TYPE, CHANNELS, LENGTH, \
|
||||||
SAMPLERATE, BITRATE, PATH, TRASHED) \
|
SAMPLERATE, BITRATE, PATH, TRASHED, FOLDER) \
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(m_Database, insert.c_str(), insert.size(), &m_Stmt, NULL);
|
rc = sqlite3_prepare_v2(m_Database, insert.c_str(), insert.size(), &m_Stmt, NULL);
|
||||||
|
|
||||||
|
|
@ -118,6 +119,8 @@ void Database::InsertSamples(std::vector<Sample> samples)
|
||||||
type = sample.GetType();
|
type = sample.GetType();
|
||||||
path = sample.GetPath();
|
path = sample.GetPath();
|
||||||
|
|
||||||
|
std::string folder;
|
||||||
|
|
||||||
rc = sqlite3_bind_int(m_Stmt, 1, sample.GetFavorite());
|
rc = sqlite3_bind_int(m_Stmt, 1, sample.GetFavorite());
|
||||||
rc = sqlite3_bind_text(m_Stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC);
|
rc = sqlite3_bind_text(m_Stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC);
|
||||||
rc = sqlite3_bind_text(m_Stmt, 3, file_extension.c_str(), file_extension.size(), SQLITE_STATIC);
|
rc = sqlite3_bind_text(m_Stmt, 3, file_extension.c_str(), file_extension.size(), SQLITE_STATIC);
|
||||||
|
|
@ -127,8 +130,9 @@ void Database::InsertSamples(std::vector<Sample> samples)
|
||||||
rc = sqlite3_bind_int(m_Stmt, 7, sample.GetLength());
|
rc = sqlite3_bind_int(m_Stmt, 7, sample.GetLength());
|
||||||
rc = sqlite3_bind_int(m_Stmt, 8, sample.GetSampleRate());
|
rc = sqlite3_bind_int(m_Stmt, 8, sample.GetSampleRate());
|
||||||
rc = sqlite3_bind_int(m_Stmt, 9, sample.GetBitrate());
|
rc = sqlite3_bind_int(m_Stmt, 9, sample.GetBitrate());
|
||||||
rc = sqlite3_bind_text(m_Stmt, 10, path.c_str(),path.size(), SQLITE_STATIC);
|
rc = sqlite3_bind_text(m_Stmt, 10, path.c_str(), path.size(), SQLITE_STATIC);
|
||||||
rc = sqlite3_bind_int(m_Stmt, 11, sample.GetTrashed());
|
rc = sqlite3_bind_int(m_Stmt, 11, sample.GetTrashed());
|
||||||
|
rc = sqlite3_bind_text(m_Stmt, 12, folder.c_str(), folder.size(), SQLITE_STATIC);
|
||||||
|
|
||||||
rc = sqlite3_step(m_Stmt);
|
rc = sqlite3_step(m_Stmt);
|
||||||
rc = sqlite3_clear_bindings(m_Stmt);
|
rc = sqlite3_clear_bindings(m_Stmt);
|
||||||
|
|
@ -222,13 +226,13 @@ void Database::UpdateFolder(const std::string& folderName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Database::UpdateFavoriteFolderDatabase(const std::string& filename, const std::string& folderName)
|
void Database::UpdateFavoriteFolder(const std::string& filename, const std::string& folderName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
rc = sqlite3_open("sample.hive", &m_Database);
|
rc = sqlite3_open("sample.hive", &m_Database);
|
||||||
|
|
||||||
std::string update = "UPDATE SAMPLES SET FAVORITEFOLDER = ? WHERE FILENAME = ?;";
|
std::string update = "UPDATE SAMPLES SET FOLDER = ? WHERE FILENAME = ?;";
|
||||||
|
|
||||||
rc = sqlite3_prepare_v2(m_Database, update.c_str(), update.size(), &m_Stmt, NULL);
|
rc = sqlite3_prepare_v2(m_Database, update.c_str(), update.size(), &m_Stmt, NULL);
|
||||||
|
|
||||||
|
|
@ -467,6 +471,51 @@ int Database::GetFavoriteColumnValueByFilename(const std::string& filename)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Database::GetFavoriteFolderByFilename(const std::string& filename)
|
||||||
|
{
|
||||||
|
std::string folder;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rc = sqlite3_open("sample.hive", &m_Database);
|
||||||
|
|
||||||
|
std::string select = "SELECT FOLDER 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..");
|
||||||
|
|
||||||
|
folder = std::string(reinterpret_cast<const char*>(sqlite3_column_text(m_Stmt, 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = sqlite3_finalize(m_Stmt);
|
||||||
|
|
||||||
|
if (rc != SQLITE_OK)
|
||||||
|
{
|
||||||
|
wxMessageDialog msgDialog(NULL, "Error! Cannot get favorite folder value 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 folder;
|
||||||
|
}
|
||||||
|
|
||||||
void Database::RemoveSampleFromDatabase(const std::string& filename)
|
void Database::RemoveSampleFromDatabase(const std::string& filename)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -596,7 +645,8 @@ std::string Database::GetSampleFileExtension(const std::string& filename)
|
||||||
|
|
||||||
wxVector<wxVector<wxVariant>>
|
wxVector<wxVector<wxVariant>>
|
||||||
Database::LoadDatabase(wxVector<wxVector<wxVariant>>& vecSet,
|
Database::LoadDatabase(wxVector<wxVector<wxVariant>>& vecSet,
|
||||||
wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item,
|
// wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item,
|
||||||
|
wxDataViewTreeCtrl& favorite_tree, wxDataViewItem& favorite_item,
|
||||||
wxTreeCtrl& trash_tree, wxTreeItemId& trash_item,
|
wxTreeCtrl& trash_tree, wxTreeItemId& trash_item,
|
||||||
bool show_extension)
|
bool show_extension)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <wx/dataview.h>
|
||||||
#include <wx/infobar.h>
|
#include <wx/infobar.h>
|
||||||
#include <wx/treebase.h>
|
#include <wx/treebase.h>
|
||||||
#include <wx/treectrl.h>
|
#include <wx/treectrl.h>
|
||||||
|
|
@ -41,7 +42,7 @@ class Database
|
||||||
// Update database
|
// Update database
|
||||||
void UpdateFavoriteColumn(const std::string& filename, int value);
|
void UpdateFavoriteColumn(const std::string& filename, int value);
|
||||||
void UpdateFolder(const std::string& folderName);
|
void UpdateFolder(const std::string& folderName);
|
||||||
void UpdateFavoriteFolderDatabase(const std::string& filename,
|
void UpdateFavoriteFolder(const std::string& filename,
|
||||||
const std::string& folderName);
|
const std::string& folderName);
|
||||||
void UpdateTrashColumn(const std::string& filename, int value);
|
void UpdateTrashColumn(const std::string& filename, int value);
|
||||||
void UpdateSamplePack(const std::string& filename, const std::string& samplePack);
|
void UpdateSamplePack(const std::string& filename, const std::string& samplePack);
|
||||||
|
|
@ -49,10 +50,11 @@ class Database
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Get from database
|
// Get from database
|
||||||
std::string GetSampleType(const std::string& filename);
|
|
||||||
int GetFavoriteColumnValueByFilename(const std::string& filename);
|
int GetFavoriteColumnValueByFilename(const std::string& filename);
|
||||||
|
std::string GetFavoriteFolderByFilename(const std::string& filename);
|
||||||
std::string GetSamplePathByFilename(const std::string& filename);
|
std::string GetSamplePathByFilename(const std::string& filename);
|
||||||
std::string GetSampleFileExtension(const std::string& filename);
|
std::string GetSampleFileExtension(const std::string& filename);
|
||||||
|
std::string GetSampleType(const std::string& filename);
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Check database
|
// Check database
|
||||||
|
|
@ -65,8 +67,11 @@ class Database
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
wxVector<wxVector<wxVariant>>
|
wxVector<wxVector<wxVariant>>
|
||||||
|
// LoadDatabase(wxVector<wxVector<wxVariant>> &vecSet,
|
||||||
|
// wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item,
|
||||||
|
// wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, bool show_extension);
|
||||||
LoadDatabase(wxVector<wxVector<wxVariant>> &vecSet,
|
LoadDatabase(wxVector<wxVector<wxVariant>> &vecSet,
|
||||||
wxTreeCtrl& favorite_tree, wxTreeItemId& favorite_item,
|
wxDataViewTreeCtrl& favorite_tree, wxDataViewItem& favorite_item,
|
||||||
wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, bool show_extension);
|
wxTreeCtrl& trash_tree, wxTreeItemId& trash_item, bool show_extension);
|
||||||
wxVector<wxVector<wxVariant>>
|
wxVector<wxVector<wxVariant>>
|
||||||
FilterDatabaseBySampleName(wxVector<wxVector<wxVariant>> &sampleVec,
|
FilterDatabaseBySampleName(wxVector<wxVector<wxVariant>> &sampleVec,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
@ -17,6 +18,7 @@
|
||||||
#include <wx/msgdlg.h>
|
#include <wx/msgdlg.h>
|
||||||
#include <wx/progdlg.h>
|
#include <wx/progdlg.h>
|
||||||
#include <wx/stdpaths.h>
|
#include <wx/stdpaths.h>
|
||||||
|
#include <wx/textdlg.h>
|
||||||
#include <wx/variant.h>
|
#include <wx/variant.h>
|
||||||
#include <wx/vector.h>
|
#include <wx/vector.h>
|
||||||
#include <wx/utils.h>
|
#include <wx/utils.h>
|
||||||
|
|
@ -98,7 +100,7 @@ MainFrame::MainFrame()
|
||||||
// m_TrashButton = new wxButton(m_CollectionViewPanel, BC_TrashButton, "Trash", wxDefaultPosition, wxDefaultSize, 0);
|
// m_TrashButton = new wxButton(m_CollectionViewPanel, BC_TrashButton, "Trash", wxDefaultPosition, wxDefaultSize, 0);
|
||||||
|
|
||||||
// Initializing wxTreeCtrl as another page of wxNotebook
|
// Initializing wxTreeCtrl as another page of wxNotebook
|
||||||
m_CollectionView = new wxTreeCtrl(m_CollectionViewPanel, BC_CollectionView, wxDefaultPosition, wxDefaultSize,
|
m_CollectionView = new wxDataViewTreeCtrl(m_CollectionViewPanel, BC_CollectionView, wxDefaultPosition, wxDefaultSize,
|
||||||
wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT);
|
wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT);
|
||||||
|
|
||||||
m_TrashPane = new wxCollapsiblePane(m_CollectionViewPanel, BC_TrashPane, "Trash",
|
m_TrashPane = new wxCollapsiblePane(m_CollectionViewPanel, BC_TrashPane, "Trash",
|
||||||
|
|
@ -112,7 +114,9 @@ MainFrame::MainFrame()
|
||||||
m_RestoreTrashedItemButton = new wxButton(m_TrashPaneWindow, BC_RestoreTrashedItemButton, "Restore item");
|
m_RestoreTrashedItemButton = new wxButton(m_TrashPaneWindow, BC_RestoreTrashedItemButton, "Restore item");
|
||||||
|
|
||||||
// Adding root to CollectionView
|
// Adding root to CollectionView
|
||||||
rootNode = m_CollectionView->AddRoot("ROOT");
|
// rootNode = m_CollectionView->AddRoot("ROOT");
|
||||||
|
root_node = m_CollectionView->AppendContainer(wxDataViewItem(wxNullPtr), "Default");
|
||||||
|
m_CollectionView->AppendItem(root_node, "sample.xyz");
|
||||||
|
|
||||||
// Addubg root to TrashedItems
|
// Addubg root to TrashedItems
|
||||||
trash_root_node = m_TrashedItems->AddRoot("ROOT");
|
trash_root_node = m_TrashedItems->AddRoot("ROOT");
|
||||||
|
|
@ -1019,7 +1023,7 @@ void MainFrame::LoadDatabase()
|
||||||
{
|
{
|
||||||
wxVector<wxVector<wxVariant>> dataset;
|
wxVector<wxVector<wxVariant>> dataset;
|
||||||
|
|
||||||
if (db.LoadDatabase(dataset, *m_CollectionView, rootNode,
|
if (db.LoadDatabase(dataset, *m_CollectionView, root_node,
|
||||||
*m_TrashedItems, trash_root_node,
|
*m_TrashedItems, trash_root_node,
|
||||||
settings.IsShowFileExtension()).empty())
|
settings.IsShowFileExtension()).empty())
|
||||||
{
|
{
|
||||||
|
|
@ -1046,20 +1050,27 @@ void MainFrame::OnCheckFavorite(wxDataViewEvent& event)
|
||||||
|
|
||||||
int selected_row = m_SampleListView->ItemToRow(event.GetItem());
|
int selected_row = m_SampleListView->ItemToRow(event.GetItem());
|
||||||
|
|
||||||
|
int row = 0, container_row = 0;
|
||||||
|
|
||||||
if (selected_row < 0) return;
|
if (selected_row < 0) return;
|
||||||
|
|
||||||
wxString selection = m_SampleListView->GetTextValue(selected_row, 1).BeforeLast('.');
|
// wxString selection = m_SampleListView->GetTextValue(selected_row, 1).BeforeLast('.');
|
||||||
|
wxString selection = m_SampleListView->GetTextValue(selected_row, 1);
|
||||||
|
|
||||||
std::deque<wxTreeItemId> nodes;
|
// std::deque<wxTreeItemId> nodes;
|
||||||
nodes.push_back(m_CollectionView->GetRootItem());
|
std::deque<wxDataViewItem> nodes;
|
||||||
|
// nodes.push_back(m_CollectionView->GetRootItem());
|
||||||
|
nodes.push_back(m_CollectionView->GetNthChild(wxDataViewItem(wxNullPtr), container_row));
|
||||||
|
|
||||||
wxTreeItemId found_item;
|
// wxTreeItemId found_item;
|
||||||
|
wxDataViewItem found_item;
|
||||||
|
|
||||||
if (m_SampleListView->GetToggleValue(selected_row, 0))
|
if (m_SampleListView->GetToggleValue(selected_row, 0))
|
||||||
{
|
{
|
||||||
while(!nodes.empty())
|
while(!nodes.empty())
|
||||||
{
|
{
|
||||||
wxTreeItemId current_item = nodes.front();
|
// wxTreeItemId current_item = nodes.front();
|
||||||
|
wxDataViewItem current_item = nodes.front();
|
||||||
nodes.pop_front();
|
nodes.pop_front();
|
||||||
|
|
||||||
if (m_CollectionView->GetItemText(current_item) == selection)
|
if (m_CollectionView->GetItemText(current_item) == selection)
|
||||||
|
|
@ -1069,13 +1080,37 @@ void MainFrame::OnCheckFavorite(wxDataViewEvent& event)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxTreeItemIdValue cookie;
|
// wxTreeItemIdValue cookie;
|
||||||
wxTreeItemId child = m_CollectionView->GetFirstChild(current_item, cookie);
|
// wxTreeItemId child = m_CollectionView->GetFirstChild(current_item, cookie);
|
||||||
|
|
||||||
while ( child.IsOk() )
|
wxLogDebug("Current item: %s", m_CollectionView->GetItemText(current_item));
|
||||||
|
|
||||||
|
while(current_item.IsOk())
|
||||||
{
|
{
|
||||||
|
wxDataViewItem child;
|
||||||
|
|
||||||
|
int child_count = m_CollectionView->GetChildCount(current_item);
|
||||||
|
int container_count = m_CollectionView->GetChildCount(wxDataViewItem(wxNullPtr));
|
||||||
|
|
||||||
|
if(row >= child_count)
|
||||||
|
{
|
||||||
|
container_row++;
|
||||||
|
row = 0;
|
||||||
|
|
||||||
|
if(container_row >= container_count)
|
||||||
|
break;
|
||||||
|
|
||||||
|
current_item = m_CollectionView->GetNthChild(wxDataViewItem(wxNullPtr), container_row);
|
||||||
|
wxLogDebug("Inside.. Current item: %s", m_CollectionView->GetItemText(current_item));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
child = m_CollectionView->GetNthChild(current_item, row);
|
||||||
|
wxLogDebug("Child item: %s", m_CollectionView->GetItemText(child));
|
||||||
|
|
||||||
nodes.push_back(child);
|
nodes.push_back(child);
|
||||||
child = m_CollectionView->GetNextChild(current_item, cookie);
|
// child = m_CollectionView->GetNextChild(current_item, cookie);
|
||||||
|
row++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1091,22 +1126,27 @@ void MainFrame::OnCheckFavorite(wxDataViewEvent& event)
|
||||||
{
|
{
|
||||||
wxLogDebug("Sample not found adding as fav.");
|
wxLogDebug("Sample not found adding as fav.");
|
||||||
|
|
||||||
wxTreeItemId selected = m_CollectionView->GetSelection();
|
// wxTreeItemId selected = m_CollectionView->GetSelection();
|
||||||
|
wxDataViewItem selected = m_CollectionView->GetSelection();
|
||||||
wxString folder = m_CollectionView->GetItemText(selected);
|
wxString folder = m_CollectionView->GetItemText(selected);
|
||||||
|
|
||||||
m_CollectionView->AppendItem(rootNode, selection);
|
if(selected.IsOk() && m_CollectionView->IsContainer(selected))
|
||||||
|
m_CollectionView->AppendItem(selected, selection);
|
||||||
|
else
|
||||||
|
m_CollectionView->AppendItem(wxDataViewItem(wxNullPtr), selection);
|
||||||
|
|
||||||
db.UpdateFavoriteColumn(selection.ToStdString(), 1);
|
db.UpdateFavoriteColumn(selection.ToStdString(), 1);
|
||||||
// db.UpdateFavoriteFolderDatabase(Selection.ToStdString(), folder.ToStdString());
|
db.UpdateFavoriteFolder(selection.ToStdString(), folder.ToStdString());
|
||||||
|
|
||||||
serialize.SerializeDataViewTreeCtrlItems(*m_CollectionView, rootNode);
|
// serialize.SerializeDataViewTreeCtrlItems(*m_CollectionView, rootNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
while(!nodes.empty())
|
while(!nodes.empty())
|
||||||
{
|
{
|
||||||
wxTreeItemId current_item = nodes.front();
|
// wxTreeItemId current_item = nodes.front();
|
||||||
|
wxDataViewItem current_item = nodes.front();
|
||||||
nodes.pop_front();
|
nodes.pop_front();
|
||||||
|
|
||||||
if (m_CollectionView->GetItemText(current_item) == selection)
|
if (m_CollectionView->GetItemText(current_item) == selection)
|
||||||
|
|
@ -1116,13 +1156,38 @@ void MainFrame::OnCheckFavorite(wxDataViewEvent& event)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxTreeItemIdValue cookie;
|
// wxTreeItemIdValue cookie;
|
||||||
wxTreeItemId child = m_CollectionView->GetFirstChild(current_item, cookie);
|
// wxTreeItemId child = m_CollectionView->GetFirstChild(current_item, cookie);
|
||||||
|
|
||||||
while (child.IsOk())
|
wxLogDebug("Current item: %s", m_CollectionView->GetItemText(current_item));
|
||||||
|
|
||||||
|
while(current_item.IsOk())
|
||||||
{
|
{
|
||||||
|
wxDataViewItem child;
|
||||||
|
|
||||||
|
int child_count = m_CollectionView->GetChildCount(current_item);
|
||||||
|
int container_count = m_CollectionView->GetChildCount(wxDataViewItem(wxNullPtr));
|
||||||
|
|
||||||
|
if(row >= child_count)
|
||||||
|
{
|
||||||
|
container_row++;
|
||||||
|
row = 0;
|
||||||
|
|
||||||
|
if(container_row >= container_count)
|
||||||
|
break;
|
||||||
|
|
||||||
|
current_item = m_CollectionView->GetNthChild(wxDataViewItem(wxNullPtr), container_row);
|
||||||
|
wxLogDebug("Inside.. Current item: %s", m_CollectionView->GetItemText(current_item));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
child = m_CollectionView->GetNthChild(current_item, row);
|
||||||
|
wxLogDebug("Child item: %s", m_CollectionView->GetItemText(child));
|
||||||
|
// child = m_CollectionView->GetNextChild(current_item, cookie);
|
||||||
|
|
||||||
nodes.push_back(child);
|
nodes.push_back(child);
|
||||||
child = m_CollectionView->GetNextChild(current_item, cookie);
|
|
||||||
|
row++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1130,8 +1195,9 @@ void MainFrame::OnCheckFavorite(wxDataViewEvent& event)
|
||||||
|
|
||||||
if (found_item.IsOk())
|
if (found_item.IsOk())
|
||||||
{
|
{
|
||||||
m_CollectionView->Delete(found_item);
|
// m_CollectionView->DeleteItem(found_item);
|
||||||
db.UpdateFavoriteColumn(selection.ToStdString(), 0);
|
// db.UpdateFavoriteColumn(selection.ToStdString(), 0);
|
||||||
|
wxMessageBox("// TODO", "Delete sample", wxOK | wxCENTER, this, wxDefaultCoord, wxDefaultCoord);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1157,12 +1223,144 @@ void MainFrame::OnExpandTrash(wxCollapsiblePaneEvent& event)
|
||||||
|
|
||||||
void MainFrame::OnClickCollectionAdd(wxCommandEvent& event)
|
void MainFrame::OnClickCollectionAdd(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
wxMessageBox("// TODO", "Add item", wxOK | wxCENTER, this, wxDefaultCoord, wxDefaultCoord);
|
// wxMessageBox("// TODO", "Add item", wxOK | wxCENTER, this, wxDefaultCoord, wxDefaultCoord);
|
||||||
|
|
||||||
|
std::deque<wxDataViewItem> nodes;
|
||||||
|
nodes.push_back(m_CollectionView->GetNthChild(wxDataViewItem(wxNullPtr), 0));
|
||||||
|
|
||||||
|
wxDataViewItem current_item, found_item;
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
int folder_count = m_CollectionView->GetChildCount(wxDataViewItem(wxNullPtr));
|
||||||
|
|
||||||
|
wxString msg;
|
||||||
|
|
||||||
|
wxTextEntryDialog* favFolder;
|
||||||
|
favFolder = new wxTextEntryDialog(this, "Enter folder name",
|
||||||
|
"Add folder", wxEmptyString,
|
||||||
|
wxTextEntryDialogStyle, wxDefaultPosition);
|
||||||
|
|
||||||
|
switch (favFolder->ShowModal())
|
||||||
|
{
|
||||||
|
case wxID_OK:
|
||||||
|
{
|
||||||
|
wxString folder_name = favFolder->GetValue();
|
||||||
|
|
||||||
|
while(!nodes.empty())
|
||||||
|
{
|
||||||
|
current_item = nodes.front();
|
||||||
|
nodes.pop_front();
|
||||||
|
|
||||||
|
if (m_CollectionView->GetItemText(current_item) == folder_name)
|
||||||
|
{
|
||||||
|
found_item = current_item;
|
||||||
|
msg = wxString::Format("Found item: %s", m_CollectionView->GetItemText(current_item));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataViewItem child = m_CollectionView->GetNthChild(wxDataViewItem(wxNullPtr), 0);
|
||||||
|
msg = wxString::Format("Row: %d :: Folder count: %d :: Child: %s",
|
||||||
|
row, folder_count, m_CollectionView->GetItemText(child));
|
||||||
|
|
||||||
|
while (row < (folder_count - 1))
|
||||||
|
{
|
||||||
|
row ++;
|
||||||
|
|
||||||
|
child = m_CollectionView->GetNthChild(wxDataViewItem(wxNullPtr), row);
|
||||||
|
nodes.push_back(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes.clear();
|
||||||
|
|
||||||
|
if (found_item.IsOk())
|
||||||
|
{
|
||||||
|
msg = wxString::Format("Another folder by the name %s already exist. Please try with a different name.",
|
||||||
|
folder_name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg = wxString::Format("Folder %s added to colletions.", folder_name);
|
||||||
|
m_CollectionView->AppendContainer(wxDataViewItem(wxNullPtr), folder_name);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case wxID_CANCEL:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_InfoBar->ShowMessage(msg, wxICON_INFORMATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainFrame::OnClickCollectionRemove(wxCommandEvent& event)
|
void MainFrame::OnClickCollectionRemove(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
wxMessageBox("// TODO", "Remove item", wxOK | wxCENTER, this, wxDefaultCoord, wxDefaultCoord);
|
// wxMessageBox("// TODO", "Remove item", wxOK | wxCENTER, this, wxDefaultCoord, wxDefaultCoord);
|
||||||
|
|
||||||
|
wxDataViewItem selected = m_CollectionView->GetSelection();
|
||||||
|
wxString folder_name = m_CollectionView->GetItemText(selected);
|
||||||
|
|
||||||
|
wxString msg;
|
||||||
|
|
||||||
|
wxMessageDialog deleteEmptyFolderDialog(this, wxString::Format(
|
||||||
|
"Are you sure you want to delete "
|
||||||
|
"%s from collections?",
|
||||||
|
folder_name),
|
||||||
|
wxMessageBoxCaptionStr,
|
||||||
|
wxYES_NO | wxNO_DEFAULT |
|
||||||
|
wxICON_QUESTION | wxSTAY_ON_TOP);
|
||||||
|
|
||||||
|
wxMessageDialog deleteFilledFolderDialog(this, wxString::Format(
|
||||||
|
"Are you sure you want to delete "
|
||||||
|
"%s and all sample inside %s from collections?",
|
||||||
|
folder_name, folder_name),
|
||||||
|
wxMessageBoxCaptionStr,
|
||||||
|
wxYES_NO | wxNO_DEFAULT |
|
||||||
|
wxICON_QUESTION | wxSTAY_ON_TOP);
|
||||||
|
|
||||||
|
if(m_CollectionView->GetChildCount(selected) <= 0)
|
||||||
|
{
|
||||||
|
switch (deleteEmptyFolderDialog.ShowModal())
|
||||||
|
{
|
||||||
|
case wxID_YES:
|
||||||
|
if (selected.IsOk())
|
||||||
|
{
|
||||||
|
m_CollectionView->DeleteItem(selected);
|
||||||
|
msg = wxString::Format("%s deleted from collections successfully.", folder_name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
msg = wxString::Format("Error! Cannot delete %s from collections.", folder_name);
|
||||||
|
break;
|
||||||
|
case wxID_NO:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (deleteFilledFolderDialog.ShowModal())
|
||||||
|
{
|
||||||
|
case wxID_YES:
|
||||||
|
if (selected.IsOk())
|
||||||
|
{
|
||||||
|
m_CollectionView->DeleteChildren(selected);
|
||||||
|
m_CollectionView->DeleteItem(selected);
|
||||||
|
msg = wxString::Format("%s and all samples inside %s have been deleted from collections successfully.",
|
||||||
|
folder_name, folder_name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
msg = wxString::Format("Error! Cannot delete %s from collections.", folder_name);
|
||||||
|
break;
|
||||||
|
case wxID_NO:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_InfoBar->ShowMessage(msg, wxICON_INFORMATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event)
|
void MainFrame::OnClickRestoreTrashItem(wxCommandEvent& event)
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,8 @@ class MainFrame : public wxFrame
|
||||||
wxBoxSizer* m_TrashItemSizer;
|
wxBoxSizer* m_TrashItemSizer;
|
||||||
wxSizerItem *m_CollectionViewTrashSizerItem;
|
wxSizerItem *m_CollectionViewTrashSizerItem;
|
||||||
wxDirCtrl* m_DirCtrl;
|
wxDirCtrl* m_DirCtrl;
|
||||||
wxTreeCtrl* m_CollectionView;
|
wxDataViewTreeCtrl* m_CollectionView;
|
||||||
wxTreeItemId rootNode;
|
wxDataViewItem root_node;
|
||||||
wxTreeItemId trash_root_node;
|
wxTreeItemId trash_root_node;
|
||||||
wxCollapsiblePane* m_TrashPane;
|
wxCollapsiblePane* m_TrashPane;
|
||||||
wxTreeCtrl* m_TrashedItems;
|
wxTreeCtrl* m_TrashedItems;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue