Skip to content

refactor: replace fragmented theme system with unified ThemeEngine#320

Merged
datlechin merged 2 commits intomainfrom
refactor/unified-theme-engine
Mar 14, 2026
Merged

refactor: replace fragmented theme system with unified ThemeEngine#320
datlechin merged 2 commits intomainfrom
refactor/unified-theme-engine

Conversation

@datlechin
Copy link
Owner

@datlechin datlechin commented Mar 14, 2026

Summary

  • Replaced 5 fragmented theme files (Theme.swift, DesignConstants.swift, SQLEditorTheme.swift, ToolbarDesignTokens.swift, DataGridFontCache.swift) with the unified ThemeEngine singleton
  • Migrated ~50 view files from hardcoded Theme.*, DesignConstants.*, SQLEditorTheme.* references to ThemeEngine.shared.colors.* / ThemeEngine.shared.activeTheme.*
  • Added HexColor.swift (hex string to NSColor/Color conversion) and ResolvedThemeColors.swift (pre-resolved NSColor cache from theme hex strings)
  • Added ThemePreviewCard.swift (visual thumbnail for theme list) and ThemeEditorFontsSection.swift (font picker with live preview)
  • Moved editor/data grid font settings into the theme system (Settings > Appearance > Fonts tab)
  • Removed font size settings from Editor and Data Grid settings tabs (now in Appearance)

Deleted files

  • Theme.swift — old static color constants
  • DesignConstants.swift — old spacing/sizing constants
  • SQLEditorTheme.swift — old editor color constants
  • ToolbarDesignTokens.swift — old toolbar styling constants
  • DataGridFontCache.swift — moved into ThemeEngine as DataGridFontCacheResolved

Test plan

  • Build succeeds
  • All views render with correct theme colors (editor, data grid, sidebar, toolbar, dialogs)
  • Settings > Appearance: font picker works, changes apply immediately
  • Theme switching applies colors across all views
  • No hardcoded color references remain (old Theme.* / DesignConstants.* patterns)

Summary by CodeRabbit

  • New Features

    • Theme preview card to visualize themes.
    • Theme editor fonts section for customizing editor and grid fonts.
    • Hex color support for flexible theme colors.
  • Changes

    • Centralized theming applied across UI components (spacing, typography, icons, colors).
    • Font controls moved from Editor/Data Grid settings into theme customization.
    • Accent tint removed in favor of system/default accent color.
    • Expanded localization keys for UI text.

@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: da7ea695-2601-4b70-a7cc-10bf67fefdac

📥 Commits

Reviewing files that changed from the base of the PR and between 98cfb16 and ac89fe7.

📒 Files selected for processing (5)
  • TablePro/Theme/HexColor.swift
  • TablePro/Views/Results/DataGridCellFactory.swift
  • TablePro/Views/Results/DataGridView.swift
  • TablePro/Views/Settings/Appearance/ThemeEditorFontsSection.swift
  • TablePro/Views/Settings/ThemePreviewCard.swift

📝 Walkthrough

Walkthrough

This PR centralizes theming into ThemeEngine: removes legacy theme/token files, adds color/hex utilities and theme UI, migrates 40+ views to ThemeEngine.shared for fonts, colors, spacing and icon sizes, introduces a themeDidChange notification and DataGridView theme observer, and removes per-window accent tinting.

Changes

Cohort / File(s) Summary
Theme infra removed
TablePro/Theme/DataGridFontCache.swift, TablePro/Theme/DesignConstants.swift, TablePro/Views/Editor/SQLEditorTheme.swift, TablePro/Theme/ToolbarDesignTokens.swift, TablePro/Theme/Theme.swift
Deleted legacy design tokens, font cache, SQL editor theme, toolbar tokens, and Theme enum; removed many public constants/types previously used across the app.
Theme infra added
TablePro/Theme/HexColor.swift, TablePro/Theme/ResolvedThemeColors.swift, TablePro/Views/Settings/ThemeEditorFontsSection.swift, TablePro/Views/Settings/ThemePreviewCard.swift
Added hex color utilities, resolvers that map theme definitions to platform colors, and UI for editing/previewing fonts and themes.
Core integrations
TablePro/Core/AI/InlineSuggestionManager.swift, TablePro/Core/Vim/VimCursorManager.swift, TablePro/Core/Services/Infrastructure/SettingsNotifications.swift, TablePro/Core/Plugins/PluginManager.swift
Repointed font/color lookups to ThemeEngine.shared; added Notification.Name.themeDidChange; changed plugin brand color fallback to Color.gray.
Editor changes
TablePro/Views/Editor/SQLEditorView.swift, TablePro/Views/Editor/TableProEditorTheme.swift, TablePro/Views/Import/SQLCodePreview.swift
Editor font, wrap, tab width, and line-number settings now come from ThemeEngine.shared; TableProEditorTheme delegates theme creation to ThemeEngine.
Data grid & coordinator
TablePro/Views/Results/DataGridView.swift, TablePro/Views/Results/DataGridCellFactory.swift, TablePro/Views/Results/CellOverlayEditor.swift, plus cell editors
Replaced DataGridFontCache usage with ThemeEngine.shared.dataGridFonts and colors; DataGridView subscribes to .themeDidChange to update fonts/styles; font measurement/mono widths now from ThemeEngine.
Widespread UI theming
(Examples) TablePro/Views/.../AboutView.swift, EmptyStateView.swift, SectionHeaderView.swift, Connection/*, OnboardingContentView.swift, WelcomeWindowView.swift, many other Views/*`
Replaced hard-coded DesignConstants values (fonts, sizes, spacing, icon sizes, colors) with ThemeEngine.shared.activeTheme equivalents across ~40 view files.
Settings UI
TablePro/Views/Settings/DataGridSettingsView.swift, TablePro/Views/Settings/EditorSettingsView.swift
Removed the in-view font configuration sections; font editing moved to the new ThemeEditorFontsSection.
App entry & accent
TablePro/TableProApp.swift
Removed per-window .tint(accentTint) usage and the private accentTint property.
Localization
TablePro/Resources/Localizable.xcstrings
Added many new localization keys for theme UI (typography, spacing, colors); many entries marked stale.
Docs
docs/*/customization/settings.mdx
Removed the Accent color row from settings documentation (multiple locales).

Sequence Diagram(s)

sequenceDiagram
  participant User as User/UI
  participant ThemeEditor as ThemeEditorFontsSection
  participant ThemeEngine as ThemeEngine.shared
  participant Notification as NotificationCenter
  participant View as DataGridView / Other Views

  User->>ThemeEditor: change font/color and save
  ThemeEditor->>ThemeEngine: update active theme
  ThemeEngine->>Notification: post themeDidChange
  Notification->>View: receives themeDidChange
  View->>ThemeEngine: read new fonts/colors
  View->>View: apply visual updates (fonts, spacing, colors)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐇 I nibbled at tokens, fonts, and hue,
Hopped through views to stitch them new,
ThemeEngine hums, a tidy tune,
Colors, sizes, fonts in tune,
A rabbit's hop—refactor's through!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and directly summarizes the main objective: replacing a fragmented theme system with a unified ThemeEngine.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/unified-theme-engine
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@datlechin datlechin merged commit 26bbc97 into main Mar 14, 2026
2 checks passed
@datlechin datlechin deleted the refactor/unified-theme-engine branch March 14, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant