OSDN Git Service

bfa2e96ca0031920956ef5dbfc1d08e61d5d9691
[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, MojuUtils;
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                                                                                                                                                                         'OnlyAHundredResAction',
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..4] of string = ('IconStyle',
102                                                                                                                                                                          'IEAction',
103                                                                                                                                                                          'CabinetBBSAction',
104                                                                                                                                                                          'ResRangeAction',
105                                                                                                                                                                          'ThreadRangeAction');
106
107         INI_FILENAME: string = 'ToolBar.ini';
108
109         //\8bæ\90Ø\82è\95\8e\9a
110         SEPARATOR_TEXT = '- \8bæ\90Ø\82è -';
111
112         function IsCheckStyle(Action: TCustomAction): Boolean;
113         function IsDropDownStyle(Action: TCustomAction): Boolean;
114         procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
115         function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
116         procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
117         procedure SaveToolBarSetting(ToolBar: TToolBar);
118     procedure KeepDefaultToolButton(ToolBar: TToolBar; TmpToolBar: TToolBar);
119     procedure MakeDefaultINIFile();
120 implementation
121
122 function ConvertToolButton( setting : string ) : string;
123 begin
124
125         // \8b\8c [\8dÅ\90V100\83\8c\83X\82Ì\82Ý\95\\8e¦] \82ð [\83\8c\83X\82Ì\95\\8e¦\94Í\88Í\82ð\90Ý\92è] \82É\92u\8a·
126         if setting = 'OnlyAHundredRes' then
127                 Result := 'ResRangeAction'
128         else
129                 Result := setting;
130
131 end;
132
133 procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
134 var
135         FileName: string;
136         ini: TMemIniFile;
137         i: Integer;
138         s: string;
139         Action: TCustomAction;
140         ToolButton: TToolButton;
141 begin
142         FileName := GikoSys.GetConfigDir + INI_FILENAME;
143         if FileExists(FileName) then begin
144                 for i := ToolBar.ButtonCount - 1 downto 0 do begin
145                         ToolBar.RemoveControl(ToolBar.Buttons[i]);
146                 end;
147                 ini := TMemIniFile.Create(FileName);
148                 try
149                         i := 0;
150                         while True do begin
151                                 s := ini.ReadString(ToolBar.Name, 'Button' + IntToStr(i), '');
152                                 s := ConvertToolButton( s );
153                                 if s = '-' then begin
154                                         ToolButton := TToolButton.Create(ToolBar);
155                                         ToolButton.Style := tbsSeparator;
156                                         ToolButton.Width := 8;
157                                         ToolButton.Left := 10000;
158                                         ToolBar.InsertControl(ToolButton);
159                                 end else if s <> '' then begin
160                                         Action := GetActionItem(ActionList, s);
161                                         if Action <> nil then begin
162                                                 ToolButton := TToolButton.Create(ToolBar);
163                                                 ToolButton.Action := Action;
164                                                 ToolButton.Left := 10000;
165                                                 SetButtonStyle(Action, ToolButton);
166                                                 ToolBar.InsertControl(ToolButton);
167                                         end;
168                                 end else
169                                         Break;
170                                 inc(i);
171                         end;
172                 finally
173                         ini.Free;
174                 end;
175         end;
176 end;
177
178 procedure SaveToolBarSetting(ToolBar: TToolBar);
179 var
180         ini: TMemIniFile;
181         i, j: Integer;
182         Action: TBasicAction;
183 begin
184         ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
185         j := 0;
186         try
187                 ini.EraseSection(ToolBar.Name);
188                 for i := 0 to ToolBar.ButtonCount - 1 do begin
189                         if ToolBar.Buttons[i].Style = tbsSeparator then begin
190                                 ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), '-');
191                                 Inc( j );
192                         end else begin
193                                 Action := ToolBar.Buttons[i].Action;
194                                 if Action <> nil then
195                                 begin
196                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), Action.Name);
197                                         Inc( j );
198                                 end;
199                         end;
200                 end;
201                 ini.UpdateFile;
202         finally
203                 ini.Free;
204         end;
205 end;
206
207 //ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
208 function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
209 var
210         i: Integer;
211 begin
212         for i := 0 to ActionList.ActionCount - 1 do begin
213                 if ActionList.Actions[i].Name = ActionName then begin
214                         Result := TCustomAction(ActionList.Actions[i]);
215                         Exit;
216                 end;
217         end;
218         Result := nil;
219 end;
220
221 //\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è
222 procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
223 begin
224         if IsCheckStyle(Action) then
225                 Button.Style := tbsCheck
226         else if IsDropDownStyle(Action) then
227                 Button.Style := tbsDropDown
228         else
229                 Button.Style := tbsButton;
230 end;
231
232 //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·
233 function IsCheckStyle(Action: TCustomAction): Boolean;
234 var
235         i: Integer;
236 begin
237         for i := 0 to Length(CHECK_STYLE) - 1 do begin
238                 if Action.Name = CHECK_STYLE[i] then begin
239                         Result := True;
240                         Exit;
241                 end;
242         end;
243         Result := False;
244 end;
245
246 //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·
247 function IsDropDownStyle(Action: TCustomAction): Boolean;
248 var
249         i: Integer;
250 begin
251         for i := 0 to Length(DROPDOWN_STYLE) - 1 do begin
252                 if Action.Name = DROPDOWN_STYLE[i] then begin
253                         Result := True;
254                         Exit;
255                 end;
256         end;
257         Result := False;
258 end;
259 procedure KeepDefaultToolButton(ToolBar: TToolBar; TmpToolBar: TToolBar);
260 var
261         i: Integer;
262 begin
263         for i := ToolBar.ButtonCount - 1 downto 0 do begin
264         ToolBar.Buttons[i].Parent := TmpToolBar;
265     end;
266 end;
267 procedure MakeDefaultINIFile();
268 var
269         ini: TMemIniFile;
270     i: Integer;
271 begin
272         //\95W\8f\80\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
273         //DEF_STANDARD:
274         //\83\8a\83X\83g\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
275         //DEF_LIST:
276         //\83u\83\89\83E\83U\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
277         //DEF_BROWSER:
278     if not FileExists(GikoSys.GetConfigDir + INI_FILENAME) then begin
279             ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
280         try
281             for i := 0 to Length(DEF_STANDARD) - 1 do begin
282                 if DEF_STANDARD[i] <> '' then
283                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), DEF_STANDARD[i])
284                 else
285                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), '-');
286             end;
287             for i := 0 to Length(DEF_LIST) - 1 do begin
288                 if DEF_LIST[i] <> '' then
289                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), DEF_LIST[i])
290                 else
291                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), '-');
292             end;
293             for i := 0 to Length(DEF_BROWSER) - 1 do begin
294                 if DEF_BROWSER[i] <> '' then
295                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), DEF_BROWSER[i])
296                 else
297                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), '-');
298             end;
299
300         finally
301                 ini.UpdateFile;
302             ini.Free;
303         end;
304     end;
305
306 end;
307
308 end.