OSDN Git Service

・Windows 95 でもお気に入りが使えるようになった。
[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..12] of string = ('BrowserMaxAction',
39                                                                                                                                                                         'BrowserMinAction',
40                                                                                                                                                                         '',
41                                                                                                                                                                         'ScrollTopAction',
42                                                                                                                                                                         'ScrollLastAction',
43                                                                                                                                                                         'ScrollNewAction',
44                                                                                                                                                                         'ScrollKokoAction',
45                                                                                                                                                                         '',
46                                                                                                                                                                         'EditorAction',
47                                                                                                                                                                         '',
48                                                                                                                                                                         'IEAction',
49                                                                                                                                                                         '',
50                                                                                                                                                                         'ItemReloadAction');
51
52
53         //\83{\83^\83\93\83X\83^\83C\83\8b\82ª"tbsCheck"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
54         CHECK_STYLE:   array[0..28] of string = ('CabinetVisibleAction',
55                                                                                                                                                                         'ArrangeAction',
56                                                                                                                                                                         'AllItemAction',
57                                                                                                                                                                         'LogItemAction',
58                                                                                                                                                                         'NewItemAction',
59                                                                                                                                                                         'SelectItemAction',
60
61                                                                                                                                                                         'StdToolBarVisibleAction',
62                                                                                                                                                                         'AddressBarVisibleAction',
63                                                                                                                                                                         'LinkBarVisibleAction',
64                                                                                                                                                                         'ListToolBarVisibleAction',
65                                                                                                                                                                         'ListNameBarVisibleAction',
66                                                                                                                                                                         'BrowserToolBarVisibleAction',
67                                                                                                                                                                         'BrowserNameBarVisibleAction',
68                                                                                                                                                                         'MsgBarVisibleAction',
69                                                                                                                                                                         'StatusBarVisibleAction',
70                                                                                                                                                                         'Cabinet2chAction',
71                                                                                                                                                                         'CabinetHistoryAction',
72                                                                                                                                                                         'LargeIconAction',
73                                                                                                                                                                         'SmallIconAction',
74                                                                                                                                                                         'ListIconAction',
75                                                                                                                                                                         'DetailIconAction',
76                                                                                                                                                                         'BrowserTabVisibleAction',
77                                                                                                                                                                         'BrowserTabTopAction',
78                                                                                                                                                                         'BrowserTabBottomAction',
79                                                                                                                                                                         'BrowserTabTabStyleAction',
80                                                                                                                                                                         'BrowserTabButtonStyleAction',
81                                                                                                                                                                         'BrowserTabFlatStyleAction',
82
83                                                                                                                                                                         'LoginAction',
84                                                                                                                                                                         'ListNumberVisibleAction'
85                                                                                                                                                                         );
86
87         //\83{\83^\83\93\82Ì\83X\83^\83C\83\8b\82ª"tbsDropDown"\83{\83^\83\93\82Ì\83A\83N\83V\83\87\83\93
88         DROPDOWN_STYLE: array[0..1] of string = ('IconStyle',
89                                                                                                                                                                          'IEAction');
90
91         INI_FILENAME: string = 'ToolBar.ini';
92
93         function IsCheckStyle(Action: TCustomAction): Boolean;
94         function IsDropDownStyle(Action: TCustomAction): Boolean;
95         procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
96         function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
97         procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
98         procedure SaveToolBarSetting(ToolBar: TToolBar);
99
100 implementation
101
102 procedure ReadToolBarSetting(ActionList: TActionList; ToolBar: TToolBar);
103 var
104         FileName: string;
105         ini: TMemIniFile;
106         i: Integer;
107         s: string;
108         Action: TCustomAction;
109         ToolButton: TToolButton;
110 begin
111         FileName := GikoSys.GetConfigDir + INI_FILENAME;
112         if FileExists(FileName) then begin
113                 for i := ToolBar.ButtonCount - 1 downto 0 do
114                         ToolBar.RemoveControl(ToolBar.Buttons[i]);
115
116                 ini := TMemIniFile.Create(FileName);
117                 try
118                         i := 0;
119                         while True do begin
120                                 s := ini.ReadString(ToolBar.Name, 'Button' + IntToStr(i), '');
121                                 if s = '-' then begin
122                                         ToolButton := TToolButton.Create(ToolBar);
123                                         ToolButton.Style := tbsSeparator;
124                                         ToolButton.Width := 8;
125                                         ToolButton.Left := 10000;
126                                         ToolBar.InsertControl(ToolButton);
127                                 end else if s <> '' then begin
128                                         Action := GetActionItem(ActionList, s);
129                                         if Action <> nil then begin
130                                                 ToolButton := TToolButton.Create(ToolBar);
131                                                 ToolButton.Action := Action;
132                                                 ToolButton.Left := 10000;
133                                                 SetButtonStyle(Action, ToolButton);
134                                                 ToolBar.InsertControl(ToolButton);
135                                         end;
136                                 end else
137                                         Break;
138                                 inc(i);
139                         end;
140                 finally
141                         ini.Free;
142                 end;
143         end;
144 end;
145
146 procedure SaveToolBarSetting(ToolBar: TToolBar);
147 var
148         ini: TMemIniFile;
149         i: Integer;
150         Action: TBasicAction;
151 begin
152         ini := TMemIniFile.Create(GikoSys.GetConfigDir + INI_FILENAME);
153         try
154                 ini.EraseSection(ToolBar.Name);
155                 for i := 0 to ToolBar.ButtonCount - 1 do begin
156                         if ToolBar.Buttons[i].Style = tbsSeparator then begin
157                                 ini.WriteString(ToolBar.Name, 'Button' + IntToStr(i), '-');
158                         end else begin
159                                 Action := ToolBar.Buttons[i].Action;
160                                 if Action <> nil then
161                                         ini.WriteString(ToolBar.Name, 'Button' + IntToStr(i), Action.Name);
162                         end;
163                 end;
164                 ini.UpdateFile;
165         finally
166                 ini.Free;
167         end;
168 end;
169
170 //ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
171 function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
172 var
173         i: Integer;
174 begin
175         for i := 0 to ActionList.ActionCount - 1 do begin
176                 if ActionList.Actions[i].Name = ActionName then begin
177                         Result := TCustomAction(ActionList.Actions[i]);
178                         Exit;
179                 end;
180         end;
181         Result := nil;
182 end;
183
184 //\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è
185 procedure SetButtonStyle(Action: TCustomAction; Button: TToolButton);
186 begin
187         if IsCheckStyle(Action) then
188                 Button.Style := tbsCheck
189         else if IsDropDownStyle(Action) then
190                 Button.Style := tbsDropDown
191         else
192                 Button.Style := tbsButton;
193 end;
194
195 //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·
196 function IsCheckStyle(Action: TCustomAction): Boolean;
197 var
198         i: Integer;
199 begin
200         for i := 0 to Length(CHECK_STYLE) - 1 do begin
201                 if Action.Name = CHECK_STYLE[i] then begin
202                         Result := True;
203                         Exit;
204                 end;
205         end;
206         Result := False;
207 end;
208
209 //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·
210 function IsDropDownStyle(Action: TCustomAction): Boolean;
211 var
212         i: Integer;
213 begin
214         for i := 0 to Length(DROPDOWN_STYLE) - 1 do begin
215                 if Action.Name = DROPDOWN_STYLE[i] then begin
216                         Result := True;
217                         Exit;
218                 end;
219         end;
220         Result := False;
221 end;
222
223 end.