Skip to content

Commit 6316fe1

Browse files
committed
Removed caches
1 parent 60c5703 commit 6316fe1

File tree

2 files changed

+58
-84
lines changed

2 files changed

+58
-84
lines changed

src/Files.App.Controls/ThemedIcon/ThemedIcon.Properties.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public ThemedIconColorType IconColorType
179179

180180
// <summary>
181181
/// Gets or sets a value indicating the Icon's design size.
182-
/// </summary>
182+
/// </summary>
183183
public double IconSize
184184
{
185185
get => (double)GetValue(IconSizeProperty);
@@ -190,16 +190,16 @@ public double IconSize
190190

191191
/// <summary>
192192
/// Gets or sets a value indicating whether the Icon should use Toggled states.
193-
/// </summary>
193+
/// </summary>
194194
public ToggleBehaviors ToggleBehavior
195195
{
196-
get => (ToggleBehaviors)GetValue( ToggleBehaviorProperty );
197-
set => SetValue( ToggleBehaviorProperty , value);
196+
get => (ToggleBehaviors)GetValue(ToggleBehaviorProperty);
197+
set => SetValue(ToggleBehaviorProperty, value);
198198
}
199199

200200
/// <summary>
201201
/// Gets or sets a value indicating whether the Icon should use Filled states.
202-
/// </summary>
202+
/// </summary>
203203
public bool IsFilled
204204
{
205205
get => (bool)GetValue(IsFilledProperty);
@@ -208,7 +208,7 @@ public bool IsFilled
208208

209209
/// <summary>
210210
/// Gets or sets a value indicating whether the Icon is in HighContrast state.
211-
/// </summary>
211+
/// </summary>
212212
public bool IsHighContrast
213213
{
214214
get => (bool)GetValue(IsHighContrastProperty);
@@ -246,7 +246,7 @@ protected virtual void OnOutlineIconPropertyChanged(string oldValue, string newV
246246
protected virtual void OnColorPropertyChanged(Brush oldValue, Brush newValue)
247247
{
248248
UpdateIconTypeStates();
249-
}
249+
}
250250

251251
// Enum changed events
252252

@@ -261,27 +261,27 @@ protected virtual void OnIconColorTypePropertyChanged(ThemedIconColorType oldVal
261261
}
262262

263263
// Double changed events
264-
264+
265265
protected virtual void OnIconSizePropertyChanged(double oldValue, double newValue)
266266
{
267-
IconSizePropertyChanged(newValue);
267+
IconSizePropertyChanged();
268268
}
269269

270270
// Boolean changed events
271271

272-
protected virtual void OnToggleBehaviorPropertyChanged(ToggleBehaviors oldValue , ToggleBehaviors newValue)
272+
protected virtual void OnToggleBehaviorPropertyChanged(ToggleBehaviors oldValue, ToggleBehaviors newValue)
273273
{
274-
ToggleBehaviorChanged(newValue);
274+
ToggleBehaviorChanged();
275275
}
276276

277277
protected virtual void OnIsFilledPropertyChanged(bool oldValue, bool newValue)
278278
{
279-
FilledChanged(newValue);
279+
FilledChanged();
280280
}
281281

282282
protected virtual void OnIsHighContrastPropertyChanged(bool oldValue, bool newValue)
283283
{
284-
HighContrastChanged(newValue);
284+
HighContrastChanged();
285285
}
286286

287287
// Object changed events

src/Files.App.Controls/ThemedIcon/ThemedIcon.cs

Lines changed: 45 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ namespace Files.App.Controls
1818
/// </summary>
1919
public partial class ThemedIcon : Control
2020
{
21-
private bool _isHighContrast;
22-
private ToggleBehaviors _toggleBehavior;
23-
private bool _ownerToggled;
24-
private bool _isEnabled;
25-
private bool _isFilled;
26-
private double _iconSize;
27-
28-
private ToggleButton? ownerToggleButton = null;
21+
private bool _ownerToggled;
22+
private bool _isEnabled;
23+
24+
private ToggleButton? ownerToggleButton = null;
2925
private AppBarToggleButton? ownerAppBarToggleButton = null;
30-
private Control? ownerControl = null;
26+
private Control? ownerControl = null;
3127

3228
public ThemedIcon()
3329
{
@@ -100,7 +96,7 @@ private void UpdateLayeredIconContent()
10096
Foreground = this.Foreground,
10197
HorizontalAlignment = HorizontalAlignment.Stretch,
10298
VerticalAlignment = VerticalAlignment.Stretch,
103-
LayerSize = _iconSize,
99+
LayerSize = IconSize,
104100
Width = layer.LayerSize,
105101
Height = layer.LayerSize
106102

@@ -120,8 +116,8 @@ private void SetPathData(string partName, string pathData, FrameworkElement elem
120116
if (GetTemplateChild(partName) is Path path)
121117
{
122118
path.Data = geometry;
123-
path.Width = _iconSize;
124-
path.Height = _iconSize;
119+
path.Width = IconSize;
120+
path.Height = IconSize;
125121
}
126122
}
127123

@@ -152,7 +148,7 @@ private void FindOwnerControlStates()
152148
ownerToggleButton.Checked += OwnerControl_IsCheckedChanged;
153149
ownerToggleButton.Unchecked += OwnerControl_IsCheckedChanged;
154150

155-
UpdateOwnerToggle( ownerToggleButton.IsChecked is true);
151+
UpdateOwnerToggle(ownerToggleButton.IsChecked is true);
156152
}
157153

158154
ownerAppBarToggleButton = this.FindAscendant<AppBarToggleButton>();
@@ -162,7 +158,7 @@ private void FindOwnerControlStates()
162158
ownerAppBarToggleButton.Checked += OwnerControl_IsCheckedChanged;
163159
ownerAppBarToggleButton.Unchecked += OwnerControl_IsCheckedChanged;
164160

165-
UpdateOwnerToggle( ownerAppBarToggleButton.IsChecked is true);
161+
UpdateOwnerToggle(ownerAppBarToggleButton.IsChecked is true);
166162
}
167163

168164
ownerControl = this.FindAscendant<Control>();
@@ -182,9 +178,9 @@ private void OwnerControl_IsCheckedChanged(object sender, RoutedEventArgs e)
182178
return;
183179

184180
if (ownerToggleButton is not null)
185-
UpdateOwnerToggle( ownerToggleButton.IsChecked is true);
181+
UpdateOwnerToggle(ownerToggleButton.IsChecked is true);
186182
else if (ownerAppBarToggleButton is not null)
187-
UpdateOwnerToggle( ownerAppBarToggleButton.IsChecked is true);
183+
UpdateOwnerToggle(ownerAppBarToggleButton.IsChecked is true);
188184
}
189185

190186
private void OwnerControl_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
@@ -196,11 +192,8 @@ private void OwnerControl_IsEnabledChanged(object sender, DependencyPropertyChan
196192
EnabledChanged(ownerControl.IsEnabled);
197193
}
198194

199-
private void ToggleBehaviorChanged(ToggleBehaviors value)
195+
private void ToggleBehaviorChanged()
200196
{
201-
// Handles the IsToggled property change
202-
_toggleBehavior = value;
203-
204197
UpdateVisualStates();
205198
}
206199

@@ -211,11 +204,8 @@ private void UpdateOwnerToggle(bool isToggled)
211204
UpdateVisualStates();
212205
}
213206

214-
private void FilledChanged(bool value)
207+
private void FilledChanged()
215208
{
216-
// Handles the IsToggled property change
217-
_isFilled = value;
218-
219209
UpdateVisualStates();
220210
}
221211

@@ -230,15 +220,11 @@ private void OnSizeChanged(object sender, SizeChangedEventArgs e)
230220
// Handles resizing of child layers when Width and Height properties change
231221
}
232222

