Skip to content

request: Support for keyboard shortcuts/accelerators in menus #89

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

Closed
pcwalton opened this issue May 31, 2016 · 10 comments
Closed

request: Support for keyboard shortcuts/accelerators in menus #89

pcwalton opened this issue May 31, 2016 · 10 comments

Comments

@pcwalton
Copy link
Contributor

This is needed to feel native on all platforms.

@andlabs
Copy link
Owner

andlabs commented May 31, 2016

That is planned, yes. I need to figure out how menus are going to work.

Potential problem: on OS X, things like copy and paste not only require accelerators to be hooked, but also hooked to specific selectors (copy:, for instance). uiArea will probably need to have special events for those, but that raises the question of how to do the same on other platforms. More predefined menu items?

@kainjow
Copy link
Contributor

kainjow commented May 31, 2016

Just extend the built-in menu types (e.g. uiMenuAppendCopyItem) but for OS X set the target to nil to use the first responder.

@aoloe
Copy link

aoloe commented Jun 1, 2016

somehow, i would prefer being able to attach the built-in action to the same action attached to the menu item.

@andlabs
Copy link
Owner

andlabs commented Jun 1, 2016

@aoloe I don't understand what you mean; could you clarify your comment please?

@aoloe
Copy link

aoloe commented Jun 1, 2016

i would prefer not to have a uiMenuAppendCopyItem in the same way i'm not fond of uiMenuAppendQuitItem (#32).

a quick and dirty "draft" of my idea would be:

item = uiMenuAppendItem(menu, "Quit");
uiMenuItemOnClicked(item, quitClicked, NULL);
uiSystemActionQuit(quitClicked);

item = uiMenuAppendItem(menu, "Copy");
uiMenuItemOnClicked(item, copyClicked, NULL);
uiSystemActionCopy(copyClicked);

i don't know if it's clearer this way or an uiSystemActionQuit() function is a good idea... but the main idea is that i'd prefer to get more transparency in what actions are triggered. Currently the Quit action is somehow a "magic" one...
It would be the same for the Copy one...

@andlabs
Copy link
Owner

andlabs commented Jun 1, 2016

Ah. So how would your event work for copying while focus is on a uiEntry? Would I have to override the entry controls to intercept the request to copy?

Also I forget how accelerators are done on GTK+; I think GtkActionGroup...

@aoloe
Copy link

aoloe commented Jun 1, 2016

my comment was about the idea of adding one more buil-in action, not about adding shortcuts...
i tried to check how qt applications manage copy but could not find anything usable for helping in this matter, sorry....

@mischnic
Copy link
Contributor

mischnic commented Mar 10, 2018

+1 (or rather +100) for "to feel native"

Here is the macOS part (all native actions I could find) :

	case typeCopy:
		item->item = [[NSMenuItem alloc] initWithTitle:toNSString(name) action:@selector(copy:) keyEquivalent:@"c"];
		[m->menu addItem:item->item];
		break;
	case typePaste:
		item->item = [[NSMenuItem alloc] initWithTitle:toNSString(name) action:@selector(paste:) keyEquivalent:@"v"];
		[m->menu addItem:item->item];
		break;
	case typeCut:
		item->item = [[NSMenuItem alloc] initWithTitle:toNSString(name) action:@selector(cut:) keyEquivalent:@"x"];
		[m->menu addItem:item->item];
		break;
	case typeSelectAll:
		item->item = [[NSMenuItem alloc] initWithTitle:toNSString(name) action:@selector(selectAll:) keyEquivalent:@"a"];
		[m->menu addItem:item->item];
		break;
	//name is ignored for these
	case typeUndo:
		item->item = [[NSMenuItem alloc] initWithTitle:@"" action:@selector(undo:) keyEquivalent:@"z"];
		[m->menu addItem:item->item];
		break;
	case typeRedo:
		item->item = [[NSMenuItem alloc] initWithTitle:@"" action:@selector(redo:) keyEquivalent:@"Z"];
		[m->menu addItem:item->item];
		break;
	case typeFullscreen:
		item->item = [[NSMenuItem alloc] initWithTitle:@"" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
		[item->item setKeyEquivalentModifierMask:(NSControlKeyMask | NSCommandKeyMask)];
		[m->menu addItem:item->item];
		break;

It works fine, but Unix and Windows support is of course missing (should all of these function be reimplemented ?).

gedit's code might be helpful: https://github.com/GNOME/gedit/blob/9a7f1542ce0fa5ddc23fc60c5848a80dd80bd8eb/gedit/gedit-commands-edit.c

@mischnic
Copy link
Contributor

mischnic commented Mar 10, 2018

Regarding the naming:

uiMenuItem *uiMenuAppendItem(uiMenu *m, const char *name){
    return uiMenuAppendTypeItem(m, name, typeRegular)
}
uiMenuItem *uiMenuAppendTypeItem(uiMenu *m, const char *name, int type);

(with type being a platform-independent enum) wouldn't require adding a function for every type (like uiSystemActionCopy or uiMenuAppendCopyItem).

@andlabs
Copy link
Owner

andlabs commented Mar 25, 2018

Replaced with #321.

@andlabs andlabs closed this as completed Mar 25, 2018
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

No branches or pull requests

5 participants