IDE: codeexplorer: move codetool access to code explorr

git-svn-id: trunk@26491 -
This commit is contained in:
mattias 2010-07-06 17:24:51 +00:00
parent 9b63777a25
commit 1317f884b2
5 changed files with 48 additions and 33 deletions

View File

@ -39,7 +39,7 @@ interface
uses
// FCL+LCL
Classes, SysUtils, LCLProc, LCLType, Forms, Controls, Graphics,
Classes, SysUtils, types, LCLProc, LCLType, Forms, Controls, Graphics,
Dialogs, Buttons, ComCtrls, Menus, AvgLvlTree, StdCtrls, ExtCtrls,
// CodeTools
BasicCodeTools, CustomCodeTool, CodeToolManager, CodeAtom, CodeCache,
@ -54,8 +54,6 @@ uses
type
TCodeExplorerView = class;
TOnGetCodeTree =
procedure(Sender: TObject; var ACodeTool: TCodeTool) of object;
TOnGetDirectivesTree =
procedure(Sender: TObject; var ADirectivesTool: TDirectivesTool) of object;
TOnJumpToCode = procedure(Sender: TObject; const Filename: string;
@ -172,7 +170,7 @@ type
FMode: TCodeExplorerMode;
FLastMode: TCodeExplorerMode;
FLastCodeValid: boolean;
FOnGetCodeTree: TOnGetCodeTree;
FLastCodeXY: TPoint;
FOnGetDirectivesTree: TOnGetDirectivesTree;
FOnJumpToCode: TOnJumpToCode;
FOnShowOptions: TNotifyEvent;
@ -250,8 +248,6 @@ type
function FilterFits(const NodeText, TheFilter: string): boolean; virtual;
function GetCurrentTreeView: TCustomTreeView;
public
property OnGetCodeTree: TOnGetCodeTree read FOnGetCodeTree
write FOnGetCodeTree;
property OnGetDirectivesTree: TOnGetDirectivesTree read FOnGetDirectivesTree
write FOnGetDirectivesTree;
property OnJumpToCode: TOnJumpToCode read FOnJumpToCode write FOnJumpToCode;
@ -1713,6 +1709,11 @@ var
ACodeTool: TCodeTool;
c: TCodeExplorerCategory;
f: TCEObserverCategory;
SrcEdit: TSourceEditorInterface;
Filename: String;
Code: TCodeBuffer;
NewXY: TPoint;
OnlyXYChanged: Boolean;
begin
if (FUpdateCount>0)
or (OnlyVisible and ((CurrentPage<>cepCode) or (not IsVisible))) then begin
@ -1725,13 +1726,23 @@ begin
try
Include(FFlags,cevRefreshing);
// get the codetool with the updated codetree
// get the current editor
if not LazarusIDE.BeginCodeTools then exit;
SrcEdit:=SourceEditorManagerIntf.ActiveEditor;
if SrcEdit=nil then exit;
// get the codetool for the current editor
Filename:=SrcEdit.FileName;
Code:=CodeToolBoss.FindFile(Filename);
if Code=nil then exit;
ACodeTool:=nil;
if Assigned(OnGetCodeTree) then
OnGetCodeTree(Self,ACodeTool);
// ToDo: check if something changed (file stamp, codebuffer stamp, defines stamp)
CodeToolBoss.Explore(Code,ACodeTool,false);
if ACodeTool=nil then exit;
fLastCodeTool:=ACodeTool;
// check for changes in the codetools
// check for changes in the codetool
OnlyXYChanged:=false;
if (ACodeTool=nil) then begin
if (FCodeFilename='') then begin
// still no tool
@ -1753,13 +1764,25 @@ begin
//debugln(['TCodeExplorerView.RefreshCode Options changed ',fLastCodeOptionsChangeStep,' ',CodeExplorerOptions.ChangeStep])
end else begin
// still the same source and options
exit;
OnlyXYChanged:=true;
if not CodeExplorerOptions.FollowCursor then
exit;
NewXY:=SrcEdit.CursorTextXY;
if ComparePoints(NewXY,FLastCodeXY)=0 then begin
// still the same cursor position
exit;
end;
end;
end;
if OnlyXYChanged then begin
end;
FLastCodeValid:=true;
FLastMode:=Mode;
fLastCodeOptionsChangeStep:=CodeExplorerOptions.ChangeStep;
FLastCodeXY:=SrcEdit.CursorTextXY;
// remember the codetools ChangeStep
if ACodeTool<>nil then begin
FCodeFilename:=ACodeTool.MainFilename;
@ -1770,7 +1793,7 @@ begin
if fCodeSortedForStartPos<>nil then
fCodeSortedForStartPos.Clear;
//DebugLn(['TCodeExplorerView.RefreshCode ',FCodeFilename]);
// start updating the CodeTreeView

View File

@ -12,7 +12,7 @@ inherited CodeExplorerUpdateOptionsFrame: TCodeExplorerUpdateOptionsFrame
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 0
Height = 53
Height = 55
Top = 0
Width = 400
Anchors = [akTop, akLeft, akRight]
@ -28,7 +28,7 @@ inherited CodeExplorerUpdateOptionsFrame: TCodeExplorerUpdateOptionsFrame
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 2
ClientHeight = 34
ClientWidth = 396
ClientWidth = 392
Columns = 2
ItemIndex = 0
Items.Strings = (
@ -45,8 +45,8 @@ inherited CodeExplorerUpdateOptionsFrame: TCodeExplorerUpdateOptionsFrame
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 0
Height = 97
Top = 59
Height = 99
Top = 61
Width = 400
Anchors = [akTop, akLeft, akRight]
AutoFill = True
@ -62,7 +62,7 @@ inherited CodeExplorerUpdateOptionsFrame: TCodeExplorerUpdateOptionsFrame
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 78
ClientWidth = 396
ClientWidth = 392
Items.Strings = (
'Manual'
'SwitchPage'
@ -77,11 +77,13 @@ inherited CodeExplorerUpdateOptionsFrame: TCodeExplorerUpdateOptionsFrame
AnchorSideTop.Side = asrBottom
Left = 6
Height = 22
Top = 162
Width = 167
Top = 166
Width = 178
BorderSpacing.Left = 6
BorderSpacing.Top = 6
Caption = 'FollowCursorCheckBox'
ParentShowHint = False
ShowHint = True
TabOrder = 2
Visible = False
end

View File

@ -74,6 +74,8 @@ begin
Items[2] := lisCEOOnIdle;
end;
FollowCursorCheckBox.Caption := lisCEFollowCursor;
FollowCursorCheckBox.Hint :=
lisWhenTheSourceEditorCursorMovesShowTheCurrentNodeIn;
end;
procedure TCodeExplorerUpdateOptionsFrame.ReadSettings(

View File

@ -4195,6 +4195,8 @@ resourcestring
lisCEOWhenSwitchingFile = 'When switching file in source editor';
lisCEOOnIdle = 'On idle';
lisCEFollowCursor = 'Follow cursor';
lisWhenTheSourceEditorCursorMovesShowTheCurrentNodeIn = 'When the source '
+'editor cursor moves, show the current node in the code explorer';
lisCECategories = 'Categories';
lisCEUses = 'Uses';
lisCEOnlyUsedInCategoryMode = 'Only used in category mode';

View File

@ -518,8 +518,6 @@ type
const Filename: string);
// code explorer events
procedure OnCodeExplorerGetCodeTree(Sender: TObject;
var ACodeTool: TCodeTool);
procedure OnCodeExplorerGetDirectivesTree(Sender: TObject;
var ADirectivesTool: TDirectivesTool);
procedure OnCodeExplorerJumpToCode(Sender: TObject; const Filename: string;
@ -8953,7 +8951,6 @@ begin
if CodeExplorerView=nil then
begin
CodeExplorerView:=TCodeExplorerView.Create(OwningComponent);
CodeExplorerView.OnGetCodeTree:=@OnCodeExplorerGetCodeTree;
CodeExplorerView.OnGetDirectivesTree:=@OnCodeExplorerGetDirectivesTree;
CodeExplorerView.OnJumpToCode:=@OnCodeExplorerJumpToCode;
CodeExplorerView.OnShowOptions:=@OnCodeExplorerShowOptions;
@ -13249,17 +13246,6 @@ begin
DoOpenEditorFile(Filename,-1,-1,[]);
end;
procedure TMainIDE.OnCodeExplorerGetCodeTree(Sender: TObject;
var ACodeTool: TCodeTool);
var
ActiveUnitInfo: TUnitInfo;
ActiveSrcEdit: TSourceEditor;
begin
ACodeTool:=nil;
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
CodeToolBoss.Explore(ActiveUnitInfo.Source,ACodeTool,false);
end;
procedure TMainIDE.OnCodeExplorerGetDirectivesTree(Sender: TObject;
var ADirectivesTool: TDirectivesTool);
var