source: trunk/Forms/FormKeyShortcuts.pas

Last change on this file was 155, checked in by chronos, 3 months ago
  • Modified: Show action icons in key shortcuts form.
File size: 2.7 KB
Line 
1unit FormKeyShortcuts;
2
3interface
4
5uses
6 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
7 ComCtrls, ActnList, LCLProc, Menus, FormEx, Generics.Collections, ImgList;
8
9type
10
11 { TFormKeyShortcuts }
12
13 TFormKeyShortcuts = class(TFormEx)
14 ListView1: TListView;
15 MenuItem1: TMenuItem;
16 PopupMenu1: TPopupMenu;
17 procedure FormCreate(Sender: TObject);
18 procedure FormDestroy(Sender: TObject);
19 procedure FormShow(Sender: TObject);
20 procedure MenuItem1Click(Sender: TObject);
21 private
22 function GetImageList: TCustomImageList;
23 procedure SetImageList(AValue: TCustomImageList);
24 public
25 SourceComponents: TObjectList<TComponent>;
26 MainForm: TForm;
27 procedure LoadFromComponent(C: TComponent);
28 property ImageList: TCustomImageList read GetImageList write SetImageList;
29 end;
30
31
32implementation
33
34{$R *.lfm}
35
36resourcestring
37 SMainForm = 'Main window';
38 SGlobal = 'Global';
39
40{ TFormKeyShortcuts }
41
42procedure TFormKeyShortcuts.FormShow(Sender: TObject);
43var
44 I: Integer;
45begin
46 try
47 ListView1.BeginUpdate;
48 ListView1.Clear;
49 for I := 0 to SourceComponents.Count - 1 do
50 LoadFromComponent(SourceComponents[I]);
51 finally
52 ListView1.EndUpdate;
53 end;
54end;
55
56procedure TFormKeyShortcuts.FormCreate(Sender: TObject);
57begin
58 SourceComponents := TObjectList<TComponent>.Create;
59 SourceComponents.OwnsObjects := False;
60end;
61
62procedure TFormKeyShortcuts.FormDestroy(Sender: TObject);
63begin
64 FreeAndNil(SourceComponents);
65end;
66
67procedure TFormKeyShortcuts.MenuItem1Click(Sender: TObject);
68begin
69 if Assigned(ListView1.Selected) then
70 TAction(ListView1.Selected.Data).Execute;
71end;
72
73function TFormKeyShortcuts.GetImageList: TCustomImageList;
74begin
75 Result := ListView1.SmallImages;
76end;
77
78procedure TFormKeyShortcuts.SetImageList(AValue: TCustomImageList);
79begin
80 ListView1.SmallImages := AValue
81end;
82
83procedure TFormKeyShortcuts.LoadFromComponent(C: TComponent);
84var
85 I: Integer;
86 NewItem: TListItem;
87begin
88 if C is TActionList then
89 with TActionList(C) do begin
90 for I := 0 to ActionCount - 1 do
91 if Actions[I] is TAction then
92 with TAction(Actions[I]) do
93 //if ShortCut > 0 then
94 begin
95 NewItem := ListView1.Items.Add;
96 NewItem.Caption := Caption;
97 NewItem.ImageIndex := ImageIndex;
98 NewItem.Data := TAction(Actions[I]);
99 with NewItem.SubItems do begin
100 if C.Owner = MainForm then Add(SMainForm)
101 else if C.Owner is TDataModule then Add(SGlobal)
102 else if C.Owner is TForm then Add(TForm(C.Owner).Caption)
103 else Add(C.Name);
104 Add(ShortCutToText(ShortCut));
105 end;
106 end;
107 end;
108 for I := 0 to C.ComponentCount - 1 do
109 LoadFromComponent(C.Components[I]);
110end;
111
112end.
113
Note: See TracBrowser for help on using the repository browser.