1 unit FileFilterPropEditor;
2 
3 {$mode objfpc}{$H+}
4 
5 interface
6 
7 uses
8   Classes, SysUtils,
9   // LCL
10   Forms, Controls, ButtonPanel, Grids, Buttons,
11   // IdeIntf
12   ObjInspStrConsts, IDEImagesIntf, IDEWindowIntf;
13 
14 type
15 
16   { TFileFilterPropEditForm }
17 
18   TFileFilterPropEditForm = class(TForm)
19     ButtonPanel1: TButtonPanel;
20     MoveDownBtn: TSpeedButton;
21     MoveUpBtn: TSpeedButton;
22     StringGrid1: TStringGrid;
23     procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
24     procedure FormCreate(Sender: TObject);
25     procedure MoveUpBtnClick(Sender: TObject);
26     procedure MoveDownBtnClick(Sender: TObject);
27     procedure StringGrid1ButtonClick(Sender: TObject; {%H-}aCol, {%H-}aRow: Integer);
28     procedure StringGrid1Click(Sender: TObject);
29     procedure StringGrid1EditingDone(Sender: TObject);
30   private
GetFilternull31     function GetFilter: string;
32     procedure SetFilter(const AValue: string);
33     procedure UpdateEnabledStates;
34   public
35     property Filter:string read GetFilter write SetFilter;
36   end;
37 
38 var
39   FileFilterPropEditForm: TFileFilterPropEditForm;
40 
41 implementation
42 
43 {$R *.lfm}
44 
45 { TFileFilterPropertyEditorForm }
46 
47 procedure TFileFilterPropEditForm.FormCreate(Sender: TObject);
48 begin
49   Caption:=peFilterEditor;
50   StringGrid1.Cells[0, 0] := peFilterName;
51   StringGrid1.Cells[1, 0] := peFilter;
52   IDEImages.AssignImage(MoveUpBtn, 'arrow_up');
53   IDEImages.AssignImage(MoveDownBtn, 'arrow_down');
54   MoveUpBtn.Hint := rscdMoveUp;
55   MoveDownBtn.Hint := rscdMoveDown;
56   IDEDialogLayoutList.ApplyLayout(Self);
57 end;
58 
59 procedure TFileFilterPropEditForm.FormClose(Sender: TObject;
60   var CloseAction: TCloseAction);
61 begin
62   IDEDialogLayoutList.SaveLayout(Self);
63 end;
64 
65 procedure TFileFilterPropEditForm.MoveUpBtnClick(Sender: TObject);
66 begin
67   with StringGrid1 do
68     MoveColRow(False, Row, Row-1);
69   UpdateEnabledStates;
70 end;
71 
72 procedure TFileFilterPropEditForm.MoveDownBtnClick(Sender: TObject);
73 begin
74   with StringGrid1 do
75     MoveColRow(False, Row, Row+1);
76   UpdateEnabledStates;
77 end;
78 
79 procedure TFileFilterPropEditForm.StringGrid1ButtonClick(Sender: TObject; aCol,
80   aRow: Integer);
81 begin
82   UpdateEnabledStates;
83 end;
84 
85 procedure TFileFilterPropEditForm.StringGrid1Click(Sender: TObject);
86 begin
87   UpdateEnabledStates;
88 end;
89 
90 procedure TFileFilterPropEditForm.StringGrid1EditingDone(Sender: TObject);
91 begin
92   UpdateEnabledStates;
93 end;
94 
TFileFilterPropEditForm.GetFilternull95 function TFileFilterPropEditForm.GetFilter: string;
96 var
97   i: integer;
98 begin
99   Result := '';
100   for i := 1 to StringGrid1.RowCount-1 do
101   begin
102     if StringGrid1.Cells[1,i] <> '' then
103     begin
104       if Result <> '' then
105         Result := Result + '|';
106       if StringGrid1.Cells[0,i] <> '' then
107         Result := Result+StringGrid1.Cells[0,i]+'|'+StringGrid1.Cells[1,i]
108       else
109         Result := Result+StringGrid1.Cells[1,i]+'|'+StringGrid1.Cells[1,i];
110     end
111     else
112       break;
113   end;
114 end;
115 
116 procedure TFileFilterPropEditForm.SetFilter(const AValue: string);
117 var
118   S: string;
119   C1, i: integer;
120 begin
121   S := AValue;
122   I := 1;
123   while (S <> '') do
124   begin
125     C1 := Pos('|',S);
126     if C1 > 0 then
127     begin
128       StringGrid1.Cells[0,i] := Copy(S, 1, C1-1);
129       Delete(S, 1, C1);
130       C1 := Pos('|',S);
131       if (C1 > 0) then
132       begin
133         StringGrid1.Cells[1,i] := Copy(S, 1, C1-1);
134         Delete(S, 1, C1);
135       end
136       else
137       begin
138         StringGrid1.Cells[1,i] := S;
139         S := '';
140       end;
141     end
142     else
143     begin
144       StringGrid1.Cells[0,i] := S;
145       StringGrid1.Cells[1,i] := S;
146       S := '';
147     end;
148     inc(i);
149   end;
150   UpdateEnabledStates;
151 end;
152 
153 procedure TFileFilterPropEditForm.UpdateEnabledStates;
154 begin
155   MoveUpBtn.Enabled := StringGrid1.Row > StringGrid1.FixedRows;
156   MoveDownBtn.Enabled := True;
157 end;
158 
159 
160 end.
161 
162