/usr/lib/lazarus/0.9.30.4/ide/findunitdlg.pas is in lazarus-src-0.9.30.4 0.9.30.4-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 | {
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
***************************************************************************
Author: Mattias Gaertner
Abstract:
Dialog to search a missing unit.
ToDo:
- search in packages on disk
}
unit FindUnitDlg;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LCLProc, Forms, Controls, Dialogs, ExtCtrls,
StdCtrls, ComCtrls, FileUtil, AvgLvlTree,
// codetools
CodeToolsStrConsts, Laz_XMLCfg, CodeCache, CodeToolManager,
// IDEIntf
LazIDEIntf, TextTools, IDEMsgIntf, PackageIntf,
// IDE
DialogProcs, PackageDefs, Project, IDEProcs, LazarusIDEStrConsts, MsgQuickFixes,
PackageLinks, PackageSystem, BasePkgManager;
type
TFindUnitDialog = class;
{ TQuickFixMissingUnit }
TQuickFixMissingUnit = class
public
Dlg: TFindUnitDialog;
Caption: string;
constructor Create(aDlg: TFindUnitDialog; aCaption: string);
end;
{ TQuickFixMissingUnitRemoveFromUses }
TQuickFixMissingUnitRemoveFromUses = class(TQuickFixMissingUnit)
public
constructor Create(aDlg: TFindUnitDialog);
end;
{ TQuickFixMissingUnitAddRequirement }
TQuickFixMissingUnitAddRequirement = class(TQuickFixMissingUnit)
public
PackageName: string;
constructor Create(aDlg: TFindUnitDialog; aPackageName: string);
end;
{ TFindUnitDialog }
TFindUnitDialog = class(TForm)
OkButton: TButton;
CancelButton: TButton;
BtnPanel: TPanel;
InfoGroupBox: TGroupBox;
ProgressBar1: TProgressBar;
QuickFixRadioGroup: TRadioGroup;
Splitter1: TSplitter;
InfoTreeView: TTreeView;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure OkButtonClick(Sender: TObject);
procedure OnIdle(Sender: TObject; var Done: Boolean);
private
FCode: TCodeBuffer;
FMainOwner: TObject;
FMainOwnerName: string;
FMissingUnitName: string;
FSearchPackages: TStrings;
FSearchPackagesIndex: integer;
fQuickFixes: TFPList;// list of TQuickFixMissingUnit
fLastUpdateProgressBar: TDateTime;
procedure InitSearchPackages;
procedure OnIteratePkgLinks(APackage: TLazPackageID);
procedure AddQuickFix(Item: TQuickFixMissingUnit);
procedure AddRequirement(Item: TQuickFixMissingUnitAddRequirement);
procedure RemoveFromUsesSection(Item: TQuickFixMissingUnitRemoveFromUses);
function MainOwnerHasRequirement(PackageName: string): boolean;
procedure UpdateProgressBar;
function CheckPackageOnDisk(PkgFilename: string): boolean;
function FindQuickFixAddRequirement(PkgName: string): TQuickFixMissingUnitAddRequirement;
public
procedure InitWithMsg(Msg: TIDEMessageLine; Line: string; aCode: TCodeBuffer;
aMissingUnitName: string);
property Code: TCodeBuffer read FCode;
property MissingUnitName: string read FMissingUnitName;
property MainOwner: TObject read FMainOwner;
property MainOwnerName: string read FMainOwnerName;
end;
{ TQuickFixUnitNotFound_Search }
TQuickFixUnitNotFound_Search = class(TIDEMsgQuickFixItem)
public
constructor Create;
function IsApplicable(Line: TIDEMessageLine): boolean; override;
procedure Execute(const Msg: TIDEMessageLine; Step: TIMQuickFixStep); override;
end;
{ TQuickFixIncludeNotFound_Search }
TQuickFixIncludeNotFound_Search = class(TIDEMsgQuickFixItem)
public
constructor Create;
function IsCodetoolsErrorIncludeFileNotFound(Msg: string;
out IncludeFile: string): boolean;
function IsApplicable(Line: TIDEMessageLine): boolean; override;
procedure Execute(const Msg: TIDEMessageLine; Step: TIMQuickFixStep); override;
end;
procedure InitFindUnitQuickFixItems;
implementation
{$R *.lfm}
procedure InitFindUnitQuickFixItems;
begin
RegisterIDEMsgQuickFix(TQuickFixUnitNotFound_Search.Create);
end;
{ TQuickFixUnitNotFound_Search }
constructor TQuickFixUnitNotFound_Search.Create;
begin
Name:='Search unit: Error: Can''t find unit Name';
Caption:=lisSearchUnit;
Steps:=[imqfoMenuItem];
end;
function TQuickFixUnitNotFound_Search.IsApplicable(Line: TIDEMessageLine
): boolean;
const
SearchStr = ') Fatal: Can''t find unit ';
var
Msg: String;
p: integer;
begin
Result:=false;
if (Line.Parts=nil) then exit;
Msg:=Line.Msg;
p:=System.Pos(SearchStr,Msg);
if p<1 then exit;
Result:=true;
end;
procedure TQuickFixUnitNotFound_Search.Execute(const Msg: TIDEMessageLine;
Step: TIMQuickFixStep);
var
AnUnitName: String;
Dlg: TFindUnitDialog;
CodeBuf: TCodeBuffer;
Filename: string;
Caret: TPoint;
begin
if Step=imqfoMenuItem then begin
DebugLn(['TQuickFixUnitNotFound_Search.Execute ']);
// get source position
if not GetMsgLineFilename(Msg,CodeBuf,false) then exit;
Msg.GetSourcePosition(Filename,Caret.Y,Caret.X);
if not LazarusIDE.BeginCodeTools then begin
DebugLn(['TQuickFixUnitNotFound_Search.Execute failed because IDE busy']);
exit;
end;
// get unitname
if not REMatches(Msg.Msg,'Fatal: Can''t find unit ([a-z_0-9]+) ','I') then begin
DebugLn('TQuickFixUnitNotFound_Search invalid message ',Msg.Msg);
exit;
end;
AnUnitName:=REVar(1);
DebugLn(['TQuickFixUnitNotFound_Search.Execute Unit=',AnUnitName]);
if (AnUnitName='') or (not IsValidIdent(AnUnitName)) then begin
DebugLn(['TQuickFixUnitNotFound_Search.Execute not an identifier "',dbgstr(AnUnitName),'"']);
exit;
end;
// show dialog
Dlg:=TFindUnitDialog.Create(nil);
try
Dlg.InitWithMsg(Msg,Msg.Msg,CodeBuf,AnUnitName);
Dlg.ShowModal;
finally
Dlg.Free;
end;
end;
end;
{ TFindUnitDialog }
procedure TFindUnitDialog.FormCreate(Sender: TObject);
begin
fQuickFixes:=TFPList.Create;
Caption:=lisFindMissingUnit;
CancelButton.Caption:=dlgCancel;
OkButton.Caption:=dlgMouseOptBtnOk;
OkButton.Enabled:=false;
InfoGroupBox.Caption:=lisInformation;
QuickFixRadioGroup.Caption:=lisQuickFixes;
Application.AddOnIdleHandler(@OnIdle);
end;
procedure TFindUnitDialog.FormDestroy(Sender: TObject);
var
i: Integer;
begin
Application.RemoveOnIdleHandler(@OnIdle);
for i:=0 to fQuickFixes.Count-1 do TObject(fQuickFixes[i]).Free;
FreeAndNil(fQuickFixes);
FreeAndNil(FSearchPackages);
end;
procedure TFindUnitDialog.OkButtonClick(Sender: TObject);
var
i: LongInt;
Item: TQuickFixMissingUnit;
begin
i:=QuickFixRadioGroup.ItemIndex;
if i<0 then begin
OkButton.Enabled:=false;
exit;
end;
Item:=TQuickFixMissingUnit(fQuickFixes[i]);
if Item is TQuickFixMissingUnitRemoveFromUses then
RemoveFromUsesSection(TQuickFixMissingUnitRemoveFromUses(Item))
else if Item is TQuickFixMissingUnitAddRequirement then
AddRequirement(TQuickFixMissingUnitAddRequirement(Item));
end;
procedure TFindUnitDialog.OnIdle(Sender: TObject; var Done: Boolean);
var
Filename: string;
i: Integer;
APackage: TLazPackage;
Found: Boolean;
t: TDateTime;
begin
t:=Now;
while (FSearchPackages<>nil) and (FSearchPackagesIndex<FSearchPackages.Count)
do begin
Filename:=FSearchPackages[FSearchPackagesIndex];
Found:=false;
// search in open packages
for i:=0 to PackageGraph.Count-1 do begin
APackage:=PackageGraph.Packages[i];
if APackage.Filename=Filename then begin
Found:=true;
if APackage.FindUnit(MissingUnitName)<>nil then begin
if MainOwnerHasRequirement(APackage.Name) then begin
// already in requirements
end else if FindQuickFixAddRequirement(APackage.Name)=nil then begin
// not yet in requirements -> add a quick fix
AddQuickFix(TQuickFixMissingUnitAddRequirement.Create(Self,APackage.Name));
end;
end;
break;
end;
end;
// search in package on disk
if not Found then begin
if CheckPackageOnDisk(Filename) then Found:=true;
end;
inc(FSearchPackagesIndex);
if FSearchPackagesIndex>=FSearchPackages.Count then begin
AddQuickFix(TQuickFixMissingUnitRemoveFromUses.Create(Self));
end;
UpdateProgressBar;
Done:=false;
if Now-t>0.5/86400 then
exit;
// process another package
end;
Done:=true;
end;
procedure TFindUnitDialog.InitSearchPackages;
var
i: Integer;
APackage: TLazPackage;
Filename: String;
begin
if FSearchPackages=nil then
FSearchPackages:=TStringList.Create;
FSearchPackages.Clear;
FSearchPackagesIndex:=0;
if MainOwner=nil then exit;
// add open packages
for i:=0 to PackageGraph.Count-1 do begin
APackage:=PackageGraph.Packages[i];
Filename:=APackage.GetResolvedFilename(true);
//DebugLn(['TFindUnitDialog.InitSearchPackages ',APackage.Name,' ',Filename]);
if (Filename='') or (not FileExistsCached(Filename)) then continue;
FSearchPackages.Add(APackage.Filename);
end;
//DebugLn(['TFindUnitDialog.InitSearchPackages ',FSearchPackages.Text]);
// add user package links
PkgLinks.IteratePackages(false,@OnIteratePkgLinks,[ploUser,ploGlobal]);
if FSearchPackages.Count>0 then begin
ProgressBar1.Max:=FSearchPackages.Count;
fLastUpdateProgressBar:=Now;
ProgressBar1.Visible:=true;
end;
end;
procedure TFindUnitDialog.OnIteratePkgLinks(APackage: TLazPackageID);
var
Link: TPackageLink;
begin
if APackage is TPackageLink then begin
Link:=TPackageLink(APackage);
FSearchPackages.Add(TrimFilename(Link.GetEffectiveFilename));
end;
end;
procedure TFindUnitDialog.AddQuickFix(Item: TQuickFixMissingUnit);
begin
fQuickFixes.Add(Item);
QuickFixRadioGroup.Items.Add(Item.Caption);
if QuickFixRadioGroup.ItemIndex<0 then
QuickFixRadioGroup.ItemIndex:=0;
OkButton.Enabled:=true;
end;
procedure TFindUnitDialog.AddRequirement(
Item: TQuickFixMissingUnitAddRequirement);
var
AProject: TProject;
APackage: TLazPackage;
NewDependency: TPkgDependency;
begin
if MainOwner is TProject then begin
AProject:=TProject(MainOwner);
//debugln(['TFindUnitDialog.AddRequirement project: ',Item.PackageName]);
NewDependency:=TPkgDependency.Create;
NewDependency.PackageName:=Item.PackageName;
if PkgBoss.AddProjectDependency(AProject,NewDependency)=mrOk then
ModalResult:=mrOK;
end else if MainOwner is TLazPackage then begin
APackage:=TLazPackage(MainOwner);
if PkgBoss.AddPackageDependency(APackage,Item.PackageName)=mrOk then
ModalResult:=mrOK;
end;
end;
procedure TFindUnitDialog.RemoveFromUsesSection(
Item: TQuickFixMissingUnitRemoveFromUses);
begin
if not CodeToolBoss.RemoveUnitFromAllUsesSections(Code,MissingUnitName) then
begin
end;
ModalResult:=mrOk;
end;
function TFindUnitDialog.MainOwnerHasRequirement(PackageName: string): boolean;
var
AProject: TProject;
APackage: TLazPackage;
begin
Result:=false;
if MainOwner=nil then exit;
if MainOwner is TProject then begin
AProject:=TProject(MainOwner);
Result:=PackageGraph.FindDependencyRecursively(
AProject.FirstRequiredDependency,PackageName)<>nil;
end else if MainOwner is TLazPackage then begin
APackage:=TLazPackage(MainOwner);
Result:=PackageGraph.FindDependencyRecursively(
APackage.FirstRequiredDependency,PackageName)<>nil;
end;
end;
procedure TFindUnitDialog.UpdateProgressBar;
begin
if (FSearchPackages=nil) or (FSearchPackagesIndex>=FSearchPackages.Count) then
begin
ProgressBar1.Visible:=false;
end;
if Now-fLastUpdateProgressBar>1/86400 then begin
ProgressBar1.Position:=FSearchPackagesIndex;
fLastUpdateProgressBar:=Now;
end;
end;
function TFindUnitDialog.CheckPackageOnDisk(PkgFilename: string): boolean;
var
r: TModalResult;
XMLConfig: TXMLConfig;
XMLCode: TCodeBuffer;
Path: String;
FileCount: LongInt;
i: Integer;
SubPath: String;
FileType: TPkgFileType;
AUnitName: String;
Filename: String;
PkgName: String;
begin
Result:=false;
PkgName:=ExtractFileNameOnly(PkgFilename);
if FindQuickFixAddRequirement(PkgName)<>nil then exit;
if not FileExistsCached(PkgFilename) then exit;
//DebugLn(['TFindUnitDialog.CheckPackageOnDisk ',PkgFilename]);
XMLConfig:=nil;
XMLCode:=nil;
try
//DebugLn(['TFindUnitDialog.CheckPackageOnDisk loading: ',PkgFilename]);
XMLConfig:=TXMLConfig.Create(nil);
r:=LoadXMLConfigFromCodeBuffer(PkgFilename,XMLConfig,
XMLCode,[lbfUpdateFromDisk,lbfRevert,lbfQuiet],false);
if r<>mrOk then begin
//DebugLn(['TFindUnitDialog.CheckPackageOnDisk failed loading: ',PkgFilename]);
exit;
end;
Path:='Package/Files/';
FileCount:=XMLConfig.GetValue(Path+'Count',0);
//DebugLn(['TFindUnitDialog.CheckPackageOnDisk FileCount=',FileCount,' ',PkgName]);
for i:=1 to FileCount do begin
SubPath:=Path+'Item'+IntToStr(i)+'/';
FileType:=PkgFileTypeIdentToType(XMLConfig.GetValue(SubPath+'Type/Value',''));
if not (FileType in PkgFileRealUnitTypes) then continue;
Filename:=XMLConfig.GetValue(SubPath+'Filename/Value','');
AUnitName:=ExtractFileNameOnly(Filename);
//DebugLn(['TFindUnitDialog.CheckPackageOnDisk ',UnitName]);
if SysUtils.CompareText(AUnitName,MissingUnitName)=0 then begin
Result:=true;
AddQuickFix(TQuickFixMissingUnitAddRequirement.Create(Self,PkgName));
exit;
end;
end;
finally
XMLConfig.Free;
end;
end;
function TFindUnitDialog.FindQuickFixAddRequirement(PkgName: string
): TQuickFixMissingUnitAddRequirement;
var
i: Integer;
begin
Result:=nil;
if fQuickFixes=nil then exit;
for i:=0 to fQuickFixes.Count-1 do begin
if TObject(fQuickFixes[i]) is TQuickFixMissingUnitAddRequirement then begin
Result:=TQuickFixMissingUnitAddRequirement(fQuickFixes[i]);
if SysUtils.CompareText(Result.PackageName,PkgName)=0 then exit;
end;
end;
Result:=nil;
end;
procedure TFindUnitDialog.InitWithMsg(Msg: TIDEMessageLine; Line: string;
aCode: TCodeBuffer; aMissingUnitName: string);
procedure AddPaths(ParentTVNode: TTreeNode; PathTitle, BaseDir, Paths: string;
Expanded: boolean);
var
p: Integer;
s: String;
PathsNode: TTreeNode;
begin
PathsNode:=InfoTreeView.Items.AddChild(ParentTVNode,PathTitle);
Paths:=CreateAbsoluteSearchPath(Paths,BaseDir);
p:=1;
repeat
s:=GetNextDirectoryInSearchPath(Paths,p);
if s<>'' then
InfoTreeView.Items.AddChild(PathsNode,dbgstr(s));
until p>length(Paths);
PathsNode.Expanded:=Expanded;
if (ParentTVNode<>nil) and Expanded then
ParentTVNode.Expanded:=true;
end;
var
UnitPath: String;
Directory: String;
DirNode: TTreeNode;
Owners: TFPList;
i: Integer;
OwnerNode: TTreeNode;
AProject: TProject;
APackage: TLazPackage;
begin
FCode:=aCode;
FMissingUnitName:=aMissingUnitName;
FMainOwner:=nil;
FMainOwnerName:='';
InfoTreeView.BeginUpdate;
InfoTreeView.Items.Clear;
Owners:=nil;
try
InfoTreeView.Items.Add(nil,'Message: '+dbgstr(Line));
InfoTreeView.Items.Add(nil,'File: '+dbgstr(aCode.Filename));
InfoTreeView.Items.Add(nil,'Missingg unit: '+dbgstr(aMissingUnitName));
Directory:=ExtractFilePath(aCode.Filename);
DirNode:=InfoTreeView.Items.Add(nil,'Directory: '+dbgstr(Directory));
// unit path of directory
UnitPath:=CodeToolBoss.GetUnitPathForDirectory(Directory);
AddPaths(DirNode,'IDE unit search path:',Directory,UnitPath,false);
//
Owners:=PackageEditingInterface.GetOwnersOfUnit(aCode.Filename);
if Owners<>nil then begin
for i:=0 to Owners.Count-1 do begin
if TObject(Owners[i]) is TProject then begin
AProject:=TProject(Owners[i]);
if FMainOwner=nil then begin
FMainOwner:=AProject;
FMainOwnerName:='project';
end;
OwnerNode:=InfoTreeView.Items.Add(nil,'Owner: Project');
AddPaths(OwnerNode,'Unit search paths',AProject.ProjectDirectory,
AProject.CompilerOptions.GetUnitPath(true),true);
end
else if TObject(Owners[i]) is TLazPackage then begin
APackage:=TLazPackage(Owners[i]);
if FMainOwner=nil then begin
FMainOwner:=APackage;
FMainOwnerName:=APackage.Name;
end;
OwnerNode:=InfoTreeView.Items.Add(nil,'Owner: Package '+APackage.IDAsString);
AddPaths(OwnerNode,'Unit search paths',APackage.Directory,
APackage.CompilerOptions.GetUnitPath(true),true);
end;
end;
end;
finally
Owners.Free;
end;
InfoTreeView.EndUpdate;
InitSearchPackages;
end;
{ TQuickFixMissingUnit }
constructor TQuickFixMissingUnit.Create(aDlg: TFindUnitDialog; aCaption: string);
begin
Dlg:=aDlg;;
Caption:=aCaption;
end;
{ TQuickFixMissingUnitAddRequirement }
constructor TQuickFixMissingUnitAddRequirement.Create(aDlg: TFindUnitDialog;
aPackageName: string);
begin
PackageName:=aPackageName;
Caption:='Add package '+PackageName+' as requirement to '+aDlg.MainOwnerName;
end;
{ TQuickFixMissingUnitRemoveFromUses }
constructor TQuickFixMissingUnitRemoveFromUses.Create(aDlg: TFindUnitDialog);
begin
Caption:='Remove unit from uses clause';
end;
{ TQuickFixIncludeNotFound_Search }
constructor TQuickFixIncludeNotFound_Search.Create;
begin
Name:='Search include file: Error: include file not found';
Caption:=lisSearchUnit;
Steps:=[imqfoMenuItem];
end;
function TQuickFixIncludeNotFound_Search.IsCodetoolsErrorIncludeFileNotFound(
Msg: string; out IncludeFile: string): boolean;
var
SearchStr: String;
p: integer;
StartPos: LongInt;
begin
IncludeFile:='';
// check for codetools 'include file not found'
SearchStr:=ctsIncludeFileNotFound;
p:=System.Pos('%',SearchStr);
if p>0 then SearchStr:=copy(SearchStr,1,p-1);
SearchStr:=SearchStr+': '+SearchStr; // e.g.: ': include file not found "'
p:=System.Pos(SearchStr,Msg);
if p<1 then exit(false);
Result:=true;
inc(p,length(SearchStr));
StartPos:=p;
while (p<=length(Msg)) and (Msg[p]<>'"') do inc(p);
IncludeFile:=copy(Msg,StartPos,p-StartPos);
end;
function TQuickFixIncludeNotFound_Search.IsApplicable(Line: TIDEMessageLine
): boolean;
var
Filename: string;
begin
Result:=IsCodetoolsErrorIncludeFileNotFound(Line.Msg,Filename)
and (Filename<>'');
end;
procedure TQuickFixIncludeNotFound_Search.Execute(const Msg: TIDEMessageLine;
Step: TIMQuickFixStep);
var
CodeBuf: TCodeBuffer;
Filename, IncludeFilename: string;
Caret: TPoint;
Dlg: TFindUnitDialog;
begin
if Step=imqfoMenuItem then begin
DebugLn(['TQuickFixIncludeNotFound_Search.Execute ']);
// get source position
if not GetMsgLineFilename(Msg,CodeBuf,false) then exit;
Msg.GetSourcePosition(Filename,Caret.Y,Caret.X);
if not LazarusIDE.BeginCodeTools then begin
DebugLn(['TQuickFixIncludeNotFound_Search.Execute failed because IDE busy']);
exit;
end;
// get include file name
if not IsCodetoolsErrorIncludeFileNotFound(Msg.Msg,IncludeFilename) then
begin
DebugLn('TQuickFixIncludeNotFound_Search invalid message ',Msg.Msg);
exit;
end;
DebugLn(['TQuickFixIncludeNotFound_Search.Execute include file=',IncludeFilename]);
// show dialog
Dlg:=TFindUnitDialog.Create(nil);
try
Dlg.InitWithMsg(Msg,Msg.Msg,CodeBuf,IncludeFilename);
Dlg.ShowModal;
finally
Dlg.Free;
end;
end;
end;
end.
|