IDE: Fixed loading of user key schemes.

1. Fix access violation on closing IDE when loaded user key scheme is present.
2. Correctly load user key scheme on IDE (re)start.
3. Search user key schemes in `userkeyschemes` subdirectory of Lazarus configuration directory.

Based on patch by Dean Mustakinov, part of issue #40559.
This commit is contained in:
Maxim Ganetsky 2023-11-11 02:16:41 +03:00
parent 9ef9c85f35
commit 18bec6520a
3 changed files with 13 additions and 7 deletions

View File

@ -5421,10 +5421,12 @@ begin
XMLConfig.GetValue('EditorOptions/Display/DoNotWarnForFont', '');
// Key Mappings options
LoadCustomKeySchemas;
fKeyMappingScheme :=
XMLConfig.GetValue('EditorOptions/KeyMapping/Scheme', KeyMapSchemeNames[kmsLazarus]);
fKeyMap.LoadFromXMLConfig(XMLConfig
, 'EditorOptions/KeyMapping/' + fKeyMappingScheme + '/');
if not fKeyMap.LoadFromXMLConfig(XMLConfig
, 'EditorOptions/KeyMapping/' + fKeyMappingScheme + '/') then
fKeyMappingScheme := KeyMapSchemeNames[kmsLazarus];
// Color options
for i := IdeHighlighterStartId to HighlighterList.Count - 1 do

View File

@ -79,6 +79,8 @@ const
ecIdePSyncroOutOffset = ecSynPSyncroEdNextCell - ecIdePSyncroEdOutNextCell;
ecIdePSyncroSelOffset = ecSynPSyncroEdStart - ecIdePSyncroEdSelStart;
KeyMappingSchemeConfigDirName = 'userkeyschemes';
type
//---------------------------------------------------------------------------
// TKeyCommandCategory is used to divide the key commands in handy packets
@ -3597,8 +3599,11 @@ begin
FileVersion:=XMLConfig.GetValue(Path+'Version/Value',0);
ExtToolCount:=XMLConfig.GetValue(Path+'ExternalToolCount/Value',0);
Result:=false;
if FileVersion>5 then begin
Cnt:=XMLConfig.GetValue(Path+'Count',0);
Result:=Cnt>0;
// load all keys from the config, this may be more than the current relations
// for example because the command is not yet registered.
for a:=1 to Cnt do begin
@ -3659,6 +3664,7 @@ begin
Relations[a].ShortcutA:=Relations[a].DefaultShortcutA;
Relations[a].ShortcutB:=Relations[a].DefaultShortcutB;
end else begin
Result:=true;
p:=1;
Key1:=word(ReadNextInt);
Shift1:=FixShift(IntToShiftState(ReadNextInt));
@ -3684,7 +3690,6 @@ begin
end;
end;
end;
Result:=true;
end;
function TKeyCommandRelationList.SaveToXMLConfig(
@ -4394,7 +4399,7 @@ begin
if not Assigned(dst) then Exit;
fn := FindAllFiles(
IncludeTrailingPathDelimiter(dir)+'keyschema', '*.xml', false);
IncludeTrailingPathDelimiter(dir)+KeyMappingSchemeConfigDirName, '*.xml', false);
if not Assigned(fn) then Exit;
try
@ -4447,6 +4452,7 @@ end;
initialization
RegisterKeyCmdIdentProcs(@IdentToIDECommand,
@IDECommandToIdent);
// CustomKeySchemas should be freed in TMainIDE.Destroy destructor
CustomKeySchemas := TStringList.Create;
CustomKeySchemas.OwnsObjects := true;
@ -4457,8 +4463,5 @@ initialization
RegisterMouseCmdNameAndOptProcs(@EditorMouseCommandToDescriptionString,
@EditorMouseCommandToConfigString);
finalization
CustomKeySchemas.Free;
end.

View File

@ -1791,6 +1791,7 @@ begin
FreeThenNil(MiscellaneousOptions);
FreeThenNil(EditorOpts);
IDECommandList := nil;
FreeThenNil(CustomKeySchemas);
FreeThenNil(IDECommandScopes);
// free control selection
FreeThenNil(TheControlSelection);