Changeset 385 for trunk/LocalPlayer


Ignore:
Timestamp:
Apr 27, 2021, 6:42:29 PM (4 years ago)
Author:
chronos
Message:
  • Added: Allow to change key bindings from Settings dialog.
  • Added: Allow to reset settings in Settings dialog.
Location:
trunk/LocalPlayer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/Term.pas

    r364 r385  
    34403440  NoMapPanel := TIsoMap.Create;
    34413441
    3442   KeyBindings.LoadFromRegistry(HKEY_CURRENT_USER, AppRegistryKey + '\KeyBindings');
    34433442  UpdateKeyShortcuts;
    34443443
     
    35393538  I: Integer;
    35403539begin
    3541   KeyBindings.SaveToRegistry(HKEY_CURRENT_USER, AppRegistryKey + '\KeyBindings');
    35423540  MainFormKeyDown := nil;
    35433541  FreeAndNil(sb);
  • trunk/LocalPlayer/UKeyBindings.pas

    r293 r385  
    1717    ShortCut: TShortCut;
    1818    ShortCut2: TShortCut;
     19    DefaultShortCut: TShortCut;
     20    DefaultShortCut2: TShortCut;
    1921    function Test(AShortCut: TShortCut): Boolean;
     22    procedure Assign(Source: TKeyBinding);
     23    procedure SetDefault;
    2024  end;
    2125
     
    2327
    2428  TKeyBindings = class(TFPGObjectList<TKeyBinding>)
     29  private
    2530  public
    2631    function AddItem(const ShortName, FullName: string; ShortCut: TShortCut; ShortCut2: TShortCut = 0): TKeyBinding; overload;
     
    2934    procedure LoadFromRegistry(RootKey: HKEY; Key: string);
    3035    procedure SaveToRegistry(RootKey: HKEY; Key: string);
     36    procedure LoadToStrings(Strings: TStrings);
     37    procedure Assign(Source: TKeyBindings);
     38    procedure ResetToDefault;
    3139  end;
    3240
     
    123131end;
    124132
     133procedure TKeyBinding.Assign(Source: TKeyBinding);
     134begin
     135  ShortName := Source.ShortName;
     136  FullName := Source.FullName;
     137  ShortCut := Source.ShortCut;
     138  ShortCut2 := Source.ShortCut2;
     139  DefaultShortCut := Source.DefaultShortCut;
     140  DefaultShortCut2 := Source.DefaultShortCut2;
     141end;
     142
     143procedure TKeyBinding.SetDefault;
     144begin
     145  ShortCut := DefaultShortCut;
     146  ShortCut2 := DefaultShortCut2;
     147end;
     148
    125149{ TKeyBindings }
    126150
     
    133157  Result.ShortCut := ShortCut;
    134158  Result.ShortCut2 := ShortCut2;
     159  Result.DefaultShortCut := ShortCut;
     160  Result.DefaultShortCut2 := ShortCut2;
    135161  Add(Result);
    136162end;
     
    205231    Free;
    206232  end;
     233end;
     234
     235procedure TKeyBindings.LoadToStrings(Strings: TStrings);
     236var
     237  I: Integer;
     238  Text: string;
     239begin
     240  Strings.Clear;
     241  for I := 0 to Count - 1 do begin
     242    Text:= '';
     243    if Items[I].ShortCut <> 0 then
     244      Text:= Text + ShortCutToText(Items[I].ShortCut);
     245    if Items[I].ShortCut2 <> 0 then begin
     246      if Text <> '' then Text := Text + ', ';
     247      Text:= Text + ShortCutToText(Items[I].ShortCut2);
     248    end;
     249    if Text <> '' then Text := Items[I].FullName + ' (' + Text + ')'
     250      else Text := Items[I].FullName;
     251    Strings.Add(Text);
     252  end;
     253end;
     254
     255procedure TKeyBindings.Assign(Source: TKeyBindings);
     256var
     257  I: Integer;
     258begin
     259  while Count < Source.Count do
     260    Add(TKeyBinding.Create);
     261  while Count > Source.Count do
     262    Delete(Count - 1);
     263  for I := 0 to Count - 1 do
     264    Items[I].Assign(Source.Items[I]);
     265end;
     266
     267procedure TKeyBindings.ResetToDefault;
     268var
     269  I: Integer;
     270begin
     271  for I := 0 to Count - 1 do
     272    Items[I].SetDefault;
    207273end;
    208274
Note: See TracChangeset for help on using the changeset viewer.