OSDN Git Service

ハ゛タ50(1.50.1.599)までの変更分をマージ
[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                 //SelectComboBox\97p\82Ì\83_\83~\81[\82Í\95Û\91\82µ\82È\82¢
197                                 if not (ToolBar.Buttons[i].Name = 'SelectComboBoxDummy') then begin
198                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), '-');
199                                         Inc( j );
200                                 end;
201                         end else begin
202                                 Action := ToolBar.Buttons[i].Action;
203                                 if Action <> nil then
204                                                                 begin
205                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), Action.Name);
206                                         Inc( j );
207                                 end;
208                         end;
209                 end;
210                 ini.UpdateFile;
211         finally
212                 ini.Free;
213         end;
214 end;
215
216 //ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
217 function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
218 var
219         i: Integer;
220 begin
221         for i := 0 to ActionList.ActionCount - 1 do begin
222                 if ActionList.Actions[i].Name = ActionName then begin
223                         Result := TCustomAction(ActionList.Actions[i]);
224                         Exit;
225                 end;
226         end;
227         Result := nil;
228 end;
229
230 //\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è
231 procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
232 begin
233         if IsCheckStyle(Action) then
234                 Button.Style := tbsCheck
235         else if IsDropDownStyle(Action) then
236                 Button.Style := tbsDropDown
237         else
238                 Button.Style := tbsButton;
239 end;
240
241 //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·
242 function IsCheckStyle(Action: TCustomAction): Boolean;
243 var
244         i: Integer;
245 begin
246         for i := 0 to Length(CHECK_STYLE) - 1 do begin
247                 if Action.Name = CHECK_STYLE[i] then begin
248                         Result := True;
249                         Exit;
250                 end;
251         end;
252         Result := False;
253 end;
254
255 //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·
256 function IsDropDownStyle(Action: TCustomAction): Boolean;
257 var
258         i: Integer;
259 begin
260         for i := 0 to Length(DROPDOWN_STYLE) - 1 do begin
261                 if Action.Name = DROPDOWN_STYLE[i] then begin
262                         Result := True;
263                         Exit;
264                 end;
265         end;
266         Result := False;
267 end;
268
269 procedure MakeDefaultINIFile();
270 var
271         ini: TMemIniFile;
272     i: Integer;
273 begin
274         //\95W\8f\80\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
275         //DEF_STANDARD:
276         //\83\8a\83X\83g\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
277         //DEF_LIST:
278         //\83u\83\89\83E\83U\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
279         //DEF_BROWSER:
280     if not FileExists(GikoSys.GetConfigDir + INI_FILENAME) then begin
281             ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
282         try
283             for i := 0 to Length(DEF_STANDARD) - 1 do begin
284                 if DEF_STANDARD[i] <> '' then
285                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), DEF_STANDARD[i])
286                 else
287                         ini.WriteString('StdToolBar', 'Button' + IntToStr(i), '-');
288             end;
289             for i := 0 to Length(DEF_LIST) - 1 do begin
290                 if DEF_LIST[i] <> '' then
291                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), DEF_LIST[i])
292                 else
293                         ini.WriteString('ListToolBar', 'Button' + IntToStr(i), '-');
294             end;
295             for i := 0 to Length(DEF_BROWSER) - 1 do begin
296                 if DEF_BROWSER[i] <> '' then
297                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), DEF_BROWSER[i])
298                 else
299                         ini.WriteString('BrowserToolBar', 'Button' + IntToStr(i), '-');
300             end;
301
302         finally
303                 ini.UpdateFile;
304             ini.Free;
305         end;
306     end;
307
308 end;
309
310 end.