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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. * 18 * * 19 *************************************************************************** 20 21 Author: Tomas Gregorovic 22 23 Abstract: 24 Browser for widget set restricted properties. 25 } 26 unit RestrictionBrowser; 27 28 {$mode objfpc}{$H+} 29 30 interface 31 32 uses 33 Classes, Contnrs, 34 // LCL 35 LCLPlatformDef, Forms, StdCtrls, ComCtrls, ExtCtrls, Buttons, 36 // LazUtils 37 LazUTF8, LazLoggerBase, 38 // LazControls 39 TreeFilterEdit, 40 // IdeIntf 41 IDEImagesIntf, 42 // IDE 43 CompatibilityRestrictions, IDEOptionDefs, LazarusIDEStrConsts; 44 45 type 46 { TRestrictionBrowserView } 47 48 TRestrictionBrowserView = class(TForm) 49 FilterEdit: TTreeFilterEdit; 50 IssueFilterGroupBox: TGroupBox; 51 IssueMemo: TMemo; 52 IssueTreeView: TTreeView; 53 NameLabel: TLabel; 54 Panel1: TPanel; 55 Splitter1: TSplitter; 56 procedure FormCreate(Sender: TObject); 57 procedure IssueTreeViewSelectionChanged(Sender: TObject); 58 procedure NameFilterEditChange(Sender: TObject); 59 private 60 FIssueList: TRestrictedList; 61 FClasses: TClassList; 62 procedure SelectFirstVisible(Sender: TObject); 63 procedure GetComponentClass(const AClass: TComponentClass); 64 procedure UpdateIssueList; 65 public 66 procedure SetIssueName(const AIssueName: String); 67 end; 68 69 var 70 RestrictionBrowserView: TRestrictionBrowserView = nil; 71 72 implementation 73 74 {$R *.lfm} 75 76 { TRestrictionBrowserView } 77 78 procedure TRestrictionBrowserView.FormCreate(Sender: TObject); 79 var 80 P: TLCLPlatform; 81 X: Integer; 82 begin 83 FIssueList := GetRestrictedList; 84 Name := NonModalIDEWindowNames[nmiwIssueBrowser]; 85 Caption := lisMenuViewRestrictionBrowser; 86 IssueFilterGroupBox.Caption := lisIssues; 87 NameLabel.Caption := lisCodeToolsDefsName; 88 IssueTreeView.Images := IDEImages.Images_16; 89 X := 10; 90 // create widget set filter buttons 91 for P := Low(TLCLPlatform) to High(TLCLPlatform) do 92 begin 93 with TSpeedButton.Create(Self) do 94 begin 95 Name := 'SpeedButton' + LCLPlatformDirNames[P]; 96 Left := X; 97 Top := 4; 98 Width := 24; 99 Height := 24; 100 GroupIndex := Integer(P) + 1; 101 Down := True; 102 AllowAllUp := True; 103 Images := IDEImages.Images_16; 104 ImageIndex := IDEImages.LoadImage('issue_'+LCLPlatformDirNames[P]); 105 if ImageIndex<0 then 106 DebugLn('Restriction Browser: Unable to load image for ' + LCLPlatformDirNames[P] + '!'); 107 ShowHint := True; 108 Hint := LCLPlatformDisplayNames[P]; 109 OnClick := @NameFilterEditChange; 110 Parent := IssueFilterGroupBox; 111 Inc(X, Width); 112 end; 113 end; 114 FilterEdit.OnAfterFilter := @SelectFirstVisible; 115 UpdateIssueList; 116 end; 117 118 procedure TRestrictionBrowserView.SelectFirstVisible(Sender: TObject); 119 var 120 nd: TTreeNode; 121 begin 122 nd := IssueTreeView.Items.GetFirstVisibleNode; 123 if Assigned(nd) then 124 IssueTreeView.Selected := nd 125 else 126 IssueMemo.Clear; 127 end; 128 129 procedure TRestrictionBrowserView.IssueTreeViewSelectionChanged(Sender: TObject); 130 var 131 Issue: TRestriction; 132 begin 133 if Assigned(IssueTreeView.Selected) then 134 begin 135 Issue := PRestriction(IssueTreeView.Selected.Data)^; 136 IssueMemo.Text := Issue.Short + LineEnding + LineEnding + Issue.Description; 137 end 138 else 139 IssueMemo.Clear; 140 end; 141 142 procedure TRestrictionBrowserView.NameFilterEditChange(Sender: TObject); 143 begin 144 UpdateIssueList; 145 end; 146 147 procedure TRestrictionBrowserView.GetComponentClass(const AClass: TComponentClass); 148 begin 149 FClasses.Add(AClass); 150 end; 151 152 procedure TRestrictionBrowserView.UpdateIssueList; 153 var 154 I, ID: PtrInt; 155 Issues: TStringListUTF8Fast; 156 P: TLCLPlatform; 157 WidgetSetFilter: TLCLPlatforms; 158 Component: TComponent; 159 begin 160 WidgetSetFilter := []; 161 for P := Low(TLCLPlatform) to High(TLCLPlatform) do 162 begin 163 Component := FindComponent('SpeedButton' + LCLPlatformDirNames[P]); 164 Assert(Component is TSpeedButton, 'Component '+Component.Name+' is not TSpeedButton'); 165 if (Component as TSpeedButton).Down then 166 Include(WidgetSetFilter, P); 167 end; 168 Issues := TStringListUTF8Fast.Create; 169 try 170 for I := 0 to High(FIssueList) do 171 if FIssueList[I].WidgetSet in WidgetSetFilter then 172 Issues.AddObject(FIssueList[I].Name, TObject(I)); 173 Issues.Sort; 174 IssueTreeView.BeginUpdate; 175 try 176 IssueTreeView.Items.Clear; 177 for I := 0 to Issues.Count - 1 do 178 begin 179 with IssueTreeView.Items.AddChild(nil, Issues[I]) do 180 begin 181 ID := PtrInt(Issues.Objects[I]); 182 ImageIndex := IDEImages.LoadImage( 183 'issue_'+LCLPlatformDirNames[FIssueList[ID].WidgetSet]); 184 StateIndex := ImageIndex; 185 SelectedIndex := ImageIndex; 186 Data := @FIssueList[ID]; 187 end; 188 end; 189 finally 190 IssueTreeView.EndUpdate; 191 end; 192 finally 193 Issues.Free; 194 end; 195 FilterEdit.InvalidateFilter; 196 end; 197 198 procedure TRestrictionBrowserView.SetIssueName(const AIssueName: String); 199 var 200 P: TLCLPlatform; 201 Component: TComponent; 202 begin 203 FilterEdit.Text := AIssueName; 204 if AIssueName <> '' then 205 begin 206 for P := Low(TLCLPlatform) to High(TLCLPlatform) do 207 begin 208 Component := FindComponent('SpeedButton' + LCLPlatformDirNames[P]); 209 Assert(Component is TSpeedButton, 'Component '+Component.Name+' is not TSpeedButton'); 210 (Component as TSpeedButton).Down := True; 211 end; 212 end; 213 UpdateIssueList; 214 end; 215 216 end. 217 218