From a1d014b6627c8a9b83a3965e12b141bf1e864c5a Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 19 Aug 2017 13:13:46 +0000 Subject: [PATCH] IDE: quickfixes: auto open changed units, bug #32284 git-svn-id: branches/fixes_1_8@55700 - --- ide/etquickfixes.pas | 82 +++++++++++++++++++++++++++------------ ide/qfinitlocalvardlg.pas | 22 +++++++---- 2 files changed, 72 insertions(+), 32 deletions(-) diff --git a/ide/etquickfixes.pas b/ide/etquickfixes.pas index 4273e4954c..04ef41c16f 100644 --- a/ide/etquickfixes.pas +++ b/ide/etquickfixes.pas @@ -95,7 +95,7 @@ type procedure QuickFix({%H-}Fixes: TMsgQuickFixes; Msg: TMessageLine); override; end; - { TQuickFixUnitNotFound_Remove } + { TQuickFixUnitNotFound_Remove, also "unit not used" } TQuickFixUnitNotFound_Remove = class(TMsgQuickFix) public @@ -327,6 +327,7 @@ var Tool: TCodeTool; Code: TCodeBuffer; Comment: String; + OldChange: Boolean; begin if not IsApplicable(Msg,MsgID,Tool) then exit; @@ -341,12 +342,18 @@ begin exit; end; - Comment:=' : '+TIDEFPCParser.GetFPCMsgPattern(Msg); - if not CodeToolBoss.AddUnitWarnDirective(Code,IntToStr(MsgID),Comment,true) then - begin - DebugLn(['TQuickFix_HideWithCompilerDirective CodeToolBoss.AddUnitWarnDirective failed']); - LazarusIDE.DoJumpToCodeToolBossError; - exit; + OldChange:=LazarusIDE.OpenEditorsOnCodeToolChange; + LazarusIDE.OpenEditorsOnCodeToolChange:=true; + try + Comment:=' : '+TIDEFPCParser.GetFPCMsgPattern(Msg); + if not CodeToolBoss.AddUnitWarnDirective(Code,IntToStr(MsgID),Comment,true) then + begin + DebugLn(['TQuickFix_HideWithCompilerDirective CodeToolBoss.AddUnitWarnDirective failed']); + LazarusIDE.DoJumpToCodeToolBossError; + exit; + end; + finally + LazarusIDE.OpenEditorsOnCodeToolChange:=OldChange; end; // success @@ -626,6 +633,7 @@ procedure TQuickFixLocalVariableNotUsed_Remove.QuickFix(Fixes: TMsgQuickFixes; var Identifier: String; Code: TCodeBuffer; + OldChange: Boolean; begin if not IsApplicable(Msg,Identifier) then exit; @@ -637,11 +645,17 @@ begin Code:=CodeToolBoss.LoadFile(Msg.GetFullFilename,true,false); if Code=nil then exit; - if not CodeToolBoss.RemoveIdentifierDefinition(Code,Msg.Column,Msg.Line) then - begin - DebugLn(['TQuickFixLocalVariableNotUsed_Remove remove failed']); - LazarusIDE.DoJumpToCodeToolBossError; - exit; + OldChange:=LazarusIDE.OpenEditorsOnCodeToolChange; + LazarusIDE.OpenEditorsOnCodeToolChange:=true; + try + if not CodeToolBoss.RemoveIdentifierDefinition(Code,Msg.Column,Msg.Line) then + begin + DebugLn(['TQuickFixLocalVariableNotUsed_Remove remove failed']); + LazarusIDE.DoJumpToCodeToolBossError; + exit; + end; + finally + LazarusIDE.OpenEditorsOnCodeToolChange:=OldChange; end; // message fixed @@ -789,6 +803,7 @@ var MissingUnitName: string; SrcUnitName: string; Code: TCodeBuffer; + OldChange: Boolean; begin if not IsApplicable(Msg,MissingUnitName,SrcUnitName) then begin debugln(['TQuickFixUnitNotFound_Remove.QuickFix invalid message ',Msg.Msg]); @@ -803,15 +818,21 @@ begin Code:=CodeToolBoss.LoadFile(Msg.GetFullFilename,true,false); if Code=nil then exit; - if not CodeToolBoss.RemoveUnitFromAllUsesSections(Code,MissingUnitName) then - begin - DebugLn(['TQuickFixUnitNotFound_Remove RemoveUnitFromAllUsesSections failed']); - LazarusIDE.DoJumpToCodeToolBossError; - exit; - end; + OldChange:=LazarusIDE.OpenEditorsOnCodeToolChange; + LazarusIDE.OpenEditorsOnCodeToolChange:=true; + try + if not CodeToolBoss.RemoveUnitFromAllUsesSections(Code,MissingUnitName) then + begin + DebugLn(['TQuickFixUnitNotFound_Remove RemoveUnitFromAllUsesSections failed']); + LazarusIDE.DoJumpToCodeToolBossError; + exit; + end; - // success - Msg.MarkFixed; + // success + Msg.MarkFixed; + finally + LazarusIDE.OpenEditorsOnCodeToolChange:=OldChange; + end; end; { TQuickFixIdentifierNotFoundAddLocal } @@ -868,6 +889,7 @@ var NewX: integer; NewY: integer; NewTopLine: integer; + OldChange: Boolean; begin if not IsApplicable(Msg,Identifier) then exit; @@ -879,11 +901,17 @@ begin Code:=CodeToolBoss.LoadFile(Msg.GetFullFilename,true,false); if Code=nil then exit; - if not CodeToolBoss.CreateVariableForIdentifier(Code,Msg.Column,Msg.Line,-1, - NewCode,NewX,NewY,NewTopLine,False) - then begin - LazarusIDE.DoJumpToCodeToolBossError; - exit; + OldChange:=LazarusIDE.OpenEditorsOnCodeToolChange; + LazarusIDE.OpenEditorsOnCodeToolChange:=true; + try + if not CodeToolBoss.CreateVariableForIdentifier(Code,Msg.Column,Msg.Line,-1, + NewCode,NewX,NewY,NewTopLine,False) + then begin + LazarusIDE.DoJumpToCodeToolBossError; + exit; + end; + finally + LazarusIDE.OpenEditorsOnCodeToolChange:=OldChange; end; // success @@ -929,7 +957,10 @@ var Tree: TAvlTree; Node: TAvlTreeNode; i: Integer; + OldChange: Boolean; begin + OldChange:=LazarusIDE.OpenEditorsOnCodeToolChange; + LazarusIDE.OpenEditorsOnCodeToolChange:=true; Tree:=TAvlTree.Create(@CompareMsgLinesSrcPos); try // get all messages to hide and sort them for position @@ -957,6 +988,7 @@ begin Node:=Node.Precessor; end; finally + LazarusIDE.OpenEditorsOnCodeToolChange:=OldChange; Tree.Free; end; end; diff --git a/ide/qfinitlocalvardlg.pas b/ide/qfinitlocalvardlg.pas index 1ce70a7fb8..ac1a49ea2f 100644 --- a/ide/qfinitlocalvardlg.pas +++ b/ide/qfinitlocalvardlg.pas @@ -120,14 +120,22 @@ begin end; procedure TQFInitLocalVarDialog.ButtonPanel1OKButtonClick(Sender: TObject); +var + OldChange: Boolean; begin - if CodeToolBoss.InsertStatements( - TInsertStatementPosDescription(InsertPositions[Max(0,WhereRadioGroup.ItemIndex)]), - Statements[Max(0,ValueRadioGroup.ItemIndex)]) - then begin - ModalResult:=mrOk; - end else begin - ModalResult:=mrAbort; + OldChange:=LazarusIDE.OpenEditorsOnCodeToolChange; + LazarusIDE.OpenEditorsOnCodeToolChange:=true; + try + if CodeToolBoss.InsertStatements( + TInsertStatementPosDescription(InsertPositions[Max(0,WhereRadioGroup.ItemIndex)]), + Statements[Max(0,ValueRadioGroup.ItemIndex)]) + then begin + ModalResult:=mrOk; + end else begin + ModalResult:=mrAbort; + end; + finally + LazarusIDE.OpenEditorsOnCodeToolChange:=OldChange; end; end;