Skip to content

Commit 9d37708

Browse files
committed
refactor(theme): streamline color picker integration and adjust UI element
1 parent 6339e06 commit 9d37708

9 files changed

Lines changed: 41 additions & 113 deletions

source/RevitDevTool/Theme/Theme.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
<ResourceDictionary.MergedDictionaries>
66
<ui:ThemesDictionary />
77
<ui:ControlsDictionary />
8+
<ResourceDictionary Source="pack://application:,,,/ColorPicker;component/styles/defaultcolorpickerstyle.xaml" />
89
</ResourceDictionary.MergedDictionaries>
910
</ResourceDictionary>

source/RevitDevTool/Theme/ThemeWatcher.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ namespace RevitDevTool.Theme;
1414
public sealed class ThemeWatcher
1515
{
1616
public static readonly ThemeWatcher Instance = new();
17-
1817
private readonly List<FrameworkElement> _observedElements = [];
18+
private readonly HashSet<FrameworkElement> _uniqueObservedElements = [];
1919

2020
public void Initialize()
2121
{
2222
UiApplication.Current.Resources = new ResourceDictionary
2323
{
2424
Source = new Uri("pack://application:,,,/RevitDevTool;component/Theme/Theme.xaml", UriKind.Absolute)
2525
};
26-
2726
#if REVIT2024_OR_GREATER
2827
Context.UiApplication.ThemeChanged += Instance.OnRevitThemeChanged;
2928
#endif
@@ -74,11 +73,7 @@ private void OnWatchedElementLoaded(object sender, RoutedEventArgs e)
7473
_observedElements.Add(element);
7574

7675
var requiredTheme = GetRequiredTheme();
77-
if (GetFrameworkElementTheme(element) == requiredTheme)
78-
{
79-
return;
80-
}
81-
76+
if (GetFrameworkElementTheme(element) == requiredTheme && !_uniqueObservedElements.Add(element)) return;
8277
ApplicationThemeManager.Apply(element);
8378
ApplicationThemeManager.Apply(requiredTheme);
8479
}
@@ -87,6 +82,10 @@ private void OnWatchedElementUnloaded(object sender, RoutedEventArgs e)
8782
{
8883
var element = (FrameworkElement) sender;
8984
_observedElements.Remove(element);
85+
if (element is Window)
86+
{
87+
_uniqueObservedElements.Clear();
88+
}
9089
}
9190

9291
public void ApplyTheme()

source/RevitDevTool/View/Settings/BoundingBoxVisualizationSettingsView.xaml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,18 @@
1111
d:DesignWidth="600"
1212
mc:Ignorable="d">
1313

14-
<Page.Resources>
15-
<ResourceDictionary>
16-
<ResourceDictionary.MergedDictionaries>
17-
<ResourceDictionary>
18-
<ResourceDictionary.MergedDictionaries>
19-
<ResourceDictionary Source="pack://application:,,,/ColorPicker;component/Styles/DefaultColorPickerStyle.xaml" />
20-
</ResourceDictionary.MergedDictionaries>
21-
</ResourceDictionary>
22-
</ResourceDictionary.MergedDictionaries>
23-
</ResourceDictionary>
24-
</Page.Resources>
25-
2614
<StackPanel Margin="20">
2715
<DockPanel>
2816
<Grid
29-
Width="300"
17+
Width="150"
3018
Height="32"
3119
DockPanel.Dock="Right">
3220
<colorPicker:PortableColorPicker
3321
SelectedColor="{Binding SurfaceColor, Mode=TwoWay, Delay=10}"
3422
ShowAlpha="False"
3523
ShowFractionalPart="False"
3624
SmallChange="5"
37-
Style="{StaticResource DefaultColorPickerStyle}"
25+
Style="{DynamicResource DefaultColorPickerStyle}"
3826
UseHintColor="False" />
3927
</Grid>
4028
<CheckBox
@@ -60,15 +48,15 @@
6048
</StackPanel>
6149
<DockPanel Margin="0,8,0,0">
6250
<Grid
63-
Width="300"
51+
Width="150"
6452
Height="32"
6553
DockPanel.Dock="Right">
6654
<colorPicker:PortableColorPicker
6755
SelectedColor="{Binding EdgeColor, Mode=TwoWay, Delay=10}"
6856
ShowAlpha="False"
6957
ShowFractionalPart="False"
7058
SmallChange="5"
71-
Style="{StaticResource DefaultColorPickerStyle}"
59+
Style="{DynamicResource DefaultColorPickerStyle}"
7260
UseHintColor="False" />
7361
</Grid>
7462
<CheckBox
@@ -78,15 +66,15 @@
7866
</DockPanel>
7967
<DockPanel Margin="0,8,0,0">
8068
<Grid
81-
Width="300"
69+
Width="150"
8270
Height="32"
8371
DockPanel.Dock="Right">
8472
<colorPicker:PortableColorPicker
8573
SelectedColor="{Binding AxisColor, Mode=TwoWay, Delay=10}"
8674
ShowAlpha="False"
8775
ShowFractionalPart="False"
8876
SmallChange="5"
89-
Style="{StaticResource DefaultColorPickerStyle}"
77+
Style="{DynamicResource DefaultColorPickerStyle}"
9078
UseHintColor="False" />
9179
</Grid>
9280
<CheckBox

source/RevitDevTool/View/Settings/FaceVisualizationSettingsView.xaml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,18 @@
1111
d:DesignWidth="600"
1212
mc:Ignorable="d">
1313

14-
<Page.Resources>
15-
<ResourceDictionary>
16-
<ResourceDictionary.MergedDictionaries>
17-
<ResourceDictionary>
18-
<ResourceDictionary.MergedDictionaries>
19-
<ResourceDictionary Source="pack://application:,,,/ColorPicker;component/Styles/DefaultColorPickerStyle.xaml" />
20-
</ResourceDictionary.MergedDictionaries>
21-
</ResourceDictionary>
22-
</ResourceDictionary.MergedDictionaries>
23-
</ResourceDictionary>
24-
</Page.Resources>
25-
2614
<StackPanel Margin="20">
2715
<DockPanel>
2816
<Grid
29-
Width="300"
17+
Width="150"
3018
Height="32"
3119
DockPanel.Dock="Right">
3220
<colorPicker:PortableColorPicker
3321
SelectedColor="{Binding SurfaceColor, Mode=TwoWay, Delay=10}"
3422
ShowAlpha="False"
3523
ShowFractionalPart="False"
3624
SmallChange="5"
37-
Style="{StaticResource DefaultColorPickerStyle}"
25+
Style="{DynamicResource DefaultColorPickerStyle}"
3826
UseHintColor="False" />
3927
</Grid>
4028
<CheckBox
@@ -76,15 +64,15 @@
7664
</StackPanel>
7765
<DockPanel Margin="0,8,0,0">
7866
<Grid
79-
Width="300"
67+
Width="150"
8068
Height="32"
8169
DockPanel.Dock="Right">
8270
<colorPicker:PortableColorPicker
8371
SelectedColor="{Binding MeshColor, Mode=TwoWay, Delay=10}"
8472
ShowAlpha="False"
8573
ShowFractionalPart="False"
8674
SmallChange="5"
87-
Style="{StaticResource DefaultColorPickerStyle}"
75+
Style="{DynamicResource DefaultColorPickerStyle}"
8876
UseHintColor="False" />
8977
</Grid>
9078
<CheckBox
@@ -94,15 +82,15 @@
9482
</DockPanel>
9583
<DockPanel Margin="0,8,0,0">
9684
<Grid
97-
Width="300"
85+
Width="150"
9886
Height="32"
9987
DockPanel.Dock="Right">
10088
<colorPicker:PortableColorPicker
10189
SelectedColor="{Binding NormalVectorColor, Mode=TwoWay, Delay=10}"
10290
ShowAlpha="False"
10391
ShowFractionalPart="False"
10492
SmallChange="5"
105-
Style="{StaticResource DefaultColorPickerStyle}"
93+
Style="{DynamicResource DefaultColorPickerStyle}"
10694
UseHintColor="False" />
10795
</Grid>
10896
<CheckBox

source/RevitDevTool/View/Settings/MeshVisualizationSettingsView.xaml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,18 @@
1111
d:DesignWidth="600"
1212
mc:Ignorable="d">
1313

14-
<Page.Resources>
15-
<ResourceDictionary>
16-
<ResourceDictionary.MergedDictionaries>
17-
<ResourceDictionary>
18-
<ResourceDictionary.MergedDictionaries>
19-
<ResourceDictionary Source="pack://application:,,,/ColorPicker;component/Styles/DefaultColorPickerStyle.xaml" />
20-
</ResourceDictionary.MergedDictionaries>
21-
</ResourceDictionary>
22-
</ResourceDictionary.MergedDictionaries>
23-
</ResourceDictionary>
24-
</Page.Resources>
25-
2614
<StackPanel Margin="20">
2715
<DockPanel>
2816
<Grid
29-
Width="300"
17+
Width="150"
3018
Height="32"
3119
DockPanel.Dock="Right">
3220
<colorPicker:PortableColorPicker
3321
SelectedColor="{Binding SurfaceColor, Mode=TwoWay, Delay=10}"
3422
ShowAlpha="False"
3523
ShowFractionalPart="False"
3624
SmallChange="5"
37-
Style="{StaticResource DefaultColorPickerStyle}"
25+
Style="{DynamicResource DefaultColorPickerStyle}"
3826
UseHintColor="False" />
3927
</Grid>
4028
<CheckBox
@@ -76,15 +64,15 @@
7664
</StackPanel>
7765
<DockPanel Margin="0,8,0,0">
7866
<Grid
79-
Width="300"
67+
Width="150"
8068
Height="32"
8169
DockPanel.Dock="Right">
8270
<colorPicker:PortableColorPicker
8371
SelectedColor="{Binding MeshColor, Mode=TwoWay, Delay=10}"
8472
ShowAlpha="False"
8573
ShowFractionalPart="False"
8674
SmallChange="5"
87-
Style="{StaticResource DefaultColorPickerStyle}"
75+
Style="{DynamicResource DefaultColorPickerStyle}"
8876
UseHintColor="False" />
8977
</Grid>
9078
<CheckBox
@@ -94,15 +82,15 @@
9482
</DockPanel>
9583
<DockPanel Margin="0,8,0,0">
9684
<Grid
97-
Width="300"
85+
Width="150"
9886
Height="32"
9987
DockPanel.Dock="Right">
10088
<colorPicker:PortableColorPicker
10189
SelectedColor="{Binding NormalVectorColor, Mode=TwoWay, Delay=10}"
10290
ShowAlpha="False"
10391
ShowFractionalPart="False"
10492
SmallChange="5"
105-
Style="{StaticResource DefaultColorPickerStyle}"
93+
Style="{DynamicResource DefaultColorPickerStyle}"
10694
UseHintColor="False" />
10795
</Grid>
10896
<CheckBox

source/RevitDevTool/View/Settings/PolylineVisualizationSettingsView.xaml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,18 @@
1111
d:DesignWidth="600"
1212
mc:Ignorable="d">
1313

14-
<Page.Resources>
15-
<ResourceDictionary>
16-
<ResourceDictionary.MergedDictionaries>
17-
<ResourceDictionary>
18-
<ResourceDictionary.MergedDictionaries>
19-
<ResourceDictionary Source="pack://application:,,,/ColorPicker;component/Styles/DefaultColorPickerStyle.xaml" />
20-
</ResourceDictionary.MergedDictionaries>
21-
</ResourceDictionary>
22-
</ResourceDictionary.MergedDictionaries>
23-
</ResourceDictionary>
24-
</Page.Resources>
25-
2614
<StackPanel Margin="20">
2715
<DockPanel>
2816
<Grid
29-
Width="300"
17+
Width="150"
3018
Height="32"
3119
DockPanel.Dock="Right">
3220
<colorPicker:PortableColorPicker
3321
SelectedColor="{Binding SurfaceColor, Mode=TwoWay, Delay=10}"
3422
ShowAlpha="False"
3523
ShowFractionalPart="False"
3624
SmallChange="5"
37-
Style="{StaticResource DefaultColorPickerStyle}"
25+
Style="{DynamicResource DefaultColorPickerStyle}"
3826
UseHintColor="False" />
3927
</Grid>
4028
<CheckBox
@@ -76,15 +64,15 @@
7664
</StackPanel>
7765
<DockPanel Margin="0,8,0,0">
7866
<Grid
79-
Width="300"
67+
Width="150"
8068
Height="32"
8169
DockPanel.Dock="Right">
8270
<colorPicker:PortableColorPicker
8371
SelectedColor="{Binding CurveColor, Mode=TwoWay, Delay=10}"
8472
ShowAlpha="False"
8573
ShowFractionalPart="False"
8674
SmallChange="5"
87-
Style="{StaticResource DefaultColorPickerStyle}"
75+
Style="{DynamicResource DefaultColorPickerStyle}"
8876
UseHintColor="False" />
8977
</Grid>
9078
<CheckBox
@@ -94,15 +82,15 @@
9482
</DockPanel>
9583
<DockPanel Margin="0,8,0,0">
9684
<Grid
97-
Width="300"
85+
Width="150"
9886
Height="32"
9987
DockPanel.Dock="Right">
10088
<colorPicker:PortableColorPicker
10189
SelectedColor="{Binding DirectionColor, Mode=TwoWay, Delay=10}"
10290
ShowAlpha="False"
10391
ShowFractionalPart="False"
10492
SmallChange="5"
105-
Style="{StaticResource DefaultColorPickerStyle}"
93+
Style="{DynamicResource DefaultColorPickerStyle}"
10694
UseHintColor="False" />
10795
</Grid>
10896
<CheckBox

source/RevitDevTool/View/Settings/SolidVisualizationSettingsView.xaml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,10 @@
1111
d:DesignWidth="600"
1212
mc:Ignorable="d">
1313

14-
<Page.Resources>
15-
<ResourceDictionary>
16-
<ResourceDictionary.MergedDictionaries>
17-
<ResourceDictionary>
18-
<ResourceDictionary.MergedDictionaries>
19-
<ResourceDictionary Source="/ColorPicker;component/Styles/DefaultColorPickerStyle.xaml" />
20-
</ResourceDictionary.MergedDictionaries>
21-
</ResourceDictionary>
22-
</ResourceDictionary.MergedDictionaries>
23-
</ResourceDictionary>
24-
</Page.Resources>
25-
2614
<StackPanel Margin="20">
2715
<DockPanel>
2816
<Grid
29-
Width="300"
17+
Width="150"
3018
Height="32"
3119
DockPanel.Dock="Right">
3220
<colorPicker:PortableColorPicker
@@ -76,15 +64,15 @@
7664
</StackPanel>
7765
<DockPanel Margin="0,8,0,0">
7866
<Grid
79-
Width="300"
67+
Width="150"
8068
Height="32"
8169
DockPanel.Dock="Right">
8270
<colorPicker:PortableColorPicker
8371
SelectedColor="{Binding EdgeColor, Mode=TwoWay, Delay=10}"
8472
ShowAlpha="False"
8573
ShowFractionalPart="False"
8674
SmallChange="5"
87-
Style="{StaticResource DefaultColorPickerStyle}"
75+
Style="{DynamicResource DefaultColorPickerStyle}"
8876
UseHintColor="False" />
8977
</Grid>
9078
<CheckBox

0 commit comments

Comments
 (0)