Skip to content

GTK: collapse sidebar widget sync into a panel-DA lookup table #409

Description

@JDonaghy

Problem

sync_sidebar_widgets() has a 30+ line match p { SidebarPanel::Git => { da.grab_focus() } ... } block that maps each panel variant to its DrawingArea ref for focus grab, plus a parallel loop for panel box visibility. Every new panel requires adding another arm.

Proposed fix

Store panel DAs in a HashMap<&str, Rc<RefCell<Option<DrawingArea>>>> keyed by panel ID string (e.g. "panel:git"git_sidebar_da_ref). The focus-grab and visibility loops become a single lookup:

if let Some(da_ref) = self.panel_da_map.get(panel_id) {
    if let Some(ref da) = *da_ref.borrow() {
        da.grab_focus();
    }
}

Same for panel box visibility — a parallel panel_box_map.

Context

Identified during #385 GTK sidebar migration (Session 375). The match arms are boilerplate that scales linearly with panel count.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions