1010We have a menu containing two items. Each item accepts a file name, one hides the file
1111and the other deletes it. Both items have an undo option.
1212Each item is a MenuItem class that accepts the corresponding command as input and executes
13- it's execute` method when it is pressed.
13+ it's ` execute` method when it is pressed.
1414
1515*TL;DR
1616Object oriented implementation of callback functions.
@@ -54,20 +54,21 @@ class DeleteFileCommand:
5454 """
5555 A command to delete a file given its name
5656 """
57+ _deleted_files_path = 'trash'
5758
5859 def __init__ (self ):
5960 # an array of deleted files, to undo them as needed
6061 self ._deleted_files = []
6162
6263 # create a directory to store deleted files
63- if not os .path .exists ('bin' ):
64- os .makedirs ('bin' )
64+ if not os .path .exists (self . _deleted_files_path ):
65+ os .makedirs (self . _deleted_files_path )
6566
6667 def execute (self , filename ):
6768 if os .path .isfile (filename ):
6869 print (f'deleting { filename } ' )
6970
70- os .rename (filename , f'bin /{ filename } ' )
71+ os .rename (filename , f'{ self . _deleted_files_path } /{ filename } ' )
7172 self ._deleted_files .append (filename )
7273 else :
7374 print (f'{ filename } dose not exists to delete' )
@@ -78,7 +79,7 @@ def undo(self):
7879
7980 print (f'un-deleting { filename } ' )
8081
81- os .rename (f'bin /{ filename } ' , filename )
82+ os .rename (f'{ self . _deleted_files_path } /{ filename } ' , filename )
8283
8384
8485class MenuItem :
0 commit comments