@@ -218,6 +218,11 @@ def __init__(self, parent, name=None, run_workbox=False, standalone=False):
218218 )
219219 self .uiCloseWorkboxACT .triggered .connect (self .uiWorkboxTAB .close_current_tab )
220220
221+ # Old workbox housekeeping
222+ self .uiEmptyWorkboxRecycleBinACT .triggered .connect (
223+ self .empty_workbox_recycle_bin
224+ )
225+
221226 # Browse previous commands
222227 self .uiGetPrevCmdACT .triggered .connect (self .getPrevCommand )
223228 self .uiGetNextCmdACT .triggered .connect (self .getNextCommand )
@@ -1004,7 +1009,7 @@ def remove_old_workbox_folders(self):
10041009 """Remove from disk any old workbox backup folders. We find all current
10051010 open workbox's workbox_ids, and add any workbox_ids from the recently
10061011 closed workbox menu. Any workbox folders which are not in that list will
1007- be deleted .
1012+ be moved to the workbox_recycle_bin .
10081013 """
10091014
10101015 # Collect the workbox_ids for all currently open workboxes, and all
@@ -1021,13 +1026,13 @@ def remove_old_workbox_folders(self):
10211026 # Look at all workbox folders on disk. If it's in the list collected
10221027 # above, it's a keeper, otherwise it's to be deleted.
10231028 keepers = []
1024- to_delete = []
1029+ to_remove = []
10251030 workbox_dir = self .prefsPath ("workboxes" )
10261031 for file in Path (workbox_dir ).iterdir ():
10271032 if file .is_file ():
10281033 continue
10291034 if file .name not in keeper_workbox_ids :
1030- to_delete .append (file )
1035+ to_remove .append (file )
10311036 else :
10321037 keepers .append (file )
10331038
@@ -1037,11 +1042,39 @@ def remove_old_workbox_folders(self):
10371042 if not keepers :
10381043 return
10391044
1040- # Go thru each to_delete folder, empty it out, and remove it.
1041- for deleter in to_delete :
1042- for file in deleter .iterdir ():
1045+ # Go thru each to_remove folder, move it to the recycle bin.
1046+ bin_path = Path (self .prefsPath ("workbox_recycle_bin" ))
1047+ for directory in to_remove :
1048+ new_path = bin_path / directory .name
1049+ # If somehow new_path already exists, remove it first
1050+ if new_path .exists ():
1051+ new_path .unlink ()
1052+ shutil .move (directory , new_path )
1053+
1054+ def empty_workbox_recycle_bin (self ):
1055+ """Remove any old workbox folders from the workbox_recycle_bin"""
1056+
1057+ msg = "Are you sure you want to empty the workbox recycle bin?"
1058+ ret = QMessageBox .question (
1059+ self ,
1060+ 'Confirm empty workbox recycle bin' ,
1061+ msg ,
1062+ QMessageBox .StandardButton .Yes | QMessageBox .StandardButton .Cancel ,
1063+ )
1064+ if ret != QMessageBox .StandardButton .Yes :
1065+ return
1066+
1067+ bin_path = Path (self .prefsPath ("workbox_recycle_bin" ))
1068+ if not bin_path .exists ():
1069+ return
1070+
1071+ for file in bin_path .iterdir ():
1072+ if file .is_dir ():
1073+ for sub_file in file .iterdir ():
1074+ sub_file .unlink ()
1075+ file .rmdir ()
1076+ else :
10431077 file .unlink ()
1044- deleter .rmdir ()
10451078
10461079 def getBoxesChangedByInstance (self , timeOffset = 0.05 ):
10471080 self .latestTimeStrsForBoxesChangedViaInstance = {}
0 commit comments