14
14
from core .exclusion_manager import ExclusionManager
15
15
from utils .file_exporter import FileExporter
16
16
from utils .theme_manager import ThemeManager
17
+ from utils .exclusion_config import load_exclusion_config , save_exclusion_config
17
18
import resources_rc
18
19
19
20
class FileTreeGeneratorApp :
@@ -22,8 +23,6 @@ def __init__(self):
22
23
self ._set_app_icon ()
23
24
24
25
# ---- Global font setup (from qrc) ----
25
- # Make sure the font is listed in your resources.qrc, e.g.:
26
- # <file>resources/Sora-VariableFont_wght.ttf</file>
27
26
font_id = QFontDatabase .addApplicationFont (":/resources/Sora-VariableFont_wght.ttf" )
28
27
if font_id != - 1 :
29
28
families = QFontDatabase .applicationFontFamilies (font_id )
@@ -48,6 +47,9 @@ def __init__(self):
48
47
# Initialize exclusion manager
49
48
self .exclusion_manager = ExclusionManager ()
50
49
50
+ # Load exclusion config and apply to panel/manager
51
+ self ._load_and_apply_exclusion_config ()
52
+
51
53
# Connect signals
52
54
self .window .address_bar .path_changed .connect (self .generate_tree )
53
55
self .window .address_bar .refresh_requested .connect (self .refresh_tree )
@@ -56,7 +58,9 @@ def __init__(self):
56
58
self .window .export_panel .export_requested .connect (self .export_tree )
57
59
self .window .exclusion_panel .exclusions_changed .connect (self .update_exclusions )
58
60
59
- # Initialize current path and tree data
61
+ # Ensure exclusion config is saved on app exit
62
+ self .app .aboutToQuit .connect (self ._save_exclusion_config )
63
+
60
64
self .current_path = ""
61
65
self .tree_data = None
62
66
@@ -77,18 +81,44 @@ def process_command_line(self):
77
81
# Set the path in the address bar and generate tree
78
82
self .window .address_bar .set_path (folder_path )
79
83
84
+ def _load_and_apply_exclusion_config (self ):
85
+ """Load exclusions and checkbox state from config.json and apply to panel/manager"""
86
+ config = load_exclusion_config ()
87
+ patterns = config .get ("patterns" , [])
88
+ use_common = config .get ("use_common" , True )
89
+ # Set UI panel
90
+ self .window .exclusion_panel .set_exclusion_patterns (patterns )
91
+ self .window .exclusion_panel .set_use_common_exclusions (use_common )
92
+ # Set backend manager
93
+ self .exclusion_manager .clear_patterns ()
94
+ for pattern in patterns :
95
+ self .exclusion_manager .add_pattern (pattern )
96
+ self .exclusion_manager .set_use_common_exclusions (use_common )
97
+
98
+ def _save_exclusion_config (self ):
99
+ """Save current exclusions and checkbox state to config.json"""
100
+ patterns = self .window .exclusion_panel .get_exclusion_patterns ()
101
+ use_common = self .window .exclusion_panel .use_common_exclusions ()
102
+ print (f"[LOG] Saving exclusion config: { len (patterns )} patterns, use_common={ use_common } " )
103
+ save_exclusion_config (patterns , use_common )
104
+ print ("[LOG] Exclusion config saved successfully." )
105
+
80
106
def update_exclusions (self ):
81
107
"""Update exclusion patterns from the UI and regenerate tree"""
82
108
# Update exclusion manager from UI
83
109
self .exclusion_manager .clear_patterns ()
84
110
patterns = self .window .exclusion_panel .get_exclusion_patterns ()
111
+ print (f"[LOG] Updating exclusions: { len (patterns )} patterns" )
85
112
for pattern in patterns :
86
113
self .exclusion_manager .add_pattern (pattern )
87
114
88
115
# Set common exclusions setting
89
- self .exclusion_manager .set_use_common_exclusions (
90
- self .window .exclusion_panel .use_common_exclusions ()
91
- )
116
+ use_common = self .window .exclusion_panel .use_common_exclusions ()
117
+ print (f"[LOG] Use common exclusions: { use_common } " )
118
+ self .exclusion_manager .set_use_common_exclusions (use_common )
119
+
120
+ # Save exclusions immediately on change
121
+ self ._save_exclusion_config ()
92
122
93
123
# Regenerate tree if we have a path
94
124
if self .current_path :
@@ -107,7 +137,6 @@ def generate_tree(self, path: str):
107
137
108
138
# Format and display the tree
109
139
self .update_tree_format ()
110
-
111
140
self .window .set_status (f"Directory scanned successfully: { path } " )
112
141
except Exception as e :
113
142
self .window .set_status (f"Error scanning directory: { str (e )} " )
0 commit comments