OSDN Git Service

「このスレッドを含むスレッド一覧を表示」をデフォルトで表示するようになった。
[gikonavigoeson/gikonavi.git] / ToolBarUtil.pas
1 unit ToolBarUtil;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Classes, Controls,
7         StdCtrls, ExtCtrls, ComCtrls, ActnList, IniFiles,
8         GikoSystem;
9
10 const
11         //\95W\8f\80\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
12         DEF_STANDARD: array[0..9]       of string = ('RoundAction',
13                                                                                                                                                                         '',
14                                                                                                                                                                         'ArrangeAction',
15                                                                                                                                                                         '',
16                                                                                                                                                                         'StopAction',
17                                                                                                                                                                         'LoginAction',
18                                                                                                                                                                         '',
19                                                                                                                                                                         'CabinetBBSAction',
20                                                                                                                                                                         'CabinetHistoryAction',
21                                                                                                                                                                         'CabinetFavoriteAction');
22         //\83\8a\83X\83g\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
23         DEF_LIST:       array[0..16] of string = ('ListNumberVisibleAction',
24                                                                                                                                                                         'IconStyle',
25                                                                                                                                                                         'UpFolderAction',
26                                                                                                                                                                         '',
27                                                                                                                                                                         'AllItemAction',
28                                                                                                                                                                         'LogItemAction',
29                                                                                                                                                                         'NewItemAction',
30                                                                                                                                                                         'SelectItemAction',
31                                                                                                                                                                         '',
32                                                                                                                                                                         'ThreadEditorAction',
33                                                                                                                                                                         '',
34                                                                                                                                                                         'BoardIEAction',
35                                                                                                                                                                         '',
36                                                                                                                                                                         'SelectListReloadAction',
37                                                                                                                                                                         'SelectThreadReloadAction',
38                                                                                                                                                                         '',
39                                                                                                                                                                         'SelectReservAction');
40         //\83u\83\89\83E\83U\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
41         DEF_BROWSER:  array[0..17] of string = ('BrowserMaxAction',
42                                                                                                                                                                         'BrowserMinAction',
43                                                                                                                                                                         '',
44                                                                                                                                                                         'ScrollTopAction',
45                                                                                                                                                                         'ScrollLastAction',
46                                                                                                                                                                         'ScrollNewAction',
47                                                                                                                                                                         'ScrollKokoAction',
48                                                                                                                                                                         '',
49                                                                                                                                                                         'AllResAction',
50                                                                                                                                                                         'SelectResAction',
51                                                                                                                                                                         '',
52                                                                                                                                                                         'EditorAction',
53                                                                                                                                                                         '',
54                                                                                                                                                                         'IEAction',
55                                                                                                                                                                         '',
56                                                                                                                                                                         'ItemReloadAction',
57                                                                                                                                                                         'OnlyAHundredRes',
58                                                                                                                                                                         'UpBoardAction'
59                                                                                                                                                                         );
60
61
62         //\83{\83^\83\93\83X\83^\83C\83\8b\82ª"tbsCheck"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
63         CHECK_STYLE:   array[0..31] of string = ('CabinetVisibleAction',
64                                                                                                                                                                         'ArrangeAction',
65                                                                                                                                                                         'AllItemAction',
66                                                                                                                                                                         'LogItemAction',
67                                                                                                                                                                         'NewItemAction',
68                                                                                                                                                                         'SelectItemAction',
69
70                                                                                                                                                                         'StdToolBarVisibleAction',
71                                                                                                                                                                         'AddressBarVisibleAction',
72                                                                                                                                                                         'LinkBarVisibleAction',
73                                                                                                                                                                         'ListToolBarVisibleAction',
74                                                                                                                                                                         'ListNameBarVisibleAction',
75                                                                                                                                                                         'BrowserToolBarVisibleAction',
76                                                                                                                                                                         'BrowserNameBarVisibleAction',
77                                                                                                                                                                         'MsgBarVisibleAction',
78                                                                                                                                                                         'StatusBarVisibleAction',
79                                                                                                                                                                         'CabinetHistoryAction',
80                                           'CabinetFavoriteAction',
81                                                                                                                                                                         'LargeIconAction',
82                                                                                                                                                                         'SmallIconAction',
83                                                                                                                                                                         'ListIconAction',
84                                                                                                                                                                         'DetailIconAction',
85                                                                                                                                                                         'BrowserTabVisibleAction',
86                                                                                                                                                                         'BrowserTabTopAction',
87                                                                                                                                                                         'BrowserTabBottomAction',
88                                                                                                                                                                         'BrowserTabTabStyleAction',
89                                                                                                                                                                         'BrowserTabButtonStyleAction',
90                                                                                                                                                                         'BrowserTabFlatStyleAction',
91                                                                                                                                                                         'LoginAction',
92                                                                                                                                                                         'ListNumberVisibleAction',
93                                                                                                                                                                         'AllResAction',
94                                                                                                                                                                         'SelectResAction',
95                                                                                     'OnlyAHundredRes'
96                                                                                                                                                                         );
97
98         //\83{\83^\83\93\82Ì\83X\83^\83C\83\8b\82ª"tbsDropDown"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
99         DROPDOWN_STYLE: array[0..2] of string = ('IconStyle',
100                                                                                                                                                                          'IEAction',
101                                            'CabinetBBSAction');
102
103         INI_FILENAME: string = 'ToolBar.ini';
104
105         //\8bæ\90Ø\82è\95\8e\9a
106         SEPARATOR_TEXT = '- \8bæ\90Ø\82è -';
107
108         function IsCheckStyle(Action: TCustomAction): Boolean;
109         function IsDropDownStyle(Action: TCustomAction): Boolean;
110         procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
111         function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
112         procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
113         procedure SaveToolBarSetting(ToolBar: TToolBar);
114     procedure KeepDefaultToolButton(ToolBar: TToolBar; TmpToolBar: TToolBar);
115     procedure MakeDefaultINIFile();
116 implementation
117
118 procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
119 var
120         FileName: string;
121         ini: TMemIniFile;
122         i: Integer;
123         s: string;
124         Action: TCustomAction;
125         ToolButton: TToolButton;
126 begin
127         FileName := GikoSys.GetConfigDir + INI_FILENAME;
128         if FileExists(FileName) then begin
129                 for i := ToolBar.ButtonCount - 1 downto 0 do begin
130                         ToolBar.RemoveControl(ToolBar.Buttons[i]);
131                 end;
132                 ini := TMemIniFile.Create(FileName);
133                 try
134                         i := 0;
135                         while True do begin
136                                 s := ini.ReadString(ToolBar.Name, 'Button' + IntToStr(i), '');
137                                 if s = '-' then begin
138                                         ToolButton := TToolButton.Create(ToolBar);
139                                         ToolButton.Style := tbsSeparator;
140                                         ToolButton.Width := 8;
141                                         ToolButton.Left := 10000;
142                                         ToolBar.InsertControl(ToolButton);
143                                 end else if s <> '' then begin
144                                         Action := GetActionItem(ActionList, s);
145                                         if Action <> nil then begin
146                                                 ToolButton := TToolButton.Create(ToolBar);
147                                                 ToolButton.Action := Action;
148                                                 ToolButton.Left := 10000;
149                                                 SetButtonStyle(Action, ToolButton);
150                                                 ToolBar.InsertControl(ToolButton);
151                                         end;
152                                 end else
153                                         Break;
154                                 inc(i);
155                         end;
156                 finally
157                         ini.Free;
158                 end;
159         end;
160 end;
161
162 procedure SaveToolBarSetting(ToolBar: TToolBar);
163 var
164         ini: TMemIniFile;
165         i, j: Integer;
166         Action: TBasicAction;
167 begin
168         ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
169         j := 0;
170         try
171                 ini.EraseSection(ToolBar.Name);
172                 for i := 0 to ToolBar.ButtonCount - 1 do begin
173                         if ToolBar.Buttons[i].Style = tbsSeparator then begin
174                                 ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), '-');
175                                 Inc( j );
176                         end else begin
177                                 Action := ToolBar.Buttons[i].Action;
178                                 if Action <> nil then
179                                 begin
180                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), Action.Name);
181                                         Inc( j );
182                                 end;
183                         end;
184                 end;
185                 ini.UpdateFile;
186         finally
187                 ini.Free;
188         end;
189 end;
190
191 //ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
192 function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
193 var
194         i: Integer;
195 begin
196         for i := 0 to ActionList.ActionCount - 1 do begin
197                 if ActionList.Actions[i].Name = ActionName then begin
198                         Result := TCustomAction(ActionList.Actions[i]);
199                         Exit;
200                 end;
201         end;
202         Result := nil;
203 end;
204
205 //\83c\81[\83\8b\83{\83^\83\93\82Ì\83X\83^\83C\83\8b\90Ý\92è\82Æ\83|\83b\83v\83A\83b\83v\90Ý\92è
206 procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
207 begin
208         if IsCheckStyle(Action) then
209                 Button.Style := tbsCheck
210         else if IsDropDownStyle(Action) then
211                 Button.Style := tbsDropDown
212         else
213                 Button.Style := tbsButton;
214 end;
215
216 //Action\82ª\83`\83F\83b\83N\83X\83^\83C\83\8b\82Ì\83A\83N\83V\83\87\83\93\82©\82Ç\82¤\82©\82ð\95Ô\82µ\82Ü\82·
217 function IsCheckStyle(Action: TCustomAction): Boolean;
218 var
219         i: Integer;
220 begin
221         for i := 0 to Length(CHECK_STYLE) - 1 do begin
222                 if Action.Name = CHECK_STYLE[i] then begin
223                         Result := True;
224                         Exit;
225                 end;
226         end;
227         Result := False;
228 end;
229
230 //Action\82ª\83h\83\8d\83b\83v\83_\83E\83\93\83X\83^\83C\83\8b\82Ì\83A\83N\83V\83\87\83\93\82©\82Ç\82¤\82©\82ð\95Ô\82µ\82Ü\82·
231 function IsDropDownStyle(Action: TCustomAction): Boolean;
232 var
233         i: Integer;
234 begin
235         for i := 0 to Length(DROPDOWN_STYLE) - 1 do begin
236                 if Action.Name = DROPDOWN_STYLE[i] then begin
237                         Result := True;
238                         Exit;
239                 end;
240         end;
241         Result := False;
242 end;
243 procedure KeepDefaultToolButton(ToolBar: TToolBar; TmpToolBar: TToolBar);
244 var
245         i: Integer;
246 begin
247         for i := ToolBar.ButtonCount - 1 downto 0 do begin
248         ToolBar.Buttons[i].Parent := TmpToolBar;
249     end;
250 end;
251 procedure MakeDefaultINIFile();
252 var
253         ini: TMemIniFile;
254     i: Integer;
255 begin
256         //\95W\8f\80\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
257         //DEF_STANDARD:
258         //\83\8a\83X\83g\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
259         //DEF_LIST:
260         //\83u\83\89\83E\83U\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
261         //DEF_BROWSER:
262     if not FileExists(GikoSys.GetConfigDir + INI_FILENAME) then begin
263             ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
264         try
265             for i := 0 to Length(DEF_STANDARD) - 1 do begin
266                 if DEF_STANDARD[i] <> '' then
267                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), DEF_STANDARD[i])
268                 else
269                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), '-');
270             end;
271             for i := 0 to Length(DEF_LIST) - 1 do begin
272                 if DEF_LIST[i] <> '' then
273                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), DEF_LIST[i])
274                 else
275                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), '-');
276             end;
277             for i := 0 to Length(DEF_BROWSER) - 1 do begin
278                 if DEF_BROWSER[i] <> '' then
279                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), DEF_BROWSER[i])
280                 else
281                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), '-');
282             end;
283
284         finally
285                 ini.UpdateFile;
286             ini.Free;
287         end;
288     end;
289
290 end;
291
292 end.