Skip to content

Commit 629b98b

Browse files
committed
Add ProcessHandledEvents to IInputHandler
1 parent 2e1823a commit 629b98b

File tree

8 files changed

+19
-30
lines changed

8 files changed

+19
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#### **In development**
44

55
> - Breaking Changes:
6+
> - Added ProcessHandledEvents to IInputHandler and removed it from InputProcessor
67
> - Features:
78
> - Added AsRef extension method to InputGesture to convert it to an InputGestureRef
89
> - Bugfixes:

Examples/Nodify.Calculator/EditorView.xaml.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ public class OperationsMenuHandler : InputElementState<NodifyEditor>
1414

1515
public OperationsMenuHandler(NodifyEditor element) : base(element)
1616
{
17+
ProcessHandledEvents = true;
1718
}
1819

1920
protected override void OnMouseUp(MouseButtonEventArgs e)
2021
{
21-
if (OpenGesture.Matches(e.Source, e))
22+
if (!e.Handled && OpenGesture.Matches(e.Source, e))
2223
{
2324
ViewModel.OpenAt(Element.MouseLocation);
2425
}
@@ -43,10 +44,6 @@ public EditorView()
4344
static EditorView()
4445
{
4546
InputProcessor.Shared<NodifyEditor>.RegisterHandlerFactory(editor => new OperationsMenuHandler(editor));
46-
47-
// Ensure the selecting handler is executed after the OperationsMenuHandler, otherwise left click events will not be received.
48-
InputProcessor.Shared<NodifyEditor>.RemoveHandlerFactory<EditorState.Selecting>();
49-
InputProcessor.Shared<NodifyEditor>.RegisterHandlerFactory(editor => new EditorState.Selecting(editor));
5047
}
5148

5249
private void OnDropNode(object sender, DragEventArgs e)

Examples/Nodify.Calculator/MainWindow.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
Value="{Binding DataContext.CloseEditorCommand ,Source={StaticResource Proxy}}"/>
5252
<Setter Property="CloseTabCommandParameter"
5353
Value="{Binding Id}"/>
54+
<Setter Property="ToolTip"
55+
Value="Double click to edit" />
5456
</Style>
5557
</shared:TabControlEx.ItemContainerStyle>
5658
</shared:TabControlEx>

Nodify/Interactivity/IInputHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@ public interface IInputHandler
2525
/// Toggled interactions usually involve two steps, and it is important to keep the input capture active until the interaction is completed.
2626
/// </remarks>
2727
bool RequiresInputCapture { get; }
28+
29+
/// <summary>
30+
/// Gets or sets a value indicating whether events that have been handled should be processed too.
31+
/// </summary>
32+
bool ProcessHandledEvents { get; }
2833
}
2934
}

Nodify/Interactivity/InputElementState.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public abstract class InputElementState<TElement> : IInputHandler
1616
protected TElement Element { get; }
1717

1818
public bool RequiresInputCapture { get; protected set; }
19+
public bool ProcessHandledEvents { get; protected set; }
1920

2021
/// <summary>
2122
/// Initializes a new instance of the <see cref="InputElementState{TElement}"/> class.

Nodify/Interactivity/InputElementStateStack.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public partial class InputElementStateStack<TElement> : IInputHandler
2020

2121
public bool RequiresInputCapture => State.RequiresInputCapture;
2222

23+
public bool ProcessHandledEvents => State.ProcessHandledEvents;
24+
2325
/// <summary>
2426
/// Initializes a new instance of the <see cref="InputElementStateStack{TElement}"/> class.
2527
/// </summary>

Nodify/Interactivity/InputProcessor.Shared.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public sealed class Shared<TElement> : InputProcessor, IInputHandler
1717
{
1818
private static readonly List<KeyValuePair<Type, Func<TElement, IInputHandler>>> _handlerFactories = new List<KeyValuePair<Type, Func<TElement, IInputHandler>>>();
1919

20+
bool IInputHandler.ProcessHandledEvents { get; }
21+
2022
/// <summary>
2123
/// Initializes a new instance of the <see cref="Shared{TElement}"/> class for the specified UI element.
2224
/// </summary>
@@ -119,10 +121,7 @@ public static class InputProcessorExtensions
119121
public static void AddSharedHandlers<TElement>(this InputProcessor inputProcessor, TElement instance)
120122
where TElement : FrameworkElement
121123
{
122-
inputProcessor.AddHandler(new InputProcessor.Shared<TElement>(instance)
123-
{
124-
ProcessHandledEvents = inputProcessor.ProcessHandledEvents
125-
});
124+
inputProcessor.AddHandler(new InputProcessor.Shared<TElement>(instance));
126125
}
127126
}
128127
}

Nodify/Interactivity/InputProcessor.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ public partial class InputProcessor
1010
{
1111
private readonly List<IInputHandler> _handlers = new List<IInputHandler>();
1212

13-
/// <summary>
14-
/// Gets or sets a value indicating whether events that have been handled should be processed.
15-
/// </summary>
16-
public bool ProcessHandledEvents { get; set; }
17-
1813
/// <summary>
1914
/// Gets a value indicating whether the processor has ongoing interactions that require input capture to remain active.
2015
/// </summary>
@@ -52,24 +47,11 @@ public void ProcessEvent(InputEventArgs e)
5247
{
5348
RequiresInputCapture = false;
5449

55-
if (!ProcessHandledEvents)
56-
{
57-
for (int i = 0; i < _handlers.Count; i++)
58-
{
59-
IInputHandler handler = _handlers[i];
60-
if (!e.Handled)
61-
{
62-
handler.HandleEvent(e);
63-
}
64-
65-
RequiresInputCapture |= handler.RequiresInputCapture;
66-
}
67-
}
68-
else
50+
for (int i = 0; i < _handlers.Count; i++)
6951
{
70-
for (int i = 0; i < _handlers.Count; i++)
52+
IInputHandler handler = _handlers[i];
53+
if (!e.Handled || handler.ProcessHandledEvents)
7154
{
72-
IInputHandler handler = _handlers[i];
7355
handler.HandleEvent(e);
7456
RequiresInputCapture |= handler.RequiresInputCapture;
7557
}

0 commit comments

Comments
 (0)