@@ -116,7 +116,7 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
116116 self .tkinter_vars = {} # keys: Tkinter event names
117117 # values: Tkinter variable instances
118118 self .top .instance_dict = {}
119- self .recent_files_path = os .path .join (
119+ self .recent_files_path = idleConf . userdir and os .path .join (
120120 idleConf .userdir , 'recent-files.lst' )
121121
122122 self .prompt_last_line = '' # Override in PyShell
@@ -924,9 +924,11 @@ def display_extra_help(helpfile=helpfile):
924924
925925 def update_recent_files_list (self , new_file = None ):
926926 "Load and update the recent files list and menus"
927+ # TODO: move to iomenu.
927928 rf_list = []
928- if os .path .exists (self .recent_files_path ):
929- with open (self .recent_files_path , 'r' ,
929+ file_path = self .recent_files_path
930+ if file_path and os .path .exists (file_path ):
931+ with open (file_path , 'r' ,
930932 encoding = 'utf_8' , errors = 'replace' ) as rf_list_file :
931933 rf_list = rf_list_file .readlines ()
932934 if new_file :
@@ -942,19 +944,19 @@ def update_recent_files_list(self, new_file=None):
942944 rf_list = [path for path in rf_list if path not in bad_paths ]
943945 ulchars = "1234567890ABCDEFGHIJK"
944946 rf_list = rf_list [0 :len (ulchars )]
945- try :
946- with open ( self . recent_files_path , 'w' ,
947- encoding = 'utf_8' , errors = 'replace' ) as rf_file :
948- rf_file . writelines ( rf_list )
949- except OSError as err :
950- if not getattr ( self . root , "recentfilelist_error_displayed" , False ) :
951- self .root . recentfilelist_error_displayed = True
952- tkMessageBox . showwarning ( title = 'IDLE Warning' ,
953- message = "Cannot update File menu Recent Files list. "
954- "Your operating system says: \n %s \n "
955- "Select OK and IDLE will continue without updating. "
956- % self . _filename_to_unicode ( str ( err )) ,
957- parent = self .text )
947+ if file_path :
948+ try :
949+ with open ( file_path , 'w' ,
950+ encoding = 'utf_8' , errors = 'replace' ) as rf_file :
951+ rf_file . writelines ( rf_list )
952+ except OSError as err :
953+ if not getattr ( self .root , "recentfiles_message" , False ):
954+ self . root . recentfiles_message = True
955+ tkMessageBox . showwarning ( title = 'IDLE Warning' ,
956+ message = "Cannot save Recent Files list to disk. \n "
957+ f" { err } \n "
958+ "Select OK to continue." ,
959+ parent = self .text )
958960 # for each edit window instance, construct the recent files menu
959961 for instance in self .top .instance_dict :
960962 menu = instance .recent_files_menu
0 commit comments