markdown · 5138 bytes Raw Blame History

Global State Audit for Tabs Feature

Overview

This document identifies all global state that needs to be encapsulated into per-tab state.


gtk_app.f90

Per-Tab State (MUST MOVE)

Variable Line Purpose
global_scan_path 58 Current directory being viewed
nav_history(MAX_HISTORY) 65 Navigation history array
nav_history_count 66 Number of entries in history
nav_history_pos 67 Current position in history
navigating_history 68 Flag for back/forward navigation
pending_synthetic_nav 82 Synthetic navigation pending flag
pending_synthetic_child_name 83 Child name for synthetic nav
synthetic_nav_attempts 84 Attempt counter

Global State (STAYS)

Variable Line Purpose Notes
app_ptr 48 GTK application App-level
main_window_ptr 49 Main window App-level
status_label_ptr 50 Status bar label Shared, updated per active tab
progress_bar_ptr 51 Progress bar widget Shared, updated per active tab
path_entry_ptr 52 Path display entry Shared, updated per active tab
app_is_shutting_down 55 Shutdown flag Global state
pending_scan_path 61 Initial scan path Only for startup
back_btn_ptr 71 Back button widget Shared UI
forward_btn_ptr 72 Forward button widget Shared UI
cancel_scan_btn_ptr 73 Cancel button widget Shared UI
info_btn_ptr 76 Info button widget Shared UI
copy_path_btn_ptr 77 Copy path button widget Shared UI
open_finder_btn_ptr 78 Open finder button widget Shared UI
delete_btn_ptr 79 Delete button widget Shared UI

treemap_renderer.f90

Per-Tab State (MUST MOVE)

Variable Line Purpose
current_view_node 57 Pointer to current view in tree
has_data 58 Whether scan data exists
scanned_path 59 Path that was scanned
layout_calculated 67 Layout calculation flag
last_width 68 Last rendered width
last_height 68 Last rendered height
show_file_extensions 71 Toggle for file extensions
use_age_based_coloring 72 Toggle for age-based colors
show_allocated_size 73 Toggle allocated vs actual size
show_hidden_files 74 Toggle dotfiles visibility
use_cushion_shading 75 Toggle 3D vs flat rendering
path_names(MAX_PATH_DEPTH) 80 Path components for navigation
path_depth 81 Depth of current path

Global State (STAYS)

Variable Line Purpose Notes
dir_cache(MAX_CACHE_SIZE) 63 Directory scan cache Shared cache across tabs
cache_count 64 Cache entry count Shared
show_progress_cb 84 Progress callback Shared callbacks
hide_progress_cb 85 Hide progress callback Shared callbacks
update_progress_cb 86 Update progress callback Shared callbacks
scan_completion_cb 87 Completion callback Shared callbacks
widget_for_redraw 90 Drawing widget pointer Shared widget

progressive_scanner.f90

Per-Tab State (MUST MOVE)

Variable Line Purpose
show_hidden_files 15 Toggle hidden files in scan
scan_state 43 Complete scan state (queue, progress, root node)
scan_idle_id 46 GTK idle callback ID for cancellation

Global State (STAYS)

Variable Line Purpose Notes
update_callback 66 Scan update callback Shared callback
complete_callback 67 Scan completion callback Shared callback
initial_level_cb 68 Initial level callback Shared callback

Summary

Total Variables to Move: 29

gtk_app.f90: 8 variables treemap_renderer.f90: 13 variables progressive_scanner.f90: 3 variables (including entire scan_state struct)

Critical Observations

  1. Scan State is Complex: The scan_state in progressive_scanner.f90 is a large struct containing:

    • Queue for breadth-first scanning
    • Progress tracking
    • Root node pointer
    • All scan context

    This entire structure needs to be per-tab.

  2. View Settings Are Per-Tab: Each tab should remember its own:

    • Show/hide extensions
    • Flat vs cushioned rendering
    • Hidden files visibility
    • Color scheme
  3. Navigation History is Per-Tab: Each tab maintains its own back/forward history.

  4. Cache Can Stay Global: The directory scan cache can be shared across tabs for efficiency.

  5. Widget Pointers Stay Global: All GTK widget pointers stay global, but their content is updated when switching tabs.


Next Steps

  1. Create tab_state type in tab_manager.f90 containing all 29 variables
  2. Create tabs(MAX_TABS) array to hold tab states
  3. Add active_tab_index to track current tab
  4. Refactor all functions to operate on tab state instead of globals
  5. Create tab switching logic to swap active state
