cody: started contains

git-svn-id: trunk@34226 -
This commit is contained in:
mattias 2011-12-16 18:56:28 +00:00
parent 385f41f533
commit 9bf66b8e04
2 changed files with 155 additions and 76 deletions

View File

@ -13,8 +13,8 @@ object CodyIdentifiersDlg: TCodyIdentifiersDlg
LCLVersion = '0.9.31' LCLVersion = '0.9.31'
object ButtonPanel1: TButtonPanel object ButtonPanel1: TButtonPanel
Left = 6 Left = 6
Height = 42 Height = 40
Top = 276 Top = 278
Width = 540 Width = 540
OKButton.Name = 'OKButton' OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True OKButton.DefaultCaption = True
@ -29,9 +29,9 @@ object CodyIdentifiersDlg: TCodyIdentifiersDlg
end end
object InfoLabel: TLabel object InfoLabel: TLabel
Left = 8 Left = 8
Height = 17 Height = 18
Top = 8 Top = 8
Width = 59 Width = 61
Caption = 'InfoLabel' Caption = 'InfoLabel'
ParentColor = False ParentColor = False
WordWrap = True WordWrap = True
@ -40,16 +40,14 @@ object CodyIdentifiersDlg: TCodyIdentifiersDlg
AnchorSideLeft.Control = Owner AnchorSideLeft.Control = Owner
AnchorSideTop.Control = HideOtherProjectsCheckBox AnchorSideTop.Control = HideOtherProjectsCheckBox
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Owner AnchorSideRight.Control = StartsSpeedButton
AnchorSideRight.Side = asrBottom
Left = 6 Left = 6
Height = 26 Height = 27
Top = 63 Top = 64
Width = 540 Width = 466
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
BorderSpacing.Left = 6 BorderSpacing.Left = 6
BorderSpacing.Top = 10 BorderSpacing.Top = 10
BorderSpacing.Right = 6
OnChange = FilterEditChange OnChange = FilterEditChange
OnExit = FilterEditExit OnExit = FilterEditExit
OnKeyDown = FilterEditKeyDown OnKeyDown = FilterEditKeyDown
@ -64,8 +62,8 @@ object CodyIdentifiersDlg: TCodyIdentifiersDlg
AnchorSideRight.Side = asrBottom AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = UnitLabel AnchorSideBottom.Control = UnitLabel
Left = 6 Left = 6
Height = 120 Height = 118
Top = 89 Top = 91
Width = 540 Width = 540
Anchors = [akTop, akLeft, akRight, akBottom] Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 6 BorderSpacing.Left = 6
@ -82,9 +80,9 @@ object CodyIdentifiersDlg: TCodyIdentifiersDlg
AnchorSideLeft.Control = InfoLabel AnchorSideLeft.Control = InfoLabel
AnchorSideBottom.Control = PackageLabel AnchorSideBottom.Control = PackageLabel
Left = 8 Left = 8
Height = 17 Height = 18
Top = 210 Top = 210
Width = 59 Width = 63
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
BorderSpacing.Bottom = 1 BorderSpacing.Bottom = 1
Caption = 'UnitLabel' Caption = 'UnitLabel'
@ -94,9 +92,9 @@ object CodyIdentifiersDlg: TCodyIdentifiersDlg
AnchorSideLeft.Control = InfoLabel AnchorSideLeft.Control = InfoLabel
AnchorSideBottom.Control = AddToImplementationUsesCheckBox AnchorSideBottom.Control = AddToImplementationUsesCheckBox
Left = 8 Left = 8
Height = 17 Height = 18
Top = 228 Top = 229
Width = 84 Width = 90
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
BorderSpacing.Bottom = 1 BorderSpacing.Bottom = 1
Caption = 'PackageLabel' Caption = 'PackageLabel'
@ -108,8 +106,8 @@ object CodyIdentifiersDlg: TCodyIdentifiersDlg
AnchorSideTop.Side = asrBottom AnchorSideTop.Side = asrBottom
Left = 8 Left = 8
Height = 22 Height = 22
Top = 31 Top = 32
Width = 193 Width = 207
BorderSpacing.Top = 6 BorderSpacing.Top = 6
Caption = 'HideOtherProjectsCheckBox' Caption = 'HideOtherProjectsCheckBox'
OnChange = HideOtherProjectsCheckBoxChange OnChange = HideOtherProjectsCheckBoxChange
@ -120,8 +118,8 @@ object CodyIdentifiersDlg: TCodyIdentifiersDlg
AnchorSideBottom.Control = ButtonPanel1 AnchorSideBottom.Control = ButtonPanel1
Left = 8 Left = 8
Height = 22 Height = 22
Top = 248 Top = 250
Width = 246 Width = 264
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
BorderSpacing.Top = 3 BorderSpacing.Top = 3
BorderSpacing.Bottom = 3 BorderSpacing.Bottom = 3
@ -130,4 +128,41 @@ object CodyIdentifiersDlg: TCodyIdentifiersDlg
ShowHint = True ShowHint = True
TabOrder = 4 TabOrder = 4
end end
object StartsSpeedButton: TSpeedButton
AnchorSideTop.Control = FilterEdit
AnchorSideRight.Control = ContainsSpeedButton
AnchorSideBottom.Control = FilterEdit
AnchorSideBottom.Side = asrBottom
Left = 472
Height = 27
Top = 64
Width = 51
Anchors = [akTop, akRight, akBottom]
AutoSize = True
Caption = 'Starts with'
GroupIndex = 1
NumGlyphs = 0
OnClick = StartsSpeedButtonClick
ShowHint = True
ParentShowHint = False
end
object ContainsSpeedButton: TSpeedButton
AnchorSideTop.Control = FilterEdit
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = FilterEdit
AnchorSideBottom.Side = asrBottom
Left = 523
Height = 27
Top = 64
Width = 23
Anchors = [akTop, akRight, akBottom]
AutoSize = True
BorderSpacing.Right = 6
Caption = 'Contains'
GroupIndex = 1
NumGlyphs = 0
ShowHint = True
ParentShowHint = False
end
end end

