OSDN Git Service

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