Skip to content

657 keybinding issue when attaching it to windows with commands with canexecute methods #971

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

vb2ae
Copy link
Member

@vb2ae vb2ae commented Feb 26, 2025

This pull request introduces the SkipAvailabilityResolution property to the ActionMessage and ActionExecutionContext classes, and updates several files to support this new property. This change aims to provide more control over whether the availability of an action should be resolved.

Key changes include:

Addition of SkipAvailabilityResolution Property:

Support for SkipAvailabilityResolution in Message Class:

Updates to Action Invocation and Parsing:

ignoreGuard2.mp4

XAML for interaction trigger

<i:Interaction.Triggers>
    <i:KeyTrigger Key="D"
                  Modifiers="Ctrl">
        <cm:ActionMessage MethodName="DoThing" IgnoreGuard="true" />
    </i:KeyTrigger>
</i:Interaction.Triggers>

XAML for Message.Bind syntax

closing #657

- Updated binding initialization to use object initializer syntax for better readability.
- Enhanced logging for `source` enabled status, including checks for `source.Name`.
- Added logging to indicate whether `source` is enabled or disabled after `CanExecute` check.
- Implemented null checks for `source` and its `DataContext` to prevent null reference exceptions.
Enhanced ActionExecutionContext and ActionMessage classes with a new IgnoreGuard property to control guard condition checks during action execution.
@vb2ae vb2ae requested review from Copilot and KasperSK February 26, 2025 02:16
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

src/Caliburn.Micro.Platform/ActionMessage.cs:542

  • [nitpick] The log message in the 'else' branch (line 549) states 'Skipping IsEnabled source because source Name is not set', which may be misleading since the branch is executed when IgnoreGuard is true rather than when source.Name is missing. Consider updating the log message to better reflect that the availability effect is intentionally skipped due to IgnoreGuard being true.
if (!context.IgnoreGuard)

@Filipsi
Copy link

Filipsi commented Feb 26, 2025

Thanks for doing this. But this PR does not close the issue.

It only solves the problem when using the ActionMessage directly, not what the issue initially described. Since you can't configure the IgnoreGuard property when you are using the Message.Attach shorthand. For that you would have to make changes to the Parser.

@KasperSK
Copy link
Member

I agree with @Filipsi, I was initially thinking of making it a static property on the ActionMessage class but that we affect all action messages. Other thoughts was to extend the parser by using another keyword than Action to indicate that this specific method should not change the Enabled status of the control.

@Filipsi
Copy link

Filipsi commented Feb 26, 2025

I also think, that this change should not be structured as a way to "ignore guard" property. Right now, when you use the keyboard shortcut, and the guard property is set to false, the target method is still invoked. This should not be the case in my opinion, since there is no point in having the guard property in the first place when you just end up ignoring it.

This should be a way to allow user to have control over whatever the ActionMessage sets IsEnabled property on the the underling control. Which would be something like "ignore availability effect" to keep the naming convention from original code.

@KasperSK
Copy link
Member

That's a great point @Filipsi and also what I was thinking it should be, perhaps a property called SkipAvailabilityUpdate that can be set for the individual ActionMessage maybe indicated by a different keyword than Action.

Also if you want to be sure that a guard is enforced you can set EnforceGuardsDuringInvocation to true.

@Filipsi
Copy link

Filipsi commented Feb 26, 2025

@KasperSK Maybe naming it ResolveAvailability or SkipAvailabilityResolution would be better? Since you are not skipping an update but preventing availability from been resolved in the first place?

I think that using different keyword then Action in the Message.Attach shorthand is a way to go.
Maybe something like Call or Invoke?

It's true that enabling the EnforceGuardsDuringInvocation flag would solve that. But it affects all other actions, which brings a significant performance overhead for larger applications. Since every action would have to double-check it's invocation guards. That's why I think this should be intrinsic part of ActionMessage behavior when not enforcing availability.

@KasperSK
Copy link
Member

KasperSK commented Feb 26, 2025

@Filipsi I like that naming it is clear what is intended by the property.

Yeah I was not sure what other Keyword it should be but Call or Invoke could work.

Good point, also it would make sense to enforce the guard when not doing availability updates. I will try and make an implementation based on this discussion.

@vb2ae
Copy link
Member Author

vb2ae commented Feb 26, 2025

@Filipsi @KasperSK I am changing property name to SkipAvailabilityResolution. What do you think about adding this to Message.Attach

 cm:Message.Attach="[Event MouseDoubleClick] = [SimpleSayHello]; [SkipAvailabilityResolution]" 

@KasperSK
Copy link
Member

@vb2ae I dont like that since we split on the ; when we parse multiple Event/Action's I think this is more appropreate: cal:Message.Attach="[Event MouseDoubleClick] = [Action SimpleSayHello];[Event Click] = [Invoke RegisterClick]"

That would make the Availability update enabled for SimpleSayHello but not for RegisterClick.

Introduce a new property `SkipAvailabilityResolution` in the
`Caliburn.Micro` namespace to control the skipping of
availability resolution during action execution.

- Added `SkipAvailabilityResolution` to `ActionExecutionContext`
  and replaced `IgnoreGuard`.