233-
private void IconSizePropertyChanged(double value)
223+
private void IconSizePropertyChanged()
234224
{
235-
// Code to handle the design time Icon Size changing
236-
_iconSize = value;
237-
238225
UpdateVisualStates();
239226
}
240227

241-
242228
private void EnabledChanged(bool value)
243229
{
244230
// Handles the IsEnabled property change
@@ -247,37 +233,25 @@ private void EnabledChanged(bool value)
247233
UpdateVisualStates();
248234
}
249235

250-
private void ThemeSettings_OnHighContrastChanged(object sender, bool e)
251-
{
252-
HighContrastChanged(e);
253-
}
254-
255-
private void HighContrastChanged(bool value)
236+
private void HighContrastChanged()
256237
{
257-
// handles HighContrast property change
258-
_isHighContrast = value;
259-
260238
UpdateVisualStates();
261239
}
262240

263241
private void InitialIconStateValues()
264242
{
265243
_isEnabled = IsEnabled;
266-
_toggleBehavior = ToggleBehavior;
267-
_isHighContrast = IsHighContrast;
268-
_iconSize = IconSize;
269244
}
270245

271246
private void UpdateIconStates()
272247
{
273-
ToggleBehaviorChanged(_toggleBehavior);
274248
EnabledChanged(_isEnabled);
275-
HighContrastChanged(_isHighContrast);
249+
250+
UpdateVisualStates();
276251
}
277252

278253
private void UpdateVisualStates()
279254
{
280-
// Updates all Icon Visual States.
281255
UpdateIconTypeStates();
282256
UpdateIconColorTypeStates();
283257
}
@@ -287,59 +261,59 @@ private void UpdateIconTypeStates()
287261
// Handles changes to the IconType and setting the correct Visual States.
288262

