Skip to content

Add Light/Dark theme switching mechanism - #899

Closed
hesamkal2009 wants to merge 1 commit into
paolosalvatori:mainfrom
hesamkal2009:fix/theme-switching
Closed

hesamkal2009 wants to merge 1 commit into
paolosalvatori:mainfrom
hesamkal2009:fix/theme-switching

Conversation

@hesamkal2009

@hesamkal2009 hesamkal2009 commented Sep 24, 2026 •

Copy link
Copy Markdown

Summary

Adds light and dark theme support to Service Bus Explorer.

Changes

  • Added View > Theme with Light and Dark options.
  • Persisted the selected theme as a per-user setting.
  • Restored the selected theme when the application starts.
  • Added theme-aware rendering for custom UI components such as the message delete button.
  • Updated the README with usage instructions and the current limitation.

Known limitation

Changing the theme currently restarts the application. This is intentional because some existing WinForms controls do not reliably repaint all of their child controls when the theme is changed dynamically.

The selected theme is persisted before the restart, so the application comes back using the newly selected theme.

A future improvement could apply the theme without restarting the application.

@hesamkal2009
hesamkal2009 force-pushed the fix/theme-switching branch 2 times, most recently from 979aea5 to b153e76 Compare September 24, 2026 23:30
@hesamkal2009 hesamkal2009 changed the title Add a theme switching mechanism Add Light/Dark theme switching mechanism Sep 25, 2026
@ErikMogensen

Copy link
Copy Markdown
Collaborator

Thanks @hesamkal2009!

Please provide screenshots of some of the dialogs/windows in the app so we see how it looks like.

@hesamkal2009

hesamkal2009 commented Sep 25, 2026 •

Copy link
Copy Markdown
Author

My pleasure, @ErikMogensen.

Sure, the Default/Light theme is intact; I just added the Dark theme. :)

It's not perfect by any means, but at least it saves my eyes when I work at night in a dark room.

image image image image image image

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Dark-theme rendering, restart argument handling, generated settings access, and control retention contain unresolved defects.

Review effort: Balanced
Findings: 4 Medium severity

Open (4)
What changed in this PR

Adds persistent light/dark theme selection with restart-based application.

Changes:

  • Introduces centralized WinForms theme application and restoration.
  • Adds theme selection, persistence, restart behavior, and themed custom rendering.
  • Documents appearance options and adds parsing tests.
File Description
ThemeManager.cs Implements theme state and control styling.
DataGridViewDeleteButtonCell.cs Adds theme-aware rendering.
Settings.settings Defines the user theme setting.
Settings.Designer.cs Exposes the generated setting.
Program.cs Initializes theming at startup.
MainForm.cs Adds theme menu and restart flow.
ThemeManagerTests.cs Tests theme parsing.
README.md Documents theme usage.
Files not reviewed (1)
  • src/ServiceBusExplorer/Properties/Settings.Designer.cs: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/ServiceBusExplorer/Forms/MainForm.cs Outdated
Comment thread src/ServiceBusExplorer/Properties/Settings.Designer.cs Outdated
Comment thread src/ServiceBusExplorer/UIHelpers/ThemeManager.cs Outdated
Comment thread src/ServiceBusExplorer/UIHelpers/ThemeManager.cs
@hesamkal2009

Copy link
Copy Markdown
Author

Hi @ErikMogensen!

Apologies if I shouldn't be tagging you directly—I wasn't sure who to tag, and since you kindly provided comments earlier, I thought I'd reach out to you. Sorry for any inconvenience, and thank you for your time!

I wanted to follow up on this PR, as I’ve addressed the previous issues/feedback. 🙂

@ErikMogensen

Copy link
Copy Markdown
Collaborator

@hesamkal2009, this is non-paid work on my free time so sometimes it takes time. That said, thanks for providing this PR 👍🏻 . Having a dark theme would be great.

I ran Claude Code on it and it had three issues with it. It is seems unlikely that any one of them would happen, but on the other hand they seem easy to fix so please fix them:

The review found 3 bugs in the theme switching implementation:

