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

[Android] Support PerformContextMenuAction #15608

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public TopLevelImpl(AvaloniaView avaloniaView, bool placeOnTop = false)
{
throw new ArgumentException("AvaloniaView.Context must not be null");
}

_view = new ViewImpl(avaloniaView.Context, this, placeOnTop);
_textInputMethod = new AndroidInputMethod<ViewImpl>(_view);
_keyboardHelper = new AndroidKeyboardEventsHelper<TopLevelImpl>(this);
Expand Down Expand Up @@ -85,7 +85,7 @@ public TopLevelImpl(AvaloniaView avaloniaView, bool placeOnTop = false)
public virtual Size ClientSize => _view.Size.ToSize(RenderScaling);

public Size? FrameSize => null;

public Action? Closed { get; set; }

public Action<RawInputEventArgs>? Input { get; set; }
Expand Down Expand Up @@ -136,7 +136,7 @@ public void SetInputRoot(IInputRoot inputRoot)
{
InputRoot = inputRoot;
}

public virtual void Show()
{
_view.Visibility = ViewStates.Visible;
Expand All @@ -148,7 +148,7 @@ void Draw()
{
Paint?.Invoke(new Rect(new Point(0, 0), ClientSize));
}

public virtual void Dispose()
{
_systemNavigationManager.Dispose();
Expand Down Expand Up @@ -264,11 +264,11 @@ public sealed override IInputConnection OnCreateInputConnection(EditorInfo? outA
}

public IPopupImpl? CreatePopup() => null;

public Action? LostFocus { get; set; }
public Action<WindowTransparencyLevel>? TransparencyLevelChanged { get; set; }

public WindowTransparencyLevel TransparencyLevel
public WindowTransparencyLevel TransparencyLevel
{
get => _transparencyLevel;
private set
Expand Down Expand Up @@ -681,5 +681,29 @@ public override bool PerformEditorAction([GeneratedEnum] ImeAction actionCode)

return extract;
}

public override bool PerformContextMenuAction(int id)
{
if (InputMethod.Client is not { } client) return false;

switch (id)
{
case global::Android.Resource.Id.SelectAll:
client.ExecuteContextMenuAction(ContextMenuAction.SelectAll);
return true;
case global::Android.Resource.Id.Cut:
client.ExecuteContextMenuAction(ContextMenuAction.Cut);
return true;
case global::Android.Resource.Id.Copy:
client.ExecuteContextMenuAction(ContextMenuAction.Copy);
return true;
case global::Android.Resource.Id.Paste:
client.ExecuteContextMenuAction(ContextMenuAction.Paste);
return true;
default:
break;
}
return base.PerformContextMenuAction(id);
}
}
}
Loading