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