Menu designer: Streamline HasAccelerator. ToDo: UTF-8 character still not used.

git-svn-id: trunk@51618 -
This commit is contained in:
juha 2016-02-13 13:09:38 +00:00
parent 6fd4274fb1
commit f40caa1942

View File

@ -5,7 +5,7 @@ unit MenuShortcuts;
interface interface
uses uses
Classes, SysUtils, types, Classes, SysUtils, strutils, types,
ActnList, ButtonPanel, Controls, Dialogs, StdCtrls, Menus, ActnList, ButtonPanel, Controls, Dialogs, StdCtrls, Menus,
Forms, Graphics, LCLType, LCLIntf, LCLProc, Forms, Graphics, LCLType, LCLIntf, LCLProc,
// LazUtils // LazUtils
@ -294,38 +294,29 @@ begin
end; end;
function HasAccelerator(const aText: string; out aShortcut: TShortCut): boolean; function HasAccelerator(const aText: string; out aShortcut: TShortCut): boolean;
// ToDo: implement the UTF-8 stuff in a more clever way.
var var
p, UTF8Len: integer; p, UTF8Len: integer;
aCopy, foundChar, accelStr: string; accelStr: string;
begin begin
if (aText = '') then begin Result := False;
aShortcut:=0; aShortcut := 0;
Exit(False); if aText = '' then Exit;
end; p := 0;
aCopy:=aText; repeat
Result:=False; p := PosEx('&', aText, p+1);
UTF8Len := LazUTF8.UTF8Length(aCopy); if (p = 0) or (p = Length(aText)) then Break;
p:=LazUTF8.UTF8Pos('&', aCopy); if aText[p+1] <> '&' then // '&&' is reduced to '&' by widgetset GUI.
while (p > 0) and (p < UTF8Len) do
begin begin
foundChar:=LazUTF8.UTF8Copy(aCopy, p+1, 1); UTF8Len := UTF8CharacterLength(@aText[p+1]);
if (foundChar <> '&') then begin accelStr := UTF8UpperCase(Copy(aText, p+1, UTF8Len)); // force uppercase
accelStr:=LazUTF8.UTF8UpperCase(foundChar); // force uppercase // ToDo: Use the whole UTF-8 character in accelStr. How?
Result:=True; aShortcut := KeyToShortCut(Ord(accelStr[1]),
Break;
end
else begin
LazUTF8.UTF8Delete(aCopy, 1, p+1);
p:=LazUTF8.UTF8Pos('&', aCopy);
end;
end;
if Result then
aShortcut:=KeyToShortCut(Ord(accelStr[1]),
{$if defined(darwin) or defined(macos) or defined(iphonesim)} [ssMeta] {$if defined(darwin) or defined(macos) or defined(iphonesim)} [ssMeta]
{$else} [ssAlt] {$endif}) {$else} [ssAlt] {$endif});
else Result := True;
aShortcut:=0; Break;
end;
until False;
end; end;
{ {
function GetAcceleratedItemsCount(aMenu: TMenu): integer; function GetAcceleratedItemsCount(aMenu: TMenu): integer;