diff --git a/ide/codeexplorer.pas b/ide/codeexplorer.pas index d3c22fea47..e337083dba 100644 --- a/ide/codeexplorer.pas +++ b/ide/codeexplorer.pas @@ -198,6 +198,8 @@ type ImgIDUnit: Integer; ImgIDVariable: Integer; ImgIDHint: Integer; + procedure ClearCodeTreeView; + procedure ClearDirectivesTreeView; function GetCodeFilter: string; function GetCurrentPage: TCodeExplorerPage; function GetDirectivesFilter: string; @@ -594,7 +596,19 @@ begin if not (cevCheckOnIdle in FFlags) then exit; if (Screen.ActiveCustomForm<>nil) and (fsModal in Screen.ActiveCustomForm.FormState) then + begin + // do not update while a modal form is shown, except for clear + if SourceEditorManagerIntf=nil then exit; + if SourceEditorManagerIntf.SourceEditorCount=0 then + begin + Exclude(FFlags,cevCheckOnIdle); + FLastCodeValid:=false; + ClearCodeTreeView; + FDirectivesFilename:=''; + ClearDirectivesTreeView; + end; exit; + end; if not IsVisible then exit; Exclude(FFlags,cevCheckOnIdle); case CurrentPage of @@ -807,6 +821,25 @@ begin Result:=CodeFilterEdit.Text; end; +procedure TCodeExplorerView.ClearCodeTreeView; +var + f: TCEObserverCategory; + c: TCodeExplorerCategory; +begin + for c:=low(TCodeExplorerCategory) to high(TCodeExplorerCategory) do + fCategoryNodes[c]:=nil; + fObserverNode:=nil; + for f:=low(TCEObserverCategory) to high(TCEObserverCategory) do + fObserverCatNodes[f]:=nil; + fSurroundingNode:=nil; + CodeTreeview.Items.Clear; +end; + +procedure TCodeExplorerView.ClearDirectivesTreeView; +begin + DirectivesTreeView.Items.Clear; +end; + function TCodeExplorerView.GetCurrentPage: TCodeExplorerPage; begin if MainNotebook.ActivePage=CodePage then @@ -2035,8 +2068,6 @@ procedure TCodeExplorerView.RefreshCode(OnlyVisible: boolean); var OldExpanded: TTreeNodeExpandedState; ACodeTool: TCodeTool; - c: TCodeExplorerCategory; - f: TCEObserverCategory; SrcEdit: TSourceEditorInterface; Filename: String; Code: TCodeBuffer; @@ -2142,14 +2173,8 @@ begin if not CurFollowNode then OldExpanded:=TTreeNodeExpandedState.Create(CodeTreeView); - for c:=low(TCodeExplorerCategory) to high(TCodeExplorerCategory) do - fCategoryNodes[c]:=nil; - fObserverNode:=nil; - for f:=low(TCEObserverCategory) to high(TCEObserverCategory) do - fObserverCatNodes[f]:=nil; - fSurroundingNode:=nil; + ClearCodeTreeView; - CodeTreeview.Items.Clear; if (ACodeTool<>nil) and (ACodeTool.Tree<>nil) and (ACodeTool.Tree.Root<>nil) then begin CreateIdentifierNodes(ACodeTool,ACodeTool.Tree.Root,nil,nil,true); @@ -2251,12 +2276,10 @@ begin DirectivesTreeView.BeginUpdate; OldExpanded:=TTreeNodeExpandedState.Create(DirectivesTreeView); - if (ADirectivesTool=nil) or (ADirectivesTool.Tree=nil) - or (ADirectivesTool.Tree.Root=nil) then + ClearDirectivesTreeView; + if (ADirectivesTool<>nil) and (ADirectivesTool.Tree<>nil) + and (ADirectivesTool.Tree.Root<>nil) then begin - DirectivesTreeView.Items.Clear; - end else begin - DirectivesTreeView.Items.Clear; CreateDirectiveNodes(ADirectivesTool,ADirectivesTool.Tree.Root,nil,nil,true); end; diff --git a/ide/main.pp b/ide/main.pp index 2e1b7d8c75..96378ef746 100644 --- a/ide/main.pp +++ b/ide/main.pp @@ -10661,8 +10661,8 @@ end; procedure TMainIDE.OnSrcNotebookCurCodeBufferChanged(Sender: TObject); begin - if SourceEditorManager.SourceEditorCount = 0 then Exit; - if CodeExplorerView<>nil then CodeExplorerView.CurrentCodeBufferChanged; + if CodeExplorerView<>nil then + CodeExplorerView.CurrentCodeBufferChanged; end; procedure TMainIDE.OnSrcNotebookShowHintForSource(SrcEdit: TSourceEditor; diff --git a/ide/sourceeditor.pp b/ide/sourceeditor.pp index 24aeb14471..c077eb0590 100644 --- a/ide/sourceeditor.pp +++ b/ide/sourceeditor.pp @@ -7284,9 +7284,12 @@ var begin // Todo: Move to manager, include window changes SrcEdit:=GetActiveSE; - if SrcEdit = nil then Exit; - if FLastCodeBuffer=SrcEdit.CodeBuffer then exit; - FLastCodeBuffer:=SrcEdit.CodeBuffer; + if SrcEdit <> nil then + begin + if FLastCodeBuffer=SrcEdit.CodeBuffer then exit; + FLastCodeBuffer:=SrcEdit.CodeBuffer; + end else if FLastCodeBuffer=nil then + exit; if assigned(Manager) and Assigned(Manager.OnCurrentCodeBufferChanged) then Manager.OnCurrentCodeBufferChanged(Self); end;