/ide/restrictionbrowser.pas

http://github.com/graemeg/lazarus · Pascal · 213 lines · 165 code · 18 blank · 30 comment · 10 complexity · ba8a4258cfa52d20088494a8b0c7087f MD5 · raw file

  1. {
  2. ***************************************************************************
  3. * *
  4. * This source is free software; you can redistribute it and/or modify *
  5. * it under the terms of the GNU General Public License as published by *
  6. * the Free Software Foundation; either version 2 of the License, or *
  7. * (at your option) any later version. *
  8. * *
  9. * This code is distributed in the hope that it will be useful, but *
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  12. * General Public License for more details. *
  13. * *
  14. * A copy of the GNU General Public License is available on the World *
  15. * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
  16. * obtain it by writing to the Free Software Foundation, *
  17. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. * *
  19. ***************************************************************************
  20. Author: Tomas Gregorovic
  21. Abstract:
  22. Browser for widget set restricted properties.
  23. }
  24. unit RestrictionBrowser;
  25. {$mode objfpc}{$H+}
  26. interface
  27. uses
  28. Classes, SysUtils, InterfaceBase, LCLProc, Contnrs, Forms, Controls, Graphics,
  29. Dialogs, StdCtrls, ComCtrls, TreeFilterEdit, ExtCtrls, Buttons,
  30. IDEImagesIntf, ObjectInspector,
  31. CompatibilityRestrictions, IDEOptionDefs, LazarusIDEStrConsts,
  32. EnvironmentOpts, LazConf;
  33. type
  34. { TRestrictionBrowserView }
  35. TRestrictionBrowserView = class(TForm)
  36. FilterEdit: TTreeFilterEdit;
  37. IssueFilterGroupBox: TGroupBox;
  38. IssueMemo: TMemo;
  39. IssueTreeView: TTreeView;
  40. NameLabel: TLabel;
  41. Panel1: TPanel;
  42. Splitter1: TSplitter;
  43. procedure FormCreate(Sender: TObject);
  44. procedure IssueTreeViewSelectionChanged(Sender: TObject);
  45. procedure NameFilterEditChange(Sender: TObject);
  46. private
  47. FIssueList: TRestrictedList;
  48. FClasses: TClassList;
  49. procedure SelectFirstVisible(Sender: TObject);
  50. procedure GetComponentClass(const AClass: TComponentClass);
  51. procedure UpdateIssueList;
  52. public
  53. procedure SetIssueName(const AIssueName: String);
  54. end;
  55. var
  56. RestrictionBrowserView: TRestrictionBrowserView = nil;
  57. implementation
  58. {$R *.lfm}
  59. { TRestrictionBrowserView }
  60. procedure TRestrictionBrowserView.FormCreate(Sender: TObject);
  61. var
  62. P: TLCLPlatform;
  63. X: Integer;
  64. begin
  65. FIssueList := GetRestrictedList;
  66. Name := NonModalIDEWindowNames[nmiwIssueBrowser];
  67. Caption := lisMenuViewRestrictionBrowser;
  68. IssueFilterGroupBox.Caption := lisIssues;
  69. NameLabel.Caption := lisCodeToolsDefsName;
  70. IssueTreeView.Images := IDEImages.Images_16;
  71. X := 10;
  72. // create widget set filter buttons
  73. for P := Low(TLCLPlatform) to High(TLCLPlatform) do
  74. begin
  75. with TSpeedButton.Create(Self) do
  76. begin
  77. Name := 'SpeedButton' + LCLPlatformDirNames[P];
  78. Left := X;
  79. Top := 4;
  80. Width := 24;
  81. Height := 24;
  82. GroupIndex := Integer(P) + 1;
  83. Down := True;
  84. AllowAllUp := True;
  85. try
  86. IDEImages.Images_16.GetBitmap(
  87. IDEImages.LoadImage(16, 'issue_'+LCLPlatformDirNames[P]), Glyph);
  88. except
  89. DebugLn('Restriction Browser: Unable to load image for ' + LCLPlatformDirNames[P] + '!');
  90. end;
  91. ShowHint := True;
  92. Hint := LCLPlatformDisplayNames[P];
  93. OnClick := @NameFilterEditChange;
  94. Parent := IssueFilterGroupBox;
  95. Inc(X, Width);
  96. end;
  97. end;
  98. FilterEdit.OnAfterFilter := @SelectFirstVisible;
  99. UpdateIssueList;
  100. end;
  101. procedure TRestrictionBrowserView.SelectFirstVisible(Sender: TObject);
  102. var
  103. nd: TTreeNode;
  104. begin
  105. nd := IssueTreeView.Items.GetFirstVisibleNode;
  106. if Assigned(nd) then
  107. IssueTreeView.Selected := nd
  108. else
  109. IssueMemo.Clear;
  110. end;
  111. procedure TRestrictionBrowserView.IssueTreeViewSelectionChanged(Sender: TObject);
  112. var
  113. Issue: TRestriction;
  114. begin
  115. if Assigned(IssueTreeView.Selected) then
  116. begin
  117. Issue := PRestriction(IssueTreeView.Selected.Data)^;
  118. IssueMemo.Text := Issue.Short + LineEnding + LineEnding + Issue.Description;
  119. end
  120. else
  121. IssueMemo.Clear;
  122. end;
  123. procedure TRestrictionBrowserView.NameFilterEditChange(Sender: TObject);
  124. begin
  125. UpdateIssueList;
  126. end;
  127. procedure TRestrictionBrowserView.GetComponentClass(const AClass: TComponentClass);
  128. begin
  129. FClasses.Add(AClass);
  130. end;
  131. procedure TRestrictionBrowserView.UpdateIssueList;
  132. var
  133. I, ID: PtrInt;
  134. Issues: TStringList;
  135. P: TLCLPlatform;
  136. WidgetSetFilter: TLCLPlatforms;
  137. Component: TComponent;
  138. begin
  139. WidgetSetFilter := [];
  140. for P := Low(TLCLPlatform) to High(TLCLPlatform) do
  141. begin
  142. Component := FindComponent('SpeedButton' + LCLPlatformDirNames[P]);
  143. Assert(Component is TSpeedButton, 'Component '+Component.Name+' is not TSpeedButton');
  144. if (Component as TSpeedButton).Down then
  145. Include(WidgetSetFilter, P);
  146. end;
  147. Issues := TStringList.Create;
  148. try
  149. for I := 0 to High(FIssueList) do
  150. if FIssueList[I].WidgetSet in WidgetSetFilter then
  151. Issues.AddObject(FIssueList[I].Name, TObject(I));
  152. Issues.Sort;
  153. IssueTreeView.BeginUpdate;
  154. try
  155. IssueTreeView.Items.Clear;
  156. for I := 0 to Issues.Count - 1 do
  157. begin
  158. with IssueTreeView.Items.AddChild(nil, Issues[I]) do
  159. begin
  160. ID := PtrInt(Issues.Objects[I]);
  161. ImageIndex := IDEImages.LoadImage(16,
  162. 'issue_'+LCLPlatformDirNames[FIssueList[ID].WidgetSet]);
  163. StateIndex := ImageIndex;
  164. SelectedIndex := ImageIndex;
  165. Data := @FIssueList[ID];
  166. end;
  167. end;
  168. finally
  169. IssueTreeView.EndUpdate;
  170. end;
  171. finally
  172. Issues.Free;
  173. end;
  174. FilterEdit.InvalidateFilter;
  175. end;
  176. procedure TRestrictionBrowserView.SetIssueName(const AIssueName: String);
  177. var
  178. P: TLCLPlatform;
  179. Component: TComponent;
  180. begin
  181. FilterEdit.Text := AIssueName;
  182. if AIssueName <> '' then
  183. begin
  184. for P := Low(TLCLPlatform) to High(TLCLPlatform) do
  185. begin
  186. Component := FindComponent('SpeedButton' + LCLPlatformDirNames[P]);
  187. Assert(Component is TSpeedButton, 'Component '+Component.Name+' is not TSpeedButton');
  188. (Component as TSpeedButton).Down := True;
  189. end;
  190. end;
  191. UpdateIssueList;
  192. end;
  193. end.