-
Notifications
You must be signed in to change notification settings - Fork 10
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
Text boxes don't have context menus and don't allow copy/paste through keyboard shortcuts #7
Comments
We probably don't have an implementation strategy for this yet. In our application we have a custom implementation of the application menu which triggers the standard selectors for the Copy/Cut/Paste commands and thus makes the shortcuts work. Obviously the drawback is that it doesn't work out of the box for normal WinForms applications. It would probably be possible to change the default menu code to include this as well, but it may not be the perfect solution. Another thing I contemplated about was properly routing the Windows WM_CLEAR/WM_COPY/WM_CUT/WM_PASTE messages and implementing them on the native controls, but that probably won't solve anything for this particular case either. I currently don't have any thoughts for the context menu. My coworker wrote the code, so he'd probably know better (@aconcagua21?). Are you interested in the standard system context menu, or also a way to use a custom one? |
Thanks for your feedback. Do you have any idea why for the NSTextView the context menu shows when it does not have focus? I'm trying to understand if it might be possible to have the same functionality when focused. Could you share a pointer how to add a custom application menu or add the default menu? |
Honestly I am quite puzzled by that. I didn't notice it until you pointed it out.
We used to translate the window menu in XplatUICocoa and provide some reasonable defaults there if no window menu was present, but it seems the code has bit-rotten and we eventually removed it. Even if it was resurrected there's still issue with the fact that it only worked on the old-school Menu/MenuItem objects and not on the newer ToolStripMenuItem code that most applications use nowadays. Unfortunately I cannot share the code from our application. We have the menu implemented using For the special menu items like Copy/Paste we register a code similar to this to the Click handler of ToolStripMenuItem: var selector = new Selector("copy:"));
var responder = NSApplication.SharedApplication.KeyWindow?.FirstResponder;
if (responder != null) {
if (!IsSwfResponder(responder))
if (SwfContainerDoCommandBySelector(responder, selector))
return; // swallowed or executed by swf container
if (responder.TryToPerformwith(selector, this))
return;
} and the helper methods: // The following selectors must match method selectors in MonoView and WindowsEventResponder
internal static readonly Selector swfControlHandleSel = new Selector("swfControlHandle");
internal static readonly Selector embeddedControlDoCommandBySelectorSel = new Selector("embeddedControl:doCommandBySelector:");
internal static bool IsSwfResponder(NSResponder responder)
{
return responder.RespondsToSelector(swfControlHandleSel);
}
internal static NSResponder NextSwfResponder(NSResponder responder)
{
while (responder != null && !IsSwfResponder(responder))
responder = responder.NextResponder;
return responder;
}
internal static bool SwfContainerDoCommandBySelector(NSResponder target, Selector command)
{
return SwfContainerDoCommandBySelector(NextSwfResponder(target), target, command);
}
internal static bool SwfContainerDoCommandBySelector(NSResponder container, NSResponder target, Selector command)
{
if (container?.RespondsToSelector(embeddedControlDoCommandBySelectorSel) ?? false)
return LibObjc.bool_objc_msgSend_IntPtr_IntPtr(container.Handle, embeddedControlDoCommandBySelectorSel.Handle, target.Handle, command.Handle);
return false;
} The approach is far from universal and I would be happy if the code is cleaned up since we now depend on the internal implementation in XplatUICocoa. I didn't think about how to clean it up though, so ideas are more than welcome. |
So far, I don't know why context menus don't work.
|
Now I remembered how I wanted to use the WM_COPY/WM_PASTE/WM_CUT messages. The idea was to implement the standard "copy:"/"paste:"/"cut:" selectors on |
Yes, that's how it is done (not in MonoView, but in WindowsEventResponder). |
The context menu problem should be resolved by 7e01729. |
Thanks for the update. I will try it but it may take a while. |
Unlike most native controls text boxes do not show a context menu on right click. There is one exception: When right-clicking on a TextBoxBase_NSTextView while it does not have focus the macOS context menu is shown. It does not work when right-clicking after the control was activated.
Also Apple+C/V/X shortcuts don't work.
I'd be happy to trying adding the functionality. However, I'm wondering if overriding the mouse button and key down events and adding the required calls here is would be the right approach.
@filipnavara Can you share any hints?
The text was updated successfully, but these errors were encountered: