IDE: Fix display of hints in the mainbar and editor toolbar for shortcuts with a sequence of keystrokes

This commit is contained in:
n7800 2024-10-26 02:03:48 +05:00 committed by Juha
parent 8f51444869
commit 43da908474
4 changed files with 42 additions and 43 deletions

View File

@ -880,6 +880,9 @@ function RegisterIDECommandScope(const Name: string): TIDECommandScope;
procedure CreateStandardIDECommandScopes; procedure CreateStandardIDECommandScopes;
function KeyAndShiftStateToEditorKeyString(const Key: TIDEShortCut): String;
function KeyValuesToCaptionStr(const ShortcutA, ShortcutB: TIDEShortCut; Brackets: Char = '['): String;
function CompareIDEShortCuts(Data1, Data2: Pointer): integer; function CompareIDEShortCuts(Data1, Data2: Pointer): integer;
function CompareIDEShortCutKey1s(Data1, Data2: Pointer): integer; function CompareIDEShortCutKey1s(Data1, Data2: Pointer): integer;
function IdentToIDECommand(const Ident: string; var Cmd: longint): boolean; function IdentToIDECommand(const Ident: string; var Cmd: longint): boolean;
@ -955,6 +958,41 @@ begin
IDECmdScopeObjectInspectorOnly:=RegisterIDECommandScope('ObjectInspectorOnly'); IDECmdScopeObjectInspectorOnly:=RegisterIDECommandScope('ObjectInspectorOnly');
end; end;
function KeyAndShiftStateToEditorKeyString(const Key: TIDEShortCut): String;
begin
Result := KeyAndShiftStateToKeyString(Key.Key1, Key.Shift1);
if Key.Key2 <> VK_UNKNOWN then
Result := Result + ', ' + KeyAndShiftStateToKeyString(Key.Key2, Key.Shift2);
end;
function KeyValuesToCaptionStr(const ShortcutA, ShortcutB: TIDEShortCut; Brackets: Char): String;
function AddBrakets(S: String): String;
begin
if Brackets = '[' then
Result := '[' + S + ']'
else if Brackets = '(' then
Result := '(' + S + ')'
else if Brackets > #0 then
Result := Brackets + S + Brackets
else
Result := S;
end;
begin
Result := '';
if (ShortcutA.Key1 = VK_UNKNOWN) and (ShortcutB.Key1 = VK_UNKNOWN) then
Result := Result{ + lisNone2 }
else
if (ShortcutA.Key1 = VK_UNKNOWN) then
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutB))
else
if (ShortcutB.Key1 = VK_UNKNOWN) then
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutA))
else
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutA))
+ ' / ' +
AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutB));
end;
type type
// in fpc 2.3.1 TShiftState is declared with {$packset 1} // in fpc 2.3.1 TShiftState is declared with {$packset 1}
{$IF sizeof(TShiftState)=2} {$IF sizeof(TShiftState)=2}
@ -1732,9 +1770,9 @@ function TIDESpecialCommand.GetShortcut: String;
begin begin
Result := ''; Result := '';
if Assigned(FCommand) then if Assigned(FCommand) then
Result := ShortCutToText(FCommand.AsShortCut); Result := KeyValuesToCaptionStr(FCommand.ShortcutA, FCommand.ShortcutB);
if Result <> '' then if Result <> '' then
Result := ' (' + Result + ')'; Result := ' ' + Result;
end; end;
procedure TIDESpecialCommand.SetCaption(aCaption: string); procedure TIDESpecialCommand.SetCaption(aCaption: string);

View File

@ -33,7 +33,7 @@ uses
// SynEdit // SynEdit
SynEdit, SynBeautifier, SynHighlighterPas, SynEditKeyCmds, SynEditTypes, SynEdit, SynBeautifier, SynHighlighterPas, SynEditKeyCmds, SynEditTypes,
// IdeIntf // IdeIntf
IDEOptionsIntf, IDEOptEditorIntf, IDEUtils, SrcEditorIntf, IDEOptionsIntf, IDEOptEditorIntf, IDEUtils, SrcEditorIntf, IDECommands,
// IDE // IDE
EditorOptions, LazarusIDEStrConsts, KeyMapping, EditorOptions, LazarusIDEStrConsts, KeyMapping,
editor_keymapping_options, editor_general_options; editor_keymapping_options, editor_general_options;

