Changeset 292 for trunk/LocalPlayer
- Timestamp:
- Mar 2, 2021, 10:45:43 PM (4 years ago)
- Location:
- trunk/LocalPlayer
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/LocalPlayer/Term.pas
r291 r292 3403 3403 i, j: integer; 3404 3404 begin 3405 KeyBindings.LoadFromRegistry(HKEY_CURRENT_USER, AppRegistryKey + '\KeyBindings'); 3405 3406 UpdateKeyShortcuts; 3406 3407 … … 3507 3508 I: Integer; 3508 3509 begin 3510 KeyBindings.SaveToRegistry(HKEY_CURRENT_USER, AppRegistryKey + '\KeyBindings'); 3509 3511 MainFormKeyDown := nil; 3510 3512 FreeAndNil(sb); -
trunk/LocalPlayer/UKeyBindings.pas
r291 r292 6 6 7 7 uses 8 Classes, SysUtils, fgl, LCLProc, LCLType, Menus ;8 Classes, SysUtils, fgl, LCLProc, LCLType, Menus, Registry; 9 9 10 10 type … … 23 23 24 24 TKeyBindings = class(TFPGObjectList<TKeyBinding>) 25 public 25 26 function AddItem(const ShortName, FullName: string; ShortCut: TShortCut; ShortCut2: TShortCut = 0): TKeyBinding; overload; 26 27 function AddItem(const ShortName, FullName: string; ShortCutText: string; ShortCutText2: string = ''): TKeyBinding; overload; 27 28 function Search(ShortName: string): TKeyBinding; 28 procedure LoadFrom File(FileName: string);29 procedure SaveTo File(FileName: string);29 procedure LoadFromRegistry(RootKey: HKEY; Key: string); 30 procedure SaveToRegistry(RootKey: HKEY; Key: string); 30 31 end; 31 32 … … 151 152 end; 152 153 153 procedure TKeyBindings.LoadFromFile(FileName: string); 154 var 155 Lines: TStringList; 154 procedure TKeyBindings.LoadFromRegistry(RootKey: HKEY; Key: string); 155 var 156 156 I: Integer; 157 KeyBinding: TKeyBinding; 158 begin 159 Lines := TStringList.Create; 160 Lines.NameValueSeparator := '='; 157 Registry: TRegistry; 158 Text: string; 159 begin 160 Registry := TRegistry.Create; 161 Registry.RootKey := RootKey; 162 with Registry do 161 163 try 162 Lines.LoadFromFile(FileName); 163 for I := 0 to Lines.Count - 1 do begin 164 KeyBinding := Search(Lines.Names[I]); 165 if Assigned(KeyBinding) then begin 166 KeyBinding.ShortCut := TextToShortCut(Lines.ValueFromIndex[I]); 164 OpenKey(Key, True); 165 for I := 0 to Count - 1 do begin 166 Text := ''; 167 if ValueExists(Items[I].ShortName) then begin 168 Text := ReadString(Items[I].ShortName); 169 if Pos(',', Text) > 0 then begin 170 Items[I].ShortCut2 := TextToShortCut(Copy(Text, Pos(',', Text) + 1, MaxInt)); 171 Items[I].ShortCut := TextToShortCut(Copy(Text, 1, Pos(',', Text) - 1)); 172 end else begin 173 Items[I].ShortCut := TextToShortCut(Text); 174 Items[I].ShortCut2 := 0; 175 end; 176 end else begin 177 Text := ShortCutToText(Items[I].ShortCut); 178 if Items[I].ShortCut2 <> 0 then Text := Text + ',' + ShortCutToText(Items[I].ShortCut2); 179 WriteString(Items[I].ShortName, Text); 167 180 end; 168 181 end; 169 182 finally 170 FreeAndNil(Lines); 171 end; 172 end; 173 174 procedure TKeyBindings.SaveToFile(FileName: string); 175 var 176 Lines: TStringList; 183 Free; 184 end; 185 end; 186 187 procedure TKeyBindings.SaveToRegistry(RootKey: HKEY; Key: string); 188 var 177 189 I: Integer; 178 begin 179 Lines := TStringList.Create; 180 Lines.NameValueSeparator := '='; 190 Registry: TRegistry; 191 Text: string; 192 begin 193 Registry := TRegistry.Create; 194 Registry.RootKey := RootKey; 195 with Registry do 181 196 try 197 OpenKey(Key, True); 182 198 for I := 0 to Count - 1 do begin 183 Lines.Add(TKeyBinding(Items[I]).ShortName + '=' + ShortCutToText(TKeyBinding(Items[I]).ShortCut)); 199 Text := ShortCutToText(Items[I].ShortCut); 200 if Items[I].ShortCut2 <> 0 then Text := Text + ',' + ShortCutToText(Items[I].ShortCut2); 201 WriteString(Items[I].ShortName, Text); 184 202 end; 185 Lines.SaveToFile(FileName);186 203 finally 187 Free AndNil(Lines);204 Free; 188 205 end; 189 206 end;
Note:
See TracChangeset
for help on using the changeset viewer.