🔴 CRITICAL: Unhandled exception in Process.Start (MainForm.cs:385)

Process.Start() can throw multiple exception types (FileNotFoundException, Win32Exception, InvalidOperationException, OutOfMemoryException) when application restart fails. With no exception handling, if the restart fails (file not found, access denied, etc.), an unhandled exception crashes the app. The theme preference is saved but the restart won't occur, leaving users confused about whether the change took effect.

🟡 MEDIUM: Missing null check for viewToolStripMenuItem (MainForm.cs:350)

The code calls viewToolStripMenuItem.DropDownItems.Insert(2, themeMenuItem) without verifying the menu item isn't null. While InitializeComponent() should initialize it, there's no defensive check. A NullReferenceException would occur if the menu structure changes or initialization fails.

🔵 LOW: GetCurrentParent() return value not null-checked (MainForm.cs:364)

The code calls selectedItem.GetCurrentParent().Items without checking if GetCurrentParent() returns null. While unlikely based on WinForms guarantees, this could theoretically throw a NullReferenceException.

@hesamkal2009

Copy link
Copy Markdown
Author

@hesamkal2009, this is non-paid work on my free time so sometimes it takes time. That said, thanks for providing this PR 👍🏻 . Having a dark theme would be great.

I ran Claude Code on it and it had three issues with it. It is seems unlikely that any one of them would happen, but on the other hand they seem easy to fix so please fix them:

The review found 3 bugs in the theme switching implementation:

🔴 CRITICAL: Unhandled exception in Process.Start (MainForm.cs:385)

Process.Start() can throw multiple exception types (FileNotFoundException, Win32Exception, InvalidOperationException, OutOfMemoryException) when application restart fails. With no exception handling, if the restart fails (file not found, access denied, etc.), an unhandled exception crashes the app. The theme preference is saved but the restart won't occur, leaving users confused about whether the change took effect.

🟡 MEDIUM: Missing null check for viewToolStripMenuItem (MainForm.cs:350)

The code calls viewToolStripMenuItem.DropDownItems.Insert(2, themeMenuItem) without verifying the menu item isn't null. While InitializeComponent() should initialize it, there's no defensive check. A NullReferenceException would occur if the menu structure changes or initialization fails.

🔵 LOW: GetCurrentParent() return value not null-checked (MainForm.cs:364)

The code calls selectedItem.GetCurrentParent().Items without checking if GetCurrentParent() returns null. While unlikely based on WinForms guarantees, this could theoretically throw a NullReferenceException.

Thank you, @ErikMogensen, for your feedback! I genuinely appreciate your dedication, as well as the efforts of all maintainers who help nurture free software and support the community.

I apologize if my previous comment caused any inconvenience. I wanted to mention it because there isn't an "Ask for re-review" button available on this PR.

I'll address the mentioned issues.
Wishing you a wonderful weekend!

Docs/tests: update theme docs and expand ThemeManager.ParseConfiguredMode tests to cover null/empty/casing and invalid values

Theme: apply FastColoredTextBox token colors and fix config parsing (cachedMode)

Theme: improve FastColoredTextBox colors for dark mode (reflection-based, best-effort)

Theme: improve confirmation and restart flow; guard shown handler; cache theme config and avoid DropDown allocations

Fix theme switching: handle Process.Start exceptions; null-check viewToolStripMenuItem and menu parent; prevent duplicate Theme menu insertion

Theme: improve FastColoredTextBox bracket and selection colors; make PropertyGrid readable in dark mode

Theme: remove invalid bracket style code that was causing compile errors

- MarkerStyle does not support BackBrush property
- Bracket highlighting is managed by selection color
- All 117 tests passing
@hesamkal2009

Copy link
Copy Markdown
Author

I love what @larrycaw made in #902.
It looks nice and slick, and it doesn't require restarting the app. A logical decision, with the maintainers' approval, would be to abandon this PR and merge that PR.

@ErikMogensen

Copy link
Copy Markdown
Collaborator

Thanks @hesamkal2009! Happy that you compared the PRs. It is, of course, not a problem to close this PR.

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.

3 participants