IDE: use unit dialog: simplified DetermineUsesSection

git-svn-id: trunk@35685 -
This commit is contained in:
mattias 2012-03-03 19:11:03 +00:00
parent 14d32a0423
commit 009b5cfb04

View File

@ -377,36 +377,26 @@ procedure TUseUnitDialog.DetermineUsesSection(ACode: TCodeBuffer; ACursorPos: TP
var var
CursorPos: TCodeXYPosition; CursorPos: TCodeXYPosition;
CleanCursorPos: Integer; CleanCursorPos: Integer;
CursorNode: TCodeTreeNode;
ImplUsesNode: TCodeTreeNode; ImplUsesNode: TCodeTreeNode;
i: Integer; i: Integer;
Tool: TCodeTool;
ImplNode: TCodeTreeNode;
begin begin
if not CodeToolBoss.InitCurCodeTool(ACode) then Exit; CodeToolBoss.Explore(ACode,Tool,false);
with CodeToolBoss.CurCodeTool do if Tool=nil then exit;
begin // collect implementation use unit nodes
CursorPos := CodeXYPosition(ACursorPos.X, ACursorPos.Y, ACode); ImplUsesNode := Tool.FindImplementationUsesSection;
ActivateGlobalWriteLock;
try
// build code tree
BuildTreeAndGetCleanPos(trTillCursor,lsrEnd,CursorPos,CleanCursorPos,
[btSetIgnoreErrorPos,btLoadDirtySource,btCursorPosOutAllowed]);
if (Tree.Root = nil) or (Tree.Root.StartPos > CleanCursorPos) then Exit;
ImplUsesNode := FindImplementationUsesSection;
if Assigned(ImplUsesNode) then if Assigned(ImplUsesNode) then
for i := 0 to FImplUsedUnits.Count - 1 do for i := 0 to FImplUsedUnits.Count - 1 do
FImplUsedUnits.Objects[i] := ImplUsesNode; FImplUsedUnits.Objects[i] := ImplUsesNode;
// find CodeTreeNode at cursor // check if cursor is behind interface section
CursorNode := BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos, True); CursorPos := CodeXYPosition(ACursorPos.X, ACursorPos.Y, ACode);
if (CursorNode.Desc in [ctnImplementation,ctnInitialization,ctnFinalization]) Tool.CaretToCleanPos(CursorPos,CleanCursorPos);
or CursorNode.HasParentOfType(ctnImplementation) ImplNode:=Tool.FindImplementationNode;
or CursorNode.HasParentOfType(ctnInitialization) if (ImplNode<>nil) and (CleanCursorPos>ImplNode.StartPos) then
or CursorNode.HasParentOfType(ctnFinalization) then
SectionRadioGroup.ItemIndex := 1; SectionRadioGroup.ItemIndex := 1;
// update
SectionRadioGroup.OnClick(SectionRadioGroup); SectionRadioGroup.OnClick(SectionRadioGroup);
finally
DeactivateGlobalWriteLock
end;
end;
end; end;
procedure TUseUnitDialog.FillAvailableUnitsList; procedure TUseUnitDialog.FillAvailableUnitsList;