OSDN Git Service

Editor(書き込みフォーム)のショートカットキーの設定を行えるようにした。
[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     Editor;
9
10 type
11         TKeySettingItem = class(TObject)
12         private
13                 FAction: TAction;
14                 FShortCut: TShortCut;
15         public
16                 property Action: TAction read FAction write FAction;
17                 property ShortCut: TShortCut read FShortCut write FShortCut;
18         end;
19
20         TKeySettingForm = class(TForm)
21     Panel1: TPanel;
22     Panel2: TPanel;
23     Panel3: TPanel;
24     OkBotton: TButton;
25     CancelBotton: TButton;
26     Label1: TLabel;
27     Label2: TLabel;
28     HotKey: THotKey;
29     SetButton: TButton;
30     StatusBar: TStatusBar;
31     Panel4: TPanel;
32     PageControl1: TPageControl;
33     TabSheet1: TTabSheet;
34     TabSheet2: TTabSheet;
35     ListView: TListView;
36     ListView1: TListView;
37                 procedure FormCreate(Sender: TObject);
38                 procedure FormDestroy(Sender: TObject);
39     procedure ListViewSelectItem(Sender: TObject; Item: TListItem;
40       Selected: Boolean);
41     procedure HotKeyEnter(Sender: TObject);
42     procedure HotKeyExit(Sender: TObject);
43     procedure FormKeyDown(Sender: TObject; var Key: Word;
44       Shift: TShiftState);
45     procedure SetButtonClick(Sender: TObject);
46     procedure OkBottonClick(Sender: TObject);
47     procedure ListViewCompare(Sender: TObject; Item1, Item2: TListItem;
48       Data: Integer; var Compare: Integer);
49         private
50                 { Private \90é\8c¾ }
51         public
52                 { Public \90é\8c¾ }
53         EditorForm: TEditorForm;
54         end;
55
56 //var
57 //      KeySettingForm: TKeySettingForm;
58
59 implementation
60
61 uses Giko;
62
63 {$R *.dfm}
64
65 procedure TKeySettingForm.FormCreate(Sender: TObject);
66 var
67         i: Integer;
68         ListItem: TListItem;
69         KeyItem: TKeySettingItem;
70
71 begin
72         for i := 0 to GikoForm.ActionList.ActionCount - 1 do begin
73                 if GikoForm.ActionList.Actions[i] is TAction then begin
74                         if GikoForm.ActionList.Actions[i].Tag <> 0 then
75                                 Continue;
76                         ListItem := ListView.Items.Add;
77                         ListItem.Caption := TAction(GikoForm.ActionList.Actions[i]).Hint;
78                         ListItem.SubItems.Add(TAction(GikoForm.ActionList.Actions[i]).Category);
79                         ListItem.SubItems.Add(ShortCutToText(TAction(GikoForm.ActionList.Actions[i]).ShortCut));
80                         ListItem.ImageIndex := TAction(GikoForm.ActionList.Actions[i]).ImageIndex;
81                         KeyItem := TKeySettingItem.Create;
82                         KeyItem.Action := TAction(GikoForm.ActionList.Actions[i]);
83                         KeyItem.ShortCut := TAction(GikoForm.ActionList.Actions[i]).ShortCut;
84                         ListItem.Data := KeyItem;
85                 end;
86         end;
87         if ListView.Items.Count > 0 then
88                 ListView.Selected := ListView.Items[0];
89     EditorForm := TEditorForm.Create(Self);
90     GikoSys.LoadEditorKeySetting(EditorForm.ActionList);
91     try
92         for i := 0 to EditorForm.ActionList.ActionCount - 1 do begin
93             if EditorForm.ActionList.Actions[i] is TAction then begin
94                 if EditorForm.ActionList.Actions[i].Tag <> 0 then
95                     Continue;
96                 ListItem := ListView1.Items.Add;
97                 ListItem.Caption := TAction(EditorForm.ActionList.Actions[i]).Hint;
98                 ListItem.SubItems.Add(TAction(EditorForm.ActionList.Actions[i]).Category);
99                 ListItem.SubItems.Add(ShortCutToText(TAction(EditorForm.ActionList.Actions[i]).ShortCut));
100                 ListItem.ImageIndex := TAction(EditorForm.ActionList.Actions[i]).ImageIndex;
101                 KeyItem := TKeySettingItem.Create;
102                 KeyItem.Action := TAction(EditorForm.ActionList.Actions[i]);
103                 KeyItem.ShortCut := TAction(EditorForm.ActionList.Actions[i]).ShortCut;
104                 ListItem.Data := KeyItem;
105             end;
106         end;
107         ListView1.SmallImages := EditorForm.HotToobarImageList;
108     finally
109
110     end;
111 //      ActionListView.SortType := stText;
112         StatusBar.Height := 21;
113         StatusBar.Width := 21;
114     PageControl1.ActivePageIndex := 0;
115 end;
116
117 procedure TKeySettingForm.FormDestroy(Sender: TObject);
118 var
119         i: Integer;
120 begin
121         for i := 0 to ListView.Items.Count - 1 do begin
122                 if TObject(ListView.Items[i].Data) is TKeySettingItem then
123                         TKeySettingItem(ListView.Items[i].Data).Free;
124         end;
125         for i := 0 to ListView1.Items.Count - 1 do begin
126                 if TObject(ListView1.Items[i].Data) is TKeySettingItem then
127                         TKeySettingItem(ListView1.Items[i].Data).Free;
128         end;
129     EditorForm.Release;
130 end;
131
132 procedure TKeySettingForm.ListViewSelectItem(Sender: TObject;
133   Item: TListItem; Selected: Boolean);
134 var
135         KeyItem: TKeySettingItem;
136 begin
137         if not Selected then Exit;
138
139         if TObject(Item.Data) is TKeySettingItem then begin
140                 KeyItem := TKeySettingItem(Item.Data);
141                 HotKey.HotKey := KeyItem.ShortCut;
142         end;
143 end;
144
145 procedure TKeySettingForm.HotKeyEnter(Sender: TObject);
146 begin
147         OkBotton.Default := False;
148         CancelBotton.Cancel := False;
149 end;
150
151 procedure TKeySettingForm.HotKeyExit(Sender: TObject);
152 begin
153         OkBotton.Default := True;
154         CancelBotton.Cancel := True;
155 end;
156
157 procedure TKeySettingForm.FormKeyDown(Sender: TObject; var Key: Word;
158   Shift: TShiftState);
159 begin
160         if Key in [8, 27, 32, 46] then begin
161                 HotKey.HotKey := ShortCut(Key, Shift);
162                 Key := 0;
163         end;
164 end;
165
166 procedure TKeySettingForm.SetButtonClick(Sender: TObject);
167 const
168         ERR_ENT = 'Enter\83L\81[\82Í\83V\83\87\81[\83g\83J\83b\83g\82Æ\82µ\82Ä\8eg\97p\82Å\82«\82Ü\82¹\82ñ';
169         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·';
170         ERR_TITLE = '\83G\83\89\81[';
171 var
172         i: Integer;
173         Item: TListItem;
174         KeyItem: TKeySettingItem;
175     ActiveListView: TListView;
176 begin
177     if PageControl1.ActivePage.TabIndex <> 0 then
178         ActiveListView := ListView1
179     else
180         ActiveListView := ListView;
181
182         if ActiveListView.Selected = nil then Exit;
183         if HotKey.HotKey = 13 then begin
184                 MsgBox(Handle, ERR_ENT, ERR_TITLE, MB_OK or MB_ICONSTOP);
185                 HotKey.SetFocus;
186                 Exit;
187         end;
188
189         //\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é
190         for i := 0 to ActiveListView.Items.Count - 1 do begin
191                 if ActiveListView.Selected = ActiveListView.Items[i] then
192                         Continue;
193                 Item := ActiveListView.Items[i];
194                 if TObject(Item.Data) is TKeySettingItem then begin
195                         KeyItem := TKeySettingItem(Item.Data);
196                         if (HotKey.HotKey <> 0) and (KeyItem.ShortCut = HotKey.HotKey) then begin
197                                 MsgBox(Handle, ERR_MSG, ERR_TITLE, MB_OK or MB_ICONSTOP);
198                                 HotKey.SetFocus;
199                                 Exit;
200                         end;
201                 end;
202         end;
203         //\83V\83\87\81[\83g\83J\83b\83g\90Ý\92è
204         if TObject(ActiveListView.Selected.Data) is TKeySettingItem then begin
205                 KeyItem := TKeySettingItem(ActiveListView.Selected.Data);
206                 KeyItem.ShortCut := HotKey.HotKey;
207                 ActiveListView.Selected.SubItems[1] := ShortCutToText(HotKey.HotKey);
208         end;
209 end;
210
211 procedure TKeySettingForm.OkBottonClick(Sender: TObject);
212 var
213         i: Integer;
214         Item: TListItem;
215         KeyItem: TKeySettingItem;
216 begin
217         for i := 0 to ListView.Items.Count - 1 do begin
218                 Item := ListView.Items[i];
219                 if TObject(Item.Data) is TKeySettingItem then begin
220                         KeyItem := TKeySettingItem(Item.Data);
221                         KeyItem.Action.ShortCut := KeyItem.ShortCut;
222                 end;
223         end;
224         for i := 0 to ListView1.Items.Count - 1 do begin
225                 Item := ListView1.Items[i];
226                 if TObject(Item.Data) is TKeySettingItem then begin
227                         KeyItem := TKeySettingItem(Item.Data);
228                         KeyItem.Action.ShortCut := KeyItem.ShortCut;
229                 end;
230         end;
231
232 end;
233
234 procedure TKeySettingForm.ListViewCompare(Sender: TObject; Item1,
235   Item2: TListItem; Data: Integer; var Compare: Integer);
236 begin
237         if Item1.SubItems[0] > Item2.SubItems[0] then
238                 Compare := 1
239         else if Item1.SubItems[0] < Item2.SubItems[0] then
240                 Compare := -1
241         else
242                 Compare := 0;
243 end;
244
245 end.