mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-25 01:30:37 +01:00
IDE: open file at cursor: for Pascal files use codetools
git-svn-id: trunk@53312 -
This commit is contained in:
parent
4eaf02c3a1
commit
31d3f43475
@ -7835,7 +7835,7 @@ end;
|
|||||||
|
|
||||||
procedure TSourceNotebook.OpenAtCursorClicked(Sender: TObject);
|
procedure TSourceNotebook.OpenAtCursorClicked(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
if assigned(Manager) and Assigned(Manager.OnOpenFileAtCursorClicked) then
|
if Assigned(Manager) and Assigned(Manager.OnOpenFileAtCursorClicked) then
|
||||||
Manager.OnOpenFileAtCursorClicked(Sender);
|
Manager.OnOpenFileAtCursorClicked(Sender);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,7 @@ uses
|
|||||||
DiskDiffsDialog, InputHistory, CheckLFMDlg, LCLMemManager, CodeToolManager,
|
DiskDiffsDialog, InputHistory, CheckLFMDlg, LCLMemManager, CodeToolManager,
|
||||||
CodeToolsStructs, ConvCodeTool, CodeCache, CodeTree, FindDeclarationTool,
|
CodeToolsStructs, ConvCodeTool, CodeCache, CodeTree, FindDeclarationTool,
|
||||||
BasicCodeTools, SynEdit, UnitResources, IDEExternToolIntf, ObjectInspector,
|
BasicCodeTools, SynEdit, UnitResources, IDEExternToolIntf, ObjectInspector,
|
||||||
PublishModule, etMessagesWnd,
|
PublishModule, etMessagesWnd, SourceSynEditor,
|
||||||
FormEditingIntf, fpjson;
|
FormEditingIntf, fpjson;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -314,23 +314,23 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function SourceFileMgr: TLazSourceFileManager;
|
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;
|
||||||
|
|
||||||
// Wrappers for TFileOpener methods.
|
// Wrappers for TFileOpener methods.
|
||||||
// WindowIndex is WindowID
|
// WindowIndex is WindowID
|
||||||
function GetAvailableUnitEditorInfo(AnUnitInfo: TUnitInfo;
|
function GetAvailableUnitEditorInfo(AnUnitInfo: TUnitInfo;
|
||||||
ACaretPoint: TPoint; WantedTopLine: integer = -1): TUnitEditorInfo;
|
ACaretPoint: TPoint; WantedTopLine: integer = -1): TUnitEditorInfo;
|
||||||
function OpenEditorFile(AFileName: string; PageIndex, WindowIndex: integer;
|
function OpenEditorFile(AFileName: string; PageIndex, WindowIndex: integer;
|
||||||
AEditorInfo: TUnitEditorInfo; Flags: TOpenFlags; UseWindowID: Boolean = False): TModalResult;
|
AEditorInfo: TUnitEditorInfo; Flags: TOpenFlags; UseWindowID: Boolean = False): TModalResult;
|
||||||
function OpenFileAtCursor(ActiveSrcEdit: TSourceEditor;
|
function OpenFileAtCursor(ActiveSrcEdit: TSourceEditor;
|
||||||
ActiveUnitInfo: TUnitInfo): TModalResult;
|
ActiveUnitInfo: TUnitInfo): TModalResult;
|
||||||
function OpenMainUnit(PageIndex, WindowIndex: integer;
|
function OpenMainUnit(PageIndex, WindowIndex: integer;
|
||||||
Flags: TOpenFlags; UseWindowID: Boolean = False): TModalResult;
|
Flags: TOpenFlags; UseWindowID: Boolean = False): TModalResult;
|
||||||
function RevertMainUnit: TModalResult;
|
function RevertMainUnit: TModalResult;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -1487,57 +1487,84 @@ var
|
|||||||
NewFilename,InFilename: string;
|
NewFilename,InFilename: string;
|
||||||
AUnitName: String;
|
AUnitName: String;
|
||||||
SearchPath: String;
|
SearchPath: String;
|
||||||
|
Edit: TIDESynEditor;
|
||||||
|
FoundType: TFindFileAtCursorFlag;
|
||||||
begin
|
begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
if (FActiveSrcEdit=nil) or (FActiveUnitInfo=nil) then exit;
|
if (FActiveSrcEdit=nil) or (FActiveUnitInfo=nil) then exit;
|
||||||
BaseDir:=ExtractFilePath(FActiveUnitInfo.Filename);
|
BaseDir:=ExtractFilePath(FActiveUnitInfo.Filename);
|
||||||
|
|
||||||
// parse FFileName at cursor
|
|
||||||
Found:=false;
|
Found:=false;
|
||||||
FFileName:=GetFilenameAtRowCol(FActiveSrcEdit.EditorComponent.LogicalCaretXY);
|
|
||||||
if FFileName='' then exit;
|
|
||||||
|
|
||||||
// check if absolute FFileName
|
// check if a filename is selected
|
||||||
if FilenameIsAbsolute(FFileName) then begin
|
Edit:=FActiveSrcEdit.EditorComponent;
|
||||||
if FileExistsCached(FFileName) then
|
if Edit.SelAvail and (Edit.BlockBegin.Y=Edit.BlockBegin.X) then begin
|
||||||
|
FFileName:=ResolveDots(Edit.SelText);
|
||||||
|
if not FilenameIsAbsolute(FFileName) then
|
||||||
|
FFileName:=ResolveDots(BaseDir+FFileName);
|
||||||
|
if FilenameIsAbsolute(FFileName) then begin
|
||||||
|
if FileExistsCached(FFileName) then
|
||||||
|
Found:=true
|
||||||
|
else
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// in a Pascal file use codetools
|
||||||
|
if FilenameIsPascalSource(FActiveUnitInfo.Filename) then begin
|
||||||
|
if CodeToolBoss.FindFileAtCursor(FActiveSrcEdit.CodeBuffer,
|
||||||
|
Edit.LogicalCaretXY.X,Edit.LogicalCaretXY.Y,FoundType,FFileName) then
|
||||||
Found:=true
|
Found:=true
|
||||||
else
|
else
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if FIsIncludeDirective then
|
if not Found then begin
|
||||||
begin
|
// parse FFileName at cursor
|
||||||
if (not Found) then begin
|
FFileName:=GetFilenameAtRowCol(FActiveSrcEdit.EditorComponent.LogicalCaretXY);
|
||||||
// search include file
|
if FFileName='' then exit;
|
||||||
SearchPath:='.;'+CodeToolBoss.DefineTree.GetIncludePathForDirectory(BaseDir);
|
// check if absolute FFileName
|
||||||
if FindFile(SearchPath) then // sets FFileName if result=true
|
if FilenameIsAbsolute(FFileName) then begin
|
||||||
Found:=true;
|
if FileExistsCached(FFileName) then
|
||||||
end;
|
Found:=true
|
||||||
end else
|
else
|
||||||
begin
|
exit;
|
||||||
if (not Found) then
|
|
||||||
begin
|
|
||||||
// search pascal unit without extension
|
|
||||||
AUnitName:=FFileName;
|
|
||||||
InFilename:='';
|
|
||||||
NewFilename:=CodeToolBoss.DirectoryCachePool.FindUnitSourceInCompletePath(
|
|
||||||
BaseDir,AUnitName,InFilename,true);
|
|
||||||
if NewFilename<>'' then begin
|
|
||||||
Found:=true;
|
|
||||||
FFileName:=NewFilename;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (not Found) and (ExtractFileExt(FFileName)<>'') then
|
if FIsIncludeDirective then
|
||||||
begin
|
begin
|
||||||
// search pascal unit with extension
|
if (not Found) then begin
|
||||||
AUnitName:=ExtractFileNameOnly(FFileName);
|
// search include file
|
||||||
InFilename:=FFileName;
|
SearchPath:='.;'+CodeToolBoss.DefineTree.GetIncludePathForDirectory(BaseDir);
|
||||||
NewFilename:=CodeToolBoss.DirectoryCachePool.FindUnitSourceInCompletePath(
|
if FindFile(SearchPath) then // sets FFileName if result=true
|
||||||
BaseDir,AUnitName,InFilename,true);
|
Found:=true;
|
||||||
if NewFilename<>'' then begin
|
end;
|
||||||
Found:=true;
|
end else
|
||||||
FFileName:=NewFilename;
|
begin
|
||||||
|
if (not Found) then
|
||||||
|
begin
|
||||||
|
// search pascal unit without extension
|
||||||
|
AUnitName:=FFileName;
|
||||||
|
InFilename:='';
|
||||||
|
NewFilename:=CodeToolBoss.DirectoryCachePool.FindUnitSourceInCompletePath(
|
||||||
|
BaseDir,AUnitName,InFilename,true);
|
||||||
|
if NewFilename<>'' then begin
|
||||||
|
Found:=true;
|
||||||
|
FFileName:=NewFilename;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if (not Found) and (ExtractFileExt(FFileName)<>'') then
|
||||||
|
begin
|
||||||
|
// search pascal unit with extension
|
||||||
|
AUnitName:=ExtractFileNameOnly(FFileName);
|
||||||
|
InFilename:=FFileName;
|
||||||
|
NewFilename:=CodeToolBoss.DirectoryCachePool.FindUnitSourceInCompletePath(
|
||||||
|
BaseDir,AUnitName,InFilename,true);
|
||||||
|
if NewFilename<>'' then begin
|
||||||
|
Found:=true;
|
||||||
|
FFileName:=NewFilename;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user