OSDN Git Service

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