mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-06 23:38:02 +02:00
Cocoa: fixed missing Accelerator key (&) support in Menu
This commit is contained in:
parent
c7bbb0b354
commit
7520a1a5ef
@ -72,6 +72,7 @@ procedure MenuTrackCancelAll;
|
||||
// the returned "Key" should not be released, as it's not memory owned
|
||||
procedure ShortcutToKeyEquivalent(const AShortCut: TShortcut; out Key: NSString; out shiftKeyMask: NSUInteger);
|
||||
|
||||
function LCLMenuItemInit(item: NSMenuItem; const lclMenuItem: TMenuItem): id;
|
||||
function LCLMenuItemInit(item: NSMenuItem; const atitle: string; ashortCut: TShortCut): id;
|
||||
function LCLMenuItemInit(item: NSMenuItem; const atitle: string; VKKey: Word = 0; State: TShiftState = []): id;
|
||||
function ToggleAppMenu(ALogicalEnabled: Boolean): Boolean;
|
||||
@ -194,6 +195,41 @@ begin
|
||||
ANSMenuItem.setState( menustate[Checked] );
|
||||
end;
|
||||
|
||||
function getHotkeyFromTitle( aTitle:String ): Word;
|
||||
var
|
||||
i: Integer;
|
||||
hotkeyChar: Char;
|
||||
begin
|
||||
Result:= 0;
|
||||
i:= aTitle.IndexOf( cHotkeyPrefix );
|
||||
if (i<0) or (i>=aTitle.Length-1) then
|
||||
Exit;
|
||||
|
||||
hotkeyChar:= aTitle.Chars[i+1];
|
||||
if hotkeyChar <> cHotkeyPrefix then
|
||||
Result:= Word( UpCase(hotkeyChar) );
|
||||
end;
|
||||
|
||||
function LCLMenuItemInit(item: NSMenuItem; const lclMenuItem: TMenuItem): id;
|
||||
var
|
||||
aShortCut: TShortCut;
|
||||
aTitle: String;
|
||||
key: Word;
|
||||
begin
|
||||
aTitle := lclMenuItem.Caption;
|
||||
aShortCut := lclMenuItem.ShortCut;
|
||||
|
||||
if aShortCut=0 then begin
|
||||
if not Assigned(lclMenuItem.Action) then begin
|
||||
key:= getHotkeyFromTitle( aTitle );
|
||||
if key<>0 then
|
||||
aShortCut:= ShortCut( key, [] );
|
||||
end;
|
||||
end;
|
||||
|
||||
Result:= LCLMenuItemInit(item, aTitle, aShortCut);
|
||||
end;
|
||||
|
||||
function LCLMenuItemInit(item: NSMenuItem; const atitle: string; ashortCut: TShortCut): id;
|
||||
var
|
||||
key : NSString;
|
||||
|
@ -268,7 +268,7 @@ begin
|
||||
end
|
||||
else
|
||||
begin
|
||||
item := LCLMenuItemInit(TCocoaMenuItem.alloc, AMenuItem.Caption, AMenuItem.ShortCut);
|
||||
item := LCLMenuItemInit(TCocoaMenuItem.alloc, AMenuItem);
|
||||
TCocoaMenuItem(item).FMenuItemTarget := AMenuItem;
|
||||
|
||||
if AMenuItem.IsInMenuBar then
|
||||
|
Loading…
Reference in New Issue
Block a user