source: trunk/Forms/UFormKeyShortcuts.pas@ 236

Last change on this file since 236 was 206, checked in by chronos, 7 years ago
  • Added: New window to list all available actions with their keyboard shortcuts.
  • Fixed: Keyboard shortcuts didn't worked for FormClient docked into FormMain.
  • Fixed: Signal a turn start to first player if a game is loaded from a file.
File size: 2.5 KB
Line 
1unit UFormKeyShortcuts;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
9 ComCtrls, ActnList, LCLProc, Menus;
10
11type
12
13 { TFormKeyShortcuts }
14
15 TFormKeyShortcuts = class(TForm)
16 ListView1: TListView;
17 MenuItem1: TMenuItem;
18 PopupMenu1: TPopupMenu;
19 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
20 procedure FormCreate(Sender: TObject);
21 procedure FormShow(Sender: TObject);
22 procedure MenuItem1Click(Sender: TObject);
23 private
24 public
25 procedure LoadFromComponent(C: TComponent);
26 end;
27
28var
29 FormKeyShortcuts: TFormKeyShortcuts;
30
31implementation
32
33uses
34 UFormMain, UCore;
35
36resourcestring
37 SMainForm = 'Main window';
38 SGlobal = 'Global';
39
40{ TFormKeyShortcuts }
41
42procedure TFormKeyShortcuts.FormShow(Sender: TObject);
43begin
44 Core.PersistentForm.Load(Self);
45 try
46 ListView1.BeginUpdate;
47 ListView1.Clear;
48 LoadFromComponent(Core);
49 LoadFromComponent(FormMain);
50 finally
51 ListView1.EndUpdate;
52 end;
53end;
54
55procedure TFormKeyShortcuts.MenuItem1Click(Sender: TObject);
56begin
57 if Assigned(ListView1.Selected) then
58 TAction(ListView1.Selected.Data).Execute;
59end;
60
61procedure TFormKeyShortcuts.FormClose(Sender: TObject;
62 var CloseAction: TCloseAction);
63begin
64 Core.PersistentForm.Save(Self);
65end;
66
67procedure TFormKeyShortcuts.FormCreate(Sender: TObject);
68begin
69 Core.CoolTranslator1.TranslateComponentRecursive(Self);
70end;
71
72procedure TFormKeyShortcuts.LoadFromComponent(C: TComponent);
73var
74 I: Integer;
75 NewItem: TListItem;
76begin
77 if C is TActionList then
78 with TActionList(C) do begin
79 for I := 0 to ActionCount - 1 do
80 if Actions[I] is TAction then
81 with TAction(Actions[I]) do
82 //if ShortCut > 0 then
83 begin
84 NewItem := ListView1.Items.Add;
85 NewItem.Caption := Caption;
86 NewItem.ImageIndex := ImageIndex;
87 NewItem.Data := TAction(Actions[I]);
88 with NewItem.SubItems do begin
89 if C.Owner is TFormMain then Add(SMainForm)
90 else if C.Owner is TDataModule then Add(SGlobal)
91 else if C.Owner is TForm then Add(TForm(C.Owner).Caption)
92 else Add(C.Name);
93 Add(ShortCutToText(ShortCut));
94 end;
95 end;
96 end;
97 for I := 0 to C.ComponentCount - 1 do
98 LoadFromComponent(C.Components[I]);
99end;
100
101initialization
102 {$I UFormKeyShortcuts.lrs}
103
104end.
105
Note: See TracBrowser for help on using the repository browser.