mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 03:59:13 +02:00
IDEint: DoRunFile: added parameter Filename to compile an arbitrary file
git-svn-id: trunk@50444 -
This commit is contained in:
parent
bdf06f4530
commit
d6b6f6739e
@ -337,7 +337,8 @@ type
|
|||||||
function DoBuildFile({%H-}ShowAbort: Boolean;
|
function DoBuildFile({%H-}ShowAbort: Boolean;
|
||||||
Filename: string = '' // if empty use active source editor file
|
Filename: string = '' // if empty use active source editor file
|
||||||
): TModalResult; virtual; abstract;
|
): TModalResult; virtual; abstract;
|
||||||
function DoRunFile: TModalResult; virtual; abstract;
|
function DoRunFile(Filename: string = '' // if empty use active source editor file
|
||||||
|
): TModalResult; virtual; abstract;
|
||||||
|
|
||||||
// project
|
// project
|
||||||
property ActiveProject: TLazProject read GetActiveProject;
|
property ActiveProject: TLazProject read GetActiveProject;
|
||||||
|
60
ide/main.pp
60
ide/main.pp
@ -818,7 +818,7 @@ type
|
|||||||
function DoBuildLazarus(Flags: TBuildLazarusFlags): TModalResult; override;
|
function DoBuildLazarus(Flags: TBuildLazarusFlags): TModalResult; override;
|
||||||
function DoBuildAdvancedLazarus(ProfileNames: TStringList): TModalResult;
|
function DoBuildAdvancedLazarus(ProfileNames: TStringList): TModalResult;
|
||||||
function DoBuildFile({%H-}ShowAbort: Boolean; Filename: string = ''): TModalResult; override;
|
function DoBuildFile({%H-}ShowAbort: Boolean; Filename: string = ''): TModalResult; override;
|
||||||
function DoRunFile: TModalResult; override;
|
function DoRunFile(Filename: string = ''): TModalResult; override;
|
||||||
function DoConfigureBuildFile: TModalResult; override;
|
function DoConfigureBuildFile: TModalResult; override;
|
||||||
function GetIDEDirectives(aFilename: string;
|
function GetIDEDirectives(aFilename: string;
|
||||||
DirectiveList: TStrings): TModalResult;
|
DirectiveList: TStrings): TModalResult;
|
||||||
@ -7284,15 +7284,23 @@ begin
|
|||||||
if ToolStatus<>itNone then exit;
|
if ToolStatus<>itNone then exit;
|
||||||
ActiveSrcEdit:=nil;
|
ActiveSrcEdit:=nil;
|
||||||
ActiveUnitInfo:=nil;
|
ActiveUnitInfo:=nil;
|
||||||
if Filename='' then begin
|
|
||||||
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
|
|
||||||
Filename:=ActiveUnitInfo.Filename;
|
|
||||||
end else begin
|
|
||||||
Filename:=TrimAndExpandFilename(Filename);
|
|
||||||
if Filename='' then exit;
|
|
||||||
end;
|
|
||||||
Result:=DoSaveProject([]);
|
Result:=DoSaveProject([]);
|
||||||
if Result<>mrOk then exit;
|
if Result<>mrOk then exit;
|
||||||
|
if Filename='' then begin
|
||||||
|
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
|
||||||
|
if not FilenameIsAbsolute(ActiveUnitInfo.Filename) then begin
|
||||||
|
Result:=DoSaveEditorFile(ActiveSrcEdit,[sfCheckAmbiguousFiles]);
|
||||||
|
if Result<>mrOk then exit;
|
||||||
|
end;
|
||||||
|
Filename:=ActiveUnitInfo.Filename;
|
||||||
|
end else begin
|
||||||
|
Filename:=TrimFilename(Filename);
|
||||||
|
if not FilenameIsAbsolute(Filename) then begin
|
||||||
|
IDEMessageDialog('Error','Unable to run file "'+Filename+'". Please save it first.',
|
||||||
|
mtError,[mbOk]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
if ExternalTools.RunningCount=0 then
|
if ExternalTools.RunningCount=0 then
|
||||||
IDEMessagesWindow.Clear;
|
IDEMessagesWindow.Clear;
|
||||||
DirectiveList:=TStringList.Create;
|
DirectiveList:=TStringList.Create;
|
||||||
@ -7361,7 +7369,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMainIDE.DoRunFile: TModalResult;
|
function TMainIDE.DoRunFile(Filename: string): TModalResult;
|
||||||
var
|
var
|
||||||
ActiveSrcEdit: TSourceEditor;
|
ActiveSrcEdit: TSourceEditor;
|
||||||
ActiveUnitInfo: TUnitInfo;
|
ActiveUnitInfo: TUnitInfo;
|
||||||
@ -7377,22 +7385,36 @@ var
|
|||||||
Params: string;
|
Params: string;
|
||||||
ExtTool: TIDEExternalToolOptions;
|
ExtTool: TIDEExternalToolOptions;
|
||||||
DirectiveList: TStringList;
|
DirectiveList: TStringList;
|
||||||
|
Code: TCodeBuffer;
|
||||||
begin
|
begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
if ToolStatus<>itNone then exit;
|
if ToolStatus<>itNone then exit;
|
||||||
ActiveSrcEdit:=nil;
|
ActiveSrcEdit:=nil;
|
||||||
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
|
ActiveUnitInfo:=nil;
|
||||||
if not FilenameIsAbsolute(ActiveUnitInfo.Filename) then begin
|
if Filename='' then begin
|
||||||
Result:=DoSaveEditorFile(ActiveSrcEdit,[sfCheckAmbiguousFiles]);
|
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
|
||||||
if Result<>mrOk then exit;
|
if not FilenameIsAbsolute(ActiveUnitInfo.Filename) then begin
|
||||||
|
Result:=DoSaveEditorFile(ActiveSrcEdit,[sfCheckAmbiguousFiles]);
|
||||||
|
if Result<>mrOk then exit;
|
||||||
|
end;
|
||||||
|
Filename:=ActiveUnitInfo.Filename;
|
||||||
|
end else begin
|
||||||
|
Filename:=TrimFilename(Filename);
|
||||||
|
if not FilenameIsAbsolute(Filename) then begin
|
||||||
|
IDEMessageDialog('Error','Unable to run file "'+Filename+'". Please save it first.',
|
||||||
|
mtError,[mbOk]);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
DirectiveList:=TStringList.Create;
|
DirectiveList:=TStringList.Create;
|
||||||
try
|
try
|
||||||
Result:=GetIDEDirectives(ActiveUnitInfo.Filename,DirectiveList);
|
Result:=GetIDEDirectives(Filename,DirectiveList);
|
||||||
if Result<>mrOk then exit;
|
if Result<>mrOk then exit;
|
||||||
|
|
||||||
if ActiveUnitInfo.Source.LineCount>0 then
|
Code:=CodeToolBoss.LoadFile(Filename,true,false);
|
||||||
FirstLine:=ActiveUnitInfo.Source.GetLine(0,false)
|
if Code=nil then exit;
|
||||||
|
if Code.LineCount>0 then
|
||||||
|
FirstLine:=Code.GetLine(0,false)
|
||||||
else
|
else
|
||||||
FirstLine:='';
|
FirstLine:='';
|
||||||
HasShebang:=copy(FirstLine,1,2)='#!';
|
HasShebang:=copy(FirstLine,1,2)='#!';
|
||||||
@ -7409,7 +7431,7 @@ begin
|
|||||||
RunWorkingDir:=GetIDEStringDirective(DirectiveList,
|
RunWorkingDir:=GetIDEStringDirective(DirectiveList,
|
||||||
IDEDirectiveNames[idedRunWorkingDir],'');
|
IDEDirectiveNames[idedRunWorkingDir],'');
|
||||||
if RunWorkingDir='' then
|
if RunWorkingDir='' then
|
||||||
RunWorkingDir:=ExtractFilePath(ActiveUnitInfo.Filename);
|
RunWorkingDir:=ExtractFilePath(Filename);
|
||||||
if not GlobalMacroList.SubstituteStr(RunWorkingDir) then begin
|
if not GlobalMacroList.SubstituteStr(RunWorkingDir) then begin
|
||||||
Result:=mrCancel;
|
Result:=mrCancel;
|
||||||
exit;
|
exit;
|
||||||
@ -7419,8 +7441,8 @@ begin
|
|||||||
else
|
else
|
||||||
DefRunCommand:=IDEDirDefaultRunCommand;
|
DefRunCommand:=IDEDirDefaultRunCommand;
|
||||||
RunCommand:=GetIDEStringDirective(DirectiveList,
|
RunCommand:=GetIDEStringDirective(DirectiveList,
|
||||||
IDEDirectiveNames[idedRunCommand],
|
IDEDirectiveNames[idedRunCommand],
|
||||||
DefRunCommand);
|
DefRunCommand);
|
||||||
if (not GlobalMacroList.SubstituteStr(RunCommand)) then
|
if (not GlobalMacroList.SubstituteStr(RunCommand)) then
|
||||||
exit(mrCancel);
|
exit(mrCancel);
|
||||||
if (RunCommand='') then
|
if (RunCommand='') then
|
||||||
|
Loading…
Reference in New Issue
Block a user