mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 18:58:04 +02:00
Jedi code format: find include files without extension (.inc, .pp, .pas)
This commit is contained in:
parent
1c97b17a3a
commit
3f542bc813
@ -117,7 +117,7 @@ begin
|
||||
begin
|
||||
// search in the same path as formated unit.
|
||||
lsFile := ExtractFilePath(TConverter(Sender).FileName) + AIncludeFileName;
|
||||
lbFileFound := FileExists(lsFile);
|
||||
lbFileFound := CheckIfFileExistsWithStdIncludeExtensions(lsFile);
|
||||
|
||||
// search in project include paths. c:\p1\;c:\p2\;c:\p3\
|
||||
liStart := 1;
|
||||
@ -137,7 +137,7 @@ begin
|
||||
lsDir:=CreateAbsolutePath(lsDir,IncludeTrailingPathDelimiter(GetCurrentDir));
|
||||
end;
|
||||
lsFile := lsDir + AIncludeFileName;
|
||||
lbFileFound := FileExists(lsFile);
|
||||
lbFileFound := CheckIfFileExistsWithStdIncludeExtensions(lsFile);
|
||||
end;
|
||||
end
|
||||
else
|
||||
@ -145,7 +145,7 @@ begin
|
||||
if FilenameIsAbsolute(AIncludeFileName) then
|
||||
begin
|
||||
lsFile := AIncludeFileName;
|
||||
lbFileFound := FileExists(lsFile);
|
||||
lbFileFound := CheckIfFileExistsWithStdIncludeExtensions(lsFile);
|
||||
end;
|
||||
end;
|
||||
if lbFileFound then
|
||||
|
@ -504,7 +504,7 @@ end;
|
||||
|
||||
procedure TJcfIdeMain.OnIncludeFile(Sender: TObject; AIncludeFileName: string; var AFileContentOrErrorMessage: string; var AFileReaded: boolean);
|
||||
var
|
||||
lsFile: string;
|
||||
lsFile, lsFileExt: string;
|
||||
lsDir: string;
|
||||
lbFileFound: boolean;
|
||||
|
||||
@ -522,43 +522,73 @@ var
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
lbFileFound := False;
|
||||
procedure TryFile(const AFN: string);
|
||||
begin
|
||||
if aFN = '' then
|
||||
Exit;
|
||||
if IsOnIdeEditor(AFN) then
|
||||
lbFileFound := True
|
||||
else
|
||||
lbFileFound := FileExists(AFN);
|
||||
if lbFileFound then
|
||||
lsFile := AFN;
|
||||
end;
|
||||
|
||||
begin
|
||||
AFileReaded := False;
|
||||
lbFileFound := False;
|
||||
lsFile := '';
|
||||
lsFileExt := LowerCase(ExtractFileExt(AIncludeFileName));
|
||||
if ExtractFilePath(AIncludeFileName) = '' then
|
||||
begin
|
||||
// seach in the same path as formated unit.
|
||||
lsFile := ExtractFilePath(TConverter(Sender).FileName) + AIncludeFileName;
|
||||
if IsOnIdeEditor(lsFile) then
|
||||
Exit;
|
||||
lbFileFound := FileExists(lsFile);
|
||||
end
|
||||
else
|
||||
begin
|
||||
if FilenameIsAbsolute(AIncludeFileName) then
|
||||
lsFile := AIncludeFileName
|
||||
else
|
||||
lsFile := ExtractFilePath(TConverter(Sender).FileName) + AIncludeFileName;
|
||||
end;
|
||||
if lsFile <> '' then
|
||||
begin
|
||||
TryFile(lsFile);
|
||||
if (not lbFileFound) and ((lsFileExt <> '.inc') and (lsFileExt <> '.pp') and (lsFileExt <> '.pas')) then
|
||||
begin
|
||||
lsFile := AIncludeFileName;
|
||||
if IsOnIdeEditor(lsFile) then
|
||||
Exit;
|
||||
lbFileFound := FileExists(lsFile);
|
||||
TryFile(lsfile + '.inc');
|
||||
if not lbFileFound then
|
||||
TryFile(lsfile + '.pp');
|
||||
if not lbFileFound then
|
||||
TryFile(lsfile + 'pas');
|
||||
end;
|
||||
if (not lbFileFound) and (lsFileExt = ExtensionSeparator) and (Length(AIncludeFileName) >= 2) then
|
||||
TryFile(Copy(AIncludeFileName, 1, Length(AIncludeFileName) - 1));
|
||||
end;
|
||||
// search in project dir and project include paths.
|
||||
if not lbFileFound then
|
||||
begin
|
||||
lsDir := LazProject1.Directory;
|
||||
lsFile := LazarusIDE.FindSourceFile(AIncludeFileName, lsDir, [fsfSearchForProject, fsfUseIncludePaths]);
|
||||
lbFileFound := lsFile <> '';
|
||||
if lsFile <> '' then
|
||||
TryFile(LazarusIDE.FindSourceFile(AIncludeFileName, lsDir, [fsfSearchForProject, fsfUseIncludePaths]));
|
||||
if (not lbFileFound) and ((lsFileExt <> '.inc') and (lsFileExt <> '.pp') and (lsFileExt <> '.pas')) then
|
||||
begin
|
||||
if IsOnIdeEditor(lsFile) then
|
||||
Exit;
|
||||
{ try default extensions .inc , .pp and .pas }
|
||||
TryFile(LazarusIDE.FindSourceFile(AIncludeFileName + '.inc', lsDir, [fsfSearchForProject, fsfUseIncludePaths]));
|
||||
if not lbFileFound then
|
||||
TryFile(LazarusIDE.FindSourceFile(AIncludeFileName + '.pp', lsDir, [fsfSearchForProject, fsfUseIncludePaths]));
|
||||
if not lbFileFound then
|
||||
TryFile(LazarusIDE.FindSourceFile(AIncludeFileName + '.pas', lsDir, [fsfSearchForProject, fsfUseIncludePaths]));
|
||||
end;
|
||||
if (not lbFileFound) and (lsFileExt = ExtensionSeparator) and (Length(AIncludeFileName) >= 2) then
|
||||
TryFile(LazarusIDE.FindSourceFile(Copy(AIncludeFileName, 1, Length(AIncludeFileName) - 1), lsDir, [fsfSearchForProject, fsfUseIncludePaths]));
|
||||
end;
|
||||
if lbFileFound then
|
||||
begin
|
||||
AFileContentOrErrorMessage := ReadFileToUTF8String(lsFile);
|
||||
AFileReaded := True;
|
||||
if not AFileReaded then
|
||||
begin
|
||||
AFileContentOrErrorMessage := ReadFileToUTF8String(lsFile);
|
||||
AFileReaded := True;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
|
@ -1,7 +1,7 @@
|
||||
unit JcfUiToolsNoGUI;
|
||||
|
||||
{$mode ObjFPC}
|
||||
|
||||
{$WARN 5024 off : Parameter "$1" not used}
|
||||
interface
|
||||
|
||||
uses
|
||||
|
@ -68,6 +68,7 @@ procedure AdvanceTextPos(const AText: String; var ARow, ACol: integer);
|
||||
function LastLineLength(const AString: string): integer;
|
||||
function ReadFileToUTF8String(AFilename: string): string;
|
||||
function GetConfigFileNameJcf:string;
|
||||
function CheckIfFileExistsWithStdIncludeExtensions(var AIncludeFile:string):boolean;
|
||||
|
||||
var
|
||||
GetConfigFileNameJcfFunction:GetConfigFileNameFunction = nil;
|
||||
@ -361,4 +362,41 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function CheckIfFileExistsWithStdIncludeExtensions(var AIncludeFile: string): boolean;
|
||||
var
|
||||
fileext: string;
|
||||
found: boolean;
|
||||
filename: string;
|
||||
begin
|
||||
if FileExists(AIncludeFile) then
|
||||
exit(True);
|
||||
found := False;
|
||||
filename := AIncludeFile;
|
||||
fileext := LowerCase(ExtractFileExt(AIncludeFile));
|
||||
if (not found) and ((fileext <> '.inc') and (fileext <> '.pp') and (fileext <> '.pas')) then
|
||||
begin
|
||||
{ try default extensions .inc , .pp and .pas }
|
||||
filename := AIncludeFile + '.inc';
|
||||
found := FileExists(filename);
|
||||
if not found then
|
||||
begin
|
||||
filename := AIncludeFile + '.pp';
|
||||
found := FileExists(filename);
|
||||
end;
|
||||
if not found then
|
||||
begin
|
||||
filename := AIncludeFile + '.pas';
|
||||
found := FileExists(filename);
|
||||
end;
|
||||
end;
|
||||
if (not found) and (fileext = ExtensionSeparator) and (Length(AIncludeFile) >= 2) then
|
||||
begin
|
||||
filename := Copy(AIncludeFile, 1, Length(AIncludeFile) - 1);
|
||||
found := FileExists(filename);
|
||||
end;
|
||||
if found then
|
||||
AIncludeFile := filename;
|
||||
Result := found;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user