OSDN Git Service

・スレタイの特定ワードを非表示にする機能に「©bbspink.com」も追加
[gikonavigoeson/gikonavi.git] / ToolBarSetting.pas
1 unit ToolBarSetting;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7         Dialogs, StdCtrls, ExtCtrls, ComCtrls, ActnList, IniFiles,
8         GikoSystem, ToolBarUtil;
9
10 type
11         TGikoToolType = (gttStandard, gttList, gttBrowser);
12
13         TToolBarItem = class
14         private
15                 FToolBar: TToolBar;
16                 FButtonActionList: TList;
17                 FToolType: TGikoToolType;
18         public
19                 constructor Create;
20                 destructor Destroy; override;
21                 property ToolBar: TToolBar read FToolBar write FToolBar;
22                 property ButtonActionList: TList read FButtonActionList write FButtonActionList;
23                 property ToolType: TGikoToolType read FToolType write FToolType;
24         end;
25
26         TToolBarSettingDialog = class(TForm)
27                 Label1: TLabel;
28                 AllListView: TListView;
29                 AddButton: TButton;
30                 RemoveButton: TButton;
31                 CurrentListView: TListView;
32                 Label2: TLabel;
33                 UpButton: TButton;
34                 DownButton: TButton;
35                 OKButton: TButton;
36                 CancelButton: TButton;
37                 Bevel1: TBevel;
38                 Label3: TLabel;
39                 ToolBarComboBox: TComboBox;
40                 SeparatorAddButton: TButton;
41                 ResetButton: TButton;
42                 procedure FormCreate(Sender: TObject);
43                 procedure FormDestroy(Sender: TObject);
44                 procedure ToolBarComboBoxChange(Sender: TObject);
45                 procedure OKButtonClick(Sender: TObject);
46                 procedure CurrentListViewData(Sender: TObject; Item: TListItem);
47                 procedure AllListViewData(Sender: TObject; Item: TListItem);
48                 procedure UpButtonClick(Sender: TObject);
49                 procedure DownButtonClick(Sender: TObject);
50                 procedure ResetButtonClick(Sender: TObject);
51                 procedure CurrentListViewChange(Sender: TObject; Item: TListItem;
52                         Change: TItemChange);
53                 procedure AllListViewChange(Sender: TObject; Item: TListItem;
54                         Change: TItemChange);
55                 procedure AddButtonClick(Sender: TObject);
56                 procedure RemoveButtonClick(Sender: TObject);
57                 procedure SeparatorAddButtonClick(Sender: TObject);
58                 procedure FormShow(Sender: TObject);
59         private
60                 { Private \90é\8c¾ }
61                 FActionList: TActionList;
62                 FAllList: TList;
63                 FToolBarIndex : Integer;        // \8f\89\8aú\95\\8e¦\82·\82é\83c\81[\83\8b\83o\81[
64                 procedure CreateListData(ToolBarItem: TToolBarItem);
65                 procedure MoveItem(Offset: Integer);
66                 procedure Sort;
67                 function SetDefaultItem(deflist: array of string; ToolBarItem: TToolBarItem): Integer;
68         public
69                 { Public \90é\8c¾ }
70                 constructor Create(AOwner: TComponent; ActionList: TActionList); reintroduce; overload; virtual;
71                 procedure AddToolBar(ToolBar: TToolBar; ToolType: TGikoToolType);
72                 property        ToolBarIndex : Integer read FToolBarIndex write FToolBarIndex;
73         end;
74
75 var
76         ToolBarSettingDialog: TToolBarSettingDialog;
77
78 function CompareCategory(Item1, Item2: Pointer): Integer;
79
80 implementation
81
82 //const
83 //      //\8bæ\90Ø\82è\95\8e\9a
84 //      SEPARATOR_TEXT = '- \8bæ\90Ø\82è -';
85
86 {$R *.dfm}
87
88 //
89 // TToolBarItem
90 //
91 constructor TToolBarItem.Create;
92 begin
93         inherited Create;
94         FButtonActionList := TList.Create;
95 end;
96
97 destructor TToolBarItem.Destroy;
98 begin
99         FButtonActionList.Free;
100         inherited Destroy;
101 end;
102
103 //
104 // TToolBarSettingDialog
105 //
106 constructor TToolBarSettingDialog.Create(AOwner: TComponent; ActionList: TActionList);
107 begin
108         inherited Create(AOwner);
109         FActionList := ActionList;
110 end;
111
112 //\83t\83H\81[\83\80\8dì\90¬
113 procedure TToolBarSettingDialog.FormCreate(Sender: TObject);
114 var
115     CenterForm: TCustomForm;
116 begin
117     CenterForm := TCustomForm(Owner);
118     if Assigned(CenterForm) then begin
119         Left := ((CenterForm.Width - Width) div 2) + CenterForm.Left;
120         Top := ((CenterForm.Height - Height) div 2) + CenterForm.Top;
121     end else begin
122         Left := (Screen.Width - Width) div 2;
123         Top := (Screen.Height - Height) div 2;
124     end;
125
126         FAllList := TList.Create;
127 end;
128
129 //\83t\83H\81[\83\80\94j\8aü
130 procedure TToolBarSettingDialog.FormDestroy(Sender: TObject);
131 var
132         i: Integer;
133 begin
134         FAllList.Free;
135         for i := 0 to ToolBarComboBox.Items.Count - 1 do
136                 ToolBarComboBox.Items.Objects[i].Free;
137 end;
138
139 //\95\\8e¦\82µ\82½\82Æ\82«
140 procedure TToolBarSettingDialog.FormShow(Sender: TObject);
141 begin
142         ToolBarComboBox.ItemIndex := FToolBarIndex;
143         ToolBarComboBoxChange(Self);
144         AllListViewChange(Sender, nil, ctState);
145         CurrentListViewChange(Sender, nil, ctState);
146 end;
147
148 //\82±\82Ì\83_\83C\83A\83\8d\83O\82Å\83J\83X\83^\83}\83C\83Y\82·\82é\83c\81[\83\8b\83o\81[\82ð\93o\98^\82·\82é
149 procedure TToolBarSettingDialog.AddToolBar(ToolBar: TToolBar; ToolType: TGikoToolType);
150 var
151         ToolBarItem: TToolBarItem;
152         i: Integer;
153 begin
154         ToolBarItem := TToolBarItem.Create;
155         ToolBarItem.ToolBar := ToolBar;
156         ToolBarItem.ToolType := ToolType;
157         for i := 0 to ToolBar.ControlCount - 1 do
158                 if ToolBar.Controls[ i ] is TToolButton Then
159                         if not (ToolBar.Controls[ i ].Name = 'SelectComboBoxDummy') Then
160                         ToolBarITem.ButtonActionList.Add(ToolBar.Controls[i].Action);
161         ToolBarComboBox.Items.AddObject(ToolBar.Caption, ToolBarItem);
162 end;
163
164
165 //\83R\83\93\83{\83{\83b\83N\83X\95Ï\8dX\8e\9e
166 procedure TToolBarSettingDialog.ToolBarComboBoxChange(Sender: TObject);
167 var
168         ToolBarItem: TToolBarItem;
169 begin
170         ToolBarItem := TToolBarItem(ToolBarComboBox.Items.Objects[ToolBarComboBox.ItemIndex]);
171         CreateListData(ToolBarItem);
172         AllListView.Items.Count := FAllList.Count;
173         CurrentListView.Items.Count := ToolBarItem.ButtonActionList.Count;
174         Sort;
175         AllListView.Refresh;
176         CurrentListView.Refresh;
177 end;
178
179 //OK\83{\83^\83\93\89\9f\82µ\82½\82Æ\82«
180 procedure TToolBarSettingDialog.OKButtonClick(Sender: TObject);
181 var
182         i: Integer;
183         j: Integer;
184         ToolButton: TToolButton;
185         ToolBarItem: TToolBarItem;
186 begin
187         for i := 0 to ToolBarComboBox.Items.Count - 1 do begin
188                 ToolBarItem := TToolBarItem(ToolBarComboBox.Items.Objects[i]);
189
190                 for j := ToolBarItem.ToolBar.ButtonCount - 1 downto 0 do
191                         ToolBarItem.ToolBar.Buttons[j].HostDockSite := nil;
192
193                 for j := 0 to ToolBarItem.ButtonActionList.Count - 1 do begin
194                         if ToolBarItem.ButtonActionList[j] = nil then begin
195                                 ToolButton := TToolButton.Create(ToolBarItem.ToolBar);
196                                 ToolButton.Style := tbsSeparator;
197                                 ToolButton.Width := 8;
198                                 ToolButton.Left := 10000;
199                                 ToolBarItem.ToolBar.InsertControl(ToolButton);
200                         end else if TObject(ToolBarItem.ButtonActionList[j]) is TCustomAction then begin
201                                 ToolButton := TToolButton.Create(ToolBarItem.ToolBar);
202                                 ToolButton.Action := TCustomAction(ToolBarItem.ButtonActionList[j]);
203                                 if ToolButton.ImageIndex = -1 then
204                                         ToolButton.ImageIndex := 51;
205
206                                 ToolButton.Left := 10000;
207                                 SetButtonStyle(ToolBarItem.ButtonActionList[j], ToolButton);
208                                 ToolBarItem.ToolBar.InsertControl(ToolButton);
209                         end;
210                 end;
211         end;
212 end;
213
214 //\91S\83c\81[\83\8b\83{\83^\83\93\83\8a\83X\83g\83r\83\85\81[\82Ì\83f\81[\83^\97v\8b\81\8e\9e
215 procedure TToolBarSettingDialog.AllListViewData(Sender: TObject; Item: TListItem);
216 var
217         Action: TCustomAction;
218 begin
219         if (FAllList.Count <= 0) or (FAllList.Count <= Item.Index) then
220                 Exit;
221         if FAllList[Item.Index] = nil then begin
222                 Item.Caption := SEPARATOR_TEXT;
223                 Item.ImageIndex := -1;
224                 Item.Data := nil;
225         end else if TObject(FAllList[Item.Index]) is TCustomAction then begin
226                 Action := TCustomAction(FAllList[Item.Index]);
227                 Item.Caption := Action.Hint;
228                 Item.ImageIndex := Action.ImageIndex;
229                 Item.Data := Action;
230         end;
231 end;
232
233 //\8c»\8dÝ\83c\81[\83\8b\83{\83^\83\93\83\8a\83X\83g\83r\83\85\81[\82Ì\83f\81[\83^\97v\8b\81\8e\9e
234 procedure TToolBarSettingDialog.CurrentListViewData(Sender: TObject; Item: TListItem);
235 var
236         Action: TCustomAction;
237         ToolBarItem: TToolBarItem;
238 begin
239         ToolBarItem := TToolBarItem(ToolBarComboBox.Items.Objects[ToolBarComboBox.ItemIndex]);
240
241         if (ToolBarItem.ButtonActionList.Count <= 0) or (ToolBarItem.ButtonActionList.Count <= Item.Index) then
242                 Exit;
243         if ToolBarItem.ButtonActionList[Item.Index] = nil then begin
244                 Item.Caption := SEPARATOR_TEXT;
245                 Item.ImageIndex := -1;
246                 Item.Data := nil;
247         end else if TObject(ToolBarItem.ButtonActionList[Item.Index]) is TCustomAction then begin
248                 Action := TCustomAction(ToolBarItem.ButtonActionList[Item.Index]);
249                 Item.Caption := Action.Hint;
250                 Item.ImageIndex := Action.ImageIndex;
251                 Item.Data := Action;
252         end;
253 end;
254
255 //\8eg\97p\82Å\82«\82é\83c\81[\83\8b\83{\83^\83\93\83\8a\83X\83g\83r\83\85\81[\82É\95\\8e¦\82·\82é\83f\81[\83^\82ð\8dì\90¬
256 procedure TToolBarSettingDialog.CreateListData(ToolBarItem: TToolBarItem);
257 var
258         i: Integer;
259         Category: string;
260 begin
261         FAllList.Clear;
262         for i := 0 to FActionList.ActionCount - 1 do begin
263                 if FActionList.Actions[i].Tag = -1 then
264                         Continue;
265                 Category := FActionList.Actions[i].Category;
266                 //\95W\8f\80\83c\81[\83\8b\83o\81[\82Í\81u\94Â\81v\81u\83X\83\8c\83b\83h\81v\88È\8aO\82Ì\82Ý\91Î\8fÛ
267                 if (ToolBarItem.ToolType = gttStandard) and ((Category = '\94Â') or (Category = '\83X\83\8c\83b\83h')) then
268                         Continue;
269                 //\83\8a\83X\83g\83c\81[\83\8b\83o\81[\82Í\81u\94Â\81v\82Ì\82Ý\91Î\8fÛ
270                 if (ToolBarItem.ToolType = gttList) and (Category <> '\94Â') then
271                         Continue;
272                 //\83u\83\89\83E\83U\83c\81[\83\8b\83o\81[\82Í\81u\83X\83\8c\83b\83h\81v\82Ì\82Ý\91Î\8fÛ
273                 if (ToolBarItem.ToolType = gttBrowser) and (Category <> '\83X\83\8c\83b\83h') then
274                         Continue;
275
276                 if ToolBarItem.ButtonActionList.IndexOf(FActionList.Actions[i]) = -1 then
277                         FAllList.Add(FActionList.Actions[i]);
278         end;
279 end;
280
281 //\8fã\82Ö\83{\83^\83\93\89\9f\82µ\82½\82Æ\82«
282 procedure TToolBarSettingDialog.UpButtonClick(Sender: TObject);
283 begin
284         MoveItem(-1);
285 end;
286
287 //\89º\82Ö\83{\83^\83\93\89\9f\82µ\82½\82Æ\82«
288 procedure TToolBarSettingDialog.DownButtonClick(Sender: TObject);
289 begin
290         MoveItem(1);
291 end;
292
293 //\83\8a\83Z\83b\83g\83{\83^\83\93\89\9f\82µ\82½\82Æ\82«
294 procedure TToolBarSettingDialog.ResetButtonClick(Sender: TObject);
295 var
296         ToolBarItem: TToolBarItem;
297         cnt: Integer;
298 begin
299         cnt := 0;
300         ToolBarItem := TToolBarItem(ToolBarComboBox.Items.Objects[ToolBarComboBox.ItemIndex]);
301         AllListView.Items.Count := 0;
302         CurrentListView.Items.Count := 0;
303         ToolBarItem.ButtonActionList.Clear;
304         case ToolBarComboBox.ItemIndex of
305                 0: cnt := SetDefaultItem(DEF_STANDARD, ToolBarItem);
306                 1: cnt := SetDefaultItem(DEF_LIST, ToolBarItem);
307                 2: cnt := SetDefaultItem(DEF_BROWSER, ToolBarItem);
308         end;
309         CreateListData(ToolBarItem);
310         AllListView.Items.Count := FAllList.Count;
311         CurrentListView.Items.Count := cnt;
312         Sort;
313         AllListView.Refresh;
314         CurrentListView.Refresh;
315 end;
316
317 function TToolBarSettingDialog.SetDefaultItem(deflist: array of string; ToolBarItem: TToolBarItem): Integer;
318 var
319         i: Integer;
320         Action: TCustomAction;
321 begin
322         Result := 0;
323         for i := 0 to Length(deflist) - 1 do begin
324                 if deflist[i] = '' then begin
325                         ToolBarItem.ButtonActionList.Add(nil);
326                         Inc(Result);
327                 end else begin
328                         Action := GetActionItem(FActionList, deflist[i]);
329                         if Action <> nil then begin
330                                 ToolBarItem.ButtonActionList.Add(Action);
331                                 Inc(Result);
332                         end;
333                 end;
334         end;
335 end;
336
337 //\83\8a\83X\83g\83r\83\85\81[\82Ì\83A\83C\83e\83\80\82ð\88Ú\93®\82·\82é
338 procedure TToolBarSettingDialog.MoveItem(Offset: Integer);
339 var
340         Item: TListItem;
341         ToolBarItem: TToolBarItem;
342 begin
343         Item := CurrentListView.Selected;
344         if (Item = nil) or (Item.Index + Offset < 0) then
345                 Exit;
346
347         ToolBarItem := TToolBarItem(ToolBarComboBox.Items.Objects[ToolBarComboBox.ItemIndex]);
348         if Item.Index + Offset >= ToolBarItem.ButtonActionList.Count then
349                 Exit;
350
351         ToolBarItem.ButtonActionList.Move(Item.Index, Item.Index + Offset);
352         CurrentListView.ItemIndex := Item.Index + Offset;
353         CurrentListView.Refresh;
354 end;
355
356 //\91S\83c\81[\83\8b\83{\83^\83\93\83\8a\83X\83g\83r\83\85\81[\82Ì\91I\91ð\95Ï\8dX\8e\9e
357 procedure TToolBarSettingDialog.AllListViewChange(Sender: TObject;
358         Item: TListItem; Change: TItemChange);
359 begin
360         AddButton.Enabled := not (Item = nil);
361 end;
362
363 //\8c»\8dÝ\83c\81[\83\8b\83{\83^\83\93\83\8a\83X\83g\83r\83\85\81[\82Ì\91I\91ð\95Ï\8dX\8e\9e
364 procedure TToolBarSettingDialog.CurrentListViewChange(Sender: TObject;
365         Item: TListItem; Change: TItemChange);
366 begin
367         UpButton.Enabled := not (Item = nil);
368         DownButton.Enabled := not (Item = nil);
369         RemoveButton.Enabled := not (Item = nil);
370         if Item = nil then
371                 Exit;
372         UpButton.Enabled := Item.Index > 0;
373         DownButton.Enabled := Item.Index < CurrentListView.Items.Count - 1;
374 end;
375
376 //\92Ç\89Á\83{\83^\83\93\89\9f\82µ\82½\82Æ\82«
377 procedure TToolBarSettingDialog.AddButtonClick(Sender: TObject);
378 var
379 //      List: TList;
380         ToolBarItem: TToolBarItem;
381         Item: TListItem;
382         Action: TCustomAction;
383 begin
384         Item := AllListView.Selected;
385         if Item = nil then
386                 Exit;
387
388         ToolBarItem := TToolBarItem(ToolBarComboBox.Items.Objects[ToolBarComboBox.ItemIndex]);
389         Action := Item.Data;
390         FAllList.Delete(Item.Index);
391         if Action <> nil then begin
392                 Item := CurrentListView.Selected;
393                 if Item = nil then
394                         ToolBarItem.ButtonActionList.Add(Action)
395                 else
396                         ToolBarItem.ButtonActionList.Insert(Item.Index + 1, Action);
397                 AllListView.Items.Count := AllListView.Items.Count - 1;
398                 AllListView.Refresh;
399                 CurrentListView.Items.Count := CurrentListView.Items.Count + 1;
400                 CurrentListView.Refresh;
401         end;
402 end;
403
404 //\8dí\8f\9c\83{\83^\83\93\89\9f\82µ\82½\82Æ\82«
405 procedure TToolBarSettingDialog.RemoveButtonClick(Sender: TObject);
406 var
407         ToolBarItem: TToolBarItem;
408         Item: TListItem;
409         Action: TCustomAction;
410 begin
411         Item := CurrentListView.Selected;
412         if Item = nil then
413                 Exit;
414
415         ToolBarItem := TToolBarItem(ToolBarComboBox.Items.Objects[ToolBarComboBox.ItemIndex]);
416         Action := Item.Data;
417         ToolBarItem.ButtonActionList.Delete(Item.Index);
418         if Action <> nil then begin
419                 FAllList.Add(Action);
420                 AllListView.Items.Count := AllListView.Items.Count + 1;
421                 Sort;
422                 AllListView.Refresh;
423         end;
424         CurrentListView.Items.Count := CurrentListView.Items.Count - 1;
425         CurrentListView.Refresh;
426 end;
427
428 //\8bæ\90Ø\82è\92Ç\89Á\83{\83^\83\93\89\9f\82µ\82½\82Æ\82«
429 procedure TToolBarSettingDialog.SeparatorAddButtonClick(Sender: TObject);
430 var
431         idx: Integer;
432         ToolBarItem: TToolBarItem;
433 begin
434         ToolBarItem := TToolBarItem(ToolBarComboBox.Items.Objects[ToolBarComboBox.ItemIndex]);
435         if CurrentListView.Selected = nil then
436                 idx := CurrentListView.Items.Count - 1
437         else
438                 idx := CurrentListView.Selected.Index;
439         ToolBarItem.ButtonActionList.Insert(idx + 1, nil);
440         CurrentListView.Items.Count := CurrentListView.Items.Count + 1;
441         CurrentListView.Refresh;
442 end;
443
444 //\91S\83c\81[\83\8b\83{\83^\83\93\83\8a\83X\83g\83r\83\85\81[\82Ì\83\\81[\83g
445 procedure TToolBarSettingDialog.Sort;
446 begin
447         FAllList.Sort(@CompareCategory);
448 end;
449
450 //\83\\81[\83g\82·\82é\82Æ\82«\82Ì\94ä\8ar
451 function CompareCategory(Item1, Item2: Pointer): Integer;
452 var
453         Action1: TCustomAction;
454         Action2: TCustomAction;
455 begin
456         if (Item1 = nil) and (Item2 = nil) then
457                 Result := 0
458         else if (Item1 = nil) and (Item2 <> nil) then
459                 Result := -1
460         else if (Item1 <> nil) and (Item2 = nil) then
461                 Result := 1
462         else begin
463                 if (TObject(Item1) is TCustomAction) and (TObject(Item1) is TCustomAction) then begin
464                         Action1 := TCustomAction(Item1);
465                         Action2 := TCustomAction(Item2);
466                         Result := AnsiCompareStr(Action1.Category + Action1.Caption, Action2.Category + Action2.Caption);
467                 end else
468                         Result := 0;
469         end;
470 end;
471
472 end.