PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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