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.

(cherry picked from commit 18bec6520a)
This commit is contained in:
Maxim Ganetsky 2023-11-11 02:16:41 +03:00
parent dd0b913271
commit 1dc998066d
3 changed files with 13 additions and 7 deletions

View File

@ -5088,10 +5088,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 := 0 to HighlighterList.Count - 1 do

View File

@ -74,6 +74,8 @@ const
ecIdePSyncroOutOffset = ecSynPSyncroEdNextCell - ecIdePSyncroEdOutNextCell;
ecIdePSyncroSelOffset = ecSynPSyncroEdStart - ecIdePSyncroEdSelStart;
KeyMappingSchemeConfigDirName = 'userkeyschemes';
type
//---------------------------------------------------------------------------
// TKeyCommandCategory is used to divide the key commands in handy packets
@ -3570,8 +3572,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
@ -3632,6 +3637,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));
@ -3657,7 +3663,6 @@ begin
end;
end;
end;
Result:=true;
end;
function TKeyCommandRelationList.SaveToXMLConfig(
@ -4367,7 +4372,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
@ -4420,11 +4425,9 @@ end;
initialization
RegisterKeyCmdIdentProcs(@IdentToIDECommand,
@IDECommandToIdent);
// CustomKeySchemas should be freed in TMainIDE.Destroy destructor
CustomKeySchemas := TStringList.Create;
CustomKeySchemas.OwnsObjects := true;
finalization
CustomKeySchemas.Free;
end.

View File

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