Skip to content

Commit

Permalink
Bugfix: "Delete All Binds" now removes an empty binds directory
Browse files Browse the repository at this point in the history
If "Delete All Binds" clears the profile directory completely, ie, there
were no user-added files or other non-BindControl debris in there, the
profile's binds directory will be removed.
  • Loading branch information
emersonrp committed Jun 15, 2024
1 parent f8d043a commit f318d88
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def WriteBindFiles(self):

def AllBindFiles(self):
files = [self.ResetFile()]
dirs = [str(self.BindsDir())]
dirs = []
for pageName in self.Pages:
page = getattr(self, pageName)
bf = page.AllBindFiles()
Expand Down Expand Up @@ -514,10 +514,9 @@ def DeleteBindFiles(self):

removed = self.doDeleteBindsFiles(self.AllBindFiles())

with DeleteDoneDialog(self, removed = removed) as dlg:
dlg.ShowModal()


if removed:
with DeleteDoneDialog(self, removed = removed) as dlg:
dlg.ShowModal()

def doDeleteBindsFiles(self, bindfiles):

Expand All @@ -532,6 +531,7 @@ def doDeleteBindsFiles(self, bindfiles):
dlg = wx.ProgressDialog('Deleting Bind Files', '',
maximum = totalfiles, style=wx.PD_APP_MODAL|wx.PD_AUTO_HIDE)

# try all 15k+ of the files
progress = 0
removed = 0
for file in bindfiles['files']:
Expand All @@ -544,6 +544,7 @@ def doDeleteBindsFiles(self, bindfiles):
dlg.Update(progress, str(file.Path))
progress = progress + 1

# try the directories
for bdir in bindfiles['dirs']:
dirpath = Path(self.BindsDir() / bdir)
if dirpath.is_dir():
Expand All @@ -559,6 +560,13 @@ def doDeleteBindsFiles(self, bindfiles):
dlg.Update(progress, bdir)
progress = progress + 1

# remove the bindsdir itself, if empty
bindsdir = Path(self.BindsDir())
try:
bindsdir.rmdir()
except Exception:
pass

# clear out our state
self.BindFiles = {}

Expand Down Expand Up @@ -634,6 +642,7 @@ def doTextCopy(self, evt):
wx.TheClipboard.Close()
else:
wx.MessageBox("Couldn't open the clipboard for copying")

class DeleteDoneDialog(wx.Dialog):
def __init__(self, parent, removed = 0):
wx.Dialog.__init__(self, parent, title = "Bindfiles Deleted")
Expand Down

0 comments on commit f318d88

Please sign in to comment.