IDE: quickfixes: auto open changed units, bug #32284

git-svn-id: branches/fixes_1_8@55700 -
This commit is contained in:
mattias 2017-08-19 13:13:46 +00:00
parent 10cd94e815
commit a1d014b662
2 changed files with 72 additions and 32 deletions

View File

@ -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;

View File

@ -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;