42
41
SysUtils, Classes, Math, Controls, Forms, Dialogs, Buttons, StdCtrls,
43
LazarusIdeStrConsts, LCLType, LCLIntf, LMessages, IDEWindowIntf, IDEContextHelpEdit,
44
ExtCtrls, ButtonPanel, Menus, StrUtils;
42
LazarusIdeStrConsts, LCLType, LCLIntf, LMessages,
43
ExtCtrls, ButtonPanel, Menus, StrUtils, ImgList,
44
IDEWindowIntf, IDEHelpIntf, IDEImagesIntf, ListFilterEdit;
47
53
TViewUnitsEntry = class
55
61
{ TViewUnitDialog }
57
63
TViewUnitDialog = class(TForm)
58
65
ButtonPanel: TButtonPanel;
66
DummySpeedButton: TSpeedButton;
67
FilterEdit: TListFilterEdit;
61
69
mniMultiSelect: TMenuItem;
70
OptionsBitBtn: TSpeedButton;
63
71
popListBox: TPopupMenu;
64
procedure EditChange(Sender: TObject);
65
procedure EditEnter(Sender: TObject);
66
procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
72
RemoveBitBtn: TSpeedButton;
73
SortAlphabeticallySpeedButton: TSpeedButton;
74
procedure ListboxDrawItem(Control: TWinControl; Index: Integer;
75
ARect: TRect; State: TOwnerDrawState);
76
procedure SortAlphabeticallySpeedButtonClick(Sender: TObject);
77
procedure OKButtonClick(Sender :TObject);
67
78
procedure HelpButtonClick(Sender: TObject);
68
procedure mniSortClick(Sender: TObject);
69
Procedure OKButtonClick(Sender :TObject);
70
Procedure CancelButtonClick(Sender :TObject);
71
procedure ListboxClick(Sender: TObject);
79
procedure CancelButtonClick(Sender :TObject);
72
80
procedure ListboxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
73
81
procedure MultiselectCheckBoxClick(Sender :TObject);
75
FBlockListBoxChange: boolean;
77
procedure SearchList(StartIndex: Integer = -1);
83
FSortAlphabetically: boolean;
85
procedure SetSortAlphabetically(const AValue: boolean);
79
87
constructor Create(TheOwner: TComponent); override;
88
property SortAlphabetically: boolean read FSortAlphabetically write SetSortAlphabetically;
82
function ShowViewUnitsDlg(Entries: TStringList; AllowMultiSelect: boolean;
83
var CheckMultiSelect: Boolean; const Caption: string): TModalResult;
84
// Entries is a list of TViewUnitsEntry(s)
91
// Entries is a list of TViewUnitsEntry(s)
92
function ShowViewUnitsDlg(Entries: TStringList; AllowMultiSelect: boolean;
93
var CheckMultiSelect: Boolean; const aCaption: string; aImageIndex: Integer): TModalResult;
94
function ShowViewUnitsDlg(Entries: TStringList; AllowMultiSelect: boolean;
95
var CheckMultiSelect: Boolean; const aCaption: string; ItemType: TIDEProjectItem): TModalResult;
90
101
function ShowViewUnitsDlg(Entries: TStringList; AllowMultiSelect: boolean;
91
var CheckMultiSelect: Boolean; const Caption: string): TModalResult;
102
var CheckMultiSelect: Boolean; const aCaption: string; aImageIndex: Integer): TModalResult;
93
104
ViewUnitDialog: TViewUnitDialog;
105
UEntry: TViewUnitsEntry;
96
108
ViewUnitDialog:=TViewUnitDialog.Create(nil);
109
with ViewUnitDialog do
98
ViewUnitDialog.Caption:=Caption;
99
ViewUnitDialog.mniMultiselect.Enabled := AllowMultiSelect;
100
ViewUnitDialog.mniMultiselect.Checked := CheckMultiSelect;
101
ViewUnitDialog.ListBox.MultiSelect := ViewUnitDialog.mniMultiselect.Enabled;
102
with ViewUnitDialog.ListBox.Items do begin
105
for i:=0 to Entries.Count-1 do
106
Add(TViewUnitsEntry(Entries.Objects[i]).Name);
109
for i:=0 to Entries.Count-1 do
110
ViewUnitDialog.ListBox.Selected[i]:=TViewUnitsEntry(Entries.Objects[i]).Selected;
111
Result:=ViewUnitDialog.ShowModal;
112
mniMultiselect.Enabled := AllowMultiSelect;
113
mniMultiselect.Checked := CheckMultiSelect;
114
ListBox.MultiSelect := mniMultiselect.Enabled;
115
if aImageIndex > -1 then FImageIndex:=aImageIndex; // otherwise FImageIndex will stay "0"
117
for i:=0 to Entries.Count-1 do begin
118
UEntry:=TViewUnitsEntry(Entries.Objects[i]);
119
FilterEdit.Data.Add(UEntry.Name);
121
FilterEdit.InvalidateFilter;
123
for i:=0 to Entries.Count-1 do begin
124
UEntry:=TViewUnitsEntry(Entries.Objects[i]);
125
if UEntry.Selected then
126
FilterEdit.SelectionList.Add(UEntry.Name);
112
130
if Result=mrOk then begin
131
// Return new selections from the dialog
132
FilterEdit.StoreSelection;
113
133
for i:=0 to Entries.Count-1 do begin
114
TViewUnitsEntry(Entries.Objects[i]).Selected:=ViewUnitDialog.ListBox.Selected[i];
134
UEntry:=TViewUnitsEntry(Entries.Objects[i]);
135
UEntry.Selected:=FilterEdit.SelectionList.IndexOf(UEntry.Name)>-1;
116
CheckMultiSelect := ViewUnitDialog.mniMultiselect.Checked;
137
CheckMultiSelect := mniMultiselect.Checked;
123
function SearchItem(Items: TStrings; Text: String; StartIndex: Integer = -1): Integer;
144
function ShowViewUnitsDlg(Entries: TStringList; AllowMultiSelect: boolean;
145
var CheckMultiSelect: Boolean; const aCaption: string;
146
ItemType: TIDEProjectItem): TModalResult;
127
// Items can be unsorted => use simple traverse
129
Text := AnsiLowerCase(Text);
130
for i := StartIndex +1 to Items.Count - 1 do
131
if AnsiContainsText(Items[i], Text) then
151
piComponent: i := IDEImages.LoadImage(16, 'item_form');
152
piFrame: i := IDEImages.LoadImage(16, 'tpanel');
153
else i:=IDEImages.LoadImage(16, 'item_unit');
155
Result:=ShowViewUnitsDlg(Entries,AllowMultiSelect,CheckMultiSelect,aCaption,i);
138
158
{ TViewUnitsEntry }
153
173
inherited Create(TheOwner);
154
174
IDEDialogLayoutList.ApplyLayout(Self,450,300);
175
//ActiveControl:=FilterEdit;
155
176
mniMultiSelect.Caption := dlgMultiSelect;
157
ButtonPanel.OKButton.Caption:=lisOk;
177
ButtonPanel.OKButton.Caption:=lisMenuOk;
158
178
ButtonPanel.HelpButton.Caption:=lisMenuHelp;
159
ButtonPanel.CancelButton.Caption:=dlgCancel;
162
Procedure TViewUnitDialog.OKButtonClick(Sender : TOBject);
179
ButtonPanel.CancelButton.Caption:=lisCancel;
180
SortAlphabeticallySpeedButton.Hint:=lisPESortFilesAlphabetically;
181
SortAlphabeticallySpeedButton.LoadGlyphFromLazarusResource('pkg_sortalphabetically');
184
procedure TViewUnitDialog.SortAlphabeticallySpeedButtonClick(Sender: TObject);
186
SortAlphabetically:=SortAlphabeticallySpeedButton.Down;
189
procedure TViewUnitDialog.ListboxDrawItem(Control: TWinControl; Index: Integer;
190
ARect: TRect; State: TOwnerDrawState);
192
if Index < 0 then Exit;
195
Canvas.FillRect(ARect);
196
IDEImages.Images_16.Draw(Canvas, 1, ARect.Top, FImageIndex);
197
Canvas.TextRect(ARect, ARect.Left + 20, ARect.Top, Items[Index]);
201
procedure TViewUnitDialog.OKButtonClick(Sender: TObject);
164
203
IDEDialogLayoutList.SaveLayout(Self);
165
204
ModalResult := mrOK;
168
207
procedure TViewUnitDialog.HelpButtonClick(Sender: TObject);
170
ShowContextHelpForIDE(Self);
173
procedure TViewUnitDialog.mniSortClick(Sender: TObject);
175
TmpList: TStringList;
179
TmpList := TStringList.Create;
181
TmpList.Assign(ListBox.Items);
182
if ListBox.MultiSelect then
184
for i := 0 to ListBox.Count -1 do
185
if ListBox.Selected[i] then
186
TmpList.Objects[i] := TObject(-1);
189
if ListBox.ItemIndex >= 0 then
190
SelName := ListBox.Items[ListBox.ItemIndex]
193
ListBox.Items := TmpList;
194
if SelName <> '' then
196
ListBox.ItemIndex := TmpList.IndexOf(SelName);
197
ListBox.MakeCurrentVisible;
199
if ListBox.MultiSelect then
201
ListBox.ClearSelection;
202
for i := 0 to TmpList.Count -1 do
203
if TmpList.Objects[i] <> nil then
204
ListBox.Selected[i] := True;
211
procedure TViewUnitDialog.EditKeyDown(Sender: TObject; var Key: Word;
214
procedure MoveItemIndex(d: integer); inline;
218
NewIndex := Min(ListBox.Items.Count - 1, Max(0, ListBox.ItemIndex + D));
219
ListBox.ItemIndex := NewIndex;
223
function PageCount: Integer;
225
if ListBox.ItemHeight > 0 then
226
Result := ListBox.Height div ListBox.ItemHeight
233
VK_UP: MoveItemIndex(-1);
237
// Avoid switching to next control in TabOrder in gtk2
240
VK_NEXT: MoveItemIndex(PageCount);
241
VK_PRIOR: MoveItemIndex(-PageCount);
242
VK_RETURN: OKButtonClick(nil);
243
VK_RIGHT: SearchList(ListBox.ItemIndex);
247
procedure TViewUnitDialog.EditChange(Sender: TObject);
249
// the change was initiated by the listbox,
250
// so don't make any changes to the listbox
251
if FBlockListBoxChange then exit;
256
procedure TViewUnitDialog.EditEnter(Sender: TObject);
261
Procedure TViewUnitDialog.CancelButtonClick(Sender : TOBject);
209
LazarusHelp.ShowHelpForIDEControl(Self);
212
procedure TViewUnitDialog.CancelButtonClick(Sender: TObject);
263
214
IDEDialogLayoutList.SaveLayout(Self);
264
215
ModalResult := mrCancel;
267
procedure TViewUnitDialog.ListboxClick(Sender: TObject);
269
FBlockListBoxChange := true;
271
if ListBox.ItemIndex <> -1 then
272
Edit.Text := ListBox.Items[ListBox.ItemIndex];
274
FBlockListBoxChange := false;
277
218
procedure TViewUnitDialog.ListboxKeyDown(Sender: TObject; var Key: Word;
278
219
Shift: TShiftState);
280
221
if Key = VK_RETURN then
223
// A hack to prevent 'O' working as shortcut for OK-button.
224
// Should be removed when issue #20599 is resolved.
225
else if (Key = VK_O) and (Shift = []) then
284
229
procedure TViewUnitDialog.MultiselectCheckBoxClick(Sender :TObject);
286
231
ListBox.Multiselect := mniMultiSelect.Checked;
289
procedure TViewUnitDialog.FocusEdit;
295
procedure TViewUnitDialog.SearchList(StartIndex: Integer);
299
Index := SearchItem(ListBox.Items, Edit.Text, StartIndex);
302
ListBox.ItemIndex := Index;
303
ListBox.MakeCurrentVisible;
304
if ListBox.MultiSelect then
306
ListBox.ClearSelection;
307
ListBox.Selected[Index] := True;
234
procedure TViewUnitDialog.SetSortAlphabetically(const AValue: boolean);
236
if FSortAlphabetically=AValue then exit;
237
FSortAlphabetically:=AValue;
238
SortAlphabeticallySpeedButton.Down:=SortAlphabetically;
239
FilterEdit.SortData:=SortAlphabetically;
240
FilterEdit.InvalidateFilter;