| 1 | unit FormKeyShortcuts;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
|---|
| 7 | ComCtrls, ActnList, LCLProc, Menus, FormEx, Generics.Collections, ImgList;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 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 |
|
|---|
| 32 | implementation
|
|---|
| 33 |
|
|---|
| 34 | {$R *.lfm}
|
|---|
| 35 |
|
|---|
| 36 | resourcestring
|
|---|
| 37 | SMainForm = 'Main window';
|
|---|
| 38 | SGlobal = 'Global';
|
|---|
| 39 |
|
|---|
| 40 | { TFormKeyShortcuts }
|
|---|
| 41 |
|
|---|
| 42 | procedure TFormKeyShortcuts.FormShow(Sender: TObject);
|
|---|
| 43 | var
|
|---|
| 44 | I: Integer;
|
|---|
| 45 | begin
|
|---|
| 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;
|
|---|
| 54 | end;
|
|---|
| 55 |
|
|---|
| 56 | procedure TFormKeyShortcuts.FormCreate(Sender: TObject);
|
|---|
| 57 | begin
|
|---|
| 58 | SourceComponents := TObjectList<TComponent>.Create;
|
|---|
| 59 | SourceComponents.OwnsObjects := False;
|
|---|
| 60 | end;
|
|---|
| 61 |
|
|---|
| 62 | procedure TFormKeyShortcuts.FormDestroy(Sender: TObject);
|
|---|
| 63 | begin
|
|---|
| 64 | FreeAndNil(SourceComponents);
|
|---|
| 65 | end;
|
|---|
| 66 |
|
|---|
| 67 | procedure TFormKeyShortcuts.MenuItem1Click(Sender: TObject);
|
|---|
| 68 | begin
|
|---|
| 69 | if Assigned(ListView1.Selected) then
|
|---|
| 70 | TAction(ListView1.Selected.Data).Execute;
|
|---|
| 71 | end;
|
|---|
| 72 |
|
|---|
| 73 | function TFormKeyShortcuts.GetImageList: TCustomImageList;
|
|---|
| 74 | begin
|
|---|
| 75 | Result := ListView1.SmallImages;
|
|---|
| 76 | end;
|
|---|
| 77 |
|
|---|
| 78 | procedure TFormKeyShortcuts.SetImageList(AValue: TCustomImageList);
|
|---|
| 79 | begin
|
|---|
| 80 | ListView1.SmallImages := AValue
|
|---|
| 81 | end;
|
|---|
| 82 |
|
|---|
| 83 | procedure TFormKeyShortcuts.LoadFromComponent(C: TComponent);
|
|---|
| 84 | var
|
|---|
| 85 | I: Integer;
|
|---|
| 86 | NewItem: TListItem;
|
|---|
| 87 | begin
|
|---|
| 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]);
|
|---|
| 110 | end;
|
|---|
| 111 |
|
|---|
| 112 | end.
|
|---|
| 113 |
|
|---|