OSDN Git Service

・TThreadItem クラス、およびクラスの受け渡し処理を追加。
[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..31] 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                                           'CabinetFavoriteAction',
76                                                                                                                                                                         'LargeIconAction',
77                                                                                                                                                                         'SmallIconAction',
78                                                                                                                                                                         'ListIconAction',
79                                                                                                                                                                         'DetailIconAction',
80                                                                                                                                                                         'BrowserTabVisibleAction',
81                                                                                                                                                                         'BrowserTabTopAction',
82                                                                                                                                                                         'BrowserTabBottomAction',
83                                                                                                                                                                         'BrowserTabTabStyleAction',
84                                                                                                                                                                         'BrowserTabButtonStyleAction',
85                                                                                                                                                                         'BrowserTabFlatStyleAction',
86                                                                                                                                                                         'LoginAction',
87                                                                                                                                                                         'ListNumberVisibleAction',
88                                                                                                                                                                         'AllResAction',
89                                                                                                                                                                         'SelectResAction'
90                                                                                                                                                                         );
91
92         //\83{\83^\83\93\82Ì\83X\83^\83C\83\8b\82ª"tbsDropDown"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
93         DROPDOWN_STYLE: array[0..1] of string = ('IconStyle',
94                                                                                                                                                                          'IEAction');
95
96         INI_FILENAME: string = 'ToolBar.ini';
97
98         function IsCheckStyle(Action: TCustomAction): Boolean;
99         function IsDropDownStyle(Action: TCustomAction): Boolean;
100         procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
101         function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
102         procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
103         procedure SaveToolBarSetting(ToolBar: TToolBar);
104
105 implementation
106
107 procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
108 var
109         FileName: string;
110         ini: TMemIniFile;
111         i: Integer;
112         s: string;
113         Action: TCustomAction;
114         ToolButton: TToolButton;
115 begin
116         FileName := GikoSys.GetConfigDir + INI_FILENAME;
117         if FileExists(FileName) then begin
118                 for i := ToolBar.ButtonCount - 1 downto 0 do
119                         ToolBar.RemoveControl(ToolBar.Buttons[i]);
120
121                 ini := TMemIniFile.Create(FileName);
122                 try
123                         i := 0;
124                         while True do begin
125                                 s := ini.ReadString(ToolBar.Name, 'Button' + IntToStr(i), '');
126                                 if s = '-' then begin
127                                         ToolButton := TToolButton.Create(ToolBar);
128                                         ToolButton.Style := tbsSeparator;
129                                         ToolButton.Width := 8;
130                                         ToolButton.Left := 10000;
131                                         ToolBar.InsertControl(ToolButton);
132                                 end else if s <> '' then begin
133                                         Action := GetActionItem(ActionList, s);
134                                         if Action <> nil then begin
135                                                 ToolButton := TToolButton.Create(ToolBar);
136                                                 ToolButton.Action := Action;
137                                                 ToolButton.Left := 10000;
138                                                 SetButtonStyle(Action, ToolButton);
139                                                 ToolBar.InsertControl(ToolButton);
140                                         end;
141                                 end else
142                                         Break;
143                                 inc(i);
144                         end;
145                 finally
146                         ini.Free;
147                 end;
148         end;
149 end;
150
151 procedure SaveToolBarSetting(ToolBar: TToolBar);
152 var
153         ini: TMemIniFile;
154         i, j: Integer;
155         Action: TBasicAction;
156 begin
157         ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
158         j := 0;
159         try
160                 ini.EraseSection(ToolBar.Name);
161                 for i := 0 to ToolBar.ButtonCount - 1 do begin
162                         if ToolBar.Buttons[i].Style = tbsSeparator then begin
163                                 ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), '-');
164                                 Inc( j );
165                         end else begin
166                                 Action := ToolBar.Buttons[i].Action;
167                                 if Action <> nil then
168                                 begin
169                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(j), Action.Name);
170                                         Inc( j );
171                                 end;
172                         end;
173                 end;
174                 ini.UpdateFile;
175         finally
176                 ini.Free;
177         end;
178 end;
179
180 //ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
181 function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
182 var
183         i: Integer;
184 begin
185         for i := 0 to ActionList.ActionCount - 1 do begin
186                 if ActionList.Actions[i].Name = ActionName then begin
187                         Result := TCustomAction(ActionList.Actions[i]);
188                         Exit;
189                 end;
190         end;
191         Result := nil;
192 end;
193
194 //\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è
195 procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
196 begin
197         if IsCheckStyle(Action) then
198                 Button.Style := tbsCheck
199         else if IsDropDownStyle(Action) then
200                 Button.Style := tbsDropDown
201         else
202                 Button.Style := tbsButton;
203 end;
204
205 //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·
206 function IsCheckStyle(Action: TCustomAction): Boolean;
207 var
208         i: Integer;
209 begin
210         for i := 0 to Length(CHECK_STYLE) - 1 do begin
211                 if Action.Name = CHECK_STYLE[i] then begin
212                         Result := True;
213                         Exit;
214                 end;
215         end;
216         Result := False;
217 end;
218
219 //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·
220 function IsDropDownStyle(Action: TCustomAction): Boolean;
221 var
222         i: Integer;
223 begin
224         for i := 0 to Length(DROPDOWN_STYLE) - 1 do begin
225                 if Action.Name = DROPDOWN_STYLE[i] then begin
226                         Result := True;
227                         Exit;
228                 end;
229         end;
230         Result := False;
231 end;
232
233 end.