OSDN Git Service

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