OSDN Git Service

・スレタイの特定ワードを非表示にする機能に「©bbspink.com」も追加
[gikonavigoeson/gikonavi.git] / PopupMenuUtil.pas
1 unit PopupMenuUtil;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Classes, Controls,
7         StdCtrls, ExtCtrls, ComCtrls, ActnList, Menus,
8     IniFiles,   GikoSystem, MojuUtils, Giko;
9
10     procedure ReadSetting(ActionList: TActionList; PopupMenu: TPopupMenu);
11     function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
12     function GetMenuItem(Section: string; PopupMenu: TPopupMenu; ActionList: TActionList; MenuName: string): TMenuItem;
13     function checkActionName(Section: string ; ActionName: string): Boolean;
14 const
15     //! \90Ý\92è\83t\83@\83C\83\8b\96¼
16         INI_FILENAME: string = 'popupmenu.ini';
17     //! \83u\83\89\83E\83U\83^\83u\83Z\83N\83V\83\87\83\93\96¼
18     BROWSER_TAB: string = 'BrowserTab';
19     //! \83Z\83N\83V\83\87\83\93\82Ì\88ê\97\97
20     SECTIONS : array[0..0] of string =( 'BrowserTab' ) ;
21
22     //! \83u\83\89\83E\83U\83^\83u\83|\83b\83v\83A\83b\83v\82É\90Ý\92è\89Â\94\\82È\83\81\83j\83\85\81[\96¼
23     ACK_BROWSER: array[0..7]    of string = (
24                                             'ItemReloadAction',
25                                             'FavoriteAddAction',
26                                             'BrowserTabCloseAction',
27                                             'NotSelectTabCloseAction',
28                                             'LeftTabCloseAction',
29                                             'RightTabCloseAction',
30                                             'ActiveLogDeleteAction',
31                                             'AllTabCloseAction');
32
33 implementation
34 procedure ReadSetting(ActionList: TActionList; PopupMenu: TPopupMenu);
35 const
36     // \93Á\8eê\83A\83N\83V\83\87\83\93\96¼
37     // \8f\84\89ñ\83A\83C\83e\83\80
38     ROUNDITEM = 'RoundItem';
39     // \93¯\88ê\94Â\83X\83\8c\83b\83h\88ê\97\97\97p
40     SAMPETHREAD='SameBoardThreadItem';
41 var
42     ini : TMemIniFile;
43     mkeys, skeys : TStringList;
44     i, j, idx: Integer;
45     value, subValue : String;
46     item, subItem : TMenuItem;
47 begin
48     if (FileExists(GikoSys.Setting.GetConfigDir + INI_FILENAME)) Then begin
49         ini := TMemIniFile.Create(GikoSys.Setting.GetConfigDir + INI_FILENAME);
50         mkeys := TStringList.Create;
51         mkeys.Sorted := true;
52         skeys := TStringList.Create;
53         skeys.Sorted := true;
54         try
55             for idx := 0 to Length(SECTIONS) - 1 do begin
56                 ini.ReadSection(SECTIONS[idx], mkeys);
57                 // main\91æ\88ê\8aK\91w sub\91æ\93ñ\8aK\91w\82Ì\95ª\97£
58                 for i := mkeys.Count - 1 downto 0 do begin
59                     if (Pos('sub', mkeys[i]) = 1) then begin
60                         skeys.Add(mkeys[i]);
61                         mkeys.Delete(i);
62                     end;
63                 end;
64                 // \91æ\88ê\8aK\91w\82Ì\8f\88\97\9d
65                 PopupMenu.Items.Clear;
66                 for i := 0 to mkeys.Count - 1 do begin
67                     value := ini.ReadString(SECTIONS[idx], mkeys[i], '-');
68                     item := GetMenuItem(SECTIONS[idx], PopupMenu, ActionList, value);
69                     if (item <> nil) then begin
70                         PopupMenu.Items.Add(item);
71                         // \83A\83N\83V\83\87\83\93\82ª\90Ý\92è\82³\82ê\82Ä\82¢\82é\82à\82Ì\82É\82Í\91æ\93ñ\91w\82Í\82Â\82¯\82È\82¢
72                         if (item.Action = nil) then begin
73                             // \91æ\93ñ\8aK\91w\82Ì\8f\88\97\9d(\82 \82ê\82Î)
74                             for j := 0 to skeys.Count - 1 do begin
75                                 if (Pos('sub.' + mkeys[i], skeys[j]) = 1) then begin
76                                     subValue := ini.ReadString(SECTIONS[idx], skeys[j], '-');
77                                     subItem := GetMenuItem(SECTIONS[idx], PopupMenu, ActionList, subValue);
78                                     if (subItem <> nil) then begin
79                                         item.Add(subItem);
80                                     end;
81                                 end;
82                             end;
83                         end;
84                     end;
85                 end;
86                 // \82±\82Ì\83Z\83N\83V\83\87\83\93\82Ì\8f\88\97\9d\82ª\8fI\82í\82Á\82½\82Ì\82Å\83N\83\8a\83A
87                 mkeys.Clear;
88                 skeys.Clear;
89             end;
90         finally
91             skeys.Free;
92             mkeys.Free;
93             ini.Free;
94         end;
95     end;
96 end;
97 //! \83\81\83j\83\85\81[\82ð\95Ô\82·
98 function GetMenuItem(Section: string; PopupMenu: TPopupMenu; ActionList: TActionList; MenuName: string): TMenuItem;
99 var
100     Action: TCustomAction;
101 begin
102     Result := nil;
103     // \83_\83u\83\8b\83N\83H\81[\83g\82Å\8en\82Ü\82é\82Æ\82«\82Í\83\89\83x\83\8b
104     if (Pos('"', MenuName)=1) then begin
105         Result := TMenuItem.Create(PopupMenu);
106         Result.Caption := Copy(MenuName, 2, Length(MenuName));
107     end else if (MenuName = '-' ) then begin
108         // \8bæ\90Ø\82è\90ü
109         Result := TMenuItem.Create(PopupMenu);
110         Result.Caption := '-';
111     end else begin
112         if (BROWSER_TAB = Section) then begin
113             // \83u\83\89\83E\83U\83^\83u\82Ì\93Á\8eê\91Î\89\9e
114             if (MenuName = 'RoundItem' ) then begin
115                 try
116                     // \8f\84\89ñ\83\81\83j\83\85\81[\97p\83_\83~\81[
117                     Result := TMenuItem.Create(PopupMenu);
118                     Result.Name := 'RoundItem';
119                     Result.Caption := GikoForm.ItemReservPMenu.Caption;
120                     Result.Hint    := GikoForm.ItemReservPMenu.Hint;
121                 except
122                     // \8aù\82É\8eg\82í\82ê\82Ä\82é\82Æ\82«\82Í\83G\83\89\81[\82É\82È\82é
123                     Result.Free;
124                     Result := nil;
125                 end;
126             end else if (MenuName = 'BoardThreadItem' ) then begin
127                 try
128                     // \93¯\88ê\94Â\83X\83\8c\83b\83h\95\\8e¦\97p\83_\83~\81[
129                     Result := TMenuItem.Create(PopupMenu);
130                     Result.Name := 'BoardThreadItem';
131                     Result.Caption := '\93¯\94Â\82Å\95\\8e¦\82µ\82Ä\82¢\82é\83X\83\8c\83b\83h';
132                 except
133                     // \8aù\82É\8eg\82í\82ê\82Ä\82é\82Æ\82«\82Í\83G\83\89\81[\82É\82È\82é
134                     Result.Free;
135                     Result := nil;
136                 end;
137             end;
138         end;
139         // \83\81\83j\83\85\81[\82ª\8c\88\82Ü\82ç\82¸\82É\81A\8b\96\89Â\82³\82ê\82½\83A\83N\83V\83\87\83\93\96¼\82È\82çAction\82©\82ç\8dì\90¬
140         if (Result = nil) and (checkActionName(Section, MenuName)) then begin
141             Action := GetActionItem(ActionList, MenuName);
142             if Action <> nil then begin
143                 Result := TMenuItem.Create(PopupMenu);
144                 Result.Action := Action;
145             end;
146         end;
147     end;
148 end;
149 //ActionName\82ÌAction\82ð\95Ô\82µ\82Ü\82·
150 function GetActionItem(ActionList: TActionList; ActionName: string): TCustomAction;
151 var
152         i: Integer;
153 begin
154         for i := 0 to ActionList.ActionCount - 1 do begin
155                 if ActionList.Actions[i].Name = ActionName then begin
156                         Result := TCustomAction(ActionList.Actions[i]);
157                         Exit;
158                 end;
159         end;
160         Result := nil;
161 end;
162
163 function checkActionName(Section: string ; ActionName: string): Boolean;
164 var
165     i : Integer;
166 begin
167     Result := False;
168     if (BROWSER_TAB = Section) then begin
169         for i :=0 to  Length(ACK_BROWSER) - 1 do begin
170             if (ACK_BROWSER[i] = ActionName) then begin
171                 Result := True;
172                 Break;
173             end;
174         end;
175     end;
176 end;
177 end.