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