OSDN Git Service

NULLワード回避のつもりがレス絞込みで障害が出たので元に戻した
[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..6]  of string = ('RoundAction',
13                                                                                                                                                                         '',
14                                                                                                                                                                         'CabinetVisibleAction',
15                                                                                                                                                                         'ArrangeAction',
16                                                                                                                                                                         '',
17                                                                                                                                                                         'StopAction',
18                                                                                                                                                                         'LoginAction');
19         //\83\8a\83X\83g\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
20         DEF_LIST:       array[0..16] of string = ('ListNumberVisibleAction',
21                                                                                                                                                                         'IconStyle',
22                                                                                                                                                                         'UpFolderAction',
23                                                                                                                                                                         '',
24                                                                                                                                                                         'AllItemAction',
25                                                                                                                                                                         'LogItemAction',
26                                                                                                                                                                         'NewItemAction',
27                                                                                                                                                                         'SelectItemAction',
28                                                                                                                                                                         '',
29                                                                                                                                                                         'ThreadEditorAction',
30                                                                                                                                                                         '',
31                                                                                                                                                                         'BoardIEAction',
32                                                                                                                                                                         '',
33                                                                                                                                                                         'SelectListReloadAction',
34                                                                                                                                                                         'SelectThreadReloadAction',
35                                                                                                                                                                         '',
36                                                                                                                                                                         'SelectReservAction');
37         //\83u\83\89\83E\83U\83c\81[\83\8b\83o\81[\83f\83t\83H\83\8b\83g
38         DEF_BROWSER:  array[0..15] of string = ('BrowserMaxAction',
39                                                                                                                                                                         'BrowserMinAction',
40                                                                                                                                                                         '',
41                                                                                                                                                                         'ScrollTopAction',
42                                                                                                                                                                         'ScrollLastAction',
43                                                                                                                                                                         'ScrollNewAction',
44                                                                                                                                                                         'ScrollKokoAction',
45                                                                                                                                                                         '',
46                                                                                                                                                                         'AllResAction',
47                                                                                                                                                                         'SelectResAction',
48                                                                                                                                                                         '',
49                                                                                                                                                                         'EditorAction',
50                                                                                                                                                                         '',
51                                                                                                                                                                         'IEAction',
52                                                                                                                                                                         '',
53                                                                                                                                                                         'ItemReloadAction');
54
55
56         //\83{\83^\83\93\83X\83^\83C\83\8b\82ª"tbsCheck"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
57         CHECK_STYLE:   array[0..30] of string = ('CabinetVisibleAction',
58                                                                                                                                                                         'ArrangeAction',
59                                                                                                                                                                         'AllItemAction',
60                                                                                                                                                                         'LogItemAction',
61                                                                                                                                                                         'NewItemAction',
62                                                                                                                                                                         'SelectItemAction',
63
64                                                                                                                                                                         'StdToolBarVisibleAction',
65                                                                                                                                                                         'AddressBarVisibleAction',
66                                                                                                                                                                         'LinkBarVisibleAction',
67                                                                                                                                                                         'ListToolBarVisibleAction',
68                                                                                                                                                                         'ListNameBarVisibleAction',
69                                                                                                                                                                         'BrowserToolBarVisibleAction',
70                                                                                                                                                                         'BrowserNameBarVisibleAction',
71                                                                                                                                                                         'MsgBarVisibleAction',
72                                                                                                                                                                         'StatusBarVisibleAction',
73                                                                                                                                                                         'Cabinet2chAction',
74                                                                                                                                                                         'CabinetHistoryAction',
75                                                                                                                                                                         'LargeIconAction',
76                                                                                                                                                                         'SmallIconAction',
77                                                                                                                                                                         'ListIconAction',
78                                                                                                                                                                         'DetailIconAction',
79                                                                                                                                                                         'BrowserTabVisibleAction',
80                                                                                                                                                                         'BrowserTabTopAction',
81                                                                                                                                                                         'BrowserTabBottomAction',
82                                                                                                                                                                         'BrowserTabTabStyleAction',
83                                                                                                                                                                         'BrowserTabButtonStyleAction',
84                                                                                                                                                                         'BrowserTabFlatStyleAction',
85                                                                                                                                                                         'LoginAction',
86                                                                                                                                                                         'ListNumberVisibleAction',
87                                                                                                                                                                         'AllResAction',
88                                                                                                                                                                         'SelectResAction'
89                                                                                                                                                                         );
90
91         //\83{\83^\83\93\82Ì\83X\83^\83C\83\8b\82ª"tbsDropDown"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
92         DROPDOWN_STYLE: array[0..1] of string = ('IconStyle',
93                                                                                                                                                                          'IEAction');
94
95         INI_FILENAME: string = 'ToolBar.ini';
96
97         function IsCheckStyle(Action: TCustomAction): Boolean;
98         function IsDropDownStyle(Action: TCustomAction): Boolean;
99         procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
100         function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
101         procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
102         procedure SaveToolBarSetting(ToolBar: TToolBar);
103
104 implementation
105
106 procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
107 var
108         FileName: string;
109         ini: TMemIniFile;
110         i: Integer;
111         s: string;
112         Action: TCustomAction;
113         ToolButton: TToolButton;
114 begin
115         FileName := GikoSys.GetConfigDir + INI_FILENAME;
116         if FileExists(FileName) then begin
117                 for i := ToolBar.ButtonCount - 1 downto 0 do
118                         ToolBar.RemoveControl(ToolBar.Buttons[i]);
119
120                 ini := TMemIniFile.Create(FileName);
121                 try
122                         i := 0;
123                         while True do begin
124                                 s := ini.ReadString(ToolBar.Name, 'Button' + IntToStr(i), '');
125                                 if s = '-' then begin
126                                         ToolButton := TToolButton.Create(ToolBar);
127                                         ToolButton.Style := tbsSeparator;
128                                         ToolButton.Width := 8;
129                                         ToolButton.Left := 10000;
130                                         ToolBar.InsertControl(ToolButton);
131                                 end else if s <> '' then begin
132                                         Action := GetActionItem(ActionList, s);
133                                         if Action <> nil then begin
134                                                 ToolButton := TToolButton.Create(ToolBar);
135                                                 ToolButton.Action := Action;
136                                                 ToolButton.Left := 10000;
137                                                 SetButtonStyle(Action, ToolButton);
138                                                 ToolBar.InsertControl(ToolButton);
139                                         end;
140                                 end else
141                                         Break;
142                                 inc(i);
143                         end;
144                 finally
145                         ini.Free;
146                 end;
147         end;
148 end;
149
150 procedure SaveToolBarSetting(ToolBar: TToolBar);
151 var
152         ini: TMemIniFile;
153         i, j: Integer;
154         Action: TBasicAction;
155 begin
156         ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
157         j := 0;
158         try
159                 ini.EraseSection(ToolBar.Name);
160                 for i := 0 to ToolBar.ButtonCount - 1 do begin
161                         if ToolBar.Buttons[i].Style = tbsSeparator then begin
162                                 ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), '-');
163                                 Inc( j );
164                         end else begin
165                                 Action := ToolBar.Buttons[i].Action;
166                                 if Action <> nil then
167                                 begin
168                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), Action.Name);
169                                         Inc( j );
170                                 end;
171                         end;
172                 end;
173                 ini.UpdateFile;
174         finally
175                 ini.Free;
176         end;
177 end;
178
179 //ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
180 function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
181 var
182         i: Integer;
183 begin
184         for i := 0 to ActionList.ActionCount - 1 do begin
185                 if ActionList.Actions[i].Name = ActionName then begin
186                         Result := TCustomAction(ActionList.Actions[i]);
187                         Exit;
188                 end;
189         end;
190         Result := nil;
191 end;
192
193 //\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è
194 procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
195 begin
196         if IsCheckStyle(Action) then
197                 Button.Style := tbsCheck
198         else if IsDropDownStyle(Action) then
199                 Button.Style := tbsDropDown
200         else
201                 Button.Style := tbsButton;
202 end;
203
204 //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·
205 function IsCheckStyle(Action: TCustomAction): Boolean;
206 var
207         i: Integer;
208 begin
209         for i := 0 to Length(CHECK_STYLE) - 1 do begin
210                 if Action.Name = CHECK_STYLE[i] then begin
211                         Result := True;
212                         Exit;
213                 end;
214         end;
215         Result := False;
216 end;
217
218 //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·
219 function IsDropDownStyle(Action: TCustomAction): Boolean;
220 var
221         i: Integer;
222 begin
223         for i := 0 to Length(DROPDOWN_STYLE) - 1 do begin
224                 if Action.Name = DROPDOWN_STYLE[i] then begin
225                         Result := True;
226                         Exit;
227                 end;
228         end;
229         Result := False;
230 end;
231
232 end.