OSDN Git Service

新規作成
[gikonavigoeson/gikonavi.git] / KeySetting.pas
1 unit KeySetting;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7         Dialogs, ComCtrls, StdCtrls, ExtCtrls, ActnList, Menus, GikoSystem, GikoUtil;
8
9 type
10         TKeySettingItem = class(TObject)
11         private
12                 FAction: TAction;
13                 FShortCut: TShortCut;
14         public
15                 property Action: TAction read FAction write FAction;
16                 property ShortCut: TShortCut read FShortCut write FShortCut;
17         end;
18
19         TKeySettingForm = class(TForm)
20     Panel1: TPanel;
21     Panel2: TPanel;
22     Panel3: TPanel;
23     OkBotton: TButton;
24     CancelBotton: TButton;
25     Label1: TLabel;
26     Label2: TLabel;
27     HotKey: THotKey;
28     SetButton: TButton;
29     StatusBar: TStatusBar;
30     Panel4: TPanel;
31     PageControl1: TPageControl;
32     TabSheet1: TTabSheet;
33     TabSheet2: TTabSheet;
34     ListView: TListView;
35     ListView1: TListView;
36                 procedure FormCreate(Sender: TObject);
37                 procedure FormDestroy(Sender: TObject);
38     procedure ListViewSelectItem(Sender: TObject; Item: TListItem;
39       Selected: Boolean);
40     procedure HotKeyEnter(Sender: TObject);
41     procedure HotKeyExit(Sender: TObject);
42     procedure FormKeyDown(Sender: TObject; var Key: Word;
43       Shift: TShiftState);
44     procedure SetButtonClick(Sender: TObject);
45     procedure OkBottonClick(Sender: TObject);
46     procedure ListViewCompare(Sender: TObject; Item1, Item2: TListItem;
47       Data: Integer; var Compare: Integer);
48         private
49                 { Private \90é\8c¾ }
50         public
51                 { Public \90é\8c¾ }
52         end;
53
54 //var
55 //      KeySettingForm: TKeySettingForm;
56
57 implementation
58
59 uses Giko;
60
61 {$R *.dfm}
62
63 procedure TKeySettingForm.FormCreate(Sender: TObject);
64 var
65         i: Integer;
66         ListItem: TListItem;
67         KeyItem: TKeySettingItem;
68 begin
69         for i := 0 to GikoForm.ActionList.ActionCount - 1 do begin
70                 if GikoForm.ActionList.Actions[i] is TAction then begin
71                         if GikoForm.ActionList.Actions[i].Tag <> 0 then
72                                 Continue;
73                         ListItem := ListView.Items.Add;
74                         ListItem.Caption := TAction(GikoForm.ActionList.Actions[i]).Hint;
75                         ListItem.SubItems.Add(TAction(GikoForm.ActionList.Actions[i]).Category);
76                         ListItem.SubItems.Add(ShortCutToText(TAction(GikoForm.ActionList.Actions[i]).ShortCut));
77                         ListItem.ImageIndex := TAction(GikoForm.ActionList.Actions[i]).ImageIndex;
78                         KeyItem := TKeySettingItem.Create;
79                         KeyItem.Action := TAction(GikoForm.ActionList.Actions[i]);
80                         KeyItem.ShortCut := TAction(GikoForm.ActionList.Actions[i]).ShortCut;
81                         ListItem.Data := KeyItem;
82                 end;
83         end;
84         if ListView.Items.Count > 0 then
85                 ListView.Selected := ListView.Items[0];
86 //      ActionListView.SortType := stText;
87         StatusBar.Height := 21;
88         StatusBar.Width := 21;
89 end;
90
91 procedure TKeySettingForm.FormDestroy(Sender: TObject);
92 var
93         i: Integer;
94 begin
95         for i := 0 to ListView.Items.Count - 1 do begin
96                 if TObject(ListView.Items[i].Data) is TKeySettingItem then
97                         TKeySettingItem(ListView.Items[i].Data).Free;
98         end;
99 end;
100
101 procedure TKeySettingForm.ListViewSelectItem(Sender: TObject;
102   Item: TListItem; Selected: Boolean);
103 var
104         KeyItem: TKeySettingItem;
105 begin
106         if not Selected then Exit;
107
108         if TObject(Item.Data) is TKeySettingItem then begin
109                 KeyItem := TKeySettingItem(Item.Data);
110                 HotKey.HotKey := KeyItem.ShortCut;
111         end;
112 end;
113
114 procedure TKeySettingForm.HotKeyEnter(Sender: TObject);
115 begin
116         OkBotton.Default := False;
117         CancelBotton.Cancel := False;
118 end;
119
120 procedure TKeySettingForm.HotKeyExit(Sender: TObject);
121 begin
122         OkBotton.Default := True;
123         CancelBotton.Cancel := True;
124 end;
125
126 procedure TKeySettingForm.FormKeyDown(Sender: TObject; var Key: Word;
127   Shift: TShiftState);
128 begin
129         if Key in [8, 27, 32, 46] then begin
130                 HotKey.HotKey := ShortCut(Key, Shift);
131                 Key := 0;
132         end;
133 end;
134
135 procedure TKeySettingForm.SetButtonClick(Sender: TObject);
136 const
137         ERR_ENT = 'Enter\83L\81[\82Í\83V\83\87\81[\83g\83J\83b\83g\82Æ\82µ\82Ä\8eg\97p\82Å\82«\82Ü\82¹\82ñ';
138         ERR_MSG = '\93ü\97Í\82µ\82½\83V\83\87\81[\83g\83J\83b\83g\82Í\8aù\82É\8eg\97p\82³\82ê\82Ä\82¢\82Ü\82·';
139         ERR_TITLE = '\83G\83\89\81[';
140 var
141         i: Integer;
142         Item: TListItem;
143         KeyItem: TKeySettingItem;
144 begin
145         if ListView.Selected = nil then Exit;
146         if HotKey.HotKey = 13 then begin
147                 MsgBox(Handle, ERR_ENT, ERR_TITLE, MB_OK or MB_ICONSTOP);
148                 HotKey.SetFocus;
149                 Exit;
150         end;
151
152         //\8c»\8dÝ\91I\91ð\82³\82ê\82Ä\82¢\82éAction\88È\8aO\82Å\93¯\82\83V\83\87\81[\83g\83J\83b\83g\82ª\82 \82ê\82Î\83G\83\89\81[\82Æ\82·\82é
153         for i := 0 to ListView.Items.Count - 1 do begin
154                 if ListView.Selected = ListView.Items[i] then
155                         Continue;
156                 Item := ListView.Items[i];
157                 if TObject(Item.Data) is TKeySettingItem then begin
158                         KeyItem := TKeySettingItem(Item.Data);
159                         if (HotKey.HotKey <> 0) and (KeyItem.ShortCut = HotKey.HotKey) then begin
160                                 MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
161                                 HotKey.SetFocus;
162                                 Exit;
163                         end;
164                 end;
165         end;
166         //\83V\83\87\81[\83g\83J\83b\83g\90Ý\92è
167         if TObject(ListView.Selected.Data) is TKeySettingItem then begin
168                 KeyItem := TKeySettingItem(ListView.Selected.Data);
169                 KeyItem.ShortCut := HotKey.HotKey;
170                 ListView.Selected.SubItems[1] := ShortCutToText(HotKey.HotKey);
171         end;
172 end;
173
174 procedure TKeySettingForm.OkBottonClick(Sender: TObject);
175 var
176         i: Integer;
177         Item: TListItem;
178         KeyItem: TKeySettingItem;
179 begin
180         for i := 0 to ListView.Items.Count - 1 do begin
181                 Item := ListView.Items[i];
182                 if TObject(Item.Data) is TKeySettingItem then begin
183                         KeyItem := TKeySettingItem(Item.Data);
184                         KeyItem.Action.ShortCut := KeyItem.ShortCut;
185                 end;
186         end;
187 end;
188
189 procedure TKeySettingForm.ListViewCompare(Sender: TObject; Item1,
190   Item2: TListItem; Data: Integer; var Compare: Integer);
191 begin
192         if Item1.SubItems[0] > Item2.SubItems[0] then
193                 Compare := 1
194         else if Item1.SubItems[0] < Item2.SubItems[0] then
195                 Compare := -1
196         else
197                 Compare := 0;
198 end;
199
200 end.