@@ -54,24 +54,24 @@ def __init__(
5454 self ,
5555 app : HimenaApplication ,
5656 menu_id : MenuId = MenuId .FILE_RECENT ,
57- file_name : str = "recent.json " ,
57+ dir_name : str = "recent" ,
5858 group : str = ActionGroup .RECENT_FILE ,
5959 n_history : int = 60 ,
6060 ):
6161 self ._disposer = lambda : None
6262 self ._app = app
6363 self ._menu_id = menu_id
64- self ._file_name = file_name
64+ self ._dir_name = dir_name
6565 self ._group = group
6666 self ._n_history = n_history
6767
6868 def update_menu (self ):
6969 """Update the menu for the recent file list."""
7070 if self ._app .name in self ._MENU_UPDATED :
71- return None
71+ return
7272 file_args = self ._list_args_for_recent ()[::- 1 ]
7373 if len (file_args ) == 0 :
74- return None
74+ return
7575 num_recent = self .num_recent_in_menu ()
7676 actions = [
7777 self .action_for_file (path , plugin , in_menu = i < num_recent )
@@ -96,7 +96,7 @@ def default(cls, app: HimenaApplication) -> RecentFileManager:
9696 def _list_args_for_recent (self ) -> list [tuple [_PathInput , str | None ]]:
9797 """List the recent files (older first)."""
9898
99- _path = data_dir () / self ._file_name
99+ _path = self .recent_json_path ()
100100 if not _path .exists ():
101101 return []
102102 with open (_path ) as f :
@@ -120,9 +120,9 @@ def _list_args_for_recent(self) -> list[tuple[_PathInput, str | None]]:
120120 def append_recent_files (
121121 self ,
122122 inputs : list [tuple [_PathInput , str | None ]],
123- ) -> None :
123+ ):
124124 """Append file(s) with plugin to the user history (duplication OK)."""
125- _path = data_dir () / self ._file_name
125+ _path = self .recent_json_path ()
126126 if _path .exists ():
127127 with open (_path ) as f :
128128 all_info = json .load (f )
@@ -141,17 +141,11 @@ def append_recent_files(
141141 if each in existing_paths :
142142 to_remove .append (existing_paths .index (each ))
143143 if isinstance (each , list ):
144- all_info .append (
145- {"type" : "group" , "path" : each , "plugin" : plugin , "time" : now }
146- )
144+ all_info .append (_make_info ("group" , each , plugin , now ))
147145 elif Path (each ).is_file ():
148- all_info .append (
149- {"type" : "file" , "path" : each , "plugin" : plugin , "time" : now }
150- )
146+ all_info .append (_make_info ("file" , each , plugin , now ))
151147 else :
152- all_info .append (
153- {"type" : "folder" , "path" : each , "plugin" : plugin , "time" : now }
154- )
148+ all_info .append (_make_info ("folder" , each , plugin , now ))
155149 for i in sorted (to_remove , reverse = True ):
156150 all_info .pop (i )
157151 if len (all_info ) > self ._n_history :
@@ -201,6 +195,14 @@ def id_title_for_file(self, file: _PathInput) -> tuple[str, str]:
201195 title = f"{ len (file )} files such as { file [0 ]} "
202196 return id , title
203197
198+ def recent_json_path (self ):
199+ """Path to the JSON file that stores the recent file list."""
200+ _data_dir = data_dir ()
201+ _recent_dir = _data_dir / self ._dir_name
202+ if not _recent_dir .exists ():
203+ _recent_dir .mkdir (parents = True , exist_ok = True )
204+ return _recent_dir / f"{ self ._app .name } .json"
205+
204206
205207class RecentSessionManager (RecentFileManager ):
206208 _MENU_UPDATED : set [str ] = set ()
@@ -209,7 +211,7 @@ class RecentSessionManager(RecentFileManager):
209211 def default (cls , app : HimenaApplication ) -> RecentSessionManager :
210212 return cls (
211213 app ,
212- file_name = "recent_sessions.json " ,
214+ dir_name = "recent_sessions" ,
213215 group = ActionGroup .RECENT_SESSION ,
214216 n_history = 20 ,
215217 )
@@ -250,3 +252,7 @@ def _update_annotation(obj):
250252
251253 obj .__annotations__ = {"ui" : MainWindow }
252254 return obj
255+
256+
257+ def _make_info (typ : str , path , plugin : str | None , now : str ) -> dict :
258+ return {"type" : typ , "path" : path , "plugin" : plugin , "time" : now }
0 commit comments