IDE: improve View Unit dialog with images

git-svn-id: trunk@31545 -
This commit is contained in:
juha 2011-07-03 18:19:58 +00:00
parent 52c2f1237a
commit 6ec341b0c1
4 changed files with 51 additions and 29 deletions

View File

@ -114,6 +114,7 @@ type
procedure MapShortToFullFilename(ShortFilename, FullFilename: string); procedure MapShortToFullFilename(ShortFilename, FullFilename: string);
procedure ApplyFilter(Immediately: Boolean = False); procedure ApplyFilter(Immediately: Boolean = False);
procedure InvalidateFilter; procedure InvalidateFilter;
procedure StoreSelection; // Calls the ViewControlWrapper method
public public
property Filter: string read fFilter write SetFilter; property Filter: string read fFilter write SetFilter;
property ImageIndexDirectory: integer read fImageIndexDirectory write fImageIndexDirectory; property ImageIndexDirectory: integer read fImageIndexDirectory write fImageIndexDirectory;
@ -322,6 +323,7 @@ procedure TViewControlTreeview.StoreSelection;
var var
ANode: TTreeNode; ANode: TTreeNode;
begin begin
fOwner.fSelectionList.Clear;
ANode:=fTreeview.Selected; ANode:=fTreeview.Selected;
while ANode<>nil do begin while ANode<>nil do begin
fOwner.fSelectionList.Insert(0,ANode.Text); fOwner.fSelectionList.Insert(0,ANode.Text);
@ -349,7 +351,6 @@ begin
end; end;
if ANode<>nil then if ANode<>nil then
fTreeview.Selected:=ANode; fTreeview.Selected:=ANode;
fSelectionList.Clear;
end; end;
end; end;
@ -478,6 +479,7 @@ procedure TViewControlListbox.StoreSelection;
var var
i: Integer; i: Integer;
begin begin
fOwner.fSelectionList.Clear;
for i := 0 to fListbox.Count-1 do begin for i := 0 to fListbox.Count-1 do begin
if fListbox.Selected[i] then if fListbox.Selected[i] then
fOwner.fSelectionList.Add(fListbox.Items[i]); fOwner.fSelectionList.Add(fListbox.Items[i]);
@ -683,5 +685,10 @@ begin
IdleConnected:=true; IdleConnected:=true;
end; end;
procedure TListFilterEdit.StoreSelection;
begin
fViewControlWrapper.StoreSelection;
end;
end. end.

View File

@ -9549,11 +9549,20 @@ begin
end; end;
end; end;
case ItemType of case ItemType of
piUnit: DlgCaption := dlgMainViewUnits; piUnit: begin
piComponent: DlgCaption := dlgMainViewForms; DlgCaption := dlgMainViewUnits;
piFrame: DlgCaption := dlgMainViewFrames; i := IDEImages.LoadImage(16, 'item_unit');
end; end;
Result := ShowViewUnitsDlg(ItemList, MultiSelect, MultiSelectCheckedState, DlgCaption); piComponent: begin
DlgCaption := dlgMainViewForms;
i := IDEImages.LoadImage(16, 'item_form');
end;
piFrame: begin
DlgCaption := dlgMainViewFrames;
i := IDEImages.LoadImage(16, 'tpanel');
end;
end;
Result := ShowViewUnitsDlg(ItemList, MultiSelect, MultiSelectCheckedState, DlgCaption, i);
end; end;
function TMainIDE.DoSelectFrame: TComponentClass; function TMainIDE.DoSelectFrame: TComponentClass;
@ -11158,7 +11167,6 @@ Begin
ViewUnitEntries := TStringList.Create; ViewUnitEntries := TStringList.Create;
ViewUnitEntries.Sorted := True; ViewUnitEntries.Sorted := True;
UnitInfos:=nil; UnitInfos:=nil;
try try
for i := 0 to Project1.UnitCount-1 do for i := 0 to Project1.UnitCount-1 do
begin begin
@ -11169,7 +11177,8 @@ Begin
ViewUnitEntries.AddObject(AName, TViewUnitsEntry.Create(AName,i,false)); ViewUnitEntries.AddObject(AName, TViewUnitsEntry.Create(AName,i,false));
end; end;
end; end;
if ShowViewUnitsDlg(ViewUnitEntries, true, MultiSelectCheckedState, lisRemoveFromProject) <> mrOk then if ShowViewUnitsDlg(ViewUnitEntries, true, MultiSelectCheckedState,
lisRemoveFromProject, IDEImages.LoadImage(16, 'item_unit')) <> mrOk then
exit(mrOk); exit(mrOk);
{ This is where we check what the user selected. } { This is where we check what the user selected. }
UnitInfos:=TFPList.Create; UnitInfos:=TFPList.Create;

View File

@ -25,6 +25,7 @@ object ViewUnitDialog: TViewUnitDialog
OnDblClick = OKButtonClick OnDblClick = OKButtonClick
OnKeyDown = ListboxKeyDown OnKeyDown = ListboxKeyDown
PopupMenu = popListBox PopupMenu = popListBox
Style = lbOwnerDrawFixed
TabOrder = 0 TabOrder = 0
end end
object ButtonPanel: TButtonPanel object ButtonPanel: TButtonPanel

View File

@ -40,8 +40,8 @@ interface
uses uses
SysUtils, Classes, Math, Controls, Forms, Dialogs, Buttons, StdCtrls, SysUtils, Classes, Math, Controls, Forms, Dialogs, Buttons, StdCtrls,
LazarusIdeStrConsts, LCLType, LCLIntf, LMessages, LazarusIdeStrConsts, LCLType, LCLIntf, LMessages,
ExtCtrls, ButtonPanel, Menus, StrUtils, ExtCtrls, ButtonPanel, Menus, StrUtils, ImgList,
IDEWindowIntf, IDEHelpIntf, ListFilterEdit; IDEWindowIntf, IDEHelpIntf, IDEImagesIntf, ListFilterEdit;
type type
TViewUnitsEntry = class TViewUnitsEntry = class
@ -73,14 +73,16 @@ type
procedure MultiselectCheckBoxClick(Sender :TObject); procedure MultiselectCheckBoxClick(Sender :TObject);
private private
FSortAlphabetically: boolean; FSortAlphabetically: boolean;
FImageIndex: Integer;
procedure SetSortAlphabetically(const AValue: boolean); procedure SetSortAlphabetically(const AValue: boolean);
function ChooseImageIndex(Str: String; Data: TObject; var IsEnabled: Boolean): Integer;
public public
constructor Create(TheOwner: TComponent); override; constructor Create(TheOwner: TComponent); override;
property SortAlphabetically: boolean read FSortAlphabetically write SetSortAlphabetically; property SortAlphabetically: boolean read FSortAlphabetically write SetSortAlphabetically;
end; end;
function ShowViewUnitsDlg(Entries: TStringList; AllowMultiSelect: boolean; function ShowViewUnitsDlg(Entries: TStringList; AllowMultiSelect: boolean;
var CheckMultiSelect: Boolean; const Caption: string): TModalResult; var CheckMultiSelect: Boolean; const aCaption: string; aImageIndex: Integer): TModalResult;
// Entries is a list of TViewUnitsEntry(s) // Entries is a list of TViewUnitsEntry(s)
implementation implementation
@ -88,20 +90,25 @@ implementation
{$R *.lfm} {$R *.lfm}
function ShowViewUnitsDlg(Entries: TStringList; AllowMultiSelect: boolean; function ShowViewUnitsDlg(Entries: TStringList; AllowMultiSelect: boolean;
var CheckMultiSelect: Boolean; const Caption: string): TModalResult; var CheckMultiSelect: Boolean; const aCaption: string; aImageIndex: Integer): TModalResult;
var var
ViewUnitDialog: TViewUnitDialog; ViewUnitDialog: TViewUnitDialog;
UEntry: TViewUnitsEntry; UEntry: TViewUnitsEntry;
TmpList: TStringList;
i: integer; i: integer;
begin begin
IDEImages.Images_16;
ViewUnitDialog:=TViewUnitDialog.Create(nil); ViewUnitDialog:=TViewUnitDialog.Create(nil);
with ViewUnitDialog do with ViewUnitDialog do
try try
Caption:=Caption; Caption:=aCaption;
mniMultiselect.Enabled := AllowMultiSelect; mniMultiselect.Enabled := AllowMultiSelect;
mniMultiselect.Checked := CheckMultiSelect; mniMultiselect.Checked := CheckMultiSelect;
ListBox.MultiSelect := mniMultiselect.Enabled; ListBox.MultiSelect := mniMultiselect.Enabled;
if aImageIndex > -1 then begin
FImageIndex:=aImageIndex;
FilterEdit.Images4Listbox:=IDEImages.Images_16;
FilterEdit.OnGetImageIndex:=@ChooseImageIndex;
end;
// Data items // Data items
for i:=0 to Entries.Count-1 do begin for i:=0 to Entries.Count-1 do begin
UEntry:=TViewUnitsEntry(Entries.Objects[i]); UEntry:=TViewUnitsEntry(Entries.Objects[i]);
@ -118,18 +125,10 @@ begin
Result:=ShowModal; Result:=ShowModal;
if Result=mrOk then begin if Result=mrOk then begin
// Return new selections from the dialog // Return new selections from the dialog
TmpList:=TStringList.Create; FilterEdit.StoreSelection;
try
for i:=0 to ListBox.Count-1 do begin
if ListBox.Selected[i] then
TmpList.Add(ListBox.Items[i]);
end;
for i:=0 to Entries.Count-1 do begin for i:=0 to Entries.Count-1 do begin
UEntry:=TViewUnitsEntry(Entries.Objects[i]); UEntry:=TViewUnitsEntry(Entries.Objects[i]);
UEntry.Selected:=TmpList.IndexOf(UEntry.Name)>-1; UEntry.Selected:=FilterEdit.SelectionList.IndexOf(UEntry.Name)>-1;
end;
finally
TmpList.Free;
end; end;
CheckMultiSelect := mniMultiselect.Checked; CheckMultiSelect := mniMultiselect.Checked;
end; end;
@ -207,6 +206,12 @@ begin
FilterEdit.InvalidateFilter; FilterEdit.InvalidateFilter;
end; end;
function TViewUnitDialog.ChooseImageIndex(Str: String; Data: TObject;
var IsEnabled: Boolean): Integer;
begin
Result:=FImageIndex;
end;
end. end.