289263
// If ToggleBehavior is Auto, we check for _ownerToggle
290-
if ( _toggleBehavior == ToggleBehaviors.Auto )
264+
if (ToggleBehavior == ToggleBehaviors.Auto)
291265
{
292-
if ( _ownerToggled is true || _isFilled is true || IsFilled is true )
266+
if (_ownerToggled is true || IsFilled is true)
293267
{
294-
VisualStateManager.GoToState( this , FilledTypeStateName , true );
268+
VisualStateManager.GoToState(this, FilledTypeStateName, true);
295269
return;
296270
}
297-
else if ( _isHighContrast is true || IsHighContrast is true || _isEnabled is false || IsEnabled is false )
271+
else if (IsHighContrast is true || _isEnabled is false || IsEnabled is false)
298272
{
299-
VisualStateManager.GoToState( this , OutlineTypeStateName , true );
300-
VisualStateManager.GoToState( this , DisabledStateName , true );
273+
VisualStateManager.GoToState(this, OutlineTypeStateName, true);
274+
VisualStateManager.GoToState(this, DisabledStateName, true);
301275
return;
302276
}
303277
else
304278
{
305-
if ( IconType == ThemedIconTypes.Layered )
279+
if (IconType == ThemedIconTypes.Layered)
306280
{
307-
VisualStateManager.GoToState( this , LayeredTypeStateName , true );
281+
VisualStateManager.GoToState(this, LayeredTypeStateName, true);
308282
}
309283
else
310284
{
311-
VisualStateManager.GoToState( this , OutlineTypeStateName , true );
285+
VisualStateManager.GoToState(this, OutlineTypeStateName, true);
312286
}
313287
}
314288
}
315289
// If ToggleBehavior is On, we only go to Filled.
316-
else if ( _toggleBehavior == ToggleBehaviors.On )
290+
else if (ToggleBehavior == ToggleBehaviors.On)
317291
{
318-
VisualStateManager.GoToState( this , FilledTypeStateName , true );
292+
VisualStateManager.GoToState(this, FilledTypeStateName, true);
319293
}
320294
// For Off, we don't respond to _ownerToggle at all
321295
else
322296
{
323-
if ( _isFilled is true || IsFilled is true )
297+
if (IsFilled is true)
324298
{
325-
VisualStateManager.GoToState( this , FilledTypeStateName , true );
299+
VisualStateManager.GoToState(this, FilledTypeStateName, true);
326300
return;
327301
}
328-
else if ( _isHighContrast is true || IsHighContrast is true || _isEnabled is false || IsEnabled is false )
302+
else if (IsHighContrast is true || _isEnabled is false || IsEnabled is false)
329303
{
330-
VisualStateManager.GoToState( this , OutlineTypeStateName , true );
331-
VisualStateManager.GoToState( this , DisabledStateName , true );
304+
VisualStateManager.GoToState(this, OutlineTypeStateName, true);
305+
VisualStateManager.GoToState(this, DisabledStateName, true);
332306
return;
333307
}
334308
else
335309
{
336-
if ( IconType == ThemedIconTypes.Layered )
310+
if (IconType == ThemedIconTypes.Layered)
337311
{
338-
VisualStateManager.GoToState( this , LayeredTypeStateName , true );
312+
VisualStateManager.GoToState(this, LayeredTypeStateName, true);
339313
}
340314
else
341315
{
342-
VisualStateManager.GoToState( this , OutlineTypeStateName , true );
316+
VisualStateManager.GoToState(this, OutlineTypeStateName, true);
343317
}
344318
}
345319
}
@@ -355,33 +329,33 @@ private void UpdateIconColorTypeStates()
355329
if (_isEnabled is false || IsEnabled is false)
356330
{
357331
// If ToggleBehavior is Auto and _ownerToggled is true
358-
if ( _toggleBehavior == ToggleBehaviors.Auto && _ownerToggled is true )
332+
if (ToggleBehavior == ToggleBehaviors.Auto && _ownerToggled is true)
359333
{
360-
VisualStateManager.GoToState( this , DisabledToggleColorStateName , true );
334+
VisualStateManager.GoToState(this, DisabledToggleColorStateName, true);
361335
}
362336
// If ToggleBehavior is On
363-
else if ( _toggleBehavior == ToggleBehaviors.On )
337+
else if (ToggleBehavior == ToggleBehaviors.On)
364338
{
365-
VisualStateManager.GoToState( this , DisabledToggleColorStateName , true );
339+
VisualStateManager.GoToState(this, DisabledToggleColorStateName, true);
366340
}
367341
// everything else uses Disabled Color
368342
else
369343
{
370-
VisualStateManager.GoToState( this , DisabledColorStateName , true );
344+
VisualStateManager.GoToState(this, DisabledColorStateName, true);
371345
}
372346
}
373347
// Everything else is Enabled
374348
else
375349
{
376350
// If ToggleBehavior is Auto and _ownerToggled is true
377-
if ( _toggleBehavior == ToggleBehaviors.Auto && _ownerToggled is true )
351+
if (ToggleBehavior == ToggleBehaviors.Auto && _ownerToggled is true)
378352
{
379353
VisualStateManager.GoToState(this, ToggleStateName, true);
380354
}
381355
// If ToggleBehavior is On
382-
else if ( _toggleBehavior == ToggleBehaviors.On )
356+
else if (ToggleBehavior == ToggleBehaviors.On)
383357
{
384-
VisualStateManager.GoToState( this , ToggleStateName , true );
358+
VisualStateManager.GoToState(this, ToggleStateName, true);
385359
}
386360
// everything else uses the appropriate color state
387361
else

0 commit comments

Comments
 (0)