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

Move LineBrush/LineStyle into Consolonia.Controls public namespace #232

Merged
merged 5 commits into from
Dec 26, 2024

Conversation

tomlm
Copy link
Collaborator

@tomlm tomlm commented Dec 26, 2024

also moved DialogWindow, MessageBox

Copy link
Contributor

coderabbitai bot commented Dec 26, 2024

📝 Walkthrough

Walkthrough

This pull request involves a comprehensive namespace reorganization within the Consolonia project, primarily focusing on moving drawing and control-related classes from Consolonia.Core.Drawing and Consolonia.Core.Controls to a consolidated Consolonia.Controls namespace. The changes span multiple files across different project components, including core libraries, gallery views, themes, and example components. The modifications primarily involve updating namespace declarations, import statements, and XML namespace references without altering the underlying functionality of the affected classes and controls.

Possibly related issues

Possibly related PRs

Suggested labels

enhancement, refactoring, namespace-reorganization


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 974137b and 69e1547.

📒 Files selected for processing (7)
  • src/Consolonia.Core/Controls/LineStyle.cs (1 hunks)
  • src/Consolonia.Core/Drawing/DrawingContextImpl.cs (1 hunks)
  • src/Consolonia.Core/Drawing/PixelBufferImplementation/DrawingBoxSymbol.cs (1 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryAnimatedLines.axaml (3 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryBorders.axaml (5 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryCanvas.axaml (2 hunks)
  • src/Example.Blazor.Components/MainPage.razor (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/Consolonia.Core/Controls/LineStyle.cs
  • src/Consolonia.Core/Drawing/PixelBufferImplementation/DrawingBoxSymbol.cs
  • src/Consolonia.Core/Drawing/DrawingContextImpl.cs
  • src/Example.Blazor.Components/MainPage.razor
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryCanvas.axaml
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryBorders.axaml
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryAnimatedLines.axaml

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/Consolonia.Gallery/Gallery/GalleryViews/GalleryColors.axaml.cs (1)

17-17: Consider using rnd.Next(256) to include the full range of byte values.

Currently, rnd.Next(255) generates numbers in the range [0..254]. If the intention is to allow a channel value of up to 255, update it to rnd.Next(256).

src/Consolonia.Core/Controls/ConsoloniaAccessText.cs (2)

31-49: Consider optimizing string operations and handling edge cases.

The current implementation could benefit from the following improvements:

  1. Performance optimization for string operations
  2. Handling of multiple underscores
  3. Support for escaped underscores (e.g., "__" to display "_")

Consider this alternative implementation:

 if (!string.IsNullOrEmpty(Text))
 {
-    var inlines = new InlineCollection();
-    int iPos = Text.IndexOf('_', StringComparison.Ordinal);
-    if (iPos >= 0 && iPos < Text.Length - 1)
-    {
-        inlines.Add(new Run(Text[..iPos]));
-        _accessRun = new Run(Text[++iPos..++iPos]);
-        inlines.Add(_accessRun);
-        inlines.Add(new Run(Text[iPos..]));
-    }
-    else
-    {
-        _accessRun = null;
-        inlines.Add(new Run(Text));
-    }
-
-    Inlines = inlines;
+    var inlines = new InlineCollection();
+    var currentPos = 0;
+    var textLength = Text.Length;
+    
+    while (currentPos < textLength)
+    {
+        var underscorePos = Text.IndexOf('_', currentPos, StringComparison.Ordinal);
+        if (underscorePos == -1 || underscorePos == textLength - 1)
+        {
+            // No more underscores or underscore at end - add remaining text
+            inlines.Add(new Run(Text[currentPos..]));
+            _accessRun = null;
+            break;
+        }
+        
+        // Handle text before underscore
+        if (underscorePos > currentPos)
+            inlines.Add(new Run(Text[currentPos..underscorePos]));
+        
+        // Check for escaped underscore
+        if (underscorePos < textLength - 1 && Text[underscorePos + 1] == '_')
+        {
+            inlines.Add(new Run("_"));
+            currentPos = underscorePos + 2;
+            continue;
+        }
+        
+        // Handle access key
+        _accessRun = new Run(Text[(underscorePos + 1)..(underscorePos + 2)]);
+        inlines.Add(_accessRun);
+        currentPos = underscorePos + 2;
+    }
+    
+    Inlines = inlines;
 }

This implementation:

  1. Handles multiple underscores correctly
  2. Supports escaped underscores
  3. Processes the string in a single pass
  4. Improves code readability with meaningful variable names

37-40: Improve string slicing readability.

The current string slicing operations are concise but could be more readable.

Consider this alternative:

-inlines.Add(new Run(Text[..iPos]));
-_accessRun = new Run(Text[++iPos..++iPos]);
-inlines.Add(_accessRun);
-inlines.Add(new Run(Text[iPos..]));
+// Add text before the underscore
+inlines.Add(new Run(Text.Substring(0, iPos)));
+
+// Move past underscore and get access key character
+iPos++;
+_accessRun = new Run(Text.Substring(iPos, 1));
+inlines.Add(_accessRun);
+
+// Add remaining text
+iPos++;
+inlines.Add(new Run(Text.Substring(iPos)));
src/Consolonia.Gallery/Gallery/GalleryViews/GalleryScrollViewer.axaml.cs (1)

69-69: Consider streamlining the split logic for multiline strings.

Using (char[])['\r', '\n'] may be less intuitive than creating a new char[] { '\r', '\n' }. While both are valid, the more conventional approach could improve readability.

Example fix:

- text.AddRange(""" ... """.Split((char[])['\r', '\n'], StringSplitOptions.RemoveEmptyEntries));
+ text.AddRange(""" ... """.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 018cb72 and 928a3b6.

📒 Files selected for processing (34)
  • src/Consolonia.Core/Controls/ConsoloniaAccessText.cs (1 hunks)
  • src/Consolonia.Core/Controls/Dialog/DialogHelpers.cs (1 hunks)
  • src/Consolonia.Core/Controls/Dialog/DialogWrap.axaml.cs (1 hunks)
  • src/Consolonia.Core/Controls/DialogWindow.cs (1 hunks)
  • src/Consolonia.Core/Controls/FileOpenPicker.axaml (1 hunks)
  • src/Consolonia.Core/Controls/FileOpenPicker.axaml.cs (1 hunks)
  • src/Consolonia.Core/Controls/FileOpenPickerViewModel.cs (1 hunks)
  • src/Consolonia.Core/Controls/FileSavePicker.axaml (1 hunks)
  • src/Consolonia.Core/Controls/FileSavePicker.axaml.cs (1 hunks)
  • src/Consolonia.Core/Controls/FileSavePickerViewModel.cs (1 hunks)
  • src/Consolonia.Core/Controls/FolderPicker.axaml (1 hunks)
  • src/Consolonia.Core/Controls/FolderPicker.axaml.cs (1 hunks)
  • src/Consolonia.Core/Controls/LineBrush.cs (1 hunks)
  • src/Consolonia.Core/Controls/LineStyle.cs (1 hunks)
  • src/Consolonia.Core/Controls/MessageBox.axaml (1 hunks)
  • src/Consolonia.Core/Controls/MessageBox.axaml.cs (1 hunks)
  • src/Consolonia.Core/Drawing/BrushExtensions.cs (1 hunks)
  • src/Consolonia.Core/Drawing/DrawingContextImpl.cs (7 hunks)
  • src/Consolonia.Core/Drawing/PixelBufferImplementation/DrawingBoxSymbol.cs (2 hunks)
  • src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBuffer.cs (2 hunks)
  • src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBufferConverter.cs (2 hunks)
  • src/Consolonia.Core/Drawing/RenderTarget.cs (2 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryAnimatedLines.axaml.cs (1 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryColors.axaml.cs (1 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryDialog.axaml.cs (1 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryMessageBox.axaml.cs (1 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryScrollViewer.axaml.cs (1 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/SomeDialogWindow.axaml (1 hunks)
  • src/Consolonia.Gallery/Gallery/GalleryViews/SomeDialogWindow.axaml.cs (1 hunks)
  • src/Consolonia.Gallery/View/XamlDialogWindow.axaml (1 hunks)
  • src/Consolonia.Gallery/View/XamlDialogWindow.axaml.cs (1 hunks)
  • src/Consolonia.Themes/Templates/Controls/DialogWindow.axaml (2 hunks)
  • src/Consolonia.Themes/TurboVisionDark/Controls/DialogWindow.axaml (1 hunks)
  • src/Example.Blazor.Components/MainPage.razor (1 hunks)
✅ Files skipped from review due to trivial changes (17)
  • src/Consolonia.Core/Controls/FolderPicker.axaml.cs
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryDialog.axaml.cs
  • src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBuffer.cs
  • src/Consolonia.Core/Controls/FileOpenPickerViewModel.cs
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryMessageBox.axaml.cs
  • src/Consolonia.Gallery/View/XamlDialogWindow.axaml.cs
  • src/Consolonia.Core/Drawing/PixelBufferImplementation/PixelBufferConverter.cs
  • src/Consolonia.Core/Drawing/RenderTarget.cs
  • src/Consolonia.Core/Controls/Dialog/DialogHelpers.cs
  • src/Consolonia.Core/Controls/FileSavePicker.axaml.cs
  • src/Consolonia.Core/Controls/MessageBox.axaml.cs
  • src/Consolonia.Core/Controls/Dialog/DialogWrap.axaml.cs
  • src/Consolonia.Core/Controls/FileOpenPicker.axaml.cs
  • src/Consolonia.Core/Controls/DialogWindow.cs
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryAnimatedLines.axaml.cs
  • src/Example.Blazor.Components/MainPage.razor
  • src/Consolonia.Core/Drawing/BrushExtensions.cs
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/Consolonia.Core/Drawing/DrawingContextImpl.cs
  • src/Consolonia.Core/Controls/LineBrush.cs
  • src/Consolonia.Core/Controls/LineStyle.cs
  • src/Consolonia.Core/Drawing/PixelBufferImplementation/DrawingBoxSymbol.cs
  • src/Consolonia.Themes/Templates/Controls/DialogWindow.axaml
🔇 Additional comments (13)
src/Consolonia.Gallery/Gallery/GalleryViews/SomeDialogWindow.axaml (1)

6-6: Namespace refactor is aligned with the PR objectives.

Changing the namespace to Consolonia.Controls is consistent with the overall refactoring effort in this pull request. Ensure all references to the old namespace are removed or updated accordingly throughout the project.

src/Consolonia.Gallery/Gallery/GalleryViews/SomeDialogWindow.axaml.cs (1)

4-4: Namespace import change is consistent.

Switching from Consolonia.Core.Controls to Consolonia.Controls matches the new organizational structure. Looks good.

src/Consolonia.Gallery/View/XamlDialogWindow.axaml (1)

6-6: Updated namespace to Consolonia.Controls looks consistent with the refactoring goals.

This is aligned with the broader reorganization from Consolonia.Core.Controls to Consolonia.Controls. Please confirm that other references in XAML or code also point to the new namespace to avoid potential bindings or type resolution issues.

src/Consolonia.Themes/TurboVisionDark/Controls/DialogWindow.axaml (1)

3-3: LGTM! The updated namespace aligns with the PR objectives.

The usage of controls="clr-namespace:Consolonia.Controls;assembly=Consolonia.Core" is consistent with the newly consolidated controls namespace. Ensure references to DialogWindow (and related controls) in other code files and XAML resources are also updated to maintain consistency.

src/Consolonia.Core/Controls/FolderPicker.axaml (2)

4-5: Namespace reorganization looks good.
By introducing Consolonia.Controls and Consolonia.Core.Controls, you’ve clearly separated core components from higher-level ones. This helps maintain a cleaner architecture and organizes code more effectively.


8-8: Ensure all bindings remain valid.
Please confirm that updating x:DataType references (e.g., controls:FolderPickerViewModelcore-controls:FolderPickerViewModel) does not break any view model data binding or constructor injection.

src/Consolonia.Core/Controls/FileSavePicker.axaml (2)

4-5: Namespace move is consistent.
Switching to Consolonia.Controls and introducing core-controls to reference Consolonia.Core.Controls clarifies library boundaries and fosters maintainability.


8-8: Confirm updated view model references.
Make sure the new data type (core-controls:FileSavePickerViewModel) and its bindings are properly recognized by related C# code, including any code-behind or tests referencing the former namespace.

src/Consolonia.Core/Controls/FileOpenPicker.axaml (2)

4-5: Consistent namespace update.
Keeping Consolonia.Controls for UI elements and Consolonia.Core.Controls for core functionalities aligns with the project’s apparent layering scheme. Great step for code clarity.


8-8: Validate the changed data type binding.
Verify that the FileOpenPickerViewModel references are correctly updated throughout the solution to the new core-controls namespace.

src/Consolonia.Core/Controls/MessageBox.axaml (2)

3-3: Consistent namespace update.

This change aligns with the refactoring objective of moving controls into the Consolonia.Controls namespace. It looks good.


7-7: Confirm references to the renamed class.

Changing the x:Class attribute to Consolonia.Controls.MessageBox may require updates wherever this class is instantiated or referenced.

Use this script to confirm no stale references remain:

✅ Verification successful

No stale references found, namespace change is safe

The search results show that all references to MessageBox are using the new namespace Consolonia.Controls.MessageBox. The class is being used correctly in:

  • src/Example.Blazor.Components/MainPage.razor
  • src/Consolonia.Blazor/readme.md
  • src/Consolonia.Gallery/Gallery/GalleryViews/GalleryMessageBox.axaml.cs

There are no references to the old namespace Consolonia.Core.Controls.MessageBox, indicating the namespace change is safe and all references have been updated correctly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find old references to the former `Consolonia.Core.Controls.MessageBox`.
rg -A 3 "Consolonia\.Core\.Controls\.MessageBox"

Length of output: 50


Script:

#!/bin/bash
# Let's search for any references to MessageBox class in the codebase
rg -A 3 "MessageBox"

# Also search for any XAML references
fd -e xaml -x rg -l "MessageBox"

# Let's also check for any using statements or imports
rg "using.*MessageBox"

Length of output: 14416

src/Consolonia.Gallery/Gallery/GalleryViews/GalleryScrollViewer.axaml.cs (1)

70-70: Ensure the spread operator aligns with expected .NET version.

Using the C# range spread operator ([.. text]) requires a recent language version. Confirm that the target framework supports this syntax to avoid potential build or runtime issues.

To verify usage, run the following search script to see if there are any references to language versions:

✅ Verification successful

Collection initializer syntax is supported in the codebase's target framework

Based on the project files analysis, the codebase is using modern .NET features:

  • The Directory.Core.Build.props shows analysis level 6.0
  • Multiple projects reference modern packages and use current SDK features
  • The collection initializer syntax [.. text] is supported since C# 8.0, which is well within the capabilities of the current setup
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Checking for usage of <LangVersion> in .csproj files or Directory.Build.props 
rg -A 3 -B 3 "<LangVersion>"

Length of output: 30


Script:

#!/bin/bash
# Let's check the project files for target framework version and other relevant settings
fd -e csproj . -x cat {}

Length of output: 13669


Script:

#!/bin/bash
# Let's check the Directory.Core.Build.props file since many projects import it
fd -g "Directory.Core.Build.props" -x cat {}

Length of output: 988


Script:

#!/bin/bash
# Let's check the global.json file for SDK version
cat global.json 2>/dev/null || echo "No global.json found"

# Also check the target framework in the specific project
fd -g "Consolonia.Gallery.csproj" -x cat {}

Length of output: 863

@tomlm tomlm marked this pull request as ready for review December 26, 2024 03:16
@tomlm tomlm requested a review from jinek December 26, 2024 03:16
@tomlm tomlm merged commit a66b163 into main Dec 26, 2024
2 checks passed
@tomlm tomlm deleted the tomlm/namespace branch December 26, 2024 06:00
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.

2 participants