OSDN Git Service

URLReplace の最適化。
[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..16] of string = ('BrowserMaxAction',
42                                                                                                                                                                         'BrowserMinAction',
43                                                                                                                                                                         '',
44                                                                                                                                                                         'ScrollTopAction',
45                                                                                                                                                                         'ScrollLastAction',
46                                                                                                                                                                         'ScrollNewAction',
47                                                                                                                                                                         'ScrollKokoAction',
48                                                                                                                                                                         '',
49                                                                                                                                                                         'SelectResAction',
50                                                                                                                                                                         'ResRangeAction',
51                                                                                                                                                                         '',
52                                                                                                                                                                         'EditorAction',
53                                                                                                                                                                         '',
54                                                                                                                                                                         'IEAction',
55                                                                                                                                                                         '',
56                                                                                                                                                                         'ItemReloadAction',
57                                                                                                                                                                         'UpBoardAction'
58                                                                                                                                                                         );
59
60
61         /// \83{\83^\83\93\83X\83^\83C\83\8b\82ª"tbsCheck"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
62         CHECK_STYLE:   array[0..33] of string = ('CabinetVisibleAction',
63                                                                                                                                                                         'ArrangeAction',
64                                                                                                                                                                         'AllItemAction',
65                                                                                                                                                                         'LogItemAction',
66                                                                                                                                                                         'NewItemAction',
67                                                                                                                                                                         'SelectItemAction',
68
69                                                                                                                                                                         'StdToolBarVisibleAction',
70                                                                                                                                                                         'AddressBarVisibleAction',
71                                                                                                                                                                         'LinkBarVisibleAction',
72                                                                                                                                                                         'ListToolBarVisibleAction',
73                                                                                                                                                                         'ListNameBarVisibleAction',
74                                                                                                                                                                         'BrowserToolBarVisibleAction',
75                                                                                                                                                                         'BrowserNameBarVisibleAction',
76                                                                                                                                                                         'MsgBarVisibleAction',
77                                                                                                                                                                         'StatusBarVisibleAction',
78                                                                                                                                                                         'CabinetHistoryAction',
79                                           'CabinetFavoriteAction',
80                                                                                                                                                                         'LargeIconAction',
81                                                                                                                                                                         'SmallIconAction',
82                                                                                                                                                                         'ListIconAction',
83                                                                                                                                                                         'DetailIconAction',
84                                                                                                                                                                         'BrowserTabVisibleAction',
85                                                                                                                                                                         'BrowserTabTopAction',
86                                                                                                                                                                         'BrowserTabBottomAction',
87                                                                                                                                                                         'BrowserTabTabStyleAction',
88                                                                                                                                                                         'BrowserTabButtonStyleAction',
89                                                                                                                                                                         'BrowserTabFlatStyleAction',
90                                                                                                                                                                         'LoginAction',
91                                                                                                                                                                         'ListNumberVisibleAction',
92                                                                                                                                                                         'AllResAction',
93                                                                                                                                                                         'SelectResAction',
94                                                                                                                                                                         'OnlyAHundredRes',
95                                                                                                                                                                         'OnlyKokoResAction',
96                                                                                                                                                                         'OnlyNewResAction'
97                                                                                                                                                                         );
98
99         /// \83{\83^\83\93\82Ì\83X\83^\83C\83\8b\82ª"tbsDropDown"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
100         /// Giko.pas : SetToolBarPopup \82à\8fC\90³\82·\82é\8e\96
101         DROPDOWN_STYLE: array[0..3] of string = ('IconStyle',
102                                                                                                                                                                          'IEAction',
103                                                                                                                                                                          'CabinetBBSAction',
104                                                                                                                                                                          'ResRangeAction');
105
106         INI_FILENAME: string = 'ToolBar.ini';
107
108         //\8bæ\90Ø\82è\95\8e\9a
109         SEPARATOR_TEXT = '- \8bæ\90Ø\82è -';
110
111         function IsCheckStyle(Action: TCustomAction): Boolean;
112         function IsDropDownStyle(Action: TCustomAction): Boolean;
113         procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
114         function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
115         procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
116         procedure SaveToolBarSetting(ToolBar: TToolBar);
117     procedure KeepDefaultToolButton(ToolBar: TToolBar; TmpToolBar: TToolBar);
118     procedure MakeDefaultINIFile();
119 implementation
120
121 procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
122 var
123         FileName: string;
124         ini: TMemIniFile;
125         i: Integer;
126         s: string;
127         Action: TCustomAction;
128         ToolButton: TToolButton;
129 begin
130         FileName := GikoSys.GetConfigDir + INI_FILENAME;
131         if FileExists(FileName) then begin
132                 for i := ToolBar.ButtonCount - 1 downto 0 do begin
133                         ToolBar.RemoveControl(ToolBar.Buttons[i]);
134                 end;
135                 ini := TMemIniFile.Create(FileName);
136                 try
137                         i := 0;
138                         while True do begin
139                                 s := ini.ReadString(ToolBar.Name, 'Button' + IntToStr(i), '');
140                                 if s = '-' then begin
141                                         ToolButton := TToolButton.Create(ToolBar);
142                                         ToolButton.Style := tbsSeparator;
143                                         ToolButton.Width := 8;
144                                         ToolButton.Left := 10000;
145                                         ToolBar.InsertControl(ToolButton);
146                                 end else if s <> '' then begin
147                                         Action := GetActionItem(ActionList, s);
148                                         if Action <> nil then begin
149                                                 ToolButton := TToolButton.Create(ToolBar);
150                                                 ToolButton.Action := Action;
151                                                 ToolButton.Left := 10000;
152                                                 SetButtonStyle(Action, ToolButton);
153                                                 ToolBar.InsertControl(ToolButton);
154                                         end;
155                                 end else
156                                         Break;
157                                 inc(i);
158                         end;
159                 finally
160                         ini.Free;
161                 end;
162         end;
163 end;
164
165 procedure SaveToolBarSetting(ToolBar: TToolBar);
166 var
167         ini: TMemIniFile;
168         i, j: Integer;
169         Action: TBasicAction;
170 begin
171         ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
172         j := 0;
173         try
174                 ini.EraseSection(ToolBar.Name);
175                 for i := 0 to ToolBar.ButtonCount - 1 do begin
176                         if ToolBar.Buttons[i].Style = tbsSeparator then begin
177                                 ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), '-');
178                                 Inc( j );
179                         end else begin
180                                 Action := ToolBar.Buttons[i].Action;
181                                 if Action <> nil then
182                                 begin
183                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), Action.Name);
184                                         Inc( j );
185                                 end;
186                         end;
187                 end;
188                 ini.UpdateFile;
189         finally
190                 ini.Free;
191         end;
192 end;
193
194 //ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
195 function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
196 var
197         i: Integer;
198 begin
199         for i := 0 to ActionList.ActionCount - 1 do begin
200                 if ActionList.Actions[i].Name = ActionName then begin
201                         Result := TCustomAction(ActionList.Actions[i]);
202                         Exit;
203                 end;
204         end;
205         Result := nil;
206 end;
207
208 //\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è
209 procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
210 begin
211         if IsCheckStyle(Action) then
212                 Button.Style := tbsCheck
213         else if IsDropDownStyle(Action) then
214                 Button.Style := tbsDropDown
215         else
216                 Button.Style := tbsButton;
217 end;
218
219 //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·
220 function IsCheckStyle(Action: TCustomAction): Boolean;
221 var
222         i: Integer;
223 begin
224         for i := 0 to Length(CHECK_STYLE) - 1 do begin
225                 if Action.Name = CHECK_STYLE[i] then begin
226                         Result := True;
227                         Exit;
228                 end;
229         end;
230         Result := False;
231 end;
232
233 //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·
234 function IsDropDownStyle(Action: TCustomAction): Boolean;
235 var
236         i: Integer;
237 begin
238         for i := 0 to Length(DROPDOWN_STYLE) - 1 do begin
239                 if Action.Name = DROPDOWN_STYLE[i] then begin
240                         Result := True;
241                         Exit;
242                 end;
243         end;
244         Result := False;
245 end;
246 procedure KeepDefaultToolButton(ToolBar: TToolBar; TmpToolBar: TToolBar);
247 var
248         i: Integer;
249 begin
250         for i := ToolBar.ButtonCount - 1 downto 0 do begin
251         ToolBar.Buttons[i].Parent := TmpToolBar;
252     end;
253 end;
254 procedure MakeDefaultINIFile();
255 var
256         ini: TMemIniFile;
257     i: Integer;
258 begin
259         //\95W\8f\80\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
260         //DEF_STANDARD:
261         //\83\8a\83X\83g\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
262         //DEF_LIST:
263         //\83u\83\89\83E\83U\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
264         //DEF_BROWSER:
265     if not FileExists(GikoSys.GetConfigDir + INI_FILENAME) then begin
266             ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
267         try
268             for i := 0 to Length(DEF_STANDARD) - 1 do begin
269                 if DEF_STANDARD[i] <> '' then
270                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), DEF_STANDARD[i])
271                 else
272                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), '-');
273             end;
274             for i := 0 to Length(DEF_LIST) - 1 do begin
275                 if DEF_LIST[i] <> '' then
276                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), DEF_LIST[i])
277                 else
278                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), '-');
279             end;
280             for i := 0 to Length(DEF_BROWSER) - 1 do begin
281                 if DEF_BROWSER[i] <> '' then
282                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), DEF_BROWSER[i])
283                 else
284                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), '-');
285             end;
286
287         finally
288                 ini.UpdateFile;
289             ini.Free;
290         end;
291     end;
292
293 end;
294
295 end.