UPD: Rename functions returning copies of files for clarity.

This commit is contained in:
cobines 2011-03-25 06:15:52 +00:00
commit 92761cffa8
7 changed files with 87 additions and 91 deletions

View file

@ -887,7 +887,7 @@ begin
else
if Sender is TSpeedButton and not Draging then
begin
aFile := ActiveFrame.ActiveFile;
aFile := ActiveFrame.CloneActiveFile;
try
if Assigned(aFile) and aFile.IsNameValid then
begin
@ -920,7 +920,7 @@ begin
begin
if not (Source is TSpeedButton) and not Draging then
begin
aFile := ActiveFrame.ActiveFile;
aFile := ActiveFrame.CloneActiveFile;
try
if Assigned(aFile) and aFile.IsNameValid then
begin
@ -957,7 +957,7 @@ begin
end
else
begin
aFile := ActiveFrame.ActiveFile;
aFile := ActiveFrame.CloneActiveFile;
try
Accept := Assigned(aFile) and aFile.IsNameValid and not Draging;
finally
@ -1458,7 +1458,7 @@ var
begin
if not (Source is TSpeedButton) and not Draging and (ssShift in GetKeyShiftState) then
begin
aFile := ActiveFrame.ActiveFile;
aFile := ActiveFrame.CloneActiveFile;
try
if Assigned(aFile) and aFile.IsNameValid then
begin
@ -1480,7 +1480,7 @@ var
begin
if (ssShift in GetKeyShiftState) and not (Source is TSpeedButton) then
begin
aFile := ActiveFrame.ActiveFile;
aFile := ActiveFrame.CloneActiveFile;
try
Accept := Assigned(aFile) and aFile.IsNameValid;
finally
@ -2523,7 +2523,7 @@ procedure TfrmMain.CopyFiles(sDestPath: String; bShowDialog: Boolean);
var
SourceFiles: TFiles = nil;
begin
SourceFiles := ActiveFrame.SelectedFiles;
SourceFiles := ActiveFrame.CloneSelectedFiles;
if Assigned(SourceFiles) then
try
CopyFiles(ActiveFrame.FileSource, NotActiveFrame.FileSource,
@ -2538,7 +2538,7 @@ procedure TfrmMain.MoveFiles(sDestPath: String; bShowDialog: Boolean);
var
SourceFiles: TFiles = nil;
begin
SourceFiles := ActiveFrame.SelectedFiles;
SourceFiles := ActiveFrame.CloneSelectedFiles;
if Assigned(SourceFiles) then
try
MoveFiles(ActiveFrame.FileSource, NotActiveFrame.FileSource,
@ -3997,7 +3997,7 @@ begin
end
else
begin
aFile:= ActiveFrame.ActiveFile;
aFile:= ActiveFrame.CloneActiveFile;
if Assigned(aFile) then
try
sCmd:= 'quote' + #32 + sCmd;

View file

@ -546,7 +546,7 @@ uses
uLng, uGlobsPaths, uPixMapManager, fMain, LCLProc, LCLVersion,
uColorExt, uDCUtils, uOSUtils, fColumnsSetConf, uShowMsg, uShowForm,
fTweakPlugin, uhotkeymanger, uTypes, StrUtils, uFindEx, uKeyboard,
fMaskInputDlg, uSearchTemplate, uMultiArc;
fMaskInputDlg, uSearchTemplate, uMultiArc, uFile;
const
stgCmdCommandIndex = 0;
@ -1923,14 +1923,17 @@ end;
procedure TfrmOptions.FillIgnoreList(bWithFullPath: Boolean);
var
I: Integer;
SelectedFiles: TFiles;
begin
with frmMain.ActiveFrame.SelectedFiles do
begin
for I:= 0 to Count - 1 do
SelectedFiles := frmMain.ActiveFrame.CloneSelectedFiles;
try
for I:= 0 to SelectedFiles.Count - 1 do
if bWithFullPath then
memIgnoreList.Lines.Add(Items[I].FullPath)
memIgnoreList.Lines.Add(SelectedFiles[I].FullPath)
else
memIgnoreList.Lines.Add(Items[I].Name);
memIgnoreList.Lines.Add(SelectedFiles[I].Name);
finally
FreeAndNil(SelectedFiles);
end;
end;

View file

@ -994,7 +994,7 @@ begin
SourcePanel := ((Source as TDrawGridEx).Parent) as TColumnsFileView;
// Get file names from source panel.
SourceFiles := SourcePanel.SelectedFiles;
SourceFiles := SourcePanel.CloneSelectedFiles;
try
// Drop onto target panel.
with Sender as TDrawGridEx do
@ -1100,7 +1100,7 @@ begin
if Assigned(OnChangeActiveFile) then
begin
aFile := ActiveFile;
aFile := CloneActiveFile;
try
OnChangeActiveFile(Self, aFile);
finally
@ -1863,7 +1863,7 @@ begin
NewFileName := edtRename.Text;
OldFileNameAbsolute := edtRename.Hint;
aFile := ActiveFile;
aFile := CloneActiveFile;
try
try
if RenameFile(FileSource, aFile, NewFileName, True) = True then
@ -3335,7 +3335,7 @@ var
begin
if (fsoSetFileProperty in FileSource.GetOperationsTypes) then
begin
aFile:= ActiveFile;
aFile:= CloneActiveFile;
if Assigned(aFile) then
try
if aFile.IsNameValid then
@ -4238,4 +4238,4 @@ begin
end;
end.

View file

@ -119,9 +119,6 @@ type
function GetCurrentPath: String; virtual;
procedure SetCurrentPath(NewPath: String); virtual;
function GetActiveDisplayFile: TDisplayFile; virtual; abstract;
function GetActiveFile: TFile;
function GetFiles: TFiles; virtual;
function GetSelectedFiles: TFiles; virtual;
function GetWorkersThread: TFunctionThread;
{en
This function should set active file by reference of TFile
@ -222,6 +219,28 @@ type
}
procedure AssignFileSources(const otherFileView: TFileView); virtual;
{en
Returns a copy of currently active file.
Caller is responsible for freeing it.
There should always be at least one file in the view at any time, but
what 'active' means depends on the specific view, so ActiveFile may
return 'nil' if there is no such file. Usually it is the file pointed
to by the cursor or some other indicator.
}
function CloneActiveFile: TFile;
{en
A list of all files in the file view.
Caller is responsible for freeing the list.
}
function CloneFiles: TFiles;
{en
A list of files selected by the user
(this should be a subset of displayed files list returned by Files).
Caller is responsible for freeing the list.
}
function CloneSelectedFiles: TFiles;
{en
Retrieves files from file source again and displays the new list of files.
Returns @true if reloading is done, @false if reloading will not be done
@ -290,27 +309,6 @@ type
property Path[FileSourceIndex, PathIndex: Integer]: UTF8String read GetPath;
property PathsCount[FileSourceIndex: Integer]: Integer read GetPathsCount;
{en
Currently active file.
Returns a cloned copy. Caller is responsible for freeing it.
There should always be at least one file in the view at any time, but
what 'active' means depends on the specific view, so ActiveFile may
return 'nil' if there is no file active. Usually it is the file pointed
to by a cursor or some other indicator.
}
property ActiveFile: TFile read GetActiveFile write SetActiveFile;
{en
A list of currently displayed files.
Caller is responsible for freeing the list.
}
property Files: TFiles read GetFiles;
{en
A list of files selected by the user
(this should be a subset of displayed files list returned by Files).
Caller is responsible for freeing the list.
}
property SelectedFiles: TFiles read GetSelectedFiles;
property Sorting: TFileSortings read FSortings write SetSorting;
property WatcherActive: Boolean read GetWatcherActive;
@ -561,7 +559,7 @@ begin
end;
end;
function TFileView.GetActiveFile: TFile;
function TFileView.CloneActiveFile: TFile;
var
aFile: TDisplayFile;
begin
@ -573,7 +571,7 @@ begin
Result := nil;
end;
function TFileView.GetFiles: TFiles;
function TFileView.CloneFiles: TFiles;
var
i: Integer;
begin
@ -585,7 +583,7 @@ begin
end;
end;
function TFileView.GetSelectedFiles: TFiles;
function TFileView.CloneSelectedFiles: TFiles;
var
i: Integer;
aFile: TDisplayFile;
@ -1444,4 +1442,4 @@ begin
end;
end.

View file

@ -618,7 +618,7 @@ var
SelectedFiles: TFiles = nil;
PathToAdd: String;
begin
SelectedFiles := FileView.SelectedFiles;
SelectedFiles := FileView.CloneSelectedFiles;
try
if SelectedFiles.Count > 0 then
begin
@ -686,7 +686,7 @@ begin
end
else
begin
aFiles:= Panel.SelectedFiles;
aFiles:= Panel.CloneSelectedFiles;
end;
if Assigned(aFiles) then
@ -711,7 +711,7 @@ var
aFile: TFile;
NewPath: String;
begin
aFile := SourcePage.FileView.ActiveFile;
aFile := SourcePage.FileView.CloneActiveFile;
if Assigned(aFile) then
try
if aFile.IsDirectory then
@ -828,7 +828,7 @@ var
begin
with frmMain do
begin
aFile := ActiveFrame.ActiveFile;
aFile := ActiveFrame.CloneActiveFile;
if Assigned(aFile) then
try
OldPosition := edtCommand.SelStart;
@ -849,7 +849,7 @@ var
begin
with frmMain do
begin
aFile := ActiveFrame.ActiveFile;
aFile := ActiveFrame.CloneActiveFile;
if Assigned(aFile) then
try
if aFile.Name = '..' then
@ -900,7 +900,7 @@ var
begin
with FrmMain do
begin
aFile := ActiveFrame.ActiveFile;
aFile := ActiveFrame.CloneActiveFile;
if Assigned(aFile) then
try
if aFile.IsNameValid and
@ -964,7 +964,7 @@ var
begin
with frmMain.ActiveFrame do
begin
aFile := ActiveFile;
aFile := CloneActiveFile;
if Assigned(aFile) then
try
if aFile.IsNameValid then
@ -986,7 +986,7 @@ var
begin
with frmMain do
begin
SelectedFiles := ActiveFrame.SelectedFiles;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
try
TestArchive(ActiveFrame, SelectedFiles);
finally
@ -1022,7 +1022,7 @@ var
begin
with frmMain do
begin
SelectedFiles := ActiveFrame.SelectedFiles;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
try
ShowPackDlg(ActiveFrame.FileSource,
nil, // No specific target (create new)
@ -1045,7 +1045,7 @@ var
begin
with frmMain do
begin
SelectedFiles := ActiveFrame.SelectedFiles;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
if Assigned(SelectedFiles) then
try
if SelectedFiles.Count > 0 then
@ -1172,7 +1172,7 @@ begin
// ------------------------------------------------------
theFilesToWipe := SelectedFiles; // free at Thread end by thread
theFilesToWipe := CloneSelectedFiles; // free at Thread end by thread
if Assigned(theFilesToWipe) then
try
@ -1300,8 +1300,8 @@ var
begin
with frmMain do
try
SelectedFiles := ActiveFrame.SelectedFiles;
ActiveFile := ActiveFrame.ActiveFile;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
ActiveFile := ActiveFrame.CloneActiveFile;
// Enter directories using View command.
if Assigned(ActiveFile) and
@ -1396,7 +1396,7 @@ begin
(not gExternalTools[etViewer].Enabled) and
([fspDirectAccess, fspLinksToLocalFiles] * ActiveFrame.FileSource.Properties <> []) then
begin
AllFiles := ActiveFrame.Files;
AllFiles := ActiveFrame.CloneFiles;
if (fspLinksToLocalFiles in ActiveFrame.FileSource.Properties) then
begin
@ -1471,7 +1471,7 @@ begin
// If files are links to local files
if (fspLinksToLocalFiles in ActiveFrame.FileSource.Properties) then
begin
SelectedFiles := ActiveFrame.SelectedFiles;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
for I := 0 to SelectedFiles.Count - 1 do
begin
aFile := SelectedFiles[I];
@ -1486,7 +1486,7 @@ begin
end
else
begin
SelectedFiles := ActiveFrame.SelectedFiles;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
end;
for i := 0 to SelectedFiles.Count - 1 do
@ -1558,7 +1558,7 @@ begin
Exit;
end;
ActiveFile := ActiveFrame.ActiveFile;
ActiveFile := ActiveFrame.CloneActiveFile;
if Assigned(ActiveFile) and ActiveFile.IsNameValid then
sPath := ActiveFile.Name // 21.05.2009 - pass name from cursor to makedir form
else
@ -1633,7 +1633,7 @@ begin
// ------------------------------------------------------
theFilesToDelete := SelectedFiles; // free at Thread end by thread
theFilesToDelete := CloneSelectedFiles; // free at Thread end by thread
if Assigned(theFilesToDelete) then
try
@ -1698,7 +1698,7 @@ begin
// Do command on TempFileSource and later delete it (or leave cached on disk?)
end;
SelectedFiles := ActiveFrame.SelectedFiles;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
try
if SelectedFiles.Count = 0 then
begin
@ -1771,7 +1771,7 @@ begin
// Do command on TempFileSource and later delete it (or leave cached on disk?)
end;
SelectedFiles := ActiveFrame.SelectedFiles;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
try
if SelectedFiles.Count = 0 then
begin
@ -1955,11 +1955,11 @@ begin
end;
try
ActiveSelectedFiles := ActiveFrame.SelectedFiles;
ActiveSelectedFiles := ActiveFrame.CloneSelectedFiles;
if ActiveSelectedFiles.Count = 1 then
begin
NotActiveSelectedFiles := NotActiveFrame.SelectedFiles;
NotActiveSelectedFiles := NotActiveFrame.CloneSelectedFiles;
if NotActiveSelectedFiles.Count = 1 then
begin
@ -2139,7 +2139,7 @@ begin
// Or create a symlink in temp filesystem and CopyIn to target file source.
end;
SelectedFiles := ActiveFrame.SelectedFiles;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
try
if SelectedFiles.Count > 1 then
msgWarning(rsMsgTooManyFilesSelected)
@ -2189,7 +2189,7 @@ begin
Exit;
end;
SelectedFiles := ActiveFrame.SelectedFiles;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
try
if SelectedFiles.Count > 1 then
msgWarning(rsMsgTooManyFilesSelected)
@ -2285,7 +2285,7 @@ begin
Exit;
end;
aFiles:= ActiveFrame.SelectedFiles;
aFiles:= ActiveFrame.CloneSelectedFiles;
if Assigned(aFiles) then
try
if aFiles.Count > 0 then
@ -2323,7 +2323,7 @@ begin
with frmMain do
if ActiveFrame.FileSource.IsClass(TFileSystemFileSource) then
begin
aFile := ActiveFrame.ActiveFile;
aFile := ActiveFrame.CloneActiveFile;
if Assigned(aFile) then
try
if aFile.IsNameValid then
@ -2423,7 +2423,7 @@ var
begin
with frmMain do
begin
SelectedFiles := ActiveFrame.SelectedFiles;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
try
Operation := ActiveFrame.FileSource.CreateCalcStatisticsOperation(SelectedFiles);
Operation.AddStateChangedListener([fsosStopped], @OnCalcStatisticsStateChanged);
@ -2459,8 +2459,8 @@ begin
Exit;
end;
SelectedFiles := ActiveFrame.SelectedFiles;
ActiveFile := ActiveFrame.ActiveFile;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
ActiveFile := ActiveFrame.CloneActiveFile;
if Assigned(ActiveFile) then
begin
FillByte(aFileProperties, SizeOf(aFileProperties), 0);
@ -2508,7 +2508,7 @@ begin
begin
if ActiveFrame.FileSource.IsClass(TFileSystemFileSource) then
begin
SelectedFiles := ActiveFrame.SelectedFiles;
SelectedFiles := ActiveFrame.CloneSelectedFiles;
if Assigned(SelectedFiles) then
try
if SelectedFiles.Count > 0 then
@ -2525,7 +2525,7 @@ begin
end
else if (fsoExecute in ActiveFrame.FileSource.GetOperationsTypes) then
begin
aFile:= ActiveFrame.ActiveFile;
aFile:= ActiveFrame.CloneActiveFile;
if Assigned(aFile) then
try
Operation:= ActiveFrame.FileSource.CreateExecuteOperation(
@ -2558,7 +2558,7 @@ begin
sl:= TStringList.Create;
try
Result:= False;
aSelectedFiles := SelectedFiles;
aSelectedFiles := CloneSelectedFiles;
for I := 0 to aSelectedFiles.Count - 1 do
begin
@ -2601,7 +2601,7 @@ begin
sl:= TStringList.Create;
try
Result:= False;
aSelectedFiles := SelectedFiles;
aSelectedFiles := CloneSelectedFiles;
for I := 0 to aSelectedFiles.Count - 1 do
begin
@ -2649,7 +2649,7 @@ begin
begin
if (fspDirectAccess in FileSource.GetProperties) then
begin
aFile:= ActiveFile;
aFile:= CloneActiveFile;
if Assigned(aFile) then
try
if aFile.IsNameValid then
@ -2662,7 +2662,7 @@ begin
end
else if (fspLinksToLocalFiles in FileSource.GetProperties) then
begin
aFile:= ActiveFile;
aFile:= CloneActiveFile;
if Assigned(aFile) then
try
if aFile.IsNameValid then
@ -2700,7 +2700,7 @@ begin
begin
sl := TStringList.Create;
try
theSelectedFiles := SelectedFiles;
theSelectedFiles := CloneSelectedFiles;
for i := 0 to theSelectedFiles.Count - 1 do
sl.Add(CurrentPath + theSelectedFiles[i].Name);

View file

@ -46,7 +46,7 @@ var
begin
QuickViewPanel:= TQuickViewPanel.Create(Application, aFileViewPage);
QuickViewPanel.CreateViewer(aFileView);
aFile := aFileView.ActiveFile;
aFile := aFileView.CloneActiveFile;
try
QuickViewPanel.FileViewChangeActiveFile(aFileView, aFile);
finally

View file

@ -118,11 +118,6 @@ var
sOutput: String = '';
parseStartIndex: Integer;
procedure BuildSelectedFilesList(var files: TFiles; panel: TFileView);
begin
files := panel.SelectedFiles;
end;
function BuildName(aFile: TFile): String;
begin
case state.funct of
@ -233,8 +228,8 @@ var
begin
try
BuildSelectedFilesList(leftFiles, leftPanel);
BuildSelectedFilesList(rightFiles, rightPanel);
leftFiles := leftPanel.CloneSelectedFiles;
rightFiles := rightPanel.CloneSelectedFiles;
if activePanel = leftPanel then
begin