Fix tag editor not changing tags and can now select multiple items at once.
This commit is contained in:
parent
5c11792df1
commit
e38fef36de
151
src/Browser.cpp
151
src/Browser.cpp
|
|
@ -29,6 +29,7 @@
|
|||
#include "Tags.hpp"
|
||||
// #include "TreeItemDialog.hpp"
|
||||
#include "Serialize.hpp"
|
||||
#include "wx/dataview.h"
|
||||
|
||||
#include <wx/fswatcher.h>
|
||||
|
||||
|
|
@ -153,7 +154,7 @@ Browser::Browser(wxWindow* window)
|
|||
|
||||
// Initializing wxDataViewListCtrl on bottom panel.
|
||||
m_SampleListView = new wxDataViewListCtrl(m_BottomRightPanel, BC_SampleListView, wxDefaultPosition, wxDefaultSize,
|
||||
wxDV_SINGLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES);
|
||||
wxDV_MULTIPLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES);
|
||||
|
||||
// Adding columns to wxDataViewListCtrl.
|
||||
m_SampleListView->AppendToggleColumn("", wxDATAVIEW_CELL_ACTIVATABLE, 30, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE);
|
||||
|
|
@ -708,6 +709,8 @@ void Browser::OnShowSampleListViewContextMenu(wxDataViewEvent& event)
|
|||
wxString sample = selection.Contains(wxString::Format(".%s", extension)) ?
|
||||
sample_with_extension : sample_without_extension;
|
||||
|
||||
std::string filename = sample.AfterLast('/').BeforeLast('.').ToStdString();
|
||||
|
||||
wxMenu menu;
|
||||
|
||||
if (m_SampleListView->GetToggleValue(selected_row, 0))
|
||||
|
|
@ -717,25 +720,56 @@ void Browser::OnShowSampleListViewContextMenu(wxDataViewEvent& event)
|
|||
|
||||
menu.Append(MN_DeleteSample, "Delete");
|
||||
menu.Append(MN_TrashSample, "Trash");
|
||||
menu.Append(MN_EditTagSample, "Edit tags");
|
||||
|
||||
if (m_SampleListView->GetSelectedItemsCount() <= 1)
|
||||
menu.Append(MN_EditTagSample, "Edit tags")->Enable(true);
|
||||
else
|
||||
menu.Append(MN_EditTagSample, "Edit tags")->Enable(false);
|
||||
|
||||
switch (m_SampleListView->GetPopupMenuSelectionFromUser(menu, event.GetPosition()))
|
||||
{
|
||||
case MN_FavoriteSample:
|
||||
if (m_SampleListView->GetToggleValue(selected_row, 0))
|
||||
if (m_SampleListView->GetSelectedItemsCount() <= 1)
|
||||
{
|
||||
m_SampleListView->SetToggleValue(false, selected_row, 0);
|
||||
msg = wxString::Format("Toggle: false");
|
||||
if (m_SampleListView->GetToggleValue(selected_row, 0))
|
||||
{
|
||||
m_SampleListView->SetToggleValue(false, selected_row, 0);
|
||||
msg = wxString::Format("Toggle: false");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_SampleListView->SetToggleValue(true, selected_row, 0);
|
||||
msg = wxString::Format("Toggle: true");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_SampleListView->SetToggleValue(true, selected_row, 0);
|
||||
msg = wxString::Format("Toggle: true");
|
||||
wxDataViewItemArray items;
|
||||
int rows = m_SampleListView->GetSelections(items);
|
||||
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
int row = m_SampleListView->ItemToRow(items[i]);
|
||||
|
||||
if (m_SampleListView->GetToggleValue(row, 0))
|
||||
{
|
||||
m_SampleListView->SetToggleValue(false, row, 0);
|
||||
msg = wxString::Format("Toggle: false");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_SampleListView->SetToggleValue(true, row, 0);
|
||||
msg = wxString::Format("Toggle: true");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MN_DeleteSample:
|
||||
{
|
||||
wxMessageDialog msgDialog(this, wxString::Format(
|
||||
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 "
|
||||
|
|
@ -745,42 +779,105 @@ void Browser::OnShowSampleListViewContextMenu(wxDataViewEvent& event)
|
|||
wxYES_NO | wxNO_DEFAULT |
|
||||
wxICON_QUESTION | wxSTAY_ON_TOP |
|
||||
wxCENTER);
|
||||
switch (msgDialog.ShowModal())
|
||||
|
||||
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)
|
||||
{
|
||||
case wxID_YES:
|
||||
msg = wxString::Format("Selected row: %d :: Sample: %s", selected_row, selection);
|
||||
db.RemoveSampleFromDatabase(selection.ToStdString());
|
||||
m_SampleListView->DeleteItem(selected_row);
|
||||
switch (singleMsgDialog.ShowModal())
|
||||
{
|
||||
case wxID_YES:
|
||||
{
|
||||
msg = wxString::Format("Selected row: %d :: Sample: %s", selected_row, selection);
|
||||
db.RemoveSampleFromDatabase(selection.ToStdString());
|
||||
m_SampleListView->DeleteItem(selected_row);
|
||||
}
|
||||
break;
|
||||
case wxID_NO:
|
||||
msg = "Cancel delete";
|
||||
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 sel = m_SampleListView->GetTextValue(row, 1);
|
||||
db.RemoveSampleFromDatabase(sel.ToStdString());
|
||||
m_SampleListView->DeleteItem(row);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
msg = "Unexpected wxMessageDialog return code!";
|
||||
case wxID_NO:
|
||||
msg = "Cancel delete";
|
||||
break;
|
||||
default:
|
||||
msg = "Unexpected wxMessageDialog return code!";
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case MN_TrashSample:
|
||||
{
|
||||
if (db.IsTrashed(selection.BeforeLast('.').ToStdString()))
|
||||
msg = "Already trashed..";
|
||||
else
|
||||
{
|
||||
msg = "Trashing..";
|
||||
if (m_SampleListView->GetToggleValue(selected_row, 0))
|
||||
if (m_SampleListView->GetSelectedItemsCount() <= 1)
|
||||
{
|
||||
m_SampleListView->SetToggleValue(false, selected_row, 0);
|
||||
db.UpdateFavoriteColumn(selection.BeforeLast('.').ToStdString(), 0);
|
||||
msg = "Trashing..";
|
||||
if (m_SampleListView->GetToggleValue(selected_row, 0))
|
||||
{
|
||||
m_SampleListView->SetToggleValue(false, selected_row, 0);
|
||||
db.UpdateFavoriteColumn(selection.BeforeLast('.').ToStdString(), 0);
|
||||
}
|
||||
db.UpdateTrashColumn(selection.BeforeLast('.').ToStdString(), 1);
|
||||
m_TrashedItems->AppendItem(trash_root_node, selection);
|
||||
m_SampleListView->DeleteItem(selected_row);
|
||||
}
|
||||
else
|
||||
{
|
||||
wxDataViewItemArray items;
|
||||
int rows = m_SampleListView->GetSelections(items);
|
||||
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
int row = m_SampleListView->ItemToRow(items[i]);
|
||||
wxString sel = m_SampleListView->GetTextValue(row, 1);
|
||||
|
||||
if (m_SampleListView->GetToggleValue(row, 0))
|
||||
{
|
||||
m_SampleListView->SetToggleValue(false, row, 0);
|
||||
db.UpdateFavoriteColumn(sel.BeforeLast('.').ToStdString(), 0);
|
||||
}
|
||||
|
||||
db.UpdateTrashColumn(sel.BeforeLast('.').ToStdString(), 1);
|
||||
m_TrashedItems->AppendItem(trash_root_node, sel);
|
||||
m_SampleListView->DeleteItem(row);
|
||||
}
|
||||
}
|
||||
db.UpdateTrashColumn(selection.BeforeLast('.').ToStdString(), 1);
|
||||
m_TrashedItems->AppendItem(trash_root_node, selection);
|
||||
m_SampleListView->DeleteItem(selected_row);
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case MN_EditTagSample:
|
||||
{
|
||||
tagEditor = new TagEditor(this, (std::string&)sample, *m_InfoBar);
|
||||
tagEditor = new TagEditor(this, filename, *m_InfoBar);
|
||||
|
||||
switch (tagEditor->ShowModal())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -229,6 +229,45 @@ void Database::UpdateFavoriteColumn(std::string filename, int value)
|
|||
}
|
||||
}
|
||||
|
||||
void Database::UpdateSamplePack(std::string filename, std::string samplePack)
|
||||
{
|
||||
try
|
||||
{
|
||||
rc = sqlite3_open("sample.hive", &m_Database);
|
||||
|
||||
std::string update = "UPDATE SAMPLES SET SAMPLEPACK = ? WHERE FILENAME = ?;";
|
||||
|
||||
rc = sqlite3_prepare_v2(m_Database, update.c_str(), update.size(), &m_Stmt, NULL);
|
||||
|
||||
rc = sqlite3_bind_text(m_Stmt, 1, samplePack.c_str(), samplePack.size(), SQLITE_STATIC);
|
||||
rc = sqlite3_bind_text(m_Stmt, 2, filename.c_str(), filename.size(), SQLITE_STATIC);
|
||||
|
||||
if (sqlite3_step(m_Stmt) == SQLITE_ROW)
|
||||
{
|
||||
wxLogDebug("Record found, updating..");
|
||||
}
|
||||
|
||||
rc = sqlite3_finalize(m_Stmt);
|
||||
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
wxMessageDialog msgDialog(NULL, "Error! Cannot update record.", "Error", wxOK | wxICON_ERROR);
|
||||
msgDialog.ShowModal();
|
||||
sqlite3_free(m_ErrMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogDebug("Updated record successfully.");
|
||||
}
|
||||
|
||||
sqlite3_close(m_Database);
|
||||
}
|
||||
catch (const std::exception &exception)
|
||||
{
|
||||
wxLogDebug(exception.what());
|
||||
}
|
||||
}
|
||||
|
||||
void Database::UpdateSampleType(std::string filename, std::string type)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class Database
|
|||
void UpdateFavoriteFolderDatabase(std::string filename,
|
||||
std::string folderName);
|
||||
void UpdateTrashColumn(std::string filename, int value);
|
||||
void UpdateSamplePack(std::string filename, std::string samplePack);
|
||||
void UpdateSampleType(std::string filename, std::string type);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -214,9 +214,8 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
|
|||
wxString genre = m_GenreText->GetValue();
|
||||
wxString comment = m_CommentText->GetValue();
|
||||
wxString type = m_SampleTypeChoice->GetStringSelection();
|
||||
wxString filename = wxString(m_Filename).AfterLast('/').BeforeLast('.');
|
||||
|
||||
std::string sampleType = db.GetSampleType(filename.ToStdString());
|
||||
std::string sampleType = db.GetSampleType(m_Filename);
|
||||
|
||||
wxString warning_msg = "Are you sure you want save these changes?";
|
||||
wxMessageDialog* msgDialog = new wxMessageDialog(this, warning_msg,
|
||||
|
|
@ -244,6 +243,10 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
|
|||
wxLogDebug("Changing artist tag..");
|
||||
tags.SetArtist(artist.ToStdString());
|
||||
|
||||
db.UpdateSamplePack(m_Filename, artist.ToStdString());
|
||||
|
||||
wxLogDebug("SAMPLE FILENAME HERE: %s", m_Filename);
|
||||
|
||||
info_msg = wxString::Format("Successfully changed artist tag to %s", artist);
|
||||
}
|
||||
|
||||
|
|
@ -274,7 +277,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
|
|||
if (m_SampleTypeCheck->GetValue() && m_SampleTypeChoice->GetStringSelection() != sampleType)
|
||||
{
|
||||
wxLogDebug("Changing type tag..");
|
||||
db.UpdateSampleType(filename.ToStdString(), type.ToStdString());
|
||||
db.UpdateSampleType(m_Filename, type.ToStdString());
|
||||
|
||||
info_msg = wxString::Format("Successfully changed type tag to %s", type);
|
||||
}
|
||||
|
|
@ -282,7 +285,7 @@ void TagEditor::OnClickApply(wxCommandEvent& event)
|
|||
case wxID_NO:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
info_msg = "Error, cannot change tag!";
|
||||
}
|
||||
|
||||
m_InfoBar.ShowMessage(info_msg, wxICON_INFORMATION);
|
||||
|
|
|
|||
Loading…
Reference in New Issue