Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure DevDiagnostics' owned windows honor theme changes #3790

Merged
merged 4 commits into from
Sep 9, 2024

Conversation

andreww-msft
Copy link
Contributor

@andreww-msft andreww-msft commented Sep 5, 2024

Summary of the pull request

Prior to this, all the theme-related work was done in BarWindow, but this didn't accommodate any other windows. We want internal tool windows to follow the theme of the main BarWindow, regardless of whether the change is from the app's own Settings or from system-wide personalization changes. To achieve this, I created a new ThemeAwareWindow class (derived from WindowEx) to abstract all the theme-related work, including for custom chrome. We also want general consistency between the main BarWindow and any other internal windows, and we can use this abstracted class to achieve this. BarWindow now derives from this, as does the first internal tool window, ClipboardMonitoringWindow. Theme changes will now propagate from the BarWindow to internal tool windows.

Any future tool windows should follow this same pattern:

  1. Derive the tool window from ThemeAwareWindow.
  2. Define a grid or panel for the icon and title (because this window sets ExtendsContentIntoTitleBar and HideIconAndSystemMenu).
  3. When the tool window is created, add it to the list of related windows for the BarWindow by calling AddRelatedWindow (to be done wherever the window is created).
  4. When the tool window is closed, remove the tool window from the list of related windows for the BarWindow (to be done in the Closed handler in the window class).
  5. See ClipboardMonitoringWindow for an example.

Closes #3718

Copy link
Contributor

@jaholme jaholme left a comment

Choose a reason for hiding this comment

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

:shipit:

Comment on lines +17 to 21
private void ThemeAwareWindow_Closed(object sender, WindowEventArgs args)
{
var barWindow = Application.Current.GetService<PrimaryWindow>().DBarWindow;
barWindow?.RemoveRelatedWindow(this);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't this be handled in the base class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because BarWindow is also derived from the same base class, and it probably isn't right for the base class to have knowledge of its derived classes.

Comment on lines +24 to +25
* 3. Add the tool window to the list of related windows for the BarWindow by calling AddRelatedWindow.
* 4. Remove the tool window from the list of related windows for the BarWindow when the tool window is closed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Both of these seem like candidates for code reusability. Maybe the base class should do this in some manner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue here is that both the main BarWindow and the tool windows derive from the same base class. You could argue that I should separate the common theme behavior from the related-window behavior - and I wouldn't disagree, but we can't derive a window class from multiple classes.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could hardcode the base class to recognize BarWindow, since it is only "one" whereas the others are dynamically "many". Also, you could look into Generics and include the BarWindow class as a type argument to do something similar but less hardcoded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I see this PR as temporary. It fixes the issues, but I will update it, incorporating this feedback, once we move to WAS 1.6, per new issue: #3803

@andreww-msft andreww-msft merged commit 323a008 into main Sep 9, 2024
4 checks passed
@andreww-msft andreww-msft deleted the user/andreww/ToolWindow-themes branch September 9, 2024 20:06
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Height="31">
<Image Source="/Images/dd.ico" Height="16" Width="16" Margin="8,2,0,0" VerticalAlignment="Center"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

What are these changes for? Why are we adding an icon to this clipboard window? I thought our text was already getting crunchy.... does this make it worse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order to leverage the same theme-awareness, I made this view the same as BarWindow in respect of ExtendsContentIntoTitleBar, hence had to add back the icon/title we already had. I will clean this all up once we move to WAS 1.6 later (#3803 tracking)- there's also some overlap with tool-window consistency (#3805 tracking), and the two should probably be done toghether.

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.

Clipboard monitor window doesn't honor theme settings
4 participants