- Updated `ActionMessage` to include the new property for
  bypassing availability checks.
- Defined a new dependency property
  `SkipAvailabilityResolutionProperty` in `Message.cs` for UI
  element attachment.
- Modified `Parser.cs` to utilize the new property when
  interpreting message text.

These changes enhance the flexibility of action execution
by allowing developers to specify when to skip availability
checks.
@vb2ae
Copy link
Member Author

vb2ae commented Mar 8, 2025

@KasperSK added Message.SkipAvailabilityResolution to bypass guard methods in Actions

<Button Padding="5" 
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        cm:Message.SkipAvailabilityResolution="true"
        cm:Message.Attach="[Event MouseDoubleClick] = [SayHello(username)];" 
        Content="Say Hello" 
        Grid.Column="1" 
        Grid.Row="1"/>

@vb2ae vb2ae requested a review from Copilot March 8, 2025 19:33
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR addresses the keybinding issue by introducing a new property to control command availability resolution and refactors code formatting for improved readability.

  • Introduces the SkipAvailabilityResolution property in various ActionMessage and related classes.
  • Updates context propagation and logging to respect the new property.
  • Improves code style by adjusting braces formatting and dependency property registration in Message.cs.

Reviewed Changes

File Description
src/Caliburn.Micro.Platform/ActionMessage.cs Adds SkipAvailabilityResolution and updates context and logging in ToString and UpdateContext.
src/Caliburn.Micro.Platform/Message.cs Registers the new attached property and provides corresponding getter/setter methods.
src/Caliburn.Micro.Platform/Platforms/Xamarin.Forms/ActionMessage.cs Introduces SkipAvailabilityResolution in the Xamarin.Forms platform implementation.
src/Caliburn.Micro.Platform/ActionExecutionContext.cs Integrates SkipAvailabilityResolution into the execution context with minor formatting updates.
src/Caliburn.Micro.Platform/Platforms/Maui/ActionMessage.cs Introduces SkipAvailabilityResolution for the Maui platform implementation.
src/Caliburn.Micro.Platform/Action.cs Passes the SkipAvailabilityResolution value into the ActionExecutionContext.
src/Caliburn.Micro.Platform/Parser.cs Sets SkipAvailabilityResolution during the ActionMessage parsing.

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/Caliburn.Micro.Platform/ActionMessage.cs:164

  • The PR description refers to an 'IgnoreGuard' property, but the code uses 'SkipAvailabilityResolution'. Consider aligning the property name for consistency.
public bool SkipAvailabilityResolution { get; set; }

vb2ae and others added 2 commits March 8, 2025 14:36
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@vb2ae vb2ae requested a review from Copilot March 8, 2025 20:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR introduces a new bool property, SkipAvailabilityResolution (alias IgnoreGuard), across multiple classes in the Caliburn.Micro library to allow bypassing availability resolution for keybindings along with some code formatting improvements.

  • Added SkipAvailabilityResolution properties to ActionMessage (in multiple platform-specific files), ActionExecutionContext, and associated updates in Message and Parser.
  • Enhanced logging and formatting consistency in various methods and adjusted binding initialization.

Reviewed Changes

File Description
src/Caliburn.Micro.Platform/ActionMessage.cs Added SkipAvailabilityResolution property and updated context assignment in UpdateContext and logging in ToString.
src/Caliburn.Micro.Platform/Message.cs Introduced an attached property and helper methods for SkipAvailabilityResolution with some changes in naming and type handling.
src/Caliburn.Micro.Platform/ActionExecutionContext.cs Added SkipAvailabilityResolution property and adjusted brace formatting.
src/Caliburn.Micro.Platform/Platforms/Maui/ActionMessage.cs Added SkipAvailabilityResolution property.
src/Caliburn.Micro.Platform/Platforms/Xamarin.Forms/ActionMessage.cs Introduced SkipAvailabilityResolution property with a default value.
src/Caliburn.Micro.Platform/Parser.cs Updated message interpretation to include SkipAvailabilityResolution from attached property.
src/Caliburn.Micro.Platform/Action.cs Updated action invocation to pass SkipAvailabilityResolution from the view.

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/Caliburn.Micro.Platform/Message.cs:53

  • [nitpick] Consider renaming the constant to 'SkipAvailabilityResolution' (without underscores) to match the naming conventions used elsewhere.
internal const string Skip_Availability_Resolution = "SkipAvailabilityResolution";

@KasperSK
Copy link
Member

KasperSK commented Mar 9, 2025

@KasperSK added Message.SkipAvailabilityResolution to bypass guard methods in Actions

<Button Padding="5" 
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        cm:Message.SkipAvailabilityResolution="true"
        cm:Message.Attach="[Event MouseDoubleClick] = [SayHello(username)];" 
        Content="Say Hello" 
        Grid.Column="1" 
        Grid.Row="1"/>

Doing it as a attached property on the Message class would still only enable to skip the availability resolution for all the ActionMessages. So we cannot have a single action message that does updates. The request was to be able to select whether or not to do the update for a specific event.

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.

3 participants