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                                                                                                                                                                         'ResRangeAction',
52                                                                                                                                                                         '',
53                                                                                                                                                                         'EditorAction',
54                                                                                                                                                                         '',
55                                                                                                                                                                         'IEAction',
56                                                                                                                                                                         '',
57                                                                                                                                                                         'ItemReloadAction',
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..33] 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                                                                                                                                                                         'OnlyKokoResAction',
97                                                                                                                                                                         'OnlyNewResAction'
98                                                                                                                                                                         );
99
100         /// \83{\83^\83\93\82Ì\83X\83^\83C\83\8b\82ª"tbsDropDown"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
101         /// Giko.pas : SetToolBarPopup \82à\8fC\90³\82·\82é\8e\96
102         DROPDOWN_STYLE: array[0..3] of string = ('IconStyle',
103                                                                                                                                                                          'IEAction',
104                                                                                                                                                                          'CabinetBBSAction',
105                                                                                                                                                                          'ResRangeAction');
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 procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
123 var
124         FileName: string;
125         ini: TMemIniFile;
126         i: Integer;
127         s: string;
128         Action: TCustomAction;
129         ToolButton: TToolButton;
130 begin
131         FileName := GikoSys.GetConfigDir + INI_FILENAME;
132         if FileExists(FileName) then begin
133                 for i := ToolBar.ButtonCount - 1 downto 0 do begin
134                         ToolBar.RemoveControl(ToolBar.Buttons[i]);
135                 end;
136                 ini := TMemIniFile.Create(FileName);
137                 try
138                         i := 0;
139                         while True do begin
140                                 s := ini.ReadString(ToolBar.Name, 'Button' + IntToStr(i), '');
141                                 if s = '-' then begin
142                                         ToolButton := TToolButton.Create(ToolBar);
143                                         ToolButton.Style := tbsSeparator;
144                                         ToolButton.Width := 8;
145                                         ToolButton.Left := 10000;
146                                         ToolBar.InsertControl(ToolButton);
147                                 end else if s <> '' then begin
148                                         Action := GetActionItem(ActionList, s);
149                                         if Action <> nil then begin
150                                                 ToolButton := TToolButton.Create(ToolBar);
151                                                 ToolButton.Action := Action;
152                                                 ToolButton.Left := 10000;
153                                                 SetButtonStyle(Action, ToolButton);
154                                                 ToolBar.InsertControl(ToolButton);
155                                         end;
156                                 end else
157                                         Break;
158                                 inc(i);
159                         end;
160                 finally
161                         ini.Free;
162                 end;
163         end;
164 end;
165
166 procedure SaveToolBarSetting(ToolBar: TToolBar);
167 var
168         ini: TMemIniFile;
169         i, j: Integer;
170         Action: TBasicAction;
171 begin
172         ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
173         j := 0;
174         try
175                 ini.EraseSection(ToolBar.Name);
176                 for i := 0 to ToolBar.ButtonCount - 1 do begin
177                         if ToolBar.Buttons[i].Style = tbsSeparator then begin
178                                 ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), '-');
179                                 Inc( j );
180                         end else begin
181                                 Action := ToolBar.Buttons[i].Action;
182                                 if Action <> nil then
183                                 begin
184                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), Action.Name);
185                                         Inc( j );
186                                 end;
187                         end;
188                 end;
189                 ini.UpdateFile;
190         finally
191                 ini.Free;
192         end;
193 end;
194
195 //ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
196 function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
197 var
198         i: Integer;
199 begin
200         for i := 0 to ActionList.ActionCount - 1 do begin
201                 if ActionList.Actions[i].Name = ActionName then begin
202                         Result := TCustomAction(ActionList.Actions[i]);
203                         Exit;
204                 end;
205         end;
206         Result := nil;
207 end;
208
209 //\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è
210 procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
211 begin
212         if IsCheckStyle(Action) then
213                 Button.Style := tbsCheck
214         else if IsDropDownStyle(Action) then
215                 Button.Style := tbsDropDown
216         else
217                 Button.Style := tbsButton;
218 end;
219
220 //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·
221 function IsCheckStyle(Action: TCustomAction): Boolean;
222 var
223         i: Integer;
224 begin
225         for i := 0 to Length(CHECK_STYLE) - 1 do begin
226                 if Action.Name = CHECK_STYLE[i] then begin
227                         Result := True;
228                         Exit;
229                 end;
230         end;
231         Result := False;
232 end;
233
234 //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·
235 function IsDropDownStyle(Action: TCustomAction): Boolean;
236 var
237         i: Integer;
238 begin
239         for i := 0 to Length(DROPDOWN_STYLE) - 1 do begin
240                 if Action.Name = DROPDOWN_STYLE[i] then begin
241                         Result := True;
242                         Exit;
243                 end;
244         end;
245         Result := False;
246 end;
247 procedure KeepDefaultToolButton(ToolBar: TToolBar; TmpToolBar: TToolBar);
248 var
249         i: Integer;
250 begin
251         for i := ToolBar.ButtonCount - 1 downto 0 do begin
252         ToolBar.Buttons[i].Parent := TmpToolBar;
253     end;
254 end;
255 procedure MakeDefaultINIFile();
256 var
257         ini: TMemIniFile;
258     i: Integer;
259 begin
260         //\95W\8f\80\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
261         //DEF_STANDARD:
262         //\83\8a\83X\83g\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
263         //DEF_LIST:
264         //\83u\83\89\83E\83U\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
265         //DEF_BROWSER:
266     if not FileExists(GikoSys.GetConfigDir + INI_FILENAME) then begin
267             ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
268         try
269             for i := 0 to Length(DEF_STANDARD) - 1 do begin
270                 if DEF_STANDARD[i] <> '' then
271                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), DEF_STANDARD[i])
272                 else
273                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), '-');
274             end;
275             for i := 0 to Length(DEF_LIST) - 1 do begin
276                 if DEF_LIST[i] <> '' then
277                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), DEF_LIST[i])
278                 else
279                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), '-');
280             end;
281             for i := 0 to Length(DEF_BROWSER) - 1 do begin
282                 if DEF_BROWSER[i] <> '' then
283                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), DEF_BROWSER[i])
284                 else
285                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), '-');
286             end;
287
288         finally
289                 ini.UpdateFile;
290             ini.Free;
291         end;
292     end;
293
294 end;
295
296 end.