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;
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..15] 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
58
59         //\83{\83^\83\93\83X\83^\83C\83\8b\82ª"tbsCheck"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
60         CHECK_STYLE:   array[0..31] of string = ('CabinetVisibleAction',
61                                                                                                                                                                         'ArrangeAction',
62                                                                                                                                                                         'AllItemAction',
63                                                                                                                                                                         'LogItemAction',
64                                                                                                                                                                         'NewItemAction',
65                                                                                                                                                                         'SelectItemAction',
66
67                                                                                                                                                                         'StdToolBarVisibleAction',
68                                                                                                                                                                         'AddressBarVisibleAction',
69                                                                                                                                                                         'LinkBarVisibleAction',
70                                                                                                                                                                         'ListToolBarVisibleAction',
71                                                                                                                                                                         'ListNameBarVisibleAction',
72                                                                                                                                                                         'BrowserToolBarVisibleAction',
73                                                                                                                                                                         'BrowserNameBarVisibleAction',
74                                                                                                                                                                         'MsgBarVisibleAction',
75                                                                                                                                                                         'StatusBarVisibleAction',
76                                                                                                                                                                         'CabinetBBSAction',
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                                                                                                                                                                         );
94
95         //\83{\83^\83\93\82Ì\83X\83^\83C\83\8b\82ª"tbsDropDown"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
96         DROPDOWN_STYLE: array[0..1] of string = ('IconStyle',
97                                                                                                                                                                          'IEAction');
98
99         INI_FILENAME: string = 'ToolBar.ini';
100
101         function IsCheckStyle(Action: TCustomAction): Boolean;
102         function IsDropDownStyle(Action: TCustomAction): Boolean;
103         procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
104         function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
105         procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
106         procedure SaveToolBarSetting(ToolBar: TToolBar);
107
108 implementation
109
110 procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
111 var
112         FileName: string;
113         ini: TMemIniFile;
114         i: Integer;
115         s: string;
116         Action: TCustomAction;
117         ToolButton: TToolButton;
118 begin
119         FileName := GikoSys.GetConfigDir + INI_FILENAME;
120         if FileExists(FileName) then begin
121                 for i := ToolBar.ButtonCount - 1 downto 0 do
122                         ToolBar.RemoveControl(ToolBar.Buttons[i]);
123
124                 ini := TMemIniFile.Create(FileName);
125                 try
126                         i := 0;
127                         while True do begin
128                                 s := ini.ReadString(ToolBar.Name, 'Button' + IntToStr(i), '');
129                                 if s = '-' then begin
130                                         ToolButton := TToolButton.Create(ToolBar);
131                                         ToolButton.Style := tbsSeparator;
132                                         ToolButton.Width := 8;
133                                         ToolButton.Left := 10000;
134                                         ToolBar.InsertControl(ToolButton);
135                                 end else if s <> '' then begin
136                                         Action := GetActionItem(ActionList, s);
137                                         if Action <> nil then begin
138                                                 ToolButton := TToolButton.Create(ToolBar);
139                                                 ToolButton.Action := Action;
140                                                 ToolButton.Left := 10000;
141                                                 SetButtonStyle(Action, ToolButton);
142                                                 ToolBar.InsertControl(ToolButton);
143                                         end;
144                                 end else
145                                         Break;
146                                 inc(i);
147                         end;
148                 finally
149                         ini.Free;
150                 end;
151         end;
152 end;
153
154 procedure SaveToolBarSetting(ToolBar: TToolBar);
155 var
156         ini: TMemIniFile;
157         i, j: Integer;
158         Action: TBasicAction;
159 begin
160         ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
161         j := 0;
162         try
163                 ini.EraseSection(ToolBar.Name);
164                 for i := 0 to ToolBar.ButtonCount - 1 do begin
165                         if ToolBar.Buttons[i].Style = tbsSeparator then begin
166                                 ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), '-');
167                                 Inc( j );
168                         end else begin
169                                 Action := ToolBar.Buttons[i].Action;
170                                 if Action <> nil then
171                                 begin
172                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), Action.Name);
173                                         Inc( j );
174                                 end;
175                         end;
176                 end;
177                 ini.UpdateFile;
178         finally
179                 ini.Free;
180         end;
181 end;
182
183 //ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
184 function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
185 var
186         i: Integer;
187 begin
188         for i := 0 to ActionList.ActionCount - 1 do begin
189                 if ActionList.Actions[i].Name = ActionName then begin
190                         Result := TCustomAction(ActionList.Actions[i]);
191                         Exit;
192                 end;
193         end;
194         Result := nil;
195 end;
196
197 //\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è
198 procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
199 begin
200         if IsCheckStyle(Action) then
201                 Button.Style := tbsCheck
202         else if IsDropDownStyle(Action) then
203                 Button.Style := tbsDropDown
204         else
205                 Button.Style := tbsButton;
206 end;
207
208 //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·
209 function IsCheckStyle(Action: TCustomAction): Boolean;
210 var
211         i: Integer;
212 begin
213         for i := 0 to Length(CHECK_STYLE) - 1 do begin
214                 if Action.Name = CHECK_STYLE[i] then begin
215                         Result := True;
216                         Exit;
217                 end;
218         end;
219         Result := False;
220 end;
221
222 //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·
223 function IsDropDownStyle(Action: TCustomAction): Boolean;
224 var
225         i: Integer;
226 begin
227         for i := 0 to Length(DROPDOWN_STYLE) - 1 do begin
228                 if Action.Name = DROPDOWN_STYLE[i] then begin
229                         Result := True;
230                         Exit;
231                 end;
232         end;
233         Result := False;
234 end;
235
236 end.