MCPcopy Index your code
hub / github.com/python/cpython / update_recent_files_list

Method update_recent_files_list

Lib/idlelib/editor.py:943–987  ·  view source on GitHub ↗

Load and update the recent files list and menus

(self, new_file=None)

Source from the content-addressed store, hash-verified

941 return display_extra_help
942
943 def update_recent_files_list(self, new_file=None):
944 "Load and update the recent files list and menus"
945 # TODO: move to iomenu.
946 rf_list = []
947 file_path = self.recent_files_path
948 if file_path and os.path.exists(file_path):
949 with open(file_path,
950 encoding='utf_8', errors='replace') as rf_list_file:
951 rf_list = rf_list_file.readlines()
952 if new_file:
953 new_file = os.path.abspath(new_file) + '\n'
954 if new_file in rf_list:
955 rf_list.remove(new_file) # move to top
956 rf_list.insert(0, new_file)
957 # clean and save the recent files list
958 bad_paths = []
959 for path in rf_list:
960 if '\0' in path or not os.path.exists(path[0:-1]):
961 bad_paths.append(path)
962 rf_list = [path for path in rf_list if path not in bad_paths]
963 ulchars = "1234567890ABCDEFGHIJK"
964 rf_list = rf_list[0:len(ulchars)]
965 if file_path:
966 try:
967 with open(file_path, 'w',
968 encoding='utf_8', errors='replace') as rf_file:
969 rf_file.writelines(rf_list)
970 except OSError as err:
971 if not getattr(self.root, "recentfiles_message", False):
972 self.root.recentfiles_message = True
973 messagebox.showwarning(title='IDLE Warning',
974 message="Cannot save Recent Files list to disk.\n"
975 f" {err}\n"
976 "Select OK to continue.",
977 parent=self.text)
978 # for each edit window instance, construct the recent files menu
979 for instance in self.top.instance_dict:
980 menu = instance.recent_files_menu
981 menu.delete(0, END) # clear, and rebuild:
982 for i, file_name in enumerate(rf_list):
983 file_name = file_name.rstrip() # zap \n
984 callback = instance.__recent_file_callback(file_name)
985 menu.add_command(label=ulchars[i] + " " + file_name,
986 command=callback,
987 underline=0)
988
989 def __recent_file_callback(self, file_name):
990 def open_recent_file(fn_closure=file_name):

Callers 3

__init__Method · 0.95
_closeMethod · 0.95
updaterecentfileslistMethod · 0.80

Calls 14

enumerateFunction · 0.85
showwarningMethod · 0.80
add_commandMethod · 0.80
openFunction · 0.50
existsMethod · 0.45
readlinesMethod · 0.45
abspathMethod · 0.45
removeMethod · 0.45
insertMethod · 0.45
appendMethod · 0.45
writelinesMethod · 0.45

Tested by

no test coverage detected