@@ -5,6 +5,8 @@ import ignore, { Ignore } from 'ignore'
55import {
66 CONTEXT_CHECKED_PATHS_STATE_KEY ,
77 CONTEXT_CHECKED_TIMESTAMPS_STATE_KEY ,
8+ CONTEXT_CHECKED_PATHS_FRF_STATE_KEY ,
9+ CONTEXT_CHECKED_TIMESTAMPS_FRF_STATE_KEY ,
810 RANGES_STATE_KEY
911} from '@/constants/state-keys'
1012import { IGNORE_PATTERNS } from '@/constants/ignore-patterns'
@@ -26,6 +28,13 @@ export interface IWorkspaceProvider {
2628 is_partially_checked ( path : string ) : boolean
2729 get_checked_files ( ) : string [ ]
2830 get_selection_timestamp ( path : string ) : number | undefined
31+ get_export_state ( ) : {
32+ regular : {
33+ checked_files : string [ ]
34+ checked_timestamps : Record < string , number >
35+ }
36+ frf : { checked_files : string [ ] ; checked_timestamps : Record < string , number > }
37+ }
2938}
3039
3140export class WorkspaceProvider
@@ -43,8 +52,47 @@ export class WorkspaceProvider
4352 private _context : vscode . ExtensionContext
4453 private _workspace_roots : string [ ] = [ ]
4554 private _workspace_names : string [ ] = [ ]
46- private _checked_items : Map < string , vscode . TreeItemCheckboxState > = new Map ( )
47- private _checked_timestamps : Map < string , number > = new Map ( )
55+
56+ private _regular_state = {
57+ checked_items : new Map < string , vscode . TreeItemCheckboxState > ( ) ,
58+ checked_timestamps : new Map < string , number > ( ) ,
59+ partially_checked_dirs : new Set < string > ( )
60+ }
61+ private _frf_state = {
62+ checked_items : new Map < string , vscode . TreeItemCheckboxState > ( ) ,
63+ checked_timestamps : new Map < string , number > ( ) ,
64+ partially_checked_dirs : new Set < string > ( )
65+ }
66+ private _is_frf_mode : boolean = false
67+
68+ private get _checked_items ( ) {
69+ return this . _is_frf_mode
70+ ? this . _frf_state . checked_items
71+ : this . _regular_state . checked_items
72+ }
73+ private set _checked_items ( val ) {
74+ if ( this . _is_frf_mode ) this . _frf_state . checked_items = val
75+ else this . _regular_state . checked_items = val
76+ }
77+ private get _checked_timestamps ( ) {
78+ return this . _is_frf_mode
79+ ? this . _frf_state . checked_timestamps
80+ : this . _regular_state . checked_timestamps
81+ }
82+ private set _checked_timestamps ( val ) {
83+ if ( this . _is_frf_mode ) this . _frf_state . checked_timestamps = val
84+ else this . _regular_state . checked_timestamps = val
85+ }
86+ private get _partially_checked_dirs ( ) {
87+ return this . _is_frf_mode
88+ ? this . _frf_state . partially_checked_dirs
89+ : this . _regular_state . partially_checked_dirs
90+ }
91+ private set _partially_checked_dirs ( val ) {
92+ if ( this . _is_frf_mode ) this . _frf_state . partially_checked_dirs = val
93+ else this . _regular_state . partially_checked_dirs = val
94+ }
95+
4896 private _combined_gitignore = ignore ( )
4997 private _user_ignore_patterns : Ignore = ignore ( )
5098 private _user_allow_patterns : Ignore = ignore ( )
@@ -62,7 +110,6 @@ export class WorkspaceProvider
62110 private _opened_from_workspace_view : Set < string > = new Set ( )
63111 private _preview_tabs : Map < string , boolean > = new Map ( )
64112 private _tab_change_handler : vscode . Disposable
65- private _partially_checked_dirs : Set < string > = new Set ( )
66113 private _file_workspace_map : Map < string , string > = new Map ( )
67114 public gitignore_initialization : Promise < void >
68115 public ranges_initialization : Promise < void >
@@ -91,6 +138,14 @@ export class WorkspaceProvider
91138 }
92139 }
93140
141+ public switch_context_state ( is_frf : boolean ) {
142+ if ( this . _is_frf_mode == is_frf ) return
143+ this . _is_frf_mode = is_frf
144+ this . _token_calculator . clear_selected_counts ( )
145+ this . refresh ( )
146+ this . _dispatch_change_events ( )
147+ }
148+
94149 constructor ( params : {
95150 workspace_folders : readonly vscode . WorkspaceFolder [ ]
96151 context : vscode . ExtensionContext
@@ -153,29 +208,75 @@ export class WorkspaceProvider
153208
154209 private async _save_checked_files_state ( ) : Promise < void > {
155210 const checked_paths = this . get_all_checked_paths ( )
211+ const paths_key = this . _is_frf_mode
212+ ? CONTEXT_CHECKED_PATHS_FRF_STATE_KEY
213+ : CONTEXT_CHECKED_PATHS_STATE_KEY
214+ const times_key = this . _is_frf_mode
215+ ? CONTEXT_CHECKED_TIMESTAMPS_FRF_STATE_KEY
216+ : CONTEXT_CHECKED_TIMESTAMPS_STATE_KEY
217+ await this . _context . workspaceState . update ( paths_key , checked_paths )
156218 await this . _context . workspaceState . update (
157- CONTEXT_CHECKED_PATHS_STATE_KEY ,
158- checked_paths
159- )
160- await this . _context . workspaceState . update (
161- CONTEXT_CHECKED_TIMESTAMPS_STATE_KEY ,
219+ times_key ,
162220 Object . fromEntries ( this . _checked_timestamps )
163221 )
164222 }
165223
166224 public load_checked_files_state ( ) {
167- const persisted_checked_paths = this . _context . workspaceState . get < string [ ] > (
168- CONTEXT_CHECKED_PATHS_STATE_KEY
169- )
170- const persisted_timestamps = this . _context . workspaceState . get <
171- Record < string , number >
172- > ( CONTEXT_CHECKED_TIMESTAMPS_STATE_KEY )
225+ const load = async ( ) => {
226+ await this . gitignore_initialization
227+ const prev_mode = this . _is_frf_mode
173228
174- if ( persisted_checked_paths && persisted_checked_paths . length > 0 ) {
175- const timestamps_map = persisted_timestamps
176- ? new Map ( Object . entries ( persisted_timestamps ) )
177- : undefined
178- this . set_checked_files ( persisted_checked_paths , timestamps_map )
229+ this . _is_frf_mode = false
230+ const reg_paths = this . _context . workspaceState . get < string [ ] > (
231+ CONTEXT_CHECKED_PATHS_STATE_KEY
232+ )
233+ const reg_times = this . _context . workspaceState . get <
234+ Record < string , number >
235+ > ( CONTEXT_CHECKED_TIMESTAMPS_STATE_KEY )
236+ if ( reg_paths && reg_paths . length > 0 ) {
237+ await this . set_checked_files (
238+ reg_paths ,
239+ reg_times ? new Map ( Object . entries ( reg_times ) ) : undefined
240+ )
241+ }
242+
243+ this . _is_frf_mode = true
244+ const frf_paths = this . _context . workspaceState . get < string [ ] > (
245+ CONTEXT_CHECKED_PATHS_FRF_STATE_KEY
246+ )
247+ const frf_times = this . _context . workspaceState . get <
248+ Record < string , number >
249+ > ( CONTEXT_CHECKED_TIMESTAMPS_FRF_STATE_KEY )
250+ if ( frf_paths && frf_paths . length > 0 ) {
251+ await this . set_checked_files (
252+ frf_paths ,
253+ frf_times ? new Map ( Object . entries ( frf_times ) ) : undefined
254+ )
255+ }
256+
257+ this . _is_frf_mode = prev_mode
258+ }
259+ load ( )
260+ }
261+
262+ public get_export_state ( ) {
263+ return {
264+ regular : {
265+ checked_files : Array . from ( this . _regular_state . checked_items . entries ( ) )
266+ . filter ( ( [ , state ] ) => state == vscode . TreeItemCheckboxState . Checked )
267+ . map ( ( [ path ] ) => path ) ,
268+ checked_timestamps : Object . fromEntries (
269+ this . _regular_state . checked_timestamps
270+ )
271+ } ,
272+ frf : {
273+ checked_files : Array . from ( this . _frf_state . checked_items . entries ( ) )
274+ . filter ( ( [ , state ] ) => state == vscode . TreeItemCheckboxState . Checked )
275+ . map ( ( [ path ] ) => path ) ,
276+ checked_timestamps : Object . fromEntries (
277+ this . _frf_state . checked_timestamps
278+ )
279+ }
179280 }
180281 }
181282
0 commit comments