Skip to content

SidebarSystem migration: Source Control panel #321

Description

@JDonaghy

Summary

Migrate the Source Control panel from hand-rolled section navigation, scroll, and collapse state to quadraui::compose::SidebarSystem.

The SC panel has the most state machine code of any sidebar (~641 lines of navigation/input handling). It uses source_control_to_tree_view() with Decoration::Header sections (Staged, Changes, Worktrees, Log). SidebarSystem replaces the core section-walk, scroll, collapse, and selection logic — the domain-specific handlers (stage, commit, push, discard) remain on the engine and dispatch from SidebarEvent matches.

Prereqs

Engine fields replaced by SidebarSystem

Field Purpose SidebarSystem equivalent
sc_selected flat row index per-section selection
sc_sections_expanded: [bool; 4] collapse state SidebarSystem internal collapse
sc_has_focus keyboard focus SidebarSystem focus state

Fields that remain (domain-specific): sc_file_statuses, sc_worktrees, sc_log, sc_ahead/behind, sc_commit_message, sc_commit_cursor, sc_commit_input_active, sc_button_focused/hovered, sc_branch_picker_*, sc_help_open, sc_diff_rx, sc_diff_pending_win.

Migration steps

  1. Define 4 SidebarSectionDefs: "staged", "changes", "worktrees", "log"
  2. Each frame: call sidebar.set_rows(section, rows) from source_control_to_tree_view() data
  3. Replace the j/k/Tab/Enter navigation in handle_sc_key() with sidebar.handle() + SidebarEvent dispatch
  4. Keep domain actions (s stage, d discard, c commit, p push, etc.) as post-event handlers that match on SidebarEvent::RowSelected
  5. Remove the 3 engine fields listed above
  6. The commit input sub-mode (sc_commit_input_active) is orthogonal — it intercepts before SidebarSystem and stays as-is
  7. TUI + GTK: replace bespoke tree paint with sidebar.render(backend, rect)
  8. Update tests in source_control.rs

Complexity note

SC has the richest interaction surface: commit input mode, branch picker popup, button bar keyboard nav, and help dialog. These are not sidebar state machine concerns — they are modal overlays that intercept before the sidebar handler runs. The migration only replaces the section/scroll/selection plumbing, which is the duplicated part.

Key files

  • src/core/engine/mod.rs — remove sc_selected, sc_sections_expanded, sc_has_focus
  • src/core/engine/source_control.rs — replace navigation in handle_sc_key(), keep domain actions
  • src/render.rs — adapt source_control_to_tree_view() to feed SidebarSystem::set_rows()
  • src/tui_main/panels.rs — replace SC render
  • src/main.rs — replace GTK SC render

Reference

See JDonaghy/quadraui#63 for the complete migration guide with code examples.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestinfrastructureBuild, CI, distributionuiUI/rendering

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions