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