Skip to content

Benjaming/mvvm#21

Closed
bgn64 wants to merge 17 commits into
mainfrom
benjaming/mvvm
Closed

Benjaming/mvvm#21
bgn64 wants to merge 17 commits into
mainfrom
benjaming/mvvm

Conversation

@bgn64

@bgn64 bgn64 commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@bgn64 bgn64 marked this pull request as ready for review September 24, 2025 22:09
Copilot AI review requested due to automatic review settings September 24, 2025 22:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a comprehensive migration to MVVM architecture for options panels in the ProfileExplorer application. The changes replace the existing code-behind event handling with proper MVVM ViewModels using the CommunityToolkit.Mvvm framework.

Key Changes

  • Added CommunityToolkit.Mvvm NuGet package for MVVM infrastructure
  • Created ViewModels for all options panels with proper two-way data binding
  • Introduced new MVVM-compatible interface (IMvvmOptionsPanel) alongside existing architecture
  • Updated XAML files to use ViewModel properties and commands instead of event handlers

Reviewed Changes

Copilot reviewed 72 out of 72 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
ProfileExplorerUI.csproj Added CommunityToolkit.Mvvm package reference
OptionsPanelHostPopup.xaml.cs Added MVVM support with CreateMvvm method and wrapper infrastructure
OptionsPanelBase.cs Introduced IMvvmOptionsPanel interface for gradual MVVM migration
ViewModels/*.cs Created comprehensive ViewModels for all options panels with proper data binding
Services/*.cs Added service layer for UI operations (dialogs, file operations, etc.)
*.xaml.cs files Converted code-behind to use ViewModels instead of direct event handling
*.xaml files Updated data bindings to use ViewModel properties with underscore suffix
FunctionMarkingSettings.cs Made Markings record public and added methods for MVVM support
ProfileLoadWindow.xaml.cs Replaced direct method call with comment indicating data binding handles reload
Various panel files Updated to use CreateMvvm method for MVVM-compatible panels

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +284 to +285
while (SelectedSymbolPathIndex_ != -1) {
SymbolPaths_.RemoveAt(SelectedSymbolPathIndex_);

Copilot AI Sep 24, 2025

Copy link

Choose a reason for hiding this comment

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

This creates an infinite loop. The condition != -1 should be >= 0 and the loop should decrement or use a different approach. The current logic will loop indefinitely if SelectedSymbolPathIndex_ is not -1.

Suggested change
while (SelectedSymbolPathIndex_ != -1) {
SymbolPaths_.RemoveAt(SelectedSymbolPathIndex_);
if (SelectedSymbolPathIndex_ >= 0 && SelectedSymbolPathIndex_ < SymbolPaths_.Count) {
SymbolPaths_.RemoveAt(SelectedSymbolPathIndex_);
// Update selection: select previous item, or -1 if list is empty
if (SymbolPaths_.Count == 0) {
SelectedSymbolPathIndex_ = -1;
} else if (SelectedSymbolPathIndex_ >= SymbolPaths_.Count) {
SelectedSymbolPathIndex_ = SymbolPaths_.Count - 1;
}

Copilot uses AI. Check for mistakes.
Comment on lines +159 to +161
private void SetLongCallStackPopupDuration() {

}

Copilot AI Sep 24, 2025

Copy link

Choose a reason for hiding this comment

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

The method body is empty. This command method should set the popup duration to a long value, similar to other duration setter methods in the codebase.

Copilot uses AI. Check for mistakes.
ItemsSource="{Binding StyleButtonContextMenuItems_, Mode=TwoWay}">
<MenuItem Header="Default" />
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=PlacemantTarget.DataContext.ItemChanged }"/>

Copilot AI Sep 24, 2025

Copy link

Choose a reason for hiding this comment

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

There's a spelling error: 'PlacemantTarget' should be 'PlacementTarget'.

Suggested change
<Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=PlacemantTarget.DataContext.ItemChanged }"/>
<Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.DataContext.ItemChanged }"/>

Copilot uses AI. Check for mistakes.

[RelayCommand]
private void RemoveMappedPath() {
var toRemove = FilePathMappings_.Where(p => p.IsSelected_).ToList();

Copilot AI Sep 24, 2025

Copy link

Choose a reason for hiding this comment

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

Inconsistent indentation. The line should be aligned with the method declaration above it.

Suggested change
var toRemove = FilePathMappings_.Where(p => p.IsSelected_).ToList();
var toRemove = FilePathMappings_.Where(p => p.IsSelected_).ToList();

Copilot uses AI. Check for mistakes.
public void PanelResetting() { }
public void PanelAfterReset() { }

public static OptionsPanelHostPopup Create<T, S>(SettingsBase settings, FrameworkElement relativeControl,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might be good to add something like [Obsolete("This method now exists primarily for legacy panels not migrated to MVVM. Use New panels should use CreateMvvm() when possible.")] over this function, just to make a note that future development probably should be using the MVVM variant instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True, I think I've transitioned all the options panels though if I remember correctly. This PR could also perform any final refactoring to remove this obsolete method

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Finishing the refactor might make the most sense imo. From a quick search, there's only one(?) instance of the Create() function still being used, in the SourceFilePanel

}

private record Markings(FunctionMarkingSet Current, List<FunctionMarkingSet> Saved);
public record Markings(FunctionMarkingSet Current, List<FunctionMarkingSet> Saved);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this still be private?

@jhpohovey jhpohovey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left a few comments @bgn64

@bgn64 bgn64 closed this Feb 26, 2026
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.

4 participants