@@ -3156,6 +3156,9 @@ def _populate_scan_chart(self, scan_tab, tab_index):
31563156 self .chart_back_button .setVisible (len (self .scan_chart_nav_stack ) > 0 )
31573157 else :
31583158 self .chart_nav_container .setVisible (False )
3159+
3160+ # Apply current theme colors to chart axes
3161+ self ._update_scan_chart_theme ()
31593162
31603163 def _update_scan_chart_for_tab (self ):
31613164 if not hasattr (self , 'scan_chart_view' ):
@@ -3164,6 +3167,8 @@ def _update_scan_chart_for_tab(self):
31643167 current_tab = self .search_tabs .get (current_index )
31653168 if current_tab and current_tab .is_scan_tab and getattr (current_tab , 'scan_chart_data' , None ):
31663169 self ._populate_scan_chart (current_tab , current_index )
3170+ # Ensure theme is applied after populating
3171+ self ._update_scan_chart_theme ()
31673172 else :
31683173 self ._clear_scan_chart ()
31693174
@@ -3277,49 +3282,74 @@ def _on_subdir_scan_complete(self, subdirs):
32773282 self .show_info ("No Subdirectories" , f"No accessible subdirectories found in:\n { target_path } " )
32783283 return
32793284
3280- # Update chart with subdirectories
3281- if self .scan_chart_tab_index is not None :
3282- tab = self .search_tabs .get (self .scan_chart_tab_index )
3283- if tab and hasattr (self , 'subdir_scan_target' ):
3284- # Convert to format: (name, size, mtime, path)
3285- chart_data = []
3285+ if not hasattr (self , 'subdir_scan_target' ):
3286+ return
3287+
3288+ # Convert to format: (name, size, mtime, path)
3289+ chart_data = []
3290+ for name , size , path in subdirs :
3291+ try :
3292+ mtime = path .stat ().st_mtime if path .exists () else 0
3293+ except :
3294+ mtime = 0
3295+ chart_data .append ((name , size , mtime , str (path )))
3296+
3297+ # Create a new tab for the subdirectory
3298+ target_path = str (self .subdir_scan_target )
3299+ tab_title = f"📊 { self .subdir_scan_target .name } "
3300+
3301+ new_tab = self .create_new_tab (
3302+ query = "" ,
3303+ directory = "" ,
3304+ tab_title = tab_title ,
3305+ is_scan_tab = True
3306+ )
3307+
3308+ # Set up the new tab with scan data
3309+ new_tab .scan_chart_data = chart_data
3310+ new_tab .scan_chart_title = f"{ self .subdir_scan_target .name } "
3311+ new_tab .is_scan_tab = True
3312+
3313+ # Get the new tab index
3314+ new_tab_index = None
3315+ for idx , tab in self .search_tabs .items ():
3316+ if tab == new_tab :
3317+ new_tab_index = idx
3318+ break
3319+
3320+ if new_tab_index is not None :
3321+ # Update global chart state to new tab
3322+ self .scan_chart_tab_index = new_tab_index
3323+ self .scan_chart_current_path = target_path
3324+
3325+ # Populate chart in new tab
3326+ self ._populate_scan_chart (new_tab , new_tab_index )
3327+
3328+ # Update tab tree with subdirectories
3329+ tree = new_tab .tree
3330+ if tree :
3331+ tree .clear ()
32863332 for name , size , path in subdirs :
3333+ item = QTreeWidgetItem ()
3334+ item .setText (0 , name )
3335+ item .setText (1 , format_size (size ))
32873336 try :
32883337 mtime = path .stat ().st_mtime if path .exists () else 0
3338+ date_str = time .strftime ('%Y-%m-%d %H:%M:%S' , time .localtime (mtime ))
32893339 except :
3290- mtime = 0
3291- chart_data .append ((name , size , mtime , str (path )))
3340+ date_str = ""
3341+ item .setText (2 , date_str )
3342+ item .setText (3 , str (path ))
3343+ tree .addTopLevelItem (item )
32923344
3293- tab .scan_chart_data = chart_data
3294- tab .scan_chart_title = f"{ self .subdir_scan_target .name } "
3295- self .scan_chart_current_path = str (self .subdir_scan_target )
3296- self ._populate_scan_chart (tab , self .scan_chart_tab_index )
3345+ # Update tab metadata
3346+ new_tab .all_file_data = chart_data
3347+ new_tab .file_data = chart_data
3348+ new_tab .current_loaded = len (chart_data )
3349+ new_tab .items_found_count = len (chart_data )
32973350
3298- # Update tab tree with subdirectories
3299- tree = tab .tree
3300- if tree :
3301- tree .clear ()
3302- for name , size , path in subdirs :
3303- item = QTreeWidgetItem ()
3304- item .setText (0 , name )
3305- item .setText (1 , format_size (size ))
3306- try :
3307- mtime = path .stat ().st_mtime if path .exists () else 0
3308- date_str = time .strftime ('%Y-%m-%d %H:%M:%S' , time .localtime (mtime ))
3309- except :
3310- date_str = ""
3311- item .setText (2 , date_str )
3312- item .setText (3 , str (path ))
3313- tree .addTopLevelItem (item )
3314-
3315- # Update tab metadata
3316- tab .all_file_data = chart_data
3317- tab .file_data = chart_data
3318- tab .current_loaded = len (chart_data )
3319- tab .items_found_count = len (chart_data )
3320-
3321- # Update status label
3322- self .lbl_items_found .setText (f"📊 { len (chart_data )} items found" )
3351+ # Update status label
3352+ self .lbl_items_found .setText (f"📊 { len (chart_data )} items found" )
33233353
33243354 def _on_subdir_scan_error (self , error_msg ):
33253355 """Handle subdirectory scan error"""
@@ -3346,14 +3376,81 @@ def on_chart_back_clicked(self):
33463376
33473377 # Pop previous state from stack
33483378 prev_state = self .scan_chart_nav_stack .pop ()
3379+ prev_path = prev_state ['path' ]
3380+
3381+ # Check if a tab already exists for this path
3382+ existing_tab_index = None
3383+ for idx , tab in self .search_tabs .items ():
3384+ if (hasattr (tab , 'is_scan_tab' ) and tab .is_scan_tab and
3385+ hasattr (tab , 'scan_chart_data' ) and tab .scan_chart_data ):
3386+ # Check if this tab's first item path matches the target path
3387+ if tab .scan_chart_data :
3388+ first_item_path = str (Path (tab .scan_chart_data [0 ][3 ]).parent ) if len (tab .scan_chart_data [0 ]) > 3 else None
3389+ if first_item_path == prev_path :
3390+ existing_tab_index = idx
3391+ break
33493392
3350- if self .scan_chart_tab_index is not None :
3351- tab = self .search_tabs .get (self .scan_chart_tab_index )
3352- if tab :
3353- tab .scan_chart_data = prev_state ['data' ]
3354- tab .scan_chart_title = prev_state ['title' ]
3355- self .scan_chart_current_path = prev_state ['path' ]
3356- self ._populate_scan_chart (tab , self .scan_chart_tab_index )
3393+ if existing_tab_index is not None :
3394+ # Switch to existing tab
3395+ self .tab_widget .setCurrentIndex (existing_tab_index )
3396+ self .scan_chart_tab_index = existing_tab_index
3397+ self .scan_chart_current_path = prev_path
3398+ else :
3399+ # Create new tab for previous state
3400+ prev_path_obj = Path (prev_path )
3401+ tab_title = f"📊 { prev_path_obj .name or prev_path_obj } "
3402+
3403+ new_tab = self .create_new_tab (
3404+ query = "" ,
3405+ directory = "" ,
3406+ tab_title = tab_title ,
3407+ is_scan_tab = True
3408+ )
3409+
3410+ # Set up the new tab with previous state data
3411+ new_tab .scan_chart_data = prev_state ['data' ]
3412+ new_tab .scan_chart_title = prev_state ['title' ]
3413+ new_tab .is_scan_tab = True
3414+
3415+ # Get the new tab index
3416+ new_tab_index = None
3417+ for idx , tab in self .search_tabs .items ():
3418+ if tab == new_tab :
3419+ new_tab_index = idx
3420+ break
3421+
3422+ if new_tab_index is not None :
3423+ # Update global chart state
3424+ self .scan_chart_tab_index = new_tab_index
3425+ self .scan_chart_current_path = prev_path
3426+
3427+ # Populate chart in new tab
3428+ self ._populate_scan_chart (new_tab , new_tab_index )
3429+
3430+ # Update tab tree with data
3431+ tree = new_tab .tree
3432+ if tree :
3433+ tree .clear ()
3434+ for item_data in prev_state ['data' ]:
3435+ item = QTreeWidgetItem ()
3436+ item .setText (0 , item_data [0 ]) # name
3437+ item .setText (1 , format_size (item_data [1 ])) # size
3438+ try :
3439+ date_str = time .strftime ('%Y-%m-%d %H:%M:%S' , time .localtime (item_data [2 ]))
3440+ except :
3441+ date_str = ""
3442+ item .setText (2 , date_str ) # mtime
3443+ item .setText (3 , item_data [3 ]) # path
3444+ tree .addTopLevelItem (item )
3445+
3446+ # Update tab metadata
3447+ new_tab .all_file_data = prev_state ['data' ]
3448+ new_tab .file_data = prev_state ['data' ]
3449+ new_tab .current_loaded = len (prev_state ['data' ])
3450+ new_tab .items_found_count = len (prev_state ['data' ])
3451+
3452+ # Update status label
3453+ self .lbl_items_found .setText (f"📊 { len (prev_state ['data' ])} items found" )
33573454
33583455 # ========== Filtering and sorting ==========
33593456 def on_filter_changed (self ):
0 commit comments