View source
1 # Global State Audit for Tabs Feature
2
3 ## Overview
4 This document identifies all global state that needs to be encapsulated into per-tab state.
5
6 ---
7
8 ## gtk_app.f90
9
10 ### Per-Tab State (MUST MOVE)
11 | Variable | Line | Purpose |
12 |----------|------|---------|
13 | `global_scan_path` | 58 | Current directory being viewed |
14 | `nav_history(MAX_HISTORY)` | 65 | Navigation history array |
15 | `nav_history_count` | 66 | Number of entries in history |
16 | `nav_history_pos` | 67 | Current position in history |
17 | `navigating_history` | 68 | Flag for back/forward navigation |
18 | `pending_synthetic_nav` | 82 | Synthetic navigation pending flag |
19 | `pending_synthetic_child_name` | 83 | Child name for synthetic nav |
20 | `synthetic_nav_attempts` | 84 | Attempt counter |
21
22 ### Global State (STAYS)
23 | Variable | Line | Purpose | Notes |
24 |----------|------|---------|-------|
25 | `app_ptr` | 48 | GTK application | App-level |
26 | `main_window_ptr` | 49 | Main window | App-level |
27 | `status_label_ptr` | 50 | Status bar label | Shared, updated per active tab |
28 | `progress_bar_ptr` | 51 | Progress bar widget | Shared, updated per active tab |
29 | `path_entry_ptr` | 52 | Path display entry | Shared, updated per active tab |
30 | `app_is_shutting_down` | 55 | Shutdown flag | Global state |
31 | `pending_scan_path` | 61 | Initial scan path | Only for startup |
32 | `back_btn_ptr` | 71 | Back button widget | Shared UI |
33 | `forward_btn_ptr` | 72 | Forward button widget | Shared UI |
34 | `cancel_scan_btn_ptr` | 73 | Cancel button widget | Shared UI |
35 | `info_btn_ptr` | 76 | Info button widget | Shared UI |
36 | `copy_path_btn_ptr` | 77 | Copy path button widget | Shared UI |
37 | `open_finder_btn_ptr` | 78 | Open finder button widget | Shared UI |
38 | `delete_btn_ptr` | 79 | Delete button widget | Shared UI |
39
40 ---
41
42 ## treemap_renderer.f90
43
44 ### Per-Tab State (MUST MOVE)
45 | Variable | Line | Purpose |
46 |----------|------|---------|
47 | `current_view_node` | 57 | Pointer to current view in tree |
48 | `has_data` | 58 | Whether scan data exists |
49 | `scanned_path` | 59 | Path that was scanned |
50 | `layout_calculated` | 67 | Layout calculation flag |
51 | `last_width` | 68 | Last rendered width |
52 | `last_height` | 68 | Last rendered height |
53 | `show_file_extensions` | 71 | Toggle for file extensions |
54 | `use_age_based_coloring` | 72 | Toggle for age-based colors |
55 | `show_allocated_size` | 73 | Toggle allocated vs actual size |
56 | `show_hidden_files` | 74 | Toggle dotfiles visibility |
57 | `use_cushion_shading` | 75 | Toggle 3D vs flat rendering |
58 | `path_names(MAX_PATH_DEPTH)` | 80 | Path components for navigation |
59 | `path_depth` | 81 | Depth of current path |
60
61 ### Global State (STAYS)
62 | Variable | Line | Purpose | Notes |
63 |----------|------|---------|-------|
64 | `dir_cache(MAX_CACHE_SIZE)` | 63 | Directory scan cache | Shared cache across tabs |
65 | `cache_count` | 64 | Cache entry count | Shared |
66 | `show_progress_cb` | 84 | Progress callback | Shared callbacks |
67 | `hide_progress_cb` | 85 | Hide progress callback | Shared callbacks |
68 | `update_progress_cb` | 86 | Update progress callback | Shared callbacks |
69 | `scan_completion_cb` | 87 | Completion callback | Shared callbacks |
70 | `widget_for_redraw` | 90 | Drawing widget pointer | Shared widget |
71
72 ---
73
74 ## progressive_scanner.f90
75
76 ### Per-Tab State (MUST MOVE)
77 | Variable | Line | Purpose |
78 |----------|------|---------|
79 | `show_hidden_files` | 15 | Toggle hidden files in scan |
80 | `scan_state` | 43 | Complete scan state (queue, progress, root node) |
81 | `scan_idle_id` | 46 | GTK idle callback ID for cancellation |
82
83 ### Global State (STAYS)
84 | Variable | Line | Purpose | Notes |
85 |----------|------|---------|-------|
86 | `update_callback` | 66 | Scan update callback | Shared callback |
87 | `complete_callback` | 67 | Scan completion callback | Shared callback |
88 | `initial_level_cb` | 68 | Initial level callback | Shared callback |
89
90 ---
91
92 ## Summary
93
94 ### Total Variables to Move: 29
95
96 **gtk_app.f90**: 8 variables
97 **treemap_renderer.f90**: 13 variables
98 **progressive_scanner.f90**: 3 variables (including entire scan_state struct)
99
100 ### Critical Observations
101
102 1. **Scan State is Complex**: The `scan_state` in progressive_scanner.f90 is a large struct containing:
103 - Queue for breadth-first scanning
104 - Progress tracking
105 - Root node pointer
106 - All scan context
107
108 This entire structure needs to be per-tab.
109
110 2. **View Settings Are Per-Tab**: Each tab should remember its own:
111 - Show/hide extensions
112 - Flat vs cushioned rendering
113 - Hidden files visibility
114 - Color scheme
115
116 3. **Navigation History is Per-Tab**: Each tab maintains its own back/forward history.
117
118 4. **Cache Can Stay Global**: The directory scan cache can be shared across tabs for efficiency.
119
120 5. **Widget Pointers Stay Global**: All GTK widget pointers stay global, but their content is updated when switching tabs.
121
122 ---
123
124 ## Next Steps
125
126 1. Create `tab_state` type in `tab_manager.f90` containing all 29 variables
127 2. Create `tabs(MAX_TABS)` array to hold tab states
128 3. Add `active_tab_index` to track current tab
129 4. Refactor all functions to operate on tab state instead of globals
130 5. Create tab switching logic to swap active state