1717from watchdog .observers import Observer
1818from watchdog .events import FileSystemEventHandler
1919
20+ # 版本信息
21+ VERSION = "0.2"
22+ APP_NAME = "多标签文件浏览器"
23+
2024pythoncom .CoInitialize () # 添加在模块初始化处
2125class FileChangeHandler (FileSystemEventHandler ):
2226 def __init__ (self , callback ):
@@ -39,7 +43,7 @@ def on_moved(self, event):
3943
4044class FileExplorerFrame (wx .Frame ):
4145 def __init__ (self ):
42- super ().__init__ (None , title = "多标签文件浏览器 " , size = (1024 , 768 ))
46+ super ().__init__ (None , title = f" { APP_NAME } v { VERSION } " , size = (1024 , 768 ))
4347
4448 # 初始化基本变量
4549 self .current_path = os .path .expanduser ("~" )
@@ -151,6 +155,20 @@ def get_selected_paths(self):
151155
152156 def on_tab_switch (self , event , side ):
153157 """切换标签页时更新监控路径"""
158+ notebook = self .left_notebook if side == "left" else self .right_notebook
159+ index = event .GetSelection ()
160+
161+ # 如果切换到"+"标签页,则创建新标签页并选中它
162+ if notebook .GetPageText (index ) == "+" :
163+ # 获取当前活动标签页的路径
164+ current_tab = self .get_current_tab (side )
165+ path = current_tab ['path' ] if current_tab else os .path .expanduser ("~" )
166+ self .add_tab (path , side )
167+ # 确保"+"标签页保持不选中状态
168+ notebook .SetSelection (notebook .GetPageCount () - 2 )
169+ event .Veto () # 阻止切换到"+"标签页
170+ return
171+
154172 current = self .get_current_tab (side )
155173 if current :
156174 self .start_watching (current ['path' ])
@@ -315,6 +333,8 @@ def add_tab(self, initial_path, side="left"):
315333 # 在"+"标签页之前插入新标签页
316334 self .tabs [side ].append (tab_data )
317335 notebook .InsertPage (notebook .GetPageCount () - 1 , panel , os .path .basename (initial_path ) or initial_path , True )
336+ # 确保"+"标签页保持不选中状态
337+ notebook .SetSelection (notebook .GetPageCount () - 2 )
318338
319339 # 刷新文件列表
320340 self .refresh_file_list (tab_data )
@@ -1328,6 +1348,8 @@ def on_notebook_dclick(self, event, side):
13281348 current_tab = self .get_current_tab (side )
13291349 path = current_tab ['path' ] if current_tab else os .path .expanduser ("~" )
13301350 self .add_tab (path , side )
1351+ # 确保"+"标签页保持不选中状态
1352+ notebook .SetSelection (notebook .GetPageCount () - 2 )
13311353 elif tab_hit [0 ] < len (self .tabs [side ]): # 不是"+"标签页
13321354 self .close_tab (tab_hit [0 ], side )
13331355 else :
0 commit comments