UPD: ChooseFile mechanism

This commit is contained in:
Alexander Koblov 2008-01-16 21:35:33 +00:00
commit fabcb5ff3d
5 changed files with 56 additions and 40 deletions

View file

@ -1335,7 +1335,7 @@ begin
end; // frameright;
if gUseExtDiff then
begin
ExecCmdFork(Format(gExtDiff + ' "%s" "%s"',[sFile1, sFile2]));
ExecCmdFork(Format('"%s" "%s" "%s"', [gExtDiff, sFile1, sFile2]));
Exit;
end;
try
@ -2613,7 +2613,7 @@ begin
if actionLst.ActionByName(Cmd) <> nil then
Result := actionLst.ActionByName(Cmd).Execute
else
Result := (ExecCmdFork(Cmd) = 0);
Result := ExecCmdFork(Format('"%s"', [Cmd]));
end;
procedure TfrmMain.UpdateWindowView;

View file

@ -38,9 +38,13 @@ const
{$IFDEF MSWINDOWS}
faFolder = faDirectory;
faSymLink = $00000400;
fmtRun = '"%s"';
fmtRunInTerm = '%s /K "%s"';
{$ELSE}
faFolder = S_IFDIR;
faSymLink = $00000040;
fmtRun = '"./%s"';
fmtRunInTerm = '%s "%s";echo "Press Enter";read';
{$ENDIF}
type
@ -94,7 +98,7 @@ function FPS_ISLNK(iAttr:Cardinal) : Boolean;
}
function FileIsExeLib(const sFileName : String) : Boolean;
function FileCopyAttr(const sSrc, sDst:String; bDropReadOnlyFlag : Boolean):Boolean;
function ExecCmdFork(const sCmd:String):Integer;
function ExecCmdFork(const sCmdLine:String):Boolean;
function GetDiskFreeSpace(Path : String; var FreeSize, TotalSize : Int64) : Boolean;
{en
Create a hard link to a file
@ -273,34 +277,41 @@ end;
(* Execute external commands *)
function ExecCmdFork(const sCmd:String):Integer;
function ExecCmdFork(const sCmdLine:String):Boolean;
{$IFDEF UNIX}
var
sCmd,
sParams : String;
pid : longint;
Begin
SplitCmdLine(sCmdLine, sCmd, sParams);
pid := fpFork;
if pid = 0 then
begin
{The child does the actual exec, and then exits}
Shell(sCmd);
FpExecLP(sCmd, [sParams]);
{ If the shell fails, we return an exitvalue of 127, to let it be known}
fpExit(127);
fpExit(127);
end
else
if pid = -1 then {Fork failed}
begin
raise Exception.Create('Fork failed:'+sCmd);
raise Exception.Create('Fork failed: ' + sCmd);
end;
Result:=0;
Result := (pid > 0);
end;
{$ELSE}
var
sFileName,
sParams : String;
sParams,
sWorkDir : String;
begin
Split(sCmd, sFileName, sParams);
ShellExecute(0, 'open',PChar(sFileName), PChar(sParams), PChar(ExtractFilePath(sCmd)), SW_SHOW);
sWorkDir := GetCurrentDir;
SplitCmdLine(sCmdLine, sFileName, sParams);
DebugLN('File: ' + sFileName + ' Params: ' + sParams + ' WorkDir: ' + sWorkDir);
Result := (ShellExecute(0, 'open', PChar(sFileName), PChar(sParams), PChar(sWorkDir), SW_SHOW) > 32);
end;
{$ENDIF}

View file

@ -27,7 +27,7 @@ function GetSplitFileName(var sFileName, sPath : String) : String;
function GetDirs (DirName : String; var Dirs : TStringList) : Longint;
function GetAbsoluteFileName(sPath, sRelativeFileName : String) : String;
function ExtractOnlyFileName(const FileName: string): string;
procedure Split(const sFileNameWithParams : String; var sFileName, sParams : String);
function SplitCmdLine(sCmdLine : String; var sCmd, sParams : String) : Boolean;
function cnvFormatFileSize(iSize:Int64):String;
function MinimizeFilePath(const PathToMince: String; Canvas: TCanvas;
MaxLen: Integer): String;
@ -145,26 +145,31 @@ begin
Result := Copy(FileName, I + 1, iDotIndex - I - 1);
end;
procedure Split(const sFileNameWithParams : String; var sFileName, sParams : String);
function SplitCmdLine(sCmdLine : String; var sCmd, sParams : String) : Boolean;
var
sr: TSearchRec;
iSpacePos : Integer;
sTempFileName : String;
iLength : Integer;
iSearchPos : Integer;
iPos : Integer;
begin
iSearchPos := 1;
sFileName := sFileNameWithParams;
iLength := Length(sFileNameWithParams);
repeat
iSpacePos := CharPos(' ', sFileNameWithParams, iSearchPos);
iSearchPos := iSpacePos + 1;
sFileName := Copy(sFileNameWithParams, 1, iSpacePos - 1 );
until (iSpacePos = 0) or (FindFirst(sFileName, faAnyFile, sr) = 0);
if sFileName = '' then
sFileName := sFileNameWithParams
if Pos('"', sCmdLine) = 1 then
begin
iPos := CharPos('"', sCmdLine, 2);
sCmd := Copy(sCmdLine, 2, iPos - 2);
sParams := Copy(sCmdLine, iPos + 2, Length(sCmdLine) - iPos + 1)
end
else
sParams := Copy(sFileNameWithParams, iSpacePos + 1, iLength - iSpacePos);
begin
iPos := Pos(#32, sCmdLine);
if iPos <> 0 then
begin
sCmd := Copy(sCmdLine, 1, iPos - 1);
sParams := Copy(sCmdLine, iPos + 1, Length(sCmdLine) - iPos + 1)
end
else
begin
sCmd := sCmdLine;
sParams := '';
end;
end;
Result := (sCmd <>'');
end;
function cnvFormatFileSize(iSize:Int64):String;

View file

@ -101,7 +101,7 @@ type
implementation
uses
SysUtils, Masks, uFileOp, uGlobs, uVFSutil,
LCLProc, SysUtils, Masks, uFileOp, uGlobs, uVFSutil,
uShowMsg, Controls, uLng, uShowForm, uVFSmodule, uDCUtils,
uOSUtils;
@ -432,8 +432,8 @@ begin
begin
System.ChDir(ActiveDir);
LastActive:=sName;
ExecuteFile(sName, False);
// ExecCmdFork('./'+sName);
LoadPanel;
Exit;
end;
@ -443,10 +443,9 @@ end;
procedure TFilePanel.ExecuteFile(const sName:String; bTerm:Boolean);
begin
if bTerm then
// ExecCmdFork(Format(gTerm,[sName+'|less']))
ExecCmdFork(Format(gTerm,[sName+';echo ''Press Enter'';read']))
ExecCmdFork(Format(fmtRunInTerm, [gTerm, sName]))
else
ExecCmdFork(sName);
ExecCmdFork(Format(fmtRun, [sName]));
end;
procedure TFilePanel.MarkAllFiles(bMarked:Boolean);
@ -647,6 +646,7 @@ begin
Exit;
end;
System.ChDir(ActiveDir);
Result := ExecCmdFork(sCmd);
end;
procedure TFilePanel.SetActiveDir(const AValue:String);

View file

@ -7,7 +7,7 @@
showing editor or viewer by configuration dialog
contributors:
Copyright (C) 2006-2007 Koblov Alexander (Alexx2000@mail.ru)
Copyright (C) 2006-2008 Koblov Alexander (Alexx2000@mail.ru)
}
@ -39,12 +39,12 @@ uses
uGlobs, uOSUtils, fEditor, fViewer;
const
sParam = ' "%s"';
sCmdLine = '"%s" "%s"';
function ShowEditorByGlob(const sFileName:String):Boolean;
begin
if gUseExtEdit then
ExecCmdFork(Format(gExtEdit + sParam,[sFileName]))
ExecCmdFork(Format(sCmdLine, [gExtEdit, sFileName]))
else
ShowEditor(sFileName);
Result:=True;
@ -55,7 +55,7 @@ var
sl:TStringList;
begin
if gUseExtView then
ExecCmdFork(Format(gExtView + sParam,[sFileName]))
ExecCmdFork(Format(sCmdLine, [gExtView, sFileName]))
else
begin
sl:=TStringList.Create;
@ -86,7 +86,7 @@ begin
end
else
for i:=0 to list.Count-1 do
ExecCmdFork(Format(gExtView + sParam,[List.Strings[i]]))
ExecCmdFork(Format(sCmdLine, [gExtView, List.Strings[i]]))
end // gUseExtView
else
ShowViewer(List, bDeleteAfterView);
@ -101,7 +101,7 @@ var
Process : TProcess;
begin
Process := TProcess.Create(nil);
Process.CommandLine := Format(gExtView + sParam,[FFileList.Strings[0]]);
Process.CommandLine := Format(sCmdLine, [gExtView, FFileList.Strings[0]]);
Process.Options := [poWaitOnExit];
Process.Execute;
Process.Free;