Skip to content

refactor(app): replace the _apply_to_live_widgets if/elif cascade with table dispatch #2408

Description

@wkentaro

This was generated by AI during triage.

Context

Noticed while reviewing #2403, which expands the Settings dialog from 2 tabs to 5.

MainWindow._apply_to_live_widgets(key_path) is the single place that pushes a changed config key onto the live widgets. Every new settings row that applies immediately has to add a branch to it. After #2403 it is a ~12-branch if/elif cascade over key_path, covering color_theme, the five menu toggles, canvas.fill_drawing, canvas.crosshair, shape.show_labels, canvas.allow_out_of_bounds_points, shape.point_size, the two color keys, labels, flags, and the label-behavior group.

Problem

The cascade is the growth point for the whole settings feature: adding a row means editing this one method, so it accumulates unrelated reasons to change (canvas setters, dock rebuilds, label-dialog rebuilds, theming). It is a pre-existing shape, not a regression introduced by #2403, but that PR roughly doubled its length and made the trend visible.

#2403 already established the fix locally: it replaced five near-identical menu-toggle branches with a toggle_actions dict lookup. The same table-dispatch idea generalises to the rest.

elif key_path in toggle_actions:
    self._sync_action_checked(
        action=toggle_actions[key_path], checked=self._config[key_path[0]]
    )

Secondary nit in the same method: toggle_actions is rebuilt on every call even though it is a fixed mapping of key_path to QAction.

Suggested change

Map key_path to a small applier callable (dict, or a field on schema.Setting) so a new settings row registers its live-apply behaviour next to its schema entry instead of appending a branch here. Keep the genuinely multi-step cases (labels, flags) as their own named methods that the table points at.

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-humanissue: Requires human implementationtype: taskissue: For other work: maintenance, refactor, docs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions