system.actions.pp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2023 by Michael Van Canneyt
  4. member of the Free Pascal development team.
  5. Delphi compatibility unit with action(list) related types.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit System.Actions;
  13. {$MODE OBJFPC}
  14. {$H+}
  15. {$modeswitch functionreferences}
  16. {$modeswitch anonymousfunctions}
  17. interface
  18. uses
  19. {$IFDEF FPC_DOTTEDUNITS}
  20. System.SysUtils, System.Classes, System.UITypes;
  21. {$ELSE}
  22. SysUtils, Classes , system.uitypes;
  23. {$ENDIF}
  24. type
  25. EActionError = class(Exception);
  26. // Some aliases to avoid confusion
  27. TShortCut = {$IFDEF FPC_DOTTEDUNITS}System.{$ENDIF}Classes.TShortCut;
  28. TImageIndex = System.UITypes.TImageIndex;
  29. TStatusAction = (
  30. saNone,
  31. saTrivial,
  32. saDefault,
  33. saRequiredEmpty,
  34. saRequired,
  35. saValid,
  36. saInvalid,
  37. saWaiting,
  38. saWarning,
  39. saUnused,
  40. saCalculated,
  41. saError,
  42. saOther);
  43. TContainedActionList = class;
  44. TContainedActionListClass = class of TContainedActionList;
  45. TCustomShortCutList = class(TStringList)
  46. private
  47. function GetShortCut(Index: Integer): TShortCut; inline;
  48. public
  49. function IndexOfShortCut(const ShortCut: TShortCut): Integer; overload;
  50. function IndexOfShortCut(const ShortCut: string): Integer; overload;
  51. property ShortCuts[Index: Integer]: TShortCut read GetShortCut;
  52. end;
  53. { TContainedAction }
  54. TContainedAction = class(TBasicAction)
  55. private
  56. FActionList: TContainedActionList;
  57. FAutoCheck: Boolean;
  58. FCaption: string;
  59. FCategory: string;
  60. FChecked: Boolean;
  61. FDisableIfNoHandler: Boolean;
  62. FEnabled: Boolean;
  63. FGroupIndex: Integer;
  64. FHelpContext: THelpContext;
  65. FHelpKeyword: string;
  66. FHelpType: THelpType;
  67. FHint: string;
  68. FImageIndex: Integer;
  69. FOnHint: THintEvent;
  70. FSavedEnabledState: Boolean;
  71. FShortCut: TShortCut;
  72. FStatusAction: TStatusAction;
  73. FVisible: Boolean;
  74. FSecondaryShortCuts : TCustomShortCutList;
  75. function GetIndex: Integer;
  76. function GetSecondaryShortCuts: TCustomShortCutList;
  77. function IsSecondaryShortCutsStored: Boolean;
  78. procedure SetActionList(AValue: TContainedActionList);
  79. procedure SetCategory(AValue: string);
  80. procedure SetIndex(AValue: Integer);
  81. procedure SetSecondaryShortCuts(AValue: TCustomShortCutList);
  82. protected
  83. procedure ReadState(Reader: TReader); override;
  84. function SecondaryShortCutsCreated: boolean;
  85. function CreateShortCutList: TCustomShortCutList; virtual;
  86. property SavedEnabledState: Boolean read FSavedEnabledState write FSavedEnabledState;
  87. function HandleShortCut: Boolean; virtual;
  88. procedure SetAutoCheck(Value: Boolean); virtual;
  89. procedure SetCaption(const Value: string); virtual;
  90. procedure SetName(const Value: TComponentName); override;
  91. procedure SetChecked(Value: Boolean); virtual;
  92. procedure SetEnabled(Value: Boolean); virtual;
  93. procedure SetGroupIndex(const Value: Integer); virtual;
  94. procedure SetHelpContext(Value: THelpContext); virtual;
  95. procedure SetHelpKeyword(const Value: string); virtual;
  96. procedure SetHelpType(Value: THelpType); virtual;
  97. procedure SetHint(const Value: string); virtual;
  98. procedure SetVisible(Value: Boolean); virtual;
  99. procedure SetShortCut(Value: TShortCut); virtual;
  100. procedure SetImageIndex(Value: TImageIndex); virtual;
  101. procedure SetStatusAction(const Value: TStatusAction); virtual;
  102. public
  103. constructor Create(AOwner: TComponent); override;
  104. destructor Destroy; override;
  105. procedure Assign(Source: TPersistent); override;
  106. function GetParentComponent: TComponent; override;
  107. function HasParent: Boolean; override;
  108. procedure SetParentComponent(AParent: TComponent); override;
  109. property ActionList: TContainedActionList read FActionList write SetActionList;
  110. function Suspended: Boolean; override;
  111. property Index: Integer read GetIndex write SetIndex stored False;
  112. property DisableIfNoHandler: Boolean read FDisableIfNoHandler write FDisableIfNoHandler default True;
  113. property AutoCheck: Boolean read FAutoCheck write SetAutoCheck default False;
  114. property Caption: string read FCaption write SetCaption;
  115. property Checked: Boolean read FChecked write SetChecked default False;
  116. property Enabled: Boolean read FEnabled write SetEnabled default True;
  117. property GroupIndex: Integer read FGroupIndex write SetGroupIndex default 0;
  118. property HelpContext: THelpContext read FHelpContext write SetHelpContext default 0;
  119. property HelpKeyword: string read FHelpKeyword write SetHelpKeyword;
  120. property HelpType: THelpType read FHelpType write SetHelpType default htKeyword;
  121. property Hint: string read FHint write SetHint;
  122. property Visible: Boolean read FVisible write SetVisible default True;
  123. property ShortCut: TShortCut read FShortCut write SetShortCut default 0;
  124. property SecondaryShortCuts: TCustomShortCutList read GetSecondaryShortCuts write SetSecondaryShortCuts stored IsSecondaryShortCutsStored;
  125. property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
  126. function DoHint(var HintStr: string): Boolean; dynamic;
  127. property OnHint: THintEvent read FOnHint write FOnHint;
  128. property StatusAction: TStatusAction read FStatusAction write SetStatusAction;
  129. published
  130. property Category: string read FCategory write SetCategory;
  131. end;
  132. TContainedActionLink = class(TBasicActionLink)
  133. protected
  134. procedure DefaultIsLinked(var Result: Boolean); virtual;
  135. function IsCaptionLinked: Boolean; virtual;
  136. function IsCheckedLinked: Boolean; virtual;
  137. function IsEnabledLinked: Boolean; virtual;
  138. function IsGroupIndexLinked: Boolean; virtual;
  139. function IsHelpContextLinked: Boolean; virtual;
  140. function IsHelpLinked: Boolean; virtual;
  141. function IsHintLinked: Boolean; virtual;
  142. function IsImageIndexLinked: Boolean; virtual;
  143. function IsShortCutLinked: Boolean; virtual;
  144. function IsVisibleLinked: Boolean; virtual;
  145. function IsStatusActionLinked: Boolean; virtual;
  146. procedure SetAutoCheck(Value: Boolean); virtual;
  147. procedure SetCaption(const Value: string); virtual;
  148. procedure SetChecked(Value: Boolean); virtual;
  149. procedure SetEnabled(Value: Boolean); virtual;
  150. procedure SetGroupIndex(Value: Integer); virtual;
  151. procedure SetHelpContext(Value: THelpContext); virtual;
  152. procedure SetHelpKeyword(const Value: string); virtual;
  153. procedure SetHelpType(Value: THelpType); virtual;
  154. procedure SetHint(const Value: string); virtual;
  155. procedure SetImageIndex(Value: Integer); virtual;
  156. procedure SetShortCut(Value: TShortCut); virtual;
  157. procedure SetVisible(Value: Boolean); virtual;
  158. procedure SetStatusAction(const Value: TStatusAction); virtual;
  159. end;
  160. TContainedActionLinkClass = class of TContainedActionLink;
  161. TContainedActionClass = class of TContainedAction;
  162. TActionListState = (asNormal,asSuspended,asSuspendedEnabled);
  163. TActionListEnumerator = class
  164. private
  165. FPosition: Integer;
  166. FList: TContainedActionList;
  167. Protected
  168. function GetCurrent: TContainedAction; inline;
  169. public
  170. constructor Create(AList: TContainedActionList);
  171. function MoveNext: Boolean; inline;
  172. property Current: TContainedAction read GetCurrent;
  173. end;
  174. TEnumActionListEvent = procedure(const Action: TContainedAction; var Done: boolean) of object;
  175. TEnumActionListRef = reference to procedure(const Action: TContainedAction; var Done: boolean);
  176. { TContainedActionList }
  177. TContainedActionList = class(TComponent)
  178. private
  179. FList: TFPList;
  180. FOnChange: TNotifyEvent;
  181. FOnExecute: TActionEvent;
  182. FOnUpdate: TActionEvent;
  183. FState: TActionListState;
  184. FOnStateChange: TNotifyEvent;
  185. procedure CorrectActionStates(ReEnabled: Boolean);
  186. function GetAction(Index: Integer): TContainedAction;
  187. procedure SetAction(Index: Integer; aValue: TContainedAction);
  188. function GetActionCount: Integer;
  189. protected
  190. Procedure SetActionIndex(Action : TContainedAction; aValue: Integer);
  191. procedure AddAction(const aAction: TContainedAction);
  192. procedure RemoveAction(const aAction: TContainedAction);
  193. procedure Change; virtual;
  194. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  195. procedure SetChildOrder(Component: TComponent; Order: Integer); override;
  196. procedure SetState(const aValue: TActionListState); virtual;
  197. procedure GetActionsInCategory(const ACategory: string; aList: TFPList; IncludeSubCategory: Boolean);
  198. function SameCategory(const Source, Dest: string;
  199. const IncludeSubCategory: Boolean = True): Boolean;
  200. function Suspended : Boolean;
  201. property OnChange: TNotifyEvent read FOnChange write FOnChange;
  202. property OnExecute: TActionEvent read FOnExecute write FOnExecute;
  203. property OnUpdate: TActionEvent read FOnUpdate write FOnUpdate;
  204. public
  205. constructor Create(AOwner: TComponent); override;
  206. destructor Destroy; override;
  207. Function IndexOfAction(Action : TBasicAction) : Integer;
  208. function ExecuteAction(Action: TBasicAction): Boolean; override;
  209. procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
  210. function GetEnumerator: TActionListEnumerator;
  211. function UpdateAction(Action: TBasicAction): Boolean; override;
  212. function EnumByCategory(Proc: TEnumActionListEvent; const Category: string; const IncludeSubCategory: Boolean = True): boolean;
  213. function EnumByCategory(Proc: TEnumActionListRef; const Category: string; const IncludeSubCategory: Boolean = True): boolean;
  214. property Actions[Index: Integer]: TContainedAction read GetAction write SetAction; default;
  215. property ActionCount: Integer read GetActionCount;
  216. property State: TActionListState read FState write SetState default asNormal;
  217. property OnStateChange: TNotifyEvent read FOnStateChange write FOnStateChange;
  218. end;
  219. type
  220. TEnumActionProcInfo = Pointer;
  221. TEnumActionProc = procedure(const Category: string; ActionClass: TBasicActionClass; Info: TEnumActionProcInfo) of object;
  222. procedure RegisterActions(const CategoryName: string; const AClasses: array of TBasicActionClass; Resource: TComponentClass);
  223. procedure UnRegisterActions(const AClasses: array of TBasicActionClass);
  224. procedure EnumRegisteredActions(Proc: TEnumActionProc; Info: TEnumActionProcInfo; FrameworkType: string = '');
  225. function CreateAction(AOwner: TComponent; ActionClass: TBasicActionClass; FrameworkType: string = ''): TBasicAction;
  226. Type
  227. TRegisterActionsProc = procedure(const aCategoryName: string; const aClasses: array of TBasicActionClass; aResource: TComponentClass);
  228. TUnRegisterActionsProc = procedure(const AClasses: array of TBasicActionClass);
  229. TEnumRegisteredActionsProc = procedure(Proc: TEnumActionProc; aInfo: Pointer; const aFrameworkType: string);
  230. TCreateActionProc = function(AOwner: TComponent; aActionClass: TBasicActionClass; const aFrameworkType: string): TBasicAction;
  231. var
  232. vDesignAction: boolean;
  233. RegisterActionsProc: TRegisterActionsProc = nil;
  234. UnRegisterActionsProc: TUnRegisterActionsProc = Nil;
  235. EnumRegisteredActionsProc: TEnumRegisteredActionsProc = Nil;
  236. CreateActionProc: TCreateActionProc = Nil;
  237. function RegisterShortCut(aShortCut: TShortCut; Index: integer = -1): integer;
  238. function UnregisterShortCut(aShortCut: TShortCut): boolean;
  239. function RegisteredShortCutCount: integer;
  240. function RegisteredShortCut(Idx: integer): TShortCut;
  241. implementation
  242. Resourcestring
  243. SErrNoRegisterActionsProc = 'No register actions handler';
  244. SErrNoUnRegisterActionsProc = 'No register actions handler';
  245. SErrNoEnumActionsProc = 'No enumerate actions handler';
  246. SErrNoCreateActionsProc = 'No action creation handler';
  247. SErrIndexOutOfBounds = 'Index %d out of bounds [%d,%d]';
  248. { ---------------------------------------------------------------------
  249. Action registry hooks
  250. ---------------------------------------------------------------------}
  251. procedure RegisterActions(const CategoryName: string; const AClasses: array of TBasicActionClass;
  252. Resource: TComponentClass);
  253. begin
  254. if not Assigned(RegisterActionsProc) then
  255. raise EActionError.Create(SErrNoRegisterActionsProc);
  256. RegisterActionsProc(CategoryName, AClasses, Resource);
  257. end;
  258. procedure UnRegisterActions(const AClasses: array of TBasicActionClass);
  259. begin
  260. if not Assigned(UnRegisterActionsProc) then
  261. raise EActionError.Create(SErrNoUnRegisterActionsProc);
  262. UnRegisterActionsProc(AClasses)
  263. end;
  264. procedure EnumRegisteredActions(Proc: TEnumActionProc; Info: TEnumActionProcInfo; FrameworkType: string = '');
  265. begin
  266. if not Assigned(EnumRegisteredActionsProc) then
  267. raise EActionError.Create(SErrNoEnumActionsProc);
  268. EnumRegisteredActionsProc(Proc, Info, FrameworkType)
  269. end;
  270. function CreateAction(AOwner: TComponent; ActionClass: TBasicActionClass; FrameworkType: string = ''): TBasicAction;
  271. var
  272. Old: boolean;
  273. begin
  274. if not Assigned(CreateActionProc) then
  275. raise EActionError.Create(SErrNoCreateActionsProc);
  276. Old:=vDesignAction;
  277. try
  278. vDesignAction:=True;
  279. Result:=CreateActionProc(AOwner,ActionClass,FrameworkType)
  280. finally
  281. vDesignAction:=old;
  282. end;
  283. end;
  284. { ---------------------------------------------------------------------
  285. TCustomShortCutList
  286. ---------------------------------------------------------------------}
  287. function TCustomShortCutList.GetShortCut(Index: Integer): TShortCut;
  288. begin
  289. Result:=TShortCut(PtrInt(Objects[Index]));
  290. end;
  291. function TCustomShortCutList.IndexOfShortCut(const ShortCut: TShortCut): Integer;
  292. var
  293. I: Integer;
  294. begin
  295. Result := -1;
  296. for I := 0 to Count - 1 do
  297. if TShortCut(PtrInt(Objects[I])) = ShortCut then
  298. begin
  299. Result := I;
  300. break;
  301. end;
  302. end;
  303. function TCustomShortCutList.IndexOfShortCut(const ShortCut: string): Integer;
  304. function Normalize(S: string): string;
  305. begin
  306. Result:=UpperCase(StringReplace(S, ' ', '', [rfReplaceAll]));
  307. end;
  308. var
  309. S: string;
  310. I: Integer;
  311. begin
  312. Result:=-1;
  313. if Trim(ShortCut)='' then
  314. exit;
  315. S:=Normalize(Shortcut);
  316. for I:=Count-1 downto 0 do
  317. if Normalize(Strings[I])=S then
  318. Exit(I);
  319. end;
  320. { ---------------------------------------------------------------------
  321. TActionListEnumerator
  322. ---------------------------------------------------------------------}
  323. constructor TActionListEnumerator.Create(AList: TContainedActionList);
  324. begin
  325. inherited Create;
  326. FPosition:=-1;
  327. FList:=aList;
  328. end;
  329. function TActionListEnumerator.GetCurrent: TContainedAction;
  330. begin
  331. Result:=FList[FPosition];
  332. end;
  333. function TActionListEnumerator.MoveNext: Boolean;
  334. begin
  335. Inc(FPosition);
  336. Result:=(FPosition<FList.ActionCount);
  337. end;
  338. { ---------------------------------------------------------------------
  339. TContainedActionList
  340. ---------------------------------------------------------------------}
  341. constructor TContainedActionList.Create(AOwner: TComponent);
  342. begin
  343. inherited Create(AOwner);
  344. FList:=TFPList.Create;
  345. FState:=asNormal;
  346. end;
  347. destructor TContainedActionList.Destroy;
  348. begin
  349. while (FList.Count>0) do
  350. TObject(FList[Flist.Count-1]).Free;
  351. FreeAndNil(FList);
  352. inherited;
  353. end;
  354. function TContainedActionList.IndexOfAction(Action: TBasicAction): Integer;
  355. begin
  356. Result:=FList.IndexOf(Action);
  357. end;
  358. procedure TContainedActionList.SetActionIndex(Action: TContainedAction;
  359. aValue: Integer);
  360. var
  361. aMax,Curr : Integer;
  362. begin
  363. aMax:=FList.Count;
  364. if aValue>aMax then
  365. aValue:=aMax-1;
  366. if aValue<0 then
  367. aValue:=0;
  368. Curr:=IndexOfAction(Action);
  369. if Curr<>aValue then
  370. FList.Move(Curr,aValue);
  371. end;
  372. procedure TContainedActionList.AddAction(const aAction: TContainedAction);
  373. begin
  374. if aAction=nil then
  375. Exit;
  376. aAction.FreeNotification(Self);
  377. aAction.FActionList:=Self;
  378. FList.Add(aAction);
  379. end;
  380. procedure TContainedActionList.Change;
  381. var
  382. I: Integer;
  383. begin
  384. if Assigned(FOnChange) then
  385. FOnChange(Self);
  386. for I:=FList.Count-1 downto 0 do
  387. TContainedAction(FList[I]).Change;
  388. end;
  389. function TContainedActionList.SameCategory(const Source, Dest: string;
  390. const IncludeSubCategory: Boolean = True): Boolean;
  391. var
  392. Len : integer;
  393. Dst : String;
  394. begin
  395. Dst:=Dest;
  396. Len:=Length(Source);
  397. if IncludeSubCategory and (Len<Length(Dst)) and (Dst[Len+1]='.') then
  398. Dst:=Copy(Dest,1,Len);
  399. Result:=SameText(Source,Dst);
  400. end;
  401. function TContainedActionList.Suspended: Boolean;
  402. begin
  403. Result:=State<>asNormal;
  404. end;
  405. procedure TContainedActionList.GetActionsInCategory(const ACategory: string; aList: TFPList; IncludeSubCategory : Boolean);
  406. var
  407. A: TContainedAction;
  408. begin
  409. for A in self do
  410. if SameCategory(aCategory,A.Category,IncludeSubCategory) then
  411. aList.Add(A);
  412. end;
  413. function TContainedActionList.EnumByCategory(Proc: TEnumActionListEvent;
  414. const Category: string;
  415. const IncludeSubCategory: Boolean = True): boolean;
  416. var
  417. P : Pointer;
  418. A: TContainedAction absolute P;
  419. Tmp: TFPList;
  420. begin
  421. Result:=False;
  422. If Not Assigned(Proc) then
  423. exit;
  424. Tmp:=TFPList.Create;
  425. try
  426. GetActionsInCategory(Category,Tmp,IncludeSubCategory);
  427. for P in Tmp do
  428. begin
  429. Proc(A,Result);
  430. if Result then
  431. exit;
  432. end;
  433. finally
  434. FreeAndNil(Tmp);
  435. end;
  436. end;
  437. function TContainedActionList.EnumByCategory(Proc: TEnumActionListRef;
  438. const Category: string;
  439. const IncludeSubCategory: Boolean = True): boolean;
  440. var
  441. P : Pointer;
  442. A: TContainedAction absolute P;
  443. Tmp: TFPList;
  444. begin
  445. Result:=False;
  446. If Not Assigned(Proc) then
  447. exit;
  448. Tmp:=TFPList.Create;
  449. try
  450. GetActionsInCategory(Category,Tmp,IncludeSubCategory);
  451. for P in Tmp do
  452. begin
  453. Proc(A,Result);
  454. if Result then
  455. exit;
  456. end;
  457. finally
  458. FreeAndNil(Tmp);
  459. end;
  460. end;
  461. function TContainedActionList.ExecuteAction(Action: TBasicAction): Boolean;
  462. begin
  463. Result:=False;
  464. if Assigned(FOnUpdate) then FOnUpdate(Action, Result);
  465. end;
  466. function TContainedActionList.UpdateAction(Action: TBasicAction): Boolean;
  467. begin
  468. Result:=False;
  469. if Assigned(FOnUpdate) then
  470. FOnUpdate(Action, Result);
  471. end;
  472. function TContainedActionList.GetAction(Index: Integer): TContainedAction;
  473. begin
  474. Result:=TContainedAction(FList[Index]);
  475. end;
  476. procedure TContainedActionList.SetAction(Index: Integer; aValue: TContainedAction);
  477. begin
  478. FList[Index]:=aValue;
  479. end;
  480. function TContainedActionList.GetActionCount: Integer;
  481. begin
  482. Result:=FList.Count;
  483. end;
  484. procedure TContainedActionList.GetChildren(Proc: TGetChildProc; Root: TComponent);
  485. var
  486. A: TContainedAction;
  487. begin
  488. for A in Self do
  489. if (Root=A.Owner) then
  490. Proc(A);
  491. end;
  492. function TContainedActionList.GetEnumerator: TActionListEnumerator;
  493. begin
  494. Result:=TActionListEnumerator.Create(Self);
  495. end;
  496. procedure TContainedActionList.Notification(AComponent: TComponent; Operation: TOperation);
  497. begin
  498. inherited Notification(AComponent, Operation);
  499. if (Operation<>opRemove) then
  500. exit;
  501. if (AComponent is TContainedAction) then
  502. RemoveAction(TContainedAction(AComponent));
  503. end;
  504. procedure TContainedActionList.RemoveAction(const aAction: TContainedAction);
  505. begin
  506. if Not Assigned(aAction) then
  507. exit;
  508. aAction.RemoveFreeNotification(Self); // just in case
  509. if FList.Remove(aAction)<0 then
  510. exit; // not our action...
  511. aAction.FActionList:=nil;
  512. end;
  513. procedure TContainedActionList.SetChildOrder(Component: TComponent; Order: Integer);
  514. var
  515. A : TContainedAction absolute Component;
  516. begin
  517. if Component is TContainedAction then
  518. if (IndexOfAction(A)>=0) then
  519. SetActionIndex(A,Order);
  520. end;
  521. procedure TContainedActionList.CorrectActionStates(ReEnabled: Boolean);
  522. var
  523. I: Integer;
  524. A: TContainedAction;
  525. begin
  526. for I:=ActionCount-1 downto 0 do
  527. begin
  528. A:=Actions[I];
  529. case State of
  530. asNormal:
  531. begin
  532. if ReEnabled then
  533. A.Enabled:=A.SavedEnabledState;
  534. A.Update;
  535. end;
  536. asSuspendedEnabled:
  537. begin
  538. A.SavedEnabledState:=A.Enabled;
  539. A.Enabled:=True;
  540. end;
  541. else
  542. //
  543. end;
  544. end;
  545. end;
  546. procedure TContainedActionList.SetState(const aValue: TActionListState);
  547. var
  548. Old: TActionListState;
  549. begin
  550. Old:=FState;
  551. if Old=aValue then exit;
  552. FState:=aValue;
  553. try
  554. if (aValue<>asSuspended) then
  555. CorrectActionStates(Old=asSuspendedEnabled);
  556. finally
  557. if Assigned(FOnStateChange) then
  558. FOnStateChange(Self);
  559. end;
  560. end;
  561. { ---------------------------------------------------------------------
  562. TContainedAction
  563. ---------------------------------------------------------------------}
  564. function TContainedAction.GetIndex: Integer;
  565. begin
  566. if Assigned(ActionList) then
  567. Result:=ActionList.IndexOfAction(Self)
  568. else
  569. Result:=-1;
  570. end;
  571. function TContainedAction.GetSecondaryShortCuts: TCustomShortCutList;
  572. begin
  573. if Not SecondaryShortCutsCreated then
  574. FSecondaryShortCuts:=CreateShortCutList;
  575. Result:=FSecondaryShortCuts;
  576. end;
  577. function TContainedAction.IsSecondaryShortCutsStored: Boolean;
  578. begin
  579. Result:=SecondaryShortCutsCreated and (FSecondaryShortCuts.Count>0);
  580. end;
  581. procedure TContainedAction.SetActionList(AValue: TContainedActionList);
  582. begin
  583. if FActionList=AValue then Exit;
  584. if Assigned(FActionList) then
  585. ActionList.RemoveAction(Self);
  586. if Assigned(aValue) then
  587. aValue.AddAction(Self); // will set FActionList
  588. end;
  589. procedure TContainedAction.SetCategory(AValue: string);
  590. begin
  591. if FCategory=AValue then Exit;
  592. FCategory:=AValue;
  593. if Assigned(ActionList) then
  594. ActionList.Change;
  595. end;
  596. procedure TContainedAction.SetIndex(AValue: Integer);
  597. begin
  598. If Assigned(ActionList) then
  599. ActionList.SetActionIndex(Self,aValue);
  600. end;
  601. procedure TContainedAction.SetSecondaryShortCuts(AValue: TCustomShortCutList);
  602. begin
  603. if aValue=FSecondaryShortCuts then
  604. exit;
  605. if Assigned(aValue) and (aValue.Count>0) then
  606. SecondaryShortCuts.Assign(aValue) // will create
  607. else
  608. FreeAndNil(FSecondaryShortCuts);
  609. end;
  610. procedure TContainedAction.ReadState(Reader: TReader);
  611. begin
  612. inherited ReadState(Reader);
  613. if Reader.Parent is TContainedActionList then
  614. ActionList:=TContainedActionList(Reader.Parent);
  615. end;
  616. function TContainedAction.SecondaryShortCutsCreated: boolean;
  617. begin
  618. Result:=Assigned(FSecondaryShortCuts);
  619. end;
  620. function TContainedAction.CreateShortCutList: TCustomShortCutList;
  621. begin
  622. Result:=TCustomShortCutList.Create;
  623. end;
  624. procedure TContainedAction.Assign(Source: TPersistent);
  625. var
  626. Src : TContainedAction absolute Source;
  627. begin
  628. if Source is TContainedAction then
  629. begin
  630. AutoCheck:=Src.AutoCheck;
  631. Caption:=Src.Caption;
  632. Checked:=Src.Checked;
  633. Enabled:=Src.Enabled;
  634. GroupIndex:=Src.GroupIndex;
  635. HelpContext:=Src.HelpContext;
  636. HelpKeyword:=Src.HelpKeyword;
  637. HelpType:=Src.HelpType;
  638. Hint:=Src.Hint;
  639. Visible:=Src.Visible;
  640. ShortCut:=Src.ShortCut;
  641. if Src.SecondaryShortCutsCreated then
  642. SecondaryShortCuts.Assign(Src.SecondaryShortCuts)
  643. else
  644. FreeAndNil(FSecondaryShortCuts);
  645. ImageIndex:=Src.ImageIndex;
  646. OnHint:=Src.OnHint;
  647. StatusAction:=Src.StatusAction;
  648. Category:=Src.Category;
  649. end;
  650. inherited Assign(Source);
  651. end;
  652. function TContainedAction.HandleShortCut: Boolean;
  653. begin
  654. Result:=Execute;
  655. end;
  656. procedure TContainedAction.SetAutoCheck(Value: Boolean);
  657. var
  658. I: Integer;
  659. Obj : TObject;
  660. L : TContainedActionLink absolute obj;
  661. begin
  662. if Value=FAutoCheck then
  663. exit;
  664. for I:=0 to ClientCount-1 do
  665. begin
  666. Obj:=GetClient(I);
  667. if Obj is TContainedActionLink then
  668. L.SetAutoCheck(Value);
  669. end;
  670. FAutoCheck:=Value;
  671. Change;
  672. end;
  673. procedure TContainedAction.SetCaption(const Value: string);
  674. var
  675. I: Integer;
  676. Obj : TObject;
  677. L : TContainedActionLink absolute obj;
  678. begin
  679. if Value=FCaption then
  680. exit;
  681. for I:=0 to ClientCount-1 do
  682. begin
  683. Obj:=GetClient(I);
  684. if Obj is TContainedActionLink then
  685. L.SetCaption(Value);
  686. end;
  687. FCaption:=Value;
  688. Change;
  689. end;
  690. procedure TContainedAction.SetName(const Value: TComponentName);
  691. var
  692. DoCaption : Boolean;
  693. begin
  694. // Should we change caption as well ?
  695. DoCaption:=(Name=Caption) and (ClientCount=0);
  696. inherited SetName(Value);
  697. // No need to set caption.
  698. if Not DoCaption then
  699. exit;
  700. // Don't do anything when loading
  701. if (csLoading in Owner.ComponentState) then
  702. exit;
  703. Caption:=Name;
  704. end;
  705. procedure TContainedAction.SetChecked(Value: Boolean);
  706. var
  707. I: Integer;
  708. Obj : TObject;
  709. A: TContainedAction;
  710. L : TContainedActionLink absolute obj;
  711. begin
  712. if Value=FChecked then
  713. exit;
  714. for I:=0 to ClientCount-1 do
  715. begin
  716. Obj:=GetClient(I);
  717. if Obj is TContainedActionLink then
  718. L.SetChecked(Value);
  719. end;
  720. FChecked:=Value;
  721. // Uncheck all others in group.
  722. if Not (Value and (GroupIndex>0) and Assigned(ActionList)) then
  723. exit;
  724. For A in ActionList do
  725. begin
  726. if (A<>Self) and (A.GroupIndex=GroupIndex) then
  727. A.Checked:=False;
  728. end;
  729. Change;
  730. end;
  731. procedure TContainedAction.SetEnabled(Value: Boolean);
  732. var
  733. I: Integer;
  734. Obj : TObject;
  735. L : TContainedActionLink absolute obj;
  736. begin
  737. if Value=FEnabled then
  738. exit;
  739. if Assigned(ActionList) then
  740. case ActionList.State of
  741. asSuspendedEnabled:
  742. Value:=True;
  743. asSuspended:
  744. begin
  745. FEnabled:=Value;
  746. exit;
  747. end;
  748. else
  749. //
  750. end;
  751. for I:=0 to ClientCount-1 do
  752. begin
  753. Obj:=GetClient(I);
  754. if Obj is TContainedActionLink then
  755. L.SetEnabled(Value);
  756. end;
  757. FEnabled:=Value;
  758. Change;
  759. end;
  760. procedure TContainedAction.SetGroupIndex(const Value: Integer);
  761. var
  762. I: Integer;
  763. Obj : TObject;
  764. L : TContainedActionLink absolute obj;
  765. A : TContainedAction;
  766. begin
  767. if Value=FGroupIndex then
  768. exit;
  769. for I:=0 to ClientCount-1 do
  770. begin
  771. Obj:=GetClient(I);
  772. if Obj is TContainedActionLink then
  773. L.SetGroupIndex(Value);
  774. end;
  775. FGroupIndex:=Value;
  776. // Uncheck others.
  777. if FChecked and (Value>0) and Assigned(ActionList) then
  778. For A in ActionList do
  779. if (A.GroupIndex=Value) then
  780. A.Checked:=False;
  781. Change;
  782. end;
  783. procedure TContainedAction.SetHelpContext(Value: THelpContext);
  784. var
  785. I: Integer;
  786. Obj : TObject;
  787. L : TContainedActionLink absolute obj;
  788. begin
  789. if Value=FHelpContext then
  790. exit;
  791. for I:=0 to ClientCount-1 do
  792. begin
  793. Obj:=GetClient(I);
  794. if Obj is TContainedActionLink then
  795. L.SetHelpContext(Value);
  796. end;
  797. FHelpContext:=Value;
  798. Change;
  799. end;
  800. procedure TContainedAction.SetHelpKeyword(const Value: string);
  801. var
  802. I: Integer;
  803. Obj : TObject;
  804. L : TContainedActionLink absolute obj;
  805. begin
  806. if Value=FHelpKeyword then
  807. exit;
  808. for I:=0 to ClientCount-1 do
  809. begin
  810. Obj:=GetClient(I);
  811. if Obj is TContainedActionLink then
  812. L.SetHelpKeyword(Value);
  813. end;
  814. FHelpKeyword:=Value;
  815. Change;
  816. end;
  817. procedure TContainedAction.SetHelpType(Value: THelpType);
  818. var
  819. I: Integer;
  820. Obj : TObject;
  821. L : TContainedActionLink absolute obj;
  822. begin
  823. if Value=FHelpType then
  824. exit;
  825. for I:=0 to ClientCount-1 do
  826. begin
  827. Obj:=GetClient(I);
  828. if Obj is TContainedActionLink then
  829. L.SetHelpType(Value);
  830. end;
  831. FHelpType:=Value;
  832. Change;
  833. end;
  834. procedure TContainedAction.SetHint(const Value: string);
  835. var
  836. I: Integer;
  837. Obj : TObject;
  838. L : TContainedActionLink absolute obj;
  839. begin
  840. if Value=FHint then
  841. exit;
  842. for I:=0 to ClientCount-1 do
  843. begin
  844. Obj:=GetClient(I);
  845. if Obj is TContainedActionLink then
  846. L.SetHint(Value);
  847. end;
  848. FHint:=Value;
  849. Change;
  850. end;
  851. procedure TContainedAction.SetVisible(Value: Boolean);
  852. var
  853. I: Integer;
  854. Obj : TObject;
  855. L : TContainedActionLink absolute obj;
  856. begin
  857. if Value=FVisible then
  858. exit;
  859. for I:=0 to ClientCount-1 do
  860. begin
  861. Obj:=GetClient(I);
  862. if Obj is TContainedActionLink then
  863. L.SetVisible(Value);
  864. end;
  865. FVisible:=Value;
  866. Change;
  867. end;
  868. procedure TContainedAction.SetShortCut(Value: TShortCut);
  869. var
  870. I: Integer;
  871. Obj : TObject;
  872. L : TContainedActionLink absolute obj;
  873. begin
  874. if Value=FImageIndex then
  875. exit;
  876. for I:=0 to ClientCount-1 do
  877. begin
  878. Obj:=GetClient(I);
  879. if Obj is TContainedActionLink then
  880. L.SetShortCut(Value);
  881. end;
  882. FShortCut:=Value;
  883. Change;
  884. end;
  885. procedure TContainedAction.SetImageIndex(Value: TImageIndex);
  886. var
  887. I: Integer;
  888. Obj : TObject;
  889. L : TContainedActionLink absolute obj;
  890. begin
  891. if Value=FImageIndex then
  892. exit;
  893. for I:=0 to ClientCount-1 do
  894. begin
  895. Obj:=GetClient(I);
  896. if Obj is TContainedActionLink then
  897. L.SetImageIndex(Value);
  898. end;
  899. FImageIndex:=Value;
  900. Change;
  901. end;
  902. procedure TContainedAction.SetStatusAction(const Value: TStatusAction);
  903. var
  904. I: Integer;
  905. Obj : TObject;
  906. L : TContainedActionLink absolute obj;
  907. begin
  908. if Value=FStatusAction then
  909. exit;
  910. for I:=0 to ClientCount-1 do
  911. begin
  912. Obj:=GetClient(I);
  913. if Obj is TContainedActionLink then
  914. L.SetStatusAction(Value);
  915. end;
  916. FStatusAction:=Value;
  917. Change;
  918. end;
  919. constructor TContainedAction.Create(AOwner: TComponent);
  920. begin
  921. inherited Create(AOwner);
  922. FEnabled:=True;
  923. FVisible:=True;
  924. FImageIndex:=-1;
  925. end;
  926. destructor TContainedAction.Destroy;
  927. begin
  928. ActionList:=Nil; // Remove ourselves from action list
  929. FreeAndNil(FSecondaryShortCuts);
  930. inherited Destroy;
  931. end;
  932. function TContainedAction.GetParentComponent: TComponent;
  933. begin
  934. if Assigned(ActionList) then
  935. Result:=ActionList
  936. else
  937. Result:=inherited GetParentComponent;
  938. end;
  939. function TContainedAction.HasParent: Boolean;
  940. begin
  941. Result:=Assigned(ActionList);
  942. If not Result then
  943. Result:=Inherited HasParent;
  944. end;
  945. procedure TContainedAction.SetParentComponent(AParent: TComponent);
  946. begin
  947. Inherited;
  948. if not (csLoading in ComponentState) and (AParent is TContainedActionList) then
  949. ActionList:=TContainedActionList(AParent);
  950. end;
  951. function TContainedAction.Suspended: Boolean;
  952. begin
  953. if Assigned(ActionList) then
  954. Result:=ActionList.Suspended
  955. else
  956. Result:=False;
  957. end;
  958. function TContainedAction.DoHint(var HintStr: string): Boolean;
  959. begin
  960. Result:=True;
  961. if Assigned(FOnHint) then
  962. FOnHint(HintStr,Result);
  963. end;
  964. { TContainedActionLink }
  965. procedure TContainedActionLink.DefaultIsLinked(var Result: Boolean);
  966. begin
  967. Result:=Action is TContainedAction;
  968. end;
  969. function TContainedActionLink.IsCaptionLinked: Boolean;
  970. begin
  971. Result:=False;
  972. DefaultIsLinked(Result);
  973. end;
  974. function TContainedActionLink.IsCheckedLinked: Boolean;
  975. begin
  976. Result:=False;
  977. DefaultIsLinked(Result);
  978. end;
  979. function TContainedActionLink.IsEnabledLinked: Boolean;
  980. begin
  981. Result:=False;
  982. DefaultIsLinked(Result);
  983. end;
  984. function TContainedActionLink.IsGroupIndexLinked: Boolean;
  985. begin
  986. Result:=False;
  987. DefaultIsLinked(Result);
  988. end;
  989. function TContainedActionLink.IsHelpContextLinked: Boolean;
  990. begin
  991. Result:=False;
  992. DefaultIsLinked(Result);
  993. end;
  994. function TContainedActionLink.IsHelpLinked: Boolean;
  995. begin
  996. Result:=False;
  997. DefaultIsLinked(Result);
  998. end;
  999. function TContainedActionLink.IsHintLinked: Boolean;
  1000. begin
  1001. Result:=False;
  1002. DefaultIsLinked(Result);
  1003. end;
  1004. function TContainedActionLink.IsImageIndexLinked: Boolean;
  1005. begin
  1006. Result:=False;
  1007. DefaultIsLinked(Result);
  1008. end;
  1009. function TContainedActionLink.IsShortCutLinked: Boolean;
  1010. begin
  1011. Result:=False;
  1012. DefaultIsLinked(Result);
  1013. end;
  1014. function TContainedActionLink.IsVisibleLinked: Boolean;
  1015. begin
  1016. Result:=False;
  1017. DefaultIsLinked(Result);
  1018. end;
  1019. function TContainedActionLink.IsStatusActionLinked: Boolean;
  1020. begin
  1021. Result:=False;
  1022. DefaultIsLinked(Result);
  1023. end;
  1024. procedure TContainedActionLink.SetAutoCheck(Value: Boolean);
  1025. begin
  1026. if Value then ; // Silence compiler
  1027. // Needs to be implemented in descendants
  1028. end;
  1029. procedure TContainedActionLink.SetCaption(const Value: string);
  1030. begin
  1031. if Value<>'' then ; // Silence compiler
  1032. // Needs to be implemented in descendants
  1033. end;
  1034. procedure TContainedActionLink.SetChecked(Value: Boolean);
  1035. begin
  1036. if Value then ; // Silence compiler
  1037. // Needs to be implemented in descendants
  1038. end;
  1039. procedure TContainedActionLink.SetEnabled(Value: Boolean);
  1040. begin
  1041. if Value then ; // Silence compiler
  1042. // Needs to be implemented in descendants
  1043. end;
  1044. procedure TContainedActionLink.SetGroupIndex(Value: Integer);
  1045. begin
  1046. if Value<>0 then ; // Silence compiler
  1047. // Needs to be implemented in descendants
  1048. end;
  1049. procedure TContainedActionLink.SetHelpContext(Value: THelpContext);
  1050. begin
  1051. if Ord(Value)<>0 then ; // Silence compiler
  1052. // Needs to be implemented in descendants
  1053. end;
  1054. procedure TContainedActionLink.SetHelpKeyword(const Value: string);
  1055. begin
  1056. if Value<>'' then ; // Silence compiler
  1057. // Needs to be implemented in descendants
  1058. end;
  1059. procedure TContainedActionLink.SetHelpType(Value: THelpType);
  1060. begin
  1061. if Ord(Value)<>0 then ; // Silence compiler
  1062. // Needs to be implemented in descendants
  1063. end;
  1064. procedure TContainedActionLink.SetHint(const Value: string);
  1065. begin
  1066. if Value<>'' then ; // Silence compiler
  1067. // Needs to be implemented in descendants
  1068. end;
  1069. procedure TContainedActionLink.SetImageIndex(Value: Integer);
  1070. begin
  1071. if Value<>0 then ; // Silence compiler
  1072. // Needs to be implemented in descendants
  1073. end;
  1074. procedure TContainedActionLink.SetShortCut(Value: TShortCut);
  1075. begin
  1076. if Value<>0 then ; // Silence compiler
  1077. // Needs to be implemented in descendants
  1078. end;
  1079. procedure TContainedActionLink.SetVisible(Value: Boolean);
  1080. begin
  1081. if Value then ; // Silence compiler
  1082. // Needs to be implemented in descendants
  1083. end;
  1084. procedure TContainedActionLink.SetStatusAction(const Value: TStatusAction);
  1085. begin
  1086. if Ord(Value)<>0 then ; // Silence compiler
  1087. // Needs to be implemented in descendants
  1088. end;
  1089. Type
  1090. TShortCutList = Class(TFPList)
  1091. private
  1092. function GetS(I : Integer): TShortCut;
  1093. procedure SetS(I : Integer; AValue: TShortCut);
  1094. Public
  1095. Property ShortCuts[I : Integer] : TShortCut Read GetS Write SetS; default;
  1096. end;
  1097. function ShToPtr(S : TShortCut) : Pointer; inline;
  1098. begin
  1099. Result:=Pointer(PtrInt(S));
  1100. end;
  1101. function PtrToSh(P : Pointer) : TShortCut; inline;
  1102. begin
  1103. Result:=TShortCut(PtrUint(P) and $FFFF);
  1104. end;
  1105. var
  1106. _ShortCuts : TShortCutList;
  1107. function RegisterShortCut(aShortCut: TShortCut; Index: integer = -1): integer;
  1108. var
  1109. Ptr : Pointer;
  1110. begin
  1111. Result:=-1;
  1112. if aShortCut<=0 then
  1113. exit;
  1114. if not Assigned(_ShortCuts) then
  1115. exit;
  1116. Ptr:=ShToPtr(aShortCut);
  1117. if _ShortCuts.IndexOf(Ptr)>=0 then
  1118. Exit;
  1119. if (Index<0) or (Index>=_ShortCuts.Count) then
  1120. Result:=_ShortCuts.Add(Ptr)
  1121. else
  1122. begin
  1123. _ShortCuts.Insert(Index,Ptr);
  1124. Result:=Index;
  1125. end;
  1126. end;
  1127. function UnregisterShortCut(aShortCut: TShortCut): boolean;
  1128. var
  1129. Idx: integer;
  1130. begin
  1131. Result:=False;
  1132. if (Integer(aShortCut)<0) then
  1133. exit;
  1134. if Not Assigned(_ShortCuts) then
  1135. exit;
  1136. Idx:=_ShortCuts.IndexOf(ShToPtr(aShortCut));
  1137. if (Idx<0) then
  1138. exit;
  1139. _ShortCuts.Delete(Idx);
  1140. Result:=True;
  1141. end;
  1142. function RegisteredShortCutCount: integer;
  1143. begin
  1144. Result:=_ShortCuts.Count;
  1145. end;
  1146. function RegisteredShortCut(Idx: integer): TShortCut;
  1147. begin
  1148. if (Idx>=0) and (Idx<_ShortCuts.Count) then
  1149. Result:=PtrToSh(_ShortCuts.Items[Idx])
  1150. else
  1151. EListError.CreateFmt(SErrIndexOutOfBounds,[Idx, 0, RegisteredShortCutCount-1]);
  1152. end;
  1153. { TShortCutList }
  1154. function TShortCutList.GetS(I : Integer): TShortCut;
  1155. begin
  1156. Result:=PtrToSh(Items[i]);
  1157. end;
  1158. procedure TShortCutList.SetS(I : Integer; AValue: TShortCut);
  1159. begin
  1160. Items[i]:=ShToPtr(aValue);
  1161. end;
  1162. initialization
  1163. _ShortCuts:=TShortCutList.Create;
  1164. vDesignAction:=False;
  1165. finalization
  1166. FreeAndNil(_ShortCuts);
  1167. end.