View File

@ -27,7 +27,8 @@
ToDo: ToDo:
-quickfix for identifier not found -quickfix for identifier not found
-use identifier: check package version -use identifier: check package version
-check for unit conflict -check for conflict: other unit with same name already in search path
-check for conflict: other identifier in scope, use unitname.identifier
-gzip? lot of cpu, may be faster on first load -gzip? lot of cpu, may be faster on first load
} }
unit CodyIdentifiersDlg; unit CodyIdentifiersDlg;
@ -110,16 +111,23 @@ type
cidaJumpToIdentifier cidaJumpToIdentifier
); );
TCodyIdentifierFilter = (
cifStartsWith,
cifContains
);
{ TCodyIdentifiersDlg } { TCodyIdentifiersDlg }
TCodyIdentifiersDlg = class(TForm) TCodyIdentifiersDlg = class(TForm)
AddToImplementationUsesCheckBox: TCheckBox; AddToImplementationUsesCheckBox: TCheckBox;
ButtonPanel1: TButtonPanel; ButtonPanel1: TButtonPanel;
ContainsSpeedButton: TSpeedButton;
FilterEdit: TEdit; FilterEdit: TEdit;
HideOtherProjectsCheckBox: TCheckBox; HideOtherProjectsCheckBox: TCheckBox;
InfoLabel: TLabel; InfoLabel: TLabel;
ItemsListBox: TListBox; ItemsListBox: TListBox;
PackageLabel: TLabel; PackageLabel: TLabel;
StartsSpeedButton: TSpeedButton;
UnitLabel: TLabel; UnitLabel: TLabel;
procedure ButtonPanel1OKButtonClick(Sender: TObject); procedure ButtonPanel1OKButtonClick(Sender: TObject);
procedure FilterEditChange(Sender: TObject); procedure FilterEditChange(Sender: TObject);
@ -133,6 +141,7 @@ type
procedure ItemsListBoxClick(Sender: TObject); procedure ItemsListBoxClick(Sender: TObject);
procedure ItemsListBoxSelectionChange(Sender: TObject; {%H-}User: boolean); procedure ItemsListBoxSelectionChange(Sender: TObject; {%H-}User: boolean);
procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean); procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean);
procedure StartsSpeedButtonClick(Sender: TObject);
private private
FDlgAction: TCodyIdentifierDlgAction; FDlgAction: TCodyIdentifierDlgAction;
FJumpButton: TBitBtn; FJumpButton: TBitBtn;
@ -142,6 +151,7 @@ type
FMaxItems: integer; FMaxItems: integer;
FNoFilterText: string; FNoFilterText: string;
FItems: TStringList; FItems: TStringList;
FLastFilterType: TCodyIdentifierFilter;
procedure SetDlgAction(NewAction: TCodyIdentifierDlgAction); procedure SetDlgAction(NewAction: TCodyIdentifierDlgAction);
procedure SetIdleConnected(AValue: boolean); procedure SetIdleConnected(AValue: boolean);
procedure SetMaxItems(AValue: integer); procedure SetMaxItems(AValue: integer);
@ -185,6 +195,7 @@ type
property MaxItems: integer read FMaxItems write SetMaxItems; property MaxItems: integer read FMaxItems write SetMaxItems;
function OwnerToString(AnOwner: TObject): string; function OwnerToString(AnOwner: TObject): string;
property DlgAction: TCodyIdentifierDlgAction read FDlgAction; property DlgAction: TCodyIdentifierDlgAction read FDlgAction;
function GetFilterType: TCodyIdentifierFilter;
end; end;
var var
@ -667,6 +678,13 @@ begin
FJumpButton.Name:='JumpButton'; FJumpButton.Name:='JumpButton';
FJumpButton.OnClick:=@JumpButtonClick; FJumpButton.OnClick:=@JumpButtonClick;
FJumpButton.Caption:= crsJumpTo; FJumpButton.Caption:= crsJumpTo;
StartsSpeedButton.Down:=true;
StartsSpeedButton.Caption:='Starts';
StartsSpeedButton.Hint:='Show only identifiers starting with filter text';
ContainsSpeedButton.Down:=false;
ContainsSpeedButton.Caption:='Contains';
ContainsSpeedButton.Hint:='Show only identifiers containing filter text';
end; end;
procedure TCodyIdentifiersDlg.HideOtherProjectsCheckBoxChange(Sender: TObject); procedure TCodyIdentifiersDlg.HideOtherProjectsCheckBoxChange(Sender: TObject);
@ -695,11 +713,17 @@ begin
UpdateGeneralInfo; UpdateGeneralInfo;
end; end;
if (FLastFilter<>GetFilterEditText) if (FLastFilter<>GetFilterEditText)
or (FLastHideOtherProjects<>HideOtherProjectsCheckBox.Checked) then or (FLastHideOtherProjects<>HideOtherProjectsCheckBox.Checked)
or (FLastFilterType<>GetFilterType) then
UpdateItemsList; UpdateItemsList;
IdleConnected:=false; IdleConnected:=false;
end; end;
procedure TCodyIdentifiersDlg.StartsSpeedButtonClick(Sender: TObject);
begin
UpdateItemsList;
end;
procedure TCodyIdentifiersDlg.SetIdleConnected(AValue: boolean); procedure TCodyIdentifiersDlg.SetIdleConnected(AValue: boolean);
begin begin
if FIdleConnected=AValue then Exit; if FIdleConnected=AValue then Exit;
@ -748,61 +772,73 @@ var
Node: TAVLTreeNode; Node: TAVLTreeNode;
begin begin
Node:=CodyUnitDictionary.Identifiers.FindLowest; Node:=CodyUnitDictionary.Identifiers.FindLowest;
//debugln(['TCodyIdentifiersDlg.UpdateItemsList Filter="',Filter,'"']); debugln(['TCodyIdentifiersDlg.UpdateItemsList Filter="',FLastFilter,'" Count=',CodyUnitDictionary.Identifiers.Count]);
while Node<>nil do begin while Node<>nil do begin
Item:=TUDIdentifier(Node.Data); Item:=TUDIdentifier(Node.Data);
if ComparePrefixIdent(FilterP,PChar(Pointer(Item.Name))) Node:=CodyUnitDictionary.Identifiers.FindSuccessor(Node);
and (AddExactMatches=(CompareIdentifiers(FilterP,PChar(Pointer(Item.Name)))=0)) debugln(['AddItems checking ',Item.Name]);
then begin if CompareIdentifiers(FilterP,PChar(Pointer(Item.Name)))=0 then begin
if Found>MaxItems then begin // exact match
inc(Found); // only count, do not check if not AddExactMatches then continue;
end else begin end else begin
GroupNode:=Item.DUnit.Groups.FindLowest; // not exact
while GroupNode<>nil do begin if AddExactMatches then continue;
Group:=TUDUnitGroup(GroupNode.Data); debugln(['AddItems ',ord(FLastFilterType),' ',Item.Name]);
GroupNode:=Item.DUnit.Groups.FindSuccessor(GroupNode); case FLastFilterType of
if not FilenameIsAbsolute(Item.DUnit.Filename) then continue; cifStartsWith:
if Group.Name='' then begin if not ComparePrefixIdent(FilterP,PChar(Pointer(Item.Name))) then continue;
// it's a unit without package cifContains:
if FLastHideOtherProjects then begin if System.Pos(FLastFilter,Item.Name)<1 then continue;
// check if unit is in unit path of current owner end;
if CurUnitPath='' then continue; end;
if FindPathInSearchPath(PChar(CurUnitPath),length(CurUnitPath), debugln(['AddItems name FITS ',ord(FLastFilterType),' ',Item.Name]);
PChar(CurUnitPath),length(CurUnitPath))=nil if Found>MaxItems then begin
then continue; inc(Found); // only count, do not check
end; continue;
end else if Group.Name=PackageNameFPCSrcDir then begin end;
// it's a FPC source directory GroupNode:=Item.DUnit.Groups.FindLowest;
// => check if it is the current one while GroupNode<>nil do begin
Dir:=ChompPathDelim(ExtractFilePath(Group.Filename)); Group:=TUDUnitGroup(GroupNode.Data);
if CompareFilenames(Dir,FPCSrcDir)<>0 then continue; GroupNode:=Item.DUnit.Groups.FindSuccessor(GroupNode);
FPCSrcFilename:=UnitSet.GetUnitSrcFile(Item.DUnit.Name); if not FilenameIsAbsolute(Item.DUnit.Filename) then continue;
if (FPCSrcFilename<>'') if Group.Name='' then begin
and (CompareFilenames(FPCSrcFilename,Item.DUnit.Filename)<>0) // it's a unit without package
then continue; // this is not the source for this target platform if FLastHideOtherProjects then begin
end else if FileExistsCached(Group.Filename) then begin // check if unit is in unit path of current owner
// lpk exists if CurUnitPath='' then continue;
end else begin if FindPathInSearchPath(PChar(CurUnitPath),length(CurUnitPath),
// lpk does not exist any more PChar(CurUnitPath),length(CurUnitPath))=nil
CodyUnitDictionary.CheckFileAsync(Group.Filename); then continue;
end; end;
s:=Item.Name+' in '+Item.DUnit.Name; end else if Group.Name=PackageNameFPCSrcDir then begin
if Group.Name<>'' then // it's a FPC source directory
s:=s+' of '+Group.Name; // => check if it is the current one
if FileExistsCached(Item.DUnit.Filename) then begin Dir:=ChompPathDelim(ExtractFilePath(Group.Filename));
inc(Found); if CompareFilenames(Dir,FPCSrcDir)<>0 then continue;
if Found<MaxItems then begin FPCSrcFilename:=UnitSet.GetUnitSrcFile(Item.DUnit.Name);
FItems.Add(Item.Name+#10+Item.DUnit.Filename+#10+Group.Name+#10+Group.Filename); if (FPCSrcFilename<>'')
sl.Add(s); and (CompareFilenames(FPCSrcFilename,Item.DUnit.Filename)<>0)
end; then continue; // this is not the source for this target platform
end else begin end else if FileExistsCached(Group.Filename) then begin
// unit does not exist any more // lpk exists
CodyUnitDictionary.CheckFileAsync(Item.DUnit.Filename); end else begin
end; // lpk does not exist any more
end; CodyUnitDictionary.CheckFileAsync(Group.Filename);
end;
s:=Item.Name+' in '+Item.DUnit.Name;
if Group.Name<>'' then
s:=s+' of '+Group.Name;
if FileExistsCached(Item.DUnit.Filename) then begin
inc(Found);
if Found<MaxItems then begin
FItems.Add(Item.Name+#10+Item.DUnit.Filename+#10+Group.Name+#10+Group.Filename);
sl.Add(s);
end;
end else begin
// unit does not exist any more
CodyUnitDictionary.CheckFileAsync(Item.DUnit.Filename);
end; end;
end; end;
Node:=CodyUnitDictionary.Identifiers.FindSuccessor(Node);
end; end;
end; end;
@ -811,6 +847,7 @@ begin
FilterP:=PChar(FLastFilter); FilterP:=PChar(FLastFilter);
FLastHideOtherProjects:=HideOtherProjectsCheckBox.Checked; FLastHideOtherProjects:=HideOtherProjectsCheckBox.Checked;
FLastFilterType:=GetFilterType;
FItems.Clear; FItems.Clear;
sl:=TStringList.Create; sl:=TStringList.Create;
@ -818,9 +855,8 @@ begin
Found:=0; Found:=0;
UnitSet:=CodeToolBoss.GetUnitSetForDirectory(''); UnitSet:=CodeToolBoss.GetUnitSetForDirectory('');
FPCSrcDir:=''; FPCSrcDir:='';
if (UnitSet<>nil) then begin if (UnitSet<>nil) then
FPCSrcDir:=ChompPathDelim(UnitSet.FPCSourceDirectory); FPCSrcDir:=ChompPathDelim(UnitSet.FPCSourceDirectory);
end;
AddItems(true); AddItems(true);
AddItems(false); AddItems(false);
if Found>sl.Count then if Found>sl.Count then
@ -1243,6 +1279,14 @@ begin
Result:=TIDEPackage(AnOwner).Name; Result:=TIDEPackage(AnOwner).Name;
end; end;
function TCodyIdentifiersDlg.GetFilterType: TCodyIdentifierFilter;
begin
if ContainsSpeedButton.Down then
exit(cifContains)
else
exit(cifStartsWith);
end;
procedure TCodyIdentifiersDlg.UpdateCurOwnerOfUnit; procedure TCodyIdentifiersDlg.UpdateCurOwnerOfUnit;
procedure GetBest(OwnerList: TFPList); procedure GetBest(OwnerList: TFPList);