Skip to content

Commit 4f551c1

Browse files
committed
CQ: Add comments
1 parent 37c35e2 commit 4f551c1

File tree

6 files changed

+149
-1
lines changed

6 files changed

+149
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33

44
namespace Files.App.Data.Contracts
55
{
6+
/// <summary>
7+
/// Defines an interface for real-time control components that manage content layout updates.
8+
/// </summary>
69
internal interface IRealTimeControl
710
{
11+
/// <summary>
12+
/// Initializes the content layout for the control.
13+
/// </summary>
814
void InitializeContentLayout();
915

16+
/// <summary>
17+
/// Updates the content layout of the control.
18+
/// </summary>
1019
void UpdateContentLayout();
1120
}
1221
}

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,46 @@
33

44
namespace Files.App.Data.Contracts
55
{
6+
/// <summary>
7+
/// Provides an interface for managing real-time layout updates and related operations.
8+
/// </summary>
69
public interface IRealTimeLayoutService
710
{
8-
11+
/// <summary>
12+
/// Gets the current flow direction for layout (e.g., LeftToRight or RightToLeft).
13+
/// </summary>
914
FlowDirection FlowDirection { get; }
15+
16+
/// <summary>
17+
/// Adds a callback to be executed when a specific target requires updates.
18+
/// </summary>
19+
/// <param name="target">The target object for which the callback is registered.</param>
20+
/// <param name="callback">The action to execute during updates.</param>
1021
void AddCallback(object target, Action callback);
1122

23+
/// <summary>
24+
/// Updates the content layout of the specified framework element.
25+
/// </summary>
26+
/// <param name="frameworkElement">The framework element to update.</param>
1227
void UpdateContent(FrameworkElement frameworkElement);
1328

29+
/// <summary>
30+
/// Updates the content layout of the specified window.
31+
/// </summary>
32+
/// <param name="window">The window whose content layout needs updating.</param>
1433
void UpdateContent(Window window);
1534

35+
/// <summary>
36+
/// Updates the culture settings for the layout.
37+
/// </summary>
38+
/// <param name="culture">The culture information to apply.</param>
1639
void UpdateCulture(CultureInfo culture);
1740

41+
/// <summary>
42+
/// Updates the title bar of the specified window.
43+
/// </summary>
44+
/// <param name="window">The window whose title bar needs updating.</param>
45+
/// <returns>True if the title bar was successfully updated; otherwise, false.</returns>
1846
bool UpdateTitleBar(Window window);
1947
}
2048
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33

44
namespace Files.App.Data.Contracts
55
{
6+
/// <summary>
7+
/// Defines an interface for real-time window components that manage content layout updates.
8+
/// </summary>
69
internal interface IRealTimeWindow
710
{
11+
/// <summary>
12+
/// Initializes the content layout for the window.
13+
/// </summary>
814
void InitializeContentLayout() { }
915

16+
/// <summary>
17+
/// Updates the content layout of the window.
18+
/// </summary>
1019
void UpdateContentLayout() { }
1120
}
1221
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,26 @@
77

88
namespace Files.App.Services.Content
99
{
10+
/// <summary>
11+
/// Provides a service to manage real-time layout updates, including content layout and title bar updates,
12+
/// while supporting flow direction based on the current culture.
13+
/// </summary>
1014
internal sealed class RealTimeLayoutService : IRealTimeLayoutService
1115
{
16+
/// <summary>
17+
/// List of weak references to target objects and their associated callbacks.
18+
/// </summary>
1219
private readonly List<(WeakReference<object> Reference, Action Callback)> _callbacks = [];
1320

21+
/// <summary>
22+
/// Gets the current flow direction based on the current UI culture (RightToLeft or LeftToRight).
23+
/// </summary>
1424
public FlowDirection FlowDirection => CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1525

26+
/// <summary>
27+
/// Updates the culture for the layout service and invokes the necessary callbacks if the flow direction changes.
28+
/// </summary>
29+
/// <param name="culture">The new culture information to apply.</param>
1630
public void UpdateCulture(CultureInfo culture)
1731
{
1832
FlowDirection tmp = FlowDirection;
@@ -24,6 +38,11 @@ public void UpdateCulture(CultureInfo culture)
2438
InvokeCallbacks();
2539
}
2640

41+
/// <summary>
42+
/// Registers a callback to be invoked when the layout needs to be updated for the specified target.
43+
/// </summary>
44+
/// <param name="target">The target object to associate with the callback.</param>
45+
/// <param name="callback">The callback to invoke when the layout is updated.</param>
2746
public void AddCallback(object target, Action callback)
2847
{
2948
var weakReference = new WeakReference<object>(target);
@@ -36,6 +55,11 @@ public void AddCallback(object target, Action callback)
3655
element.Unloaded += (sender, args) => RemoveCallback(target);
3756
}
3857

58+
/// <summary>
59+
/// Updates the title bar layout of the specified window based on the current flow direction.
60+
/// </summary>
61+
/// <param name="window">The window whose title bar layout needs updating.</param>
62+
/// <returns>True if the title bar layout was successfully updated; otherwise, false.</returns>
3963
public bool UpdateTitleBar(Window window)
4064
{
4165
try
@@ -58,23 +82,38 @@ public bool UpdateTitleBar(Window window)
5882
return true;
5983
}
6084

85+
/// <summary>
86+
/// Updates the content layout of the specified window to match the current flow direction.
87+
/// </summary>
88+
/// <param name="window">The window whose content layout needs updating.</param>
6189
public void UpdateContent(Window window)
6290
{
6391
if (window.Content is FrameworkElement frameworkElement)
6492
frameworkElement.FlowDirection = FlowDirection;
6593
}
6694

95+
/// <summary>
96+
/// Updates the content layout of the specified framework element to match the current flow direction.
97+
/// </summary>
98+
/// <param name="frameworkElement">The framework element whose content layout needs updating.</param>
6799
public void UpdateContent(FrameworkElement frameworkElement)
68100
{
69101
frameworkElement.FlowDirection = FlowDirection;
70102
}
71103

104+
/// <summary>
105+
/// Removes the callback associated with the specified target.
106+
/// </summary>
107+
/// <param name="target">The target object whose callback needs to be removed.</param>
72108
private void RemoveCallback(object target)
73109
{
74110
_callbacks.RemoveAll(item =>
75111
item.Reference.TryGetTarget(out var targetObject) && targetObject == target);
76112
}
77113

114+
/// <summary>
115+
/// Invokes all registered callbacks for targets that are still valid.
116+
/// </summary>
78117
private void InvokeCallbacks()
79118
{
80119
_callbacks.Where(item =>

src/Files.Core.SourceGenerator/Constants.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,39 @@ internal class StringsPropertyGenerator
9999
internal const char ConstantSeparator = '/';
100100
}
101101

102+
/// <summary>
103+
/// Provides functionality for generating real-time layout specifications.
104+
/// </summary>
102105
internal class RealTimeLayoutGenerator
103106
{
107+
/// <summary>
108+
/// The name of the real-time specification window.
109+
/// </summary>
104110
internal const string SpecificationWindowName = "IRealTimeWindow";
105111

112+
/// <summary>
113+
/// The name of the real-time specification control.
114+
/// </summary>
106115
internal const string SpecificationControlName = "IRealTimeControl";
107116

117+
/// <summary>
118+
/// Specifies the types of real-time layout specifications.
119+
/// </summary>
108120
internal enum SpecificationType
109121
{
122+
/// <summary>
123+
/// No specification type.
124+
/// </summary>
110125
None = 0,
126+
127+
/// <summary>
128+
/// Specifies a window layout.
129+
/// </summary>
111130
Window,
131+
132+
/// <summary>
133+
/// Specifies a control layout.
134+
/// </summary>
112135
Control
113136
}
114137
}

src/Files.Core.SourceGenerator/Generators/RealTimeLayoutGenerator.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55

66
namespace Files.Core.SourceGenerator.Generators
77
{
8+
/// <summary>
9+
/// Generates additional source code for classes based on their inheritance from specific types
10+
/// (e.g., IRealTimeWindow or IRealTimeControl).
11+
/// </summary>
812
[Generator]
913
public class RealTimeLayoutGenerator : IIncrementalGenerator
1014
{
15+
/// <summary>
16+
/// Initializes the incremental source generator with context-specific configuration.
17+
/// </summary>
18+
/// <param name="context">The incremental generator initialization context.</param>
1119
public void Initialize(IncrementalGeneratorInitializationContext context)
1220
{
1321
var candidateClasses = context.SyntaxProvider
@@ -28,6 +36,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
2836
});
2937
}
3038

39+
/// <summary>
40+
/// Determines if the syntax node is a valid candidate for generation.
41+
/// </summary>
42+
/// <param name="syntaxNode">The syntax node to evaluate.</param>
43+
/// <returns>True if the node is a valid class candidate; otherwise, false.</returns>
3144
private static bool IsValidCandidate(SyntaxNode syntaxNode)
3245
{
3346
if (syntaxNode is ClassDeclarationSyntax classDeclaration)
@@ -38,6 +51,11 @@ private static bool IsValidCandidate(SyntaxNode syntaxNode)
3851
return false;
3952
}
4053

54+
/// <summary>
55+
/// Retrieves a class declaration and its specification type if it matches the criteria.
56+
/// </summary>
57+
/// <param name="context">The syntax context for the generator.</param>
58+
/// <returns>A tuple containing the class declaration and its specification type, or null if no match.</returns>
4159
private static (ClassDeclarationSyntax Class, SpecificationType Type)? GetCandidateClass(GeneratorSyntaxContext context)
4260
{
4361
var classDeclaration = (ClassDeclarationSyntax)context.Node;
@@ -60,6 +78,13 @@ private static (ClassDeclarationSyntax Class, SpecificationType Type)? GetCandid
6078
return null;
6179
}
6280

81+
/// <summary>
82+
/// Generates the source code for a class based on the provided namespace, class name, and type.
83+
/// </summary>
84+
/// <param name="namespaceName">The namespace of the class.</param>
85+
/// <param name="className">The name of the class.</param>
86+
/// <param name="type">The type of the specification (Window or Control).</param>
87+
/// <returns>The generated source code as a string.</returns>
6388
private static string GenerateClass(string namespaceName, string className, SpecificationType type)
6489
{
6590
// Namespace
@@ -111,6 +136,11 @@ private static string GenerateClass(string namespaceName, string className, Spec
111136
return compilationUnit.ToFullString();
112137
}
113138

139+
/// <summary>
140+
/// Creates the body statements for the InitializeContentLayout method.
141+
/// </summary>
142+
/// <param name="type">The type of the specification (Window or Control).</param>
143+
/// <returns>A collection of statements for the method body.</returns>
114144
private static IEnumerable<StatementSyntax> CreateInitializeContentLayoutBody(SpecificationType type)
115145
{
116146
var statements = new List<StatementSyntax>
@@ -128,6 +158,11 @@ private static IEnumerable<StatementSyntax> CreateInitializeContentLayoutBody(Sp
128158
return statements;
129159
}
130160

161+
/// <summary>
162+
/// Creates the body statements for the UpdateContentLayout method.
163+
/// </summary>
164+
/// <param name="type">The type of the specification (Window or Control).</param>
165+
/// <returns>A collection of statements for the method body.</returns>
131166
private static IEnumerable<StatementSyntax> CreateUpdateContentLayoutBody(SpecificationType type)
132167
{
133168
var statements = new List<StatementSyntax>();
@@ -140,6 +175,11 @@ private static IEnumerable<StatementSyntax> CreateUpdateContentLayoutBody(Specif
140175
return statements;
141176
}
142177

178+
/// <summary>
179+
/// Retrieves the namespace of a given syntax node.
180+
/// </summary>
181+
/// <param name="node">The syntax node to evaluate.</param>
182+
/// <returns>The namespace name as a string.</returns>
143183
private static string GetNamespace(SyntaxNode node)
144184
{
145185
while (node != null)

0 commit comments

Comments
 (0)