View File

@ -31,7 +31,7 @@ uses
// LazControls // LazControls
DividerBevel, DividerBevel,
// IDEIntf // IDEIntf
EditorSyntaxHighlighterDef, IDEOptionsIntf, IDEOptEditorIntf, EditorSyntaxHighlighterDef, IDEOptionsIntf, IDEOptEditorIntf, IDECommands,
// SynEdit // SynEdit
SynEdit, SynHighlighterPas, SynEditKeyCmds, SynEditHighlighterFoldBase, SynEdit, SynHighlighterPas, SynEditKeyCmds, SynEditHighlighterFoldBase,
// IDE // IDE

View File

@ -232,7 +232,6 @@ type
end; end;
function IDEShortCutEmpty(const Key: TIDEShortCut): boolean; function IDEShortCutEmpty(const Key: TIDEShortCut): boolean;
function KeyAndShiftStateToEditorKeyString(const Key: TIDEShortCut): String;
function EditorCommandToDescriptionString(cmd: word): String; function EditorCommandToDescriptionString(cmd: word): String;
function EditorMouseCommandToDescriptionString(cmd: TSynEditorMouseCommand): String; function EditorMouseCommandToDescriptionString(cmd: TSynEditorMouseCommand): String;
function EditorMouseCommandToConfigString(cmd: TSynEditorMouseCommand): String; function EditorMouseCommandToConfigString(cmd: TSynEditorMouseCommand): String;
@ -241,8 +240,6 @@ function KeySchemeNameToSchemeType(const SchemeName: string): TKeyMapScheme;
function ShiftStateToCfgStr(Shift: TShiftState): string; function ShiftStateToCfgStr(Shift: TShiftState): string;
function KeyValuesToCfgStr(const ShortcutA, ShortcutB: TIDEShortCut): string; function KeyValuesToCfgStr(const ShortcutA, ShortcutB: TIDEShortCut): string;
function KeyValuesToCaptionStr(const ShortcutA, ShortcutB: TIDEShortCut;
Brackets: Char = '['): String;
function CfgStrToShiftState(const s: string): TShiftState; function CfgStrToShiftState(const s: string): TShiftState;
function CompareLoadedKeyCommands(Data1, Data2: Pointer): integer; function CompareLoadedKeyCommands(Data1, Data2: Pointer): integer;
@ -1002,47 +999,11 @@ begin
Result := ''; Result := '';
end; end;
function KeyValuesToCaptionStr(const ShortcutA, ShortcutB: TIDEShortCut;
Brackets: Char): String;
function AddBrakets(S: String): String;
begin
if Brackets = '[' then
Result := '[' + S + ']'
else if Brackets = '(' then
Result := '(' + S + ')'
else if Brackets > #0 then
Result := Brackets + S + Brackets
else
Result := S;
end;
begin
Result := '';
if (ShortcutA.Key1 = VK_UNKNOWN) and (ShortcutB.Key1 = VK_UNKNOWN) then
Result := Result{ + lisNone2 }
else
if (ShortcutA.Key1 = VK_UNKNOWN) then
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutB))
else
if (ShortcutB.Key1 = VK_UNKNOWN) then
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutA))
else
Result := Result + AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutA))
+ ' '+lisOr+' ' +
AddBrakets(KeyAndShiftStateToEditorKeyString(ShortcutB));
end;
function IDEShortCutEmpty(const Key: TIDEShortCut): boolean; function IDEShortCutEmpty(const Key: TIDEShortCut): boolean;
begin begin
Result:=(Key.Key1=VK_UNKNOWN) and (Key.Key2=VK_UNKNOWN); Result:=(Key.Key1=VK_UNKNOWN) and (Key.Key2=VK_UNKNOWN);
end; end;
function KeyAndShiftStateToEditorKeyString(const Key: TIDEShortCut): String;
begin
Result := KeyAndShiftStateToKeyString(Key.Key1, Key.Shift1);
if (Key.Key2 <> VK_UNKNOWN) then
Result := Result + ', ' + KeyAndShiftStateToKeyString(Key.Key2, Key.Shift2);
end;
{ TKeyStrokeList } { TKeyStrokeList }
procedure TKeyStrokeList.Add(aKeyStroke: TSynEditKeyStroke); procedure TKeyStrokeList.Add(aKeyStroke: TSynEditKeyStroke);