Skip to content

Commit 580e4f5

Browse files
committed
CQ: Update
1 parent d8c717c commit 580e4f5

File tree

2 files changed

+41
-48
lines changed

2 files changed

+41
-48
lines changed

src/Files.App/Data/Contracts/IRealTimeLayoutService.cs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,44 @@ public interface IRealTimeLayoutService
1717
FlowDirection FlowDirection { get; }
1818

1919
/// <summary>
20-
/// Adds a callback to be executed when a specific target requires updates.
20+
/// Updates the culture settings for the layout.
2121
/// </summary>
22-
/// <param name="target">The target object for which the callback is registered.</param>
23-
/// <param name="callback">The action to execute during updates.</param>
24-
void AddCallback(object target, Action callback);
22+
/// <param name="culture">The culture information to apply.</param>
23+
void UpdateCulture(CultureInfo culture);
2524

2625
/// <summary>
27-
/// Updates the content layout of the specified framework element.
26+
/// Adds a callback for a <see cref="Window"/> implementing <see cref="IRealTimeWindow"/>.
27+
/// The callback is automatically removed when the window is closed.
2828
/// </summary>
29-
/// <param name="frameworkElement">The framework element to update.</param>
30-
void UpdateContent(FrameworkElement frameworkElement);
29+
/// <param name="target">The <see cref="Window"/> instance that implements <see cref="IRealTimeWindow"/>.</param>
30+
/// <param name="callback">The action to be executed when the callback is triggered.</param>
31+
void AddCallback(Window target, Action callback);
3132

3233
/// <summary>
33-
/// Updates the content layout of the specified window.
34+
/// Adds a callback for a <see cref="FrameworkElement"/> implementing <see cref="IRealTimeControl"/>.
35+
/// The callback is automatically removed when the element is unloaded.
3436
/// </summary>
35-
/// <param name="window">The window whose content layout needs updating.</param>
36-
void UpdateContent(Window window);
37+
/// <param name="target">The <see cref="FrameworkElement"/> instance that implements <see cref="IRealTimeControl"/>.</param>
38+
/// <param name="callback">The action to be executed when the callback is triggered.</param>
39+
void AddCallback(FrameworkElement target, Action callback);
3740

3841
/// <summary>
39-
/// Updates the culture settings for the layout.
42+
/// Updates the title bar layout of the specified window based on the current flow direction.
4043
/// </summary>
41-
/// <param name="culture">The culture information to apply.</param>
42-
void UpdateCulture(CultureInfo culture);
44+
/// <param name="window">The window whose title bar layout needs updating.</param>
45+
/// <returns>True if the title bar layout was successfully updated; otherwise, false.</returns>
46+
bool UpdateTitleBar(Window window);
4347

4448
/// <summary>
45-
/// Updates the title bar of the specified window.
49+
/// Updates the content layout of the specified window to match the current flow direction.
4650
/// </summary>
47-
/// <param name="window">The window whose title bar needs updating.</param>
48-
/// <returns>True if the title bar was successfully updated; otherwise, false.</returns>
49-
bool UpdateTitleBar(Window window);
51+
/// <param name="window">The window whose content layout needs updating.</param>
52+
void UpdateContent(Window window);
53+
54+
/// <summary>
55+
/// Updates the content layout of the specified framework element to match the current flow direction.
56+
/// </summary>
57+
/// <param name="frameworkElement">The framework element whose content layout needs updating.</param>
58+
void UpdateContent(FrameworkElement frameworkElement);
5059
}
5160
}

src/Files.App/Services/Content/RealTimeLayoutService.cs

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,10 @@ internal sealed class RealTimeLayoutService : IRealTimeLayoutService
2121
/// </summary>
2222
private readonly List<(WeakReference<object> Reference, Action Callback)> _callbacks = [];
2323

24-
/// <summary>
25-
/// Gets the current flow direction based on the current UI culture (RightToLeft or LeftToRight).
26-
/// </summary>
24+
/// <inheritdoc/>
2725
public FlowDirection FlowDirection => CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
2826

29-
/// <summary>
30-
/// Updates the culture for the layout service and invokes the necessary callbacks if the flow direction changes.
31-
/// </summary>
32-
/// <param name="culture">The new culture information to apply.</param>
27+
/// /// <inheritdoc/>
3328
public void UpdateCulture(CultureInfo culture)
3429
{
3530
FlowDirection tmp = FlowDirection;
@@ -41,28 +36,23 @@ public void UpdateCulture(CultureInfo culture)
4136
InvokeCallbacks();
4237
}
4338

44-
/// <summary>
45-
/// Registers a callback to be invoked when the layout needs to be updated for the specified target.
46-
/// </summary>
47-
/// <param name="target">The target object to associate with the callback.</param>
48-
/// <param name="callback">The callback to invoke when the layout is updated.</param>
49-
public void AddCallback(object target, Action callback)
39+
/// <inheritdoc/>
40+
public void AddCallback(Window target, Action callback)
5041
{
5142
var weakReference = new WeakReference<object>(target);
5243
_callbacks.Add((weakReference, callback));
44+
target.Closed += (sender, args) => RemoveCallback(target);
45+
}
5346

54-
if (target is Window window)
55-
window.Closed += (sender, args) => RemoveCallback(target);
56-
57-
if (target is FrameworkElement element)
58-
element.Unloaded += (sender, args) => RemoveCallback(target);
47+
/// <inheritdoc/>
48+
public void AddCallback(FrameworkElement target, Action callback)
49+
{
50+
var weakReference = new WeakReference<object>(target);
51+
_callbacks.Add((weakReference, callback));
52+
target.Unloaded += (sender, args) => RemoveCallback(target);
5953
}
6054

61-
/// <summary>
62-
/// Updates the title bar layout of the specified window based on the current flow direction.
63-
/// </summary>
64-
/// <param name="window">The window whose title bar layout needs updating.</param>
65-
/// <returns>True if the title bar layout was successfully updated; otherwise, false.</returns>
55+
/// <inheritdoc/>
6656
public bool UpdateTitleBar(Window window)
6757
{
6858
try
@@ -85,20 +75,14 @@ public bool UpdateTitleBar(Window window)
8575
return true;
8676
}
8777

88-
/// <summary>
89-
/// Updates the content layout of the specified window to match the current flow direction.
90-
/// </summary>
91-
/// <param name="window">The window whose content layout needs updating.</param>
78+
/// <inheritdoc/>
9279
public void UpdateContent(Window window)
9380
{
9481
if (window.Content is FrameworkElement frameworkElement)
9582
frameworkElement.FlowDirection = FlowDirection;
9683
}
9784

98-
/// <summary>
99-
/// Updates the content layout of the specified framework element to match the current flow direction.
100-
/// </summary>
101-
/// <param name="frameworkElement">The framework element whose content layout needs updating.</param>
85+
/// <inheritdoc/>
10286
public void UpdateContent(FrameworkElement frameworkElement)
10387
{
10488
frameworkElement.FlowDirection = FlowDirection;

0 commit comments

Comments
 (0)