From 08aa1df2cab3ead8d6ca064de8af63a2319cd187 Mon Sep 17 00:00:00 2001 From: apoorv569 Date: Wed, 9 Jun 2021 07:03:20 +0530 Subject: [PATCH] Changed the toggle column to app icon. --- assets/icons/icon-hive_16x16-gs.png | Bin 0 -> 5799 bytes src/Database.cpp | 14 +- src/MainFrame.cpp | 474 ++++++++++++++++++++++++++-- 3 files changed, 455 insertions(+), 33 deletions(-) create mode 100644 assets/icons/icon-hive_16x16-gs.png diff --git a/assets/icons/icon-hive_16x16-gs.png b/assets/icons/icon-hive_16x16-gs.png new file mode 100644 index 0000000000000000000000000000000000000000..0873946700f75c41cce354e715438933690a6683 GIT binary patch literal 5799 zcmeHKXH-*J*A9--1`q`S0VM=W0MmOUbfgIhfk9AILUIEUNJ0t;Fd~DX4uT^B7C@{N z8%0E=i&96Vhz#n8g(4z?1pzzn4fgfDe_ZQ(|Cy|NbMM~Ie$L*{+4r2>KN+6Rn(Bt? z5C}xm)y0ts{%R`@Rb}vOGCs|MKxU6c`}j$iEE!ZN5^#B808|ns1fYPN$Av)Tx6iBz zKid!2c-L+|sp=9J*B@woa#A_wU3l29%OlSc#v}WZ9;j)1Tv+mA_4LqF)`!d6TbA}a ztls0a!rJ<6>zsp}zv#E_ao&Hho-V!}RhmV(gr=MudxdMEY#im>v+}Y-Rgv8$jBnmm zIcxJiKkJy-j5H5J9hIchop=4EL|v5L@8>H@DssO0rjtl>rPgq3Hr?C2jw-919yPle zs9`7nRLcplbDor4u0KXcKGm~MjoVGPx~1>)u<-B4o%(M*beC`Mz4Xj8 z@ATxcgO`I}T=RT>wXLx5;Jqj5VO1v1wd`}8#z#%VN%{`fDjIl`|etDnK z6AA55^74g_g2aJqzLgJ7q^r#ns6=h@31Qs(*KL6|O|~oKfMr7F`2kpPVVfa*V8~&s z*||+fyH@q6MW?HZJ8A@XFPtKCOH}^)59y=}X_bv2~!(?O$ zTH~R3{I1KM#nw~pH@fZWio3Ffmx3-_Y0!I=d}g6DU;j2M$TnucupyEPak{w@qCtTN zCI&!FjSiU2ldtZ`zvN|q{h6{Fd^X><KQu$p(6rC9yVOldV8>3=QlcKNM;{Rs*N*TZgwEW$Im=v@pz)LC@Z|!06vD2_l+j zz=MKOnWFZF?qT<`nkr4_eX&;!0B5|?#qE6h5|jIpUaRU)XS`TpkW^6N^d7czB>w!V zKrQpvZt78RIQ`<|BIn+_Rp{rg-P79L>yQ3@j9WW!xvRxp*$TgCTT!mhnERTeuOiyx zezPlZ>uMf*o|JkDJ$Sg$^10CLP>z&=XiVzK1u|UA_u2P6J>5&^ZwPFX05$^Bn%&N% zbBFkaQTR&4z^KJys-=zX<{K~JANVb+CQgRdN+Yt`^&`zDuKS1$H|Az964M`56g)EB zQoh-`?BT%v2AFm%4LlG_Y{C?)V592l++4xd*(aJ|dkoJw=KVr$&6(YwsaLMu``qM5O%KE7bb zG2bJq3+&HyoZQ-yYhs_aZAn9emk>dIRpKWVM*P!V_nY=?8{0c~vUS%Vub*C;sE1i> zJk{S@-PF6%wqV}@t~6OGlbp{az)CTj{&@ z_mt=xRSj`*E>>4Gx|VHNo^$)0X4~6(FW)`C^@;nu(vU9inxzf>q&BC0b8;3EaKn^7 zc!^&aJ2%C@<;ITXf3i>JdDrZo@EfdZ@V8v!Kc4e0F}13us$QD8)g?%2=WeLI-2x-{ zl~vik2X%kt-KM{Kr4mrpUR zZ}N;gWWP#^qN@p05pN)zf>Sp%g+f&gee;-WL%k0s?|z_lJ$b64ktvG30Kd5!+@TD4 z;7;V{v6{*jgdg380g_+qM@2Akofg4YT&3I?5lNJ42a zKMw}fK_CL4cqAT)MmWiNkyx0uI@C(U;Zm87t3FYHcQjatL?Wc3P%@beDZ?QJqF@w; zLZP70SQHkE01*gr6ko!UBlu!71;s}WM?lOL@q`kdfDcu0vVsIs2@M7V{m{?(g$q4A zzR>fcQjSx$mB0-W*3H{dyu@AVRqnLnLAQiCzr$~S=G5eN+ z!~PO4l#0S;%Hgn4Ko}4XLdD>ynD2&kcJ*LZXtcu*Y$Y^fqWS4SF5F+P7C+-rObZn(1{9X1 z=u?nj#tzm(br1n8i9qBd5QNcSij<&=$eH$rT78@p7oHeIL@7G{Q_p(?5g+e9J_2F9 z85a~f)3#I=`{N*DRwVFI12FERiygw^2Ls^q{i&fo+j;+GvM6{mg@mP$5qP3PVSEq^ z!6KtE2n>-(!2mdbgvGIE%J{-A7H}mpmI$y51}g=t0UKzh8Yp~5O7rj0vJgO_6B>&_ zpos`H*#}LeVklHJ*%D2l;?OYEr-D(6r}}fnR;d4@iPa3?n`Hou`)C7~7jU&geOazP zX{M0zfB5+{7yrW%KZ3JOCg3 z7bF8;XI^c134pIc%0ceVj*w}^_i%N78fZ}yy7-GB5UneUL#atnzyXaa5?2o=l|f}y z2u4*ECE5Ui%t~-|wDTcf&Gl|~H)3gTzE{+HJO#63_@TNG~&X9Bo^iHkJW>m9z7Kk&0)VO%k-_IV!ojNew|Kd-+@LLl`UcbnxU8&ubRt^7D-Wo#ArL0edOJ1K)0rR-4u^X%Iy!o93&|oEnp@x2);5)qkzw&y zQ@_d3&`?Ss{oa&{<8!(3``ANxLrojQl=&WAhk1rtT3WIGdne{Y$RA9RNaTI87I{e9 z-qy`EL3=i2KQB|-6p_O%y|rVcLiK*sVoy4~b7UfWc$kOCaI3?6aIgypMCH#qJ3Bem z8>U;e=FZ)c*EQ^19x%3e$T(-HZrti(;m(v4&6vo@$-Q~Jz+^jBB~wS?4ZkJxU)MpP zsV={Vm#uBD=q>CCBaWt}>BPunJ+8~rR;0D4x(zRwWjedDvC;nR+qY@PkWFQ4^L;F6 zWNYi17cM$FItxted+)2jbANF$Ka##F%_#Y04Fg_<)!2$@yhPbvIMN|qG%_+WT3ub; z^pZNud@$?UwQI|UjFk-7 #include +#include +#include #include #include #include +#include +#include #include "Database.hpp" #include "SettingsDialog.hpp" @@ -871,9 +875,14 @@ Database::LoadDatabase(wxVector>& vecSet, trash_tree.AppendItem(trash_item, filename); else { + wxVariant icon_c, icon_gs; + icon_c << wxDataViewIconText(wxEmptyString, wxIcon("../assets/icons/icon-hive_16x16.png")); + icon_gs << wxDataViewIconText(wxEmptyString, wxIcon("../assets/icons/icon-hive_16x16-gs.png")); + if (favorite == 1) { - vec.push_back(true); + // vec.push_back(true); + vec.push_back(icon_c); wxLogDebug("Loading collection items.."); @@ -923,7 +932,8 @@ Database::LoadDatabase(wxVector>& vecSet, } else - vec.push_back(false); + // vec.push_back(false); + vec.push_back(icon_gs); if (show_extension) { diff --git a/src/MainFrame.cpp b/src/MainFrame.cpp index b9cd75b..6cae975 100644 --- a/src/MainFrame.cpp +++ b/src/MainFrame.cpp @@ -6,18 +6,24 @@ #include #include #include +#include #include #include #include #include +#include #include #include +#include #include +#include #include #include #include +// #include "wx/gtk/colour.h" #include #include +#include #include #include #include @@ -35,6 +41,10 @@ #include +#define ICON_APP "../assets/icons/icon-hive_24x24.png" +#define ICON_COLOURED "../assets/icons/icon-hive_16x16.png" +#define ICON_GREYSCALE "../assets/icons/icon-hive_16x16-gs.png" + MainFrame::MainFrame() : wxFrame(NULL, wxID_ANY, "Sample Hive", wxDefaultPosition), m_ConfigFilepath("config.yaml"), m_DatabaseFilepath("sample.hive") @@ -167,7 +177,8 @@ MainFrame::MainFrame() wxDV_MULTIPLE | wxDV_HORIZ_RULES | wxDV_VERT_RULES); // Adding columns to wxDataViewListCtrl. - m_SampleListView->AppendToggleColumn("", wxDATAVIEW_CELL_ACTIVATABLE, 30, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE); + // m_SampleListView->AppendToggleColumn("", wxDATAVIEW_CELL_ACTIVATABLE, 30, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE); + m_SampleListView->AppendIconTextColumn("Favorite", wxDATAVIEW_CELL_ACTIVATABLE, 30, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE); m_SampleListView->AppendTextColumn("Filename", wxDATAVIEW_CELL_INERT, 320, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE); m_SampleListView->AppendTextColumn("Sample Pack", wxDATAVIEW_CELL_INERT, 200, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE); m_SampleListView->AppendTextColumn("Type", wxDATAVIEW_CELL_INERT, 120, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE); @@ -210,7 +221,7 @@ MainFrame::MainFrame() Bind(wxEVT_COLLAPSIBLEPANE_CHANGED, &MainFrame::OnExpandTrash, this, BC_TrashPane); Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &MainFrame::OnClickSampleView, this, BC_SampleListView); - Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, &MainFrame::OnCheckFavorite, this, BC_SampleListView); + Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &MainFrame::OnCheckFavorite, this, BC_SampleListView); Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, &MainFrame::OnDragFromSampleView, this); m_SampleListView->Connect(wxEVT_DROP_FILES, wxDropFilesEventHandler(MainFrame::OnDragAndDropToSampleListView), NULL, this); Bind(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, &MainFrame::OnShowSampleListViewContextMenu, this, BC_SampleListView); @@ -430,11 +441,15 @@ void MainFrame::AddSamples(wxArrayString& files) sample.SetBitrate(tags.GetAudioInfo().bitrate); wxVector data; - + + wxVariant icon; + icon << wxDataViewIconText(wxEmptyString, wxIcon(ICON_GREYSCALE)); + if (tags.IsFileValid()) { data.clear(); - data.push_back(false); + // data.push_back(false); + data.push_back(icon); data.push_back(filename); data.push_back(sample.GetSamplePack()); data.push_back(""); @@ -569,8 +584,6 @@ void MainFrame::OnDragAndDropToCollectionView(wxDropFilesEvent& event) if(drop_target.IsOk() && m_CollectionView->IsContainer(drop_target)) { - m_SampleListView->SetToggleValue(true, row, 0); - m_CollectionView->AppendItem(drop_target, files[i]); db.UpdateFavoriteColumn(files[i].ToStdString(), 1); @@ -579,6 +592,13 @@ void MainFrame::OnDragAndDropToCollectionView(wxDropFilesEvent& event) else wxLogDebug("%s is not a folder. Try dropping on folder.", m_CollectionView->GetItemText(drop_target)); + + m_SampleListView->SetValue(wxVariant(wxDataViewIconText(wxEmptyString, wxIcon(ICON_COLOURED))), + row, 0); + + // m_SampleListView->SetToggleValue(true, row, 0); + + wxLogDebug("Number of children: %d", m_CollectionView->GetChildCount(wxDataViewItem(wxNullPtr))); } } } @@ -862,7 +882,7 @@ void MainFrame::OnShowSampleListViewContextMenu(wxDataViewEvent& event) else return; - wxString selection = m_SampleListView->GetTextValue(selected_row, 1); + wxString selection = m_SampleListView->GetTextValue(selected_row, 1).BeforeLast('.'); // wxString sample_with_extension = db.GetSamplePathByFilename(selection.BeforeLast('.').ToStdString()); // wxString sample_without_extension = db.GetSamplePathByFilename(selection.ToStdString()); @@ -882,7 +902,12 @@ void MainFrame::OnShowSampleListViewContextMenu(wxDataViewEvent& event) wxMenu menu; - if (m_SampleListView->GetToggleValue(selected_row, 0)) + // if (m_SampleListView->GetToggleValue(selected_row, 0)) + // menu.Append(MN_FavoriteSample, "Remove from favorites"); + // else + // menu.Append(MN_FavoriteSample, "Add to favorites"); + + if (db.GetFavoriteColumnValueByFilename(selection.ToStdString()) == 1) menu.Append(MN_FavoriteSample, "Remove from favorites"); else menu.Append(MN_FavoriteSample, "Add to favorites"); @@ -898,17 +923,194 @@ void MainFrame::OnShowSampleListViewContextMenu(wxDataViewEvent& event) switch (m_SampleListView->GetPopupMenuSelectionFromUser(menu, event.GetPosition())) { case MN_FavoriteSample: + { + int row = 0, container_row = 0; + if (m_SampleListView->GetSelectedItemsCount() <= 1) { - if (m_SampleListView->GetToggleValue(selected_row, 0)) + // if(!column) + // { + // wxLogDebug("Column is not OK"); + // return; + // } + + // if (m_SampleListView->GetToggleValue(selected_row, 0)) + // if(db.GetFavoriteColumnValueByFilename(selection.ToStdString()) == 1) + // { + // // m_SampleListView->SetToggleValue(false, selected_row, 0); + // CheckForDuplicates(selection, selected_row); + // msg = wxString::Format("Toggle: false"); + // } + // else if(db.GetFavoriteColumnValueByFilename(selection.ToStdString()) == 0) + // { + // // m_SampleListView->SetToggleValue(true, selected_row, 0); + // CheckForDuplicates(selection, selected_row); + // msg = wxString::Format("Toggle: true"); + // } + std::deque nodes; + nodes.push_back(m_CollectionView->GetNthChild(wxDataViewItem(wxNullPtr), container_row)); + + wxDataViewItem found_item; + + // if(!column) + // { + // wxLogDebug("something wrong with column.."); + // return; + // } + + if(db.GetFavoriteColumnValueByFilename(selection.ToStdString()) == 0) { - m_SampleListView->SetToggleValue(false, selected_row, 0); - msg = wxString::Format("Toggle: false"); + wxLogDebug("Column matches.. looking!"); + while(!nodes.empty()) + { + wxDataViewItem current_item = nodes.front(); + nodes.pop_front(); + + if (m_CollectionView->GetItemText(current_item) == selection) + { + found_item = current_item; + wxLogDebug(m_CollectionView->GetItemText(current_item)); + break; + } + + 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); + row++; + } + } + + nodes.clear(); + + if (found_item.IsOk()) + { + wxString msg = wxString::Format("%s already added as favorite.", selection); + wxMessageDialog msgDialog(NULL, msg, "Info", wxOK | wxICON_INFORMATION); + msgDialog.ShowModal(); + } + else + { + wxLogDebug("Sample not found adding as fav."); + + wxDataViewItem selected = m_CollectionView->GetSelection(); + wxString folder; + + if(selected.IsOk() && m_CollectionView->IsContainer(selected)) + { + folder = m_CollectionView->GetItemText(selected); + m_CollectionView->AppendItem(selected, selection); + } + else + { + folder = m_CollectionView->GetItemText(favorites_folder); + m_CollectionView->AppendItem(favorites_folder, selection); + } + + m_SampleListView->SetValue(wxVariant(wxDataViewIconText(wxEmptyString, wxIcon(ICON_COLOURED))), + selected_row, 0); + + db.UpdateFavoriteColumn(selection.ToStdString(), 1); + db.UpdateFavoriteFolder(selection.ToStdString(), folder.ToStdString()); + + wxLogDebug("Adding %s to folder: %s", selection, folder); + } } - else + else if(db.GetFavoriteColumnValueByFilename(selection.ToStdString()) == 1) { - m_SampleListView->SetToggleValue(true, selected_row, 0); - msg = wxString::Format("Toggle: true"); + wxString folder_name = db.GetFavoriteFolderByFilename(selection.ToStdString()); + + while(!nodes.empty()) + { + wxDataViewItem current_item = nodes.front(); + nodes.pop_front(); + + wxLogDebug("%s folder name is: %s", selection, folder_name); + + if (m_CollectionView->GetItemText(current_item) == folder_name) + { + found_item = current_item; + wxLogDebug("Found folder: %s", m_CollectionView->GetItemText(found_item)); + } + + 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)); + + if (m_CollectionView->GetItemText(child) == selection) + { + found_item = child; + wxLogDebug("Will delete %s", m_CollectionView->GetItemText(found_item)); + break; + } + + nodes.push_back(child); + + row++; + } + } + + nodes.clear(); + + if (found_item.IsOk()) + { + wxLogDebug("Folder: %s :: Child: %s", folder_name, m_CollectionView->GetItemText(found_item)); + + m_CollectionView->DeleteItem(found_item); + + m_SampleListView->SetValue(wxVariant(wxDataViewIconText(wxEmptyString, wxIcon(ICON_GREYSCALE))), + selected_row, 0); + + db.UpdateFavoriteColumn(selection.ToStdString(), 0); + db.UpdateFavoriteFolder(selection.ToStdString(), m_CollectionView->GetItemText(favorites_folder).ToStdString()); + } + else + { + wxLogDebug("%s not added as favorite, cannot delete.", selection); + } } } else @@ -916,23 +1118,193 @@ void MainFrame::OnShowSampleListViewContextMenu(wxDataViewEvent& event) wxDataViewItemArray items; int rows = m_SampleListView->GetSelections(items); + std::deque nodes; + nodes.push_back(m_CollectionView->GetNthChild(wxDataViewItem(wxNullPtr), container_row)); + + wxDataViewItem found_item; + wxFileDataObject file_data; + wxArrayString files; + wxString name; + for (int i = 0; i < rows; i++) { - int row = m_SampleListView->ItemToRow(items[i]); + int item_row = m_SampleListView->ItemToRow(items[i]); - if (m_SampleListView->GetToggleValue(row, 0)) + name = m_SampleListView->GetTextValue(item_row, 1); + + file_data.AddFile(name.BeforeLast('.')); + + files = file_data.GetFilenames(); + + // 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"); + // } + + if(db.GetFavoriteColumnValueByFilename(files[i].ToStdString()) == 0) { - m_SampleListView->SetToggleValue(false, row, 0); - msg = wxString::Format("Toggle: false"); + wxLogDebug("Column matches.. looking!"); + while(!nodes.empty()) + { + wxDataViewItem current_item = nodes.front(); + nodes.pop_front(); + + if (m_CollectionView->GetItemText(current_item) == files[i]) + { + found_item = current_item; + wxLogDebug(m_CollectionView->GetItemText(current_item)); + break; + } + + 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); + row++; + } + } + + nodes.clear(); + + if (found_item.IsOk()) + { + wxString msg = wxString::Format("%s already added as favorite.", files[i]); + wxMessageDialog msgDialog(NULL, msg, "Info", wxOK | wxICON_INFORMATION); + msgDialog.ShowModal(); + } + else + { + wxLogDebug("Sample not found adding as fav."); + + wxDataViewItem selected = m_CollectionView->GetSelection(); + wxString folder; + + if(selected.IsOk() && m_CollectionView->IsContainer(selected)) + { + folder = m_CollectionView->GetItemText(selected); + m_CollectionView->AppendItem(selected, files[i]); + } + else + { + folder = m_CollectionView->GetItemText(favorites_folder); + m_CollectionView->AppendItem(favorites_folder, files[i]); + } + + m_SampleListView->SetValue(wxVariant(wxDataViewIconText(wxEmptyString, wxIcon(ICON_COLOURED))), + item_row, 0); + + db.UpdateFavoriteColumn(files[i].ToStdString(), 1); + db.UpdateFavoriteFolder(files[i].ToStdString(), folder.ToStdString()); + + wxLogDebug("Adding %s to folder: %s", files[i], folder); + } } - else + else if(db.GetFavoriteColumnValueByFilename(files[i].ToStdString()) == 1) { - m_SampleListView->SetToggleValue(true, row, 0); - msg = wxString::Format("Toggle: true"); + wxString folder_name = db.GetFavoriteFolderByFilename(files[i].ToStdString()); + + while(!nodes.empty()) + { + wxDataViewItem current_item = nodes.front(); + nodes.pop_front(); + + wxLogDebug("%s folder name is: %s", files[i], folder_name); + + if (m_CollectionView->GetItemText(current_item) == folder_name) + { + found_item = current_item; + wxLogDebug("Found folder: %s", m_CollectionView->GetItemText(found_item)); + } + + 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)); + + if (m_CollectionView->GetItemText(child) == files[i]) + { + found_item = child; + wxLogDebug("Will delete %s", m_CollectionView->GetItemText(found_item)); + break; + } + + nodes.push_back(child); + + row++; + } + } + + nodes.clear(); + + if (found_item.IsOk()) + { + wxLogDebug("Folder: %s :: Child: %s", folder_name, m_CollectionView->GetItemText(found_item)); + + m_CollectionView->DeleteItem(found_item); + + m_SampleListView->SetValue(wxVariant(wxDataViewIconText(wxEmptyString, wxIcon(ICON_GREYSCALE))), + item_row, 0); + + db.UpdateFavoriteColumn(files[i].ToStdString(), 0); + db.UpdateFavoriteFolder(files[i].ToStdString(), m_CollectionView->GetItemText(favorites_folder).ToStdString()); + } + else + { + wxLogDebug("%s not added as favorite, cannot delete.", files[i]); + } } } } break; + } case MN_DeleteSample: { wxDataViewItemArray items; @@ -1015,9 +1387,14 @@ void MainFrame::OnShowSampleListViewContextMenu(wxDataViewEvent& event) if (m_SampleListView->GetSelectedItemsCount() <= 1) { msg = "Trashing.."; - if (m_SampleListView->GetToggleValue(selected_row, 0)) + if(db.GetFavoriteColumnValueByFilename(selection.ToStdString())) + // if (m_SampleListView->GetToggleValue(selected_row, 0)) { - m_SampleListView->SetToggleValue(false, selected_row, 0); + // m_SampleListView->SetToggleValue(false, selected_row, 0); + + m_SampleListView->SetValue(wxVariant(wxDataViewIconText(wxEmptyString, wxIcon(ICON_GREYSCALE))), + selected_row, 0); + db.UpdateFavoriteColumn(filename, 0); } db.UpdateTrashColumn(filename, 1); @@ -1029,23 +1406,35 @@ void MainFrame::OnShowSampleListViewContextMenu(wxDataViewEvent& event) wxDataViewItemArray items; int rows = m_SampleListView->GetSelections(items); + wxString name; + wxFileDataObject file_data; + wxArrayString files; + for (int i = 0; i < rows; i++) { - int row = m_SampleListView->ItemToRow(items[i]); + int item_row = m_SampleListView->ItemToRow(items[i]); - wxString text_value = m_SampleListView->GetTextValue(row, 1); + wxString text_value = m_SampleListView->GetTextValue(item_row, 1); std::string multi_selection = text_value.Contains(wxString::Format(".%s", extension)) ? text_value.BeforeLast('.').ToStdString() : text_value.ToStdString() ; - if (m_SampleListView->GetToggleValue(row, 0)) + file_data.AddFile(multi_selection); + + files = file_data.GetFilenames(); + + // if (m_SampleListView->GetToggleValue(row, 0)) + if(db.GetFavoriteColumnValueByFilename(files[i].ToStdString())) { - m_SampleListView->SetToggleValue(false, row, 0); + // m_SampleListView->SetToggleValue(false, row, 0); + m_SampleListView->SetValue(wxVariant(wxDataViewIconText(wxEmptyString, wxIcon(ICON_GREYSCALE))), + item_row, 0); + db.UpdateFavoriteColumn(multi_selection, 0); } db.UpdateTrashColumn(multi_selection, 1); m_TrashedItems->AppendItem(trash_root_node, multi_selection); - m_SampleListView->DeleteItem(row); + m_SampleListView->DeleteItem(item_row); } } } @@ -1116,6 +1505,16 @@ void MainFrame::OnCheckFavorite(wxDataViewEvent& event) Database db(*m_InfoBar); Serializer serialize(m_ConfigFilepath); + wxDataViewColumn* column = m_SampleListView->GetCurrentColumn(); + + if(!column) + { + wxLogDebug("Column not found"); + return; + } + + wxLogDebug("Current column: %s", column->GetTitle()); + int selected_row = m_SampleListView->ItemToRow(event.GetItem()); int row = 0, container_row = 0; @@ -1135,8 +1534,9 @@ void MainFrame::OnCheckFavorite(wxDataViewEvent& event) // wxTreeItemId found_item; wxDataViewItem found_item; - if (m_SampleListView->GetToggleValue(selected_row, 0)) + if(column->GetTitle() == "Favorite" && db.GetFavoriteColumnValueByFilename(selection.ToStdString()) == 0) { + wxLogDebug("Column matches.. looking!"); while(!nodes.empty()) { // wxTreeItemId current_item = nodes.front(); @@ -1219,6 +1619,12 @@ void MainFrame::OnCheckFavorite(wxDataViewEvent& event) // db.UpdateFavoriteFolder(selection.ToStdString(), folder.ToStdString()); } + // column->SetBitmap(wxBitmap(ICON_GREYSCALE)); + // icon << wxDataViewIconText(wxEmptyString, wxIcon(ICON_GREYSCALE)); + + m_SampleListView->SetValue(wxVariant(wxDataViewIconText(wxEmptyString, wxIcon(ICON_COLOURED))), + selected_row, 0); + db.UpdateFavoriteColumn(selection.ToStdString(), 1); db.UpdateFavoriteFolder(selection.ToStdString(), folder.ToStdString()); @@ -1226,7 +1632,7 @@ void MainFrame::OnCheckFavorite(wxDataViewEvent& event) // serialize.SerializeDataViewTreeCtrlItems(*m_CollectionView, rootNode); } } - else + else if(column->GetTitle() == "Favorite" && db.GetFavoriteColumnValueByFilename(selection.ToStdString()) == 1) { wxString folder_name = db.GetFavoriteFolderByFilename(selection.ToStdString()); @@ -1310,6 +1716,12 @@ void MainFrame::OnCheckFavorite(wxDataViewEvent& event) // } m_CollectionView->DeleteItem(found_item); + m_SampleListView->SetValue(wxVariant(wxDataViewIconText(wxEmptyString, wxIcon(ICON_GREYSCALE))), + selected_row, 0); + + db.UpdateFavoriteColumn(selection.ToStdString(), 0); + db.UpdateFavoriteFolder(selection.ToStdString(), m_CollectionView->GetItemText(favorites_folder).ToStdString()); + // wxLogDebug("Found %s folder name is: %s", selection, folder_name); // wxMessageBox("// TODO", "Delete sample", wxOK | wxCENTER, this, wxDefaultCoord, wxDefaultCoord); } @@ -1607,7 +2019,7 @@ void MainFrame::LoadConfigFile() this->SetFont(settings.GetFontType()); this->SetSize(width, height); this->CenterOnScreen(wxBOTH); - this->SetIcon(wxIcon("../assets/icons/icon-hive_24x24.png", wxICON_DEFAULT_TYPE, -1, -1)); + this->SetIcon(wxIcon(ICON_APP, wxICON_DEFAULT_TYPE, -1, -1)); } void MainFrame::RefreshDatabase()