OSDN Git Service

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