mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-28 18:11:35 +01:00
Menu designer: Streamline HasAccelerator. ToDo: UTF-8 character still not used.
git-svn-id: trunk@51618 -
This commit is contained in:
parent
6fd4274fb1
commit
f40caa1942
@ -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
|
UTF8Len := UTF8CharacterLength(@aText[p+1]);
|
||||||
foundChar:=LazUTF8.UTF8Copy(aCopy, p+1, 1);
|
accelStr := UTF8UpperCase(Copy(aText, p+1, UTF8Len)); // force uppercase
|
||||||
if (foundChar <> '&') then begin
|
// ToDo: Use the whole UTF-8 character in accelStr. How?
|
||||||
accelStr:=LazUTF8.UTF8UpperCase(foundChar); // force uppercase
|
aShortcut := KeyToShortCut(Ord(accelStr[1]),
|
||||||
Result:=True;
|
{$if defined(darwin) or defined(macos) or defined(iphonesim)} [ssMeta]
|
||||||
|
{$else} [ssAlt] {$endif});
|
||||||
|
Result := True;
|
||||||
Break;
|
Break;
|
||||||
end
|
|
||||||
else begin
|
|
||||||
LazUTF8.UTF8Delete(aCopy, 1, p+1);
|
|
||||||
p:=LazUTF8.UTF8Pos('&', aCopy);
|
|
||||||
end;
|
end;
|
||||||
end;
|
until False;
|
||||||
if Result then
|
|
||||||
aShortcut:=KeyToShortCut(Ord(accelStr[1]),
|
|
||||||
{$if defined(darwin) or defined(macos) or defined(iphonesim)} [ssMeta]
|
|
||||||
{$else} [ssAlt] {$endif})
|
|
||||||
else
|
|
||||||
aShortcut:=0;
|
|
||||||
end;
|
end;
|
||||||
{
|
{
|
||||||
function GetAcceleratedItemsCount(aMenu: TMenu): integer;
|
function GetAcceleratedItemsCount(aMenu: TMenu): integer;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user