mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 17:59:22 +02:00
IDE: Optimise the logic for symlinked files. Issue #32292.
git-svn-id: trunk@55994 -
This commit is contained in:
parent
832ce1039a
commit
fd4150950b
@ -339,7 +339,6 @@ function SourceFileMgr: TLazSourceFileManager;
|
|||||||
function CreateSrcEditPageName(const AnUnitName, AFilename: string;
|
function CreateSrcEditPageName(const AnUnitName, AFilename: string;
|
||||||
IgnoreEditor: TSourceEditor): string;
|
IgnoreEditor: TSourceEditor): string;
|
||||||
procedure UpdateDefaultPasFileExt;
|
procedure UpdateDefaultPasFileExt;
|
||||||
function SplitSrcPath(const ASearchPath, ACurrentDir: string): string;
|
|
||||||
|
|
||||||
// Wrappers for TFileOpener methods.
|
// Wrappers for TFileOpener methods.
|
||||||
// WindowIndex is WindowID
|
// WindowIndex is WindowID
|
||||||
@ -390,9 +389,8 @@ begin
|
|||||||
LazProjectFileDescriptors.DefaultPascalFileExt:=DefPasExt;
|
LazProjectFileDescriptors.DefaultPascalFileExt:=DefPasExt;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SplitSrcPath(const ASearchPath, ACurrentDir: string): string;
|
function UseCurrentDirInSrcPath(const ASearchPath, ACurrentDir: string): string;
|
||||||
// Splits a ";" separated list of search paths into a TStringList.
|
// Replace path "." with ACurrentDir in a ";" separated list of search paths.
|
||||||
// Replace path "." with ACurrentDir.
|
|
||||||
var
|
var
|
||||||
p: Integer;
|
p: Integer;
|
||||||
Dir: String;
|
Dir: String;
|
||||||
@ -1217,30 +1215,27 @@ end;
|
|||||||
|
|
||||||
function TFileOpener.ResolvePossibleSymlink: TModalResult;
|
function TFileOpener.ResolvePossibleSymlink: TModalResult;
|
||||||
// Check if symlink and ask user if the real file should be opened instead.
|
// Check if symlink and ask user if the real file should be opened instead.
|
||||||
// Note that compiler never resolves symlinks, so files in the compiler
|
// Compiler never resolves symlinks, files in compiler search path must not be resolved.
|
||||||
// search path must not be resolved.
|
// If there already is an editor with a "physical" target of a symlink, use it.
|
||||||
var
|
var
|
||||||
Path, Target: String; // Search path and target file for the symlink.
|
SPath, Target: String; // Search path and target file for the symlink.
|
||||||
begin
|
begin
|
||||||
Result := mrOK;
|
Result := mrOK;
|
||||||
Assert(FileExistsCached(FFilename),'TFileOpener.ResolveSymlink: '+FFilename+' does not exist.');
|
Assert(FileExistsCached(FFilename),'TFileOpener.ResolveSymlink: '+FFilename+' does not exist.');
|
||||||
// Include absolute Project1.Directory in the search path.
|
|
||||||
Path := SplitSrcPath(CodeToolBoss.GetCompleteSrcPathForDirectory(''), Project1.Directory);
|
|
||||||
if (SearchDirectoryInSearchPath(Path, ExtractFilePath(FFileName)) > 0)
|
|
||||||
or Assigned(SourceEditorManager.SourceEditorIntfWithFilename(FFileName))
|
|
||||||
then // FileName found in search path or in editor -> all good.
|
|
||||||
Exit;
|
|
||||||
// File is not in project search path nor open in editor => check for a symlink.
|
|
||||||
Target := GetPhysicalFilenameCached(FFileName,false);
|
Target := GetPhysicalFilenameCached(FFileName,false);
|
||||||
if Target <> FFilename then
|
if Target = FFilename then Exit; // Not a symlink, continue with FFilename.
|
||||||
begin // A symlink
|
// ToDo: Check if there is an editor with a symlink for this "physical" file.
|
||||||
if (SearchDirectoryInSearchPath(Path, ExtractFilePath(Target)) > 0)
|
|
||||||
|
// Include absolute Project1.Directory in the search path.
|
||||||
|
SPath := UseCurrentDirInSrcPath(CodeToolBoss.GetCompleteSrcPathForDirectory(''),
|
||||||
|
Project1.Directory);
|
||||||
|
// Check if "physical" target for a symlink is found in search path or in editor.
|
||||||
|
if (SearchDirectoryInSearchPath(SPath, ExtractFilePath(Target)) > 0)
|
||||||
or Assigned(SourceEditorManager.SourceEditorIntfWithFilename(Target))
|
or Assigned(SourceEditorManager.SourceEditorIntfWithFilename(Target))
|
||||||
then // Target found in search path or in editor -> use Target name.
|
then // Target found -> use Target name.
|
||||||
FFileName := Target
|
FFileName := Target
|
||||||
else // Neither filename nor target was found anywhere, ask user.
|
else // Not found anywhere, ask user.
|
||||||
Result := ChooseSymlink(FFileName, Target);
|
Result := ChooseSymlink(FFileName, Target);
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFileOpener.OpenEditorFile(APageIndex, AWindowIndex: integer;
|
function TFileOpener.OpenEditorFile(APageIndex, AWindowIndex: integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user