Skip to content

Commit 405902c

Browse files
committed
Fix superitems not updating correctly
DirectoryData.cpp, DirectoryData.hpp ~ percentOfParent is const FolderDisplay.hpp ~ UpdateTitle is now public FolderDisplay.cpp ~ fix race condition by scheduling main UI event after reconnection ~ update parent item's subfolders slot in addition to size interface_derived.h ~ recalculate stats in ProgressUpdate ~ update all titles in current display
1 parent 0b1a330 commit 405902c

5 files changed

Lines changed: 46 additions & 21 deletions

File tree

source/DirectoryData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ vector<DirectoryData*> DirectoryData::getSuperFolders(){
8080
Return a string representing the item's % size of the superitem
8181
@returns size rounded to 1 decimal place e.g (5.2%)
8282
*/
83-
long double DirectoryData::percentOfParent(){
83+
long double DirectoryData::percentOfParent() const{
8484
// if (parent == nullptr){return "[waiting]";}
8585
// //round to 2 decimal places, then attach unit
8686
// char buffer[10];

source/DirectoryData.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ class DirectoryData{
4545
void resetStats();
4646
void recalculateStats();
4747
vector<DirectoryData*> getSuperFolders();
48-
long double percentOfParent();
48+
long double percentOfParent() const;
4949
};

source/FolderDisplay.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,6 @@ void FolderDisplay::Size(FolderDisplay* parent, wxDataViewItem updateItem){
267267
//invoke event to notify needs to update UI
268268
wxPostEvent(this, event);
269269

270-
//invoke main UI event
271-
//notify parent to connect new pointer to display
272-
273-
wxCommandEvent* evt = new wxCommandEvent(progEvt, RESEVT);
274-
//pass along the address to the DirectoryData to the event
275-
uintptr_t* addr = new uintptr_t(prog * 100);
276-
evt->SetClientData(addr);
277-
eventManager->GetEventHandler()->QueueEvent(evt);
278-
279270
};
280271
//called on progress updates
281272
SizeItem(data->Path, uicallback);
@@ -299,8 +290,26 @@ void FolderDisplay::OnUpdateUI(wxCommandEvent& event){
299290
//add files once
300291
if (prog == 100){
301292
auto old_parent = data->parent;
302-
data = fd;
293+
//update size in parent
294+
if (old_parent != nullptr){
295+
old_parent->size -= data->size;
296+
data = fd;
297+
old_parent->size += data->size;
298+
299+
//reconnect item in SubFolders of parent
300+
for(int i = 0; i < old_parent->subFolders.size(); i++){
301+
DirectoryData* parentItem = old_parent->subFolders[i];
302+
if (parentItem->Path == data->Path){
303+
old_parent->subFolders[i] = data;
304+
break;
305+
}
306+
}
307+
}
308+
else{
309+
data = fd;
310+
}
303311
data->parent = old_parent;
312+
304313
UpdateTitle(false);
305314
//update percents
306315
auto count = data->subFolders.size();
@@ -323,4 +332,13 @@ void FolderDisplay::OnUpdateUI(wxCommandEvent& event){
323332
//set sort descending
324333
ListCtrl->GetColumn(1)->SetSortOrder(false);
325334
}
335+
336+
//invoke main UI event
337+
//notify parent to connect new pointer to display
338+
339+
wxCommandEvent* evt = new wxCommandEvent(progEvt, RESEVT);
340+
//pass along the address to the DirectoryData to the event
341+
uintptr_t* addr = new uintptr_t(prog);
342+
evt->SetClientData(addr);
343+
eventManager->GetEventHandler()->QueueEvent(evt);
326344
}

source/FolderDisplay.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ class FolderDisplay : public FolderDisplayBase{
4949
void display();
5050
static string sizeToString(const fileSize&);
5151
bool abort = true;
52+
53+
/**
54+
Sets the label in this display to the size of the item
55+
@param isSizing pass true if the size operation is in progress, false otherwise
56+
@note If the size of the current DirectoryData is 0, the item's size will display as Needs reload because the minimum size FatFileFinder reports is 1 byte.
57+
*/
58+
void UpdateTitle(bool isSizing = false){
59+
ItemName->SetLabel((isSizing? "(Sizing) " : "") + std::filesystem::path(data->Path).filename().string() + " - " + (data->size == 0? "Needs reload" : sizeToString(data->size)));
60+
}
61+
5262
private:
5363
wxWindow* eventManager = nullptr;
5464
std::thread worker;
@@ -77,15 +87,6 @@ class FolderDisplay : public FolderDisplayBase{
7787
void OnSelectionActivated(wxDataViewEvent&);
7888
void OnUpdateUI(wxCommandEvent&);
7989

80-
81-
/**
82-
Sets the label in this display to the size of the item
83-
@param isSizing pass true if the size operation is in progress, false otherwise
84-
@note If the size of the current DirectoryData is 0, the item's size will display as Needs reload because the minimum size FatFileFinder reports is 1 byte.
85-
*/
86-
void UpdateTitle(bool isSizing = false){
87-
ItemName->SetLabel((isSizing? "(Sizing) " : "") + std::filesystem::path(data->Path).filename().string() + " - " + (data->size == 0? "Needs reload" : sizeToString(data->size)));
88-
}
8990
wxDECLARE_EVENT_TABLE();
9091

9192
public:

source/interface_derived.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ class MainFrame : public MainFrameBase
4545

4646
void ProgressUpdate(int progress){
4747
progressBar->SetValue(progress);
48+
if (progress == 100){
49+
currentDisplay[0]->data->recalculateStats();
50+
for (FolderDisplay* disp : currentDisplay){
51+
disp->UpdateTitle();
52+
}
53+
}
4854
UpdateTitlebar(progress, FolderDisplay::sizeToString(currentDisplay[0]->data->size));
4955
}
5056

0 commit comments

Comments
 (0)