IDE: Use Unit dialog now adds the correct char case for unit name + other improvements from Anton Panferov

git-svn-id: trunk@31724 -
This commit is contained in:
juha 2011-07-17 08:31:21 +00:00
parent 212b14965d
commit 4352638a91
4 changed files with 60 additions and 28 deletions

View File

@ -80,8 +80,11 @@ object UseUnitDialog: TUseUnitDialog
BorderSpacing.Around = 6
ItemHeight = 0
OnDblClick = UnitsListBoxDblClick
OnDrawItem = UnitsListBoxDrawItem
ScrollWidth = 347
Style = lbOwnerDrawFixed
TabOrder = 1
TopIndex = -1
end
object AllUnitsCheckBox: TCheckBox
AnchorSideLeft.Control = Owner

View File

@ -49,6 +49,8 @@ type
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure UnitsListBoxDblClick(Sender: TObject);
procedure UnitsListBoxDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
private
UnitImgInd: Integer;
FMainUsedUnits: TStrings;
@ -60,7 +62,6 @@ type
function SelectedUnit: string;
function InterfaceSelected: Boolean;
procedure EnableOnlyInterface;
function ChooseImageIndex(Str: String; Data: TObject; var IsEnabled: Boolean): Integer;
public
end;
@ -124,8 +125,6 @@ begin
ButtonPanel1.OKButton.Caption:=lisOk;
ButtonPanel1.CancelButton.Caption:=dlgCancel;
UnitImgInd := IDEImages.LoadImage(16, 'item_unit');
FilterEdit.Images4Listbox:=IDEImages.Images_16;
FilterEdit.OnGetImageIndex:=@ChooseImageIndex;
FProjUnits:=TStringList.Create;
end;
@ -166,11 +165,20 @@ begin
ModalResult := mrOK;
end;
function TUseUnitDialog.ChooseImageIndex(Str: String; Data: TObject;
var IsEnabled: Boolean): Integer;
procedure TUseUnitDialog.UnitsListBoxDrawItem(Control: TWinControl;
Index: Integer; ARect: TRect; State: TOwnerDrawState);
var ena: Boolean;
begin
IsEnabled:=Data=Nil;
Result:=UnitImgInd;
if Index < 0 then Exit;
with UnitsListBox do
begin
Canvas.FillRect(ARect);
ena := not Assigned(Items.Objects[Index]);
if not (ena or (odSelected in State)) then
UnitsListBox.Canvas.Font.Color := clGreen;
IDEImages.Images_16.Draw(Canvas, 1, ARect.Top, UnitImgInd, ena);
Canvas.TextRect(ARect, ARect.Left + 20, ARect.Top, Items[Index]);
end;
end;
function TUseUnitDialog.GetAvailableProjUnits(SrcEdit: TSourceEditor): TModalResult;
@ -238,7 +246,7 @@ begin
if (FMainUsedUnits.IndexOf(curUnit) < 0)
and (FImplUsedUnits.IndexOf(curUnit) < 0)
and (FOtherUnits.IndexOf(curUnit) < 0) then
FOtherUnits.AddObject(IdentifierList.FilteredItems[i].Identifier, TObject(1));
FOtherUnits.AddObject(IdentifierList.FilteredItems[i].Identifier, IdentifierList.FilteredItems[i]);
end;
end;
FOtherUnits.Sort;
@ -248,11 +256,28 @@ begin
end;
function TUseUnitDialog.SelectedUnit: string;
var
IdentItem: TIdentifierListItem;
CodeBuf: TCodeBuffer;
begin
if UnitsListBox.ItemIndex >= 0 then
Result := UnitsListBox.Items[UnitsListBox.ItemIndex]
else
Result := '';
with UnitsListBox do
if ItemIndex >= 0 then
begin
IdentItem := TIdentifierListItem(Items.Objects[ItemIndex]);
if Assigned(IdentItem) then
begin
Result := IdentItem.Identifier;
CodeBuf := CodeToolBoss.FindUnitSource(
SourceEditorManager.ActiveEditor.CodeBuffer, Result, '');
if CodeBuf = nil then
Exit(IdentItem.Identifier);
Result := CodeToolBoss.GetSourceName(CodeBuf, True);
if Result = '' then
Result := IdentItem.Identifier;
end else
Result := Items[ItemIndex];
end else
Result := '';
end;
function TUseUnitDialog.InterfaceSelected: Boolean;

View File

@ -24,12 +24,12 @@ object ViewUnitDialog: TViewUnitDialog
ClickOnSelChange = False
ItemHeight = 0
OnDblClick = OKButtonClick
OnDrawItem = ListboxDrawItem
OnKeyDown = ListboxKeyDown
PopupMenu = popListBox
ScrollWidth = 362
Style = lbOwnerDrawFixed
TabOrder = 0
TopIndex = -1
end
object ButtonPanel: TButtonPanel
Left = 6
@ -78,6 +78,8 @@ object ViewUnitDialog: TViewUnitDialog
object FilterEdit: TListFilterEdit
AnchorSideLeft.Control = SortAlphabeticallySpeedButton
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = SortAlphabeticallySpeedButton
AnchorSideTop.Side = asrCenter
Left = 26
Height = 23
Top = 2
@ -85,7 +87,7 @@ object ViewUnitDialog: TViewUnitDialog
FilteredListbox = Listbox
ButtonWidth = 23
NumGlyphs = 0
Anchors = [akLeft, akRight]
Anchors = [akTop, akLeft, akRight]
Font.Color = clBtnShadow
MaxLength = 0
ParentFont = False

View File

@ -65,6 +65,8 @@ type
popListBox: TPopupMenu;
RemoveBitBtn: TSpeedButton;
SortAlphabeticallySpeedButton: TSpeedButton;
procedure ListboxDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
procedure SortAlphabeticallySpeedButtonClick(Sender: TObject);
procedure OKButtonClick(Sender :TObject);
procedure HelpButtonClick(Sender: TObject);
@ -75,15 +77,14 @@ type
FSortAlphabetically: boolean;
FImageIndex: Integer;
procedure SetSortAlphabetically(const AValue: boolean);
function ChooseImageIndex(Str: String; Data: TObject; var IsEnabled: Boolean): Integer;
public
constructor Create(TheOwner: TComponent); override;
property SortAlphabetically: boolean read FSortAlphabetically write SetSortAlphabetically;
end;
// Entries is a list of TViewUnitsEntry(s)
function ShowViewUnitsDlg(Entries: TStringList; AllowMultiSelect: boolean;
var CheckMultiSelect: Boolean; const aCaption: string; aImageIndex: Integer): TModalResult;
// Entries is a list of TViewUnitsEntry(s)
implementation
@ -103,11 +104,7 @@ begin
mniMultiselect.Enabled := AllowMultiSelect;
mniMultiselect.Checked := CheckMultiSelect;
ListBox.MultiSelect := mniMultiselect.Enabled;
if aImageIndex > -1 then begin
FImageIndex:=aImageIndex;
FilterEdit.Images4Listbox:=IDEImages.Images_16;
FilterEdit.OnGetImageIndex:=@ChooseImageIndex;
end;
if aImageIndex > -1 then FImageIndex:=aImageIndex; // otherwise FImageIndex will stay "0"
// Data items
for i:=0 to Entries.Count-1 do begin
UEntry:=TViewUnitsEntry(Entries.Objects[i]);
@ -167,6 +164,18 @@ begin
SortAlphabetically:=SortAlphabeticallySpeedButton.Down;
end;
procedure TViewUnitDialog.ListboxDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
begin
if Index < 0 then Exit;
with ListBox do
begin
Canvas.FillRect(ARect);
IDEImages.Images_16.Draw(Canvas, 1, ARect.Top, FImageIndex);
Canvas.TextRect(ARect, ARect.Left + 20, ARect.Top, Items[Index]);
end;
end;
procedure TViewUnitDialog.OKButtonClick(Sender: TObject);
Begin
IDEDialogLayoutList.SaveLayout(Self);
@ -205,12 +214,5 @@ begin
FilterEdit.InvalidateFilter;
end;
function TViewUnitDialog.ChooseImageIndex(Str: String; Data: TObject;
var IsEnabled: Boolean): Integer;
begin
Result:=FImageIndex;
end;
end.