UPD: Restored cm_OpenArchive (without detection, only for registered archives).

UPD: Moved functions changing to upper, lower directory to generic file view and use them for Ctrl+PgUp, Ctrl+PgDown commands.
UPD: Some cleanup, refactoring.
This commit is contained in:
cobines 2009-11-21 07:41:30 +00:00
commit 2a448b3049
6 changed files with 109 additions and 133 deletions

View file

@ -1583,56 +1583,32 @@ End;
procedure TfrmMain.HandleActionHotKeys(var Key: Word; Shift: TShiftState);
begin
// ---- 30.04.2009 - переписал для удаления в корзину. ----
If ((Key = VK_F8) or (Key = VK_DELETE)) and
((not IsCommandLineVisible) or ((not edtCommand.Focused) and (edtCommand.Tag = 0))) then
begin
if gUseTrash and mbCheckTrash(ActiveFrame.CurrentPath) then // 14.05.2009 - additional check for various linux distributives.
begin
if Shift=[ssShift] then // если шифт - удаляем напрямую
Actions.cm_Delete('')
else Actions.cm_Delete('recycle'); // без шифта удаляем в корзину
end
else Actions.cm_Delete(''); // если корзина отключена в конфигурации, или (для линукс) нет программы gvsf-trash, то удалять напрямую.
Key := 0;
Exit;
end;
// ---------------------------------------------------------
if (Key=VK_Return) or (Key=VK_SELECT) then
begin
with ActiveFrame do
begin
if (Shift=[])or (Shift=[ssCaps]) then // 21.05.2009 - не учитываем CapsLock при перемещении по панелям
case Key of
VK_F8, VK_DELETE:
// ---- 30.04.2009 - переписал для удаления в корзину. ----
if ((not IsCommandLineVisible) or ((not edtCommand.Focused) and (edtCommand.Tag = 0))) then
begin
if (not IsCommandLineVisible) or (edtCommand.Text='') then
if gUseTrash and mbCheckTrash(ActiveFrame.CurrentPath) then // 14.05.2009 - additional check for various linux distributives.
begin
// Delegated to ActiveFrame.
if Shift=[ssShift] then // если шифт - удаляем напрямую
Actions.cm_Delete('')
else
Actions.cm_Delete('recycle'); // без шифта удаляем в корзину
end
else
begin
ExecuteCommandLine(False);
Key:=0;
Exit;
end;
end; //Shift=[] + 21.05.2009 - не учитываем CapsLock при перемещении по панелям
Actions.cm_Delete(''); // если корзина отключена в конфигурации, или (для линукс) нет программы gvsf-trash, то удалять напрямую.
Key := 0;
end;
// execute command line in terminal (Shift+Enter)
if Shift=[ssShift] then
VK_RETURN, VK_SELECT:
if IsCommandLineVisible and (edtCommand.Text <> '') and
(Shift - [ssCaps, ssShift] = []) then
begin
if (not IsCommandLineVisible) or (edtCommand.Text='') then
begin
// Delegated to ActiveFrame.
end
else
begin
ExecuteCommandLine(True);
Key := 0;
Exit;
end;
// execute command line (in terminal with Shift)
ExecuteCommandLine(Shift = [ssShift]);
Key:=0;
end;
end;
end; // handle ENTER with some modifier
end;
end;
procedure TfrmMain.FormKeyPress(Sender: TObject; var Key: Char);
@ -2219,28 +2195,6 @@ begin
else
HandleActionHotKeys(Key, Shift);
end;
// CTRL+PgDown
if (Shift=[ssCtrl]) and (Key=VK_NEXT) then
begin
// Delegate to ActiveFrame (actually should be via hotkey and appropriate command).
with ActiveFrame do
begin
{
if IsActiveItemValid then
begin
if FPS_ISDIR(pnlFile.GetActiveItem^.iMode) or (pnlFile.GetActiveItem^.bLinkIsDir) then
pnlFile.cdDownLevel(pnlFile.GetActiveItem)
else
Actions.cm_OpenArchive('');
//actOpenArchive.Execute;
end;
}
end;
Key:=0;
Exit;
end;
end;
procedure TfrmMain.pnlLeftResize(Sender: TObject);

View file

@ -151,8 +151,7 @@ procedure ShowViewer(const FilesToView:TStringList; const aFileSource: IFileSour
implementation
uses
uLng, uShowMsg, uGlobs, LCLType, LConvEncoding, uClassesEx, uFindMmap, uDCUtils,
uOSUtils;
uLng, uShowMsg, uGlobs, LCLType, LConvEncoding, uClassesEx, uFindMmap, uDCUtils;
procedure ShowViewer(const FilesToView:TStringList; const aFileSource: IFileSource);
var
@ -344,8 +343,6 @@ end;
procedure TfrmViewer.frmViewerClose(Sender: TObject;
var CloseAction: TCloseAction);
var
I, Count : Integer;
begin
// TODO: may be better automtic save
// (see also TfrmViewer.miSavePosClick)

View file

@ -327,9 +327,6 @@ type
procedure LoadConfiguration(Section: String; TabIndex: Integer); override;
procedure SaveConfiguration(Section: String; TabIndex: Integer); override;
procedure cdUpLevel;
procedure cdDownLevel(AFile: TFile);
procedure SelectFile(AFile: TColumnsViewFile);
procedure MakeVisible(iRow:Integer);
procedure MakeSelectedVisible;
@ -540,40 +537,6 @@ begin
end;
end;
procedure TColumnsFileView.cdUpLevel;
var
PreviousSubDirectory,
sUpLevel: String;
begin
// Check if this is root level of the current file source.
if FileSource.IsPathAtRoot(CurrentPath) then
begin
// If there is a higher level file source then change to it.
if FileSourcesCount > 1 then
begin
RemoveLastFileSource;
Reload;
UpdateView;
end;
end
else
begin
PreviousSubDirectory := ExtractFileName(ExcludeTrailingPathDelimiter(CurrentPath));
sUpLevel:= GetParentDir(CurrentPath);
if sUpLevel <> EmptyStr then
begin
CurrentPath := sUpLevel;
SetActiveFile(PreviousSubDirectory);
end;
end;
end;
procedure TColumnsFileView.cdDownLevel(AFile: TFile);
begin
CurrentPath := CurrentPath + AFile.Name + DirectorySeparator;
end;
procedure TColumnsFileView.SelectFile(AFile: TColumnsViewFile);
begin
InvertFileSelection(AFile);
@ -1146,13 +1109,13 @@ begin
begin
if TheFile.Name = '..' then
begin
cdUpLevel;
ChangePathToParent(True);
Exit;
end;
if TheFile.IsDirectory or TheFile.IsLinkToDirectory then // deeper and deeper
begin
cdDownLevel(TheFile);
ChangePathToChild(TheFile);
Exit;
end;
@ -2053,7 +2016,7 @@ begin
VK_LEFT:
if (Shift = []) and gLynxLike then
begin
cdUpLevel;
ChangePathToParent(True);
Key := 0;
end;
@ -2118,7 +2081,7 @@ begin
begin
if (frmMain.edtCommand.Tag = 0) then
begin
cdUpLevel;
ChangePathToParent(True);
RedrawGrid;
end;
Key := 0;

View file

@ -23,6 +23,8 @@ procedure ChooseFile(aFileView: TFileView; aFile: TFile);
}
function ChooseFileSource(aFileView: TFileView; aFile: TFile): Boolean;
function ChooseArchive(aFileView: TFileView; aFile: TFile): Boolean;
function RenameFile(aFileSource: IFileSource; const aFile: TFile;
const NewFileName: UTF8String; Interactive: Boolean): Boolean;
@ -110,20 +112,8 @@ var
begin
Result := False;
// Opening archives directly only from FileSystem.
if aFileView.FileSource.IsClass(TFileSystemFileSource) then
begin
// Check if there is a registered WCX plugin for possible archive.
FileSource := FileSourceManager.Find(TWcxArchiveFileSource, aFile.Path + aFile.Name);
if not Assigned(FileSource) then
FileSource := TWcxArchiveFileSource.CreateByArchiveName(aFile.Path + aFile.Name);
if Assigned(FileSource) then
begin
aFileView.AddFileSource(FileSource, FileSource.GetRootDir);
Exit(True);
end;
end;
if ChooseArchive(aFileView, aFile) then
Exit;
// Work only for TVfsFileSource.
if aFileView.FileSource.IsClass(TVfsFileSource) then
@ -141,6 +131,28 @@ begin
end;
end;
function ChooseArchive(aFileView: TFileView; aFile: TFile): Boolean;
var
FileSource: IFileSource;
begin
Result := False;
// Opening archives directly only from FileSystem.
if aFileView.FileSource.IsClass(TFileSystemFileSource) then
begin
// Check if there is a registered WCX plugin for possible archive.
FileSource := FileSourceManager.Find(TWcxArchiveFileSource, aFile.Path + aFile.Name);
if not Assigned(FileSource) then
FileSource := TWcxArchiveFileSource.CreateByArchiveName(aFile.Path + aFile.Name);
if Assigned(FileSource) then
begin
aFileView.AddFileSource(FileSource, FileSource.GetRootDir);
Exit(True);
end;
end;
end;
function RenameFile(aFileSource: IFileSource; const aFile: TFile;
const NewFileName: UTF8String; Interactive: Boolean): Boolean;
var

View file

@ -96,6 +96,19 @@ type
procedure SetActiveFile(const aFileName: String); virtual; overload;
{en
Changes the current path to a parent directory.
@param(AllowChangingFileSource
If this parameter is @true and current path is the root path
of the current file source, then the current file source will
be removed (closed) and a previous file source will be displayed.)
}
procedure ChangePathToParent(AllowChangingFileSource: Boolean); virtual;
{en
Change the current path to a subdirectory pointed to by aFile.
}
procedure ChangePathToChild(const aFile: TFile); virtual;
procedure ExecuteCommand(CommandName: String; Parameter: String = ''); virtual;
{en
@ -275,6 +288,44 @@ procedure TFileView.SetActiveFile(const aFileName: String);
begin
end;
procedure TFileView.ChangePathToParent(AllowChangingFileSource: Boolean);
var
PreviousSubDirectory,
sUpLevel: String;
begin
// Check if this is root level of the current file source.
if FileSource.IsPathAtRoot(CurrentPath) then
begin
// If there is a higher level file source then change to it.
if (FileSourcesCount > 1) and AllowChangingFileSource then
begin
RemoveLastFileSource;
Reload;
UpdateView;
end;
end
else
begin
PreviousSubDirectory := ExtractFileName(ExcludeTrailingPathDelimiter(CurrentPath));
sUpLevel:= FileSource.GetParentDir(CurrentPath);
if sUpLevel <> EmptyStr then
begin
CurrentPath := sUpLevel;
SetActiveFile(PreviousSubDirectory);
end;
end;
end;
procedure TFileView.ChangePathToChild(const aFile: TFile);
begin
if Assigned(aFile) and aFile.IsNameValid and
(aFile.IsDirectory or aFile.IsLinkToDirectory) then
begin
CurrentPath := CurrentPath + IncludeTrailingPathDelimiter(aFile.Name);
end;
end;
procedure TFileView.ExecuteCommand(CommandName: String; Parameter: String);
var
Method: TMethod;

View file

@ -887,14 +887,20 @@ begin
end;
procedure TActs.cm_OpenArchive(param:string);
var
aFile: TFile;
begin
{
with frmMain.ActiveFrame.pnlFile do
with frmMain.ActiveFrame do
begin
if IsItemValid(GetActiveItem) then
TryOpenArchive(GetActiveItem);
aFile := ActiveFile;
if Assigned(aFile) and aFile.IsNameValid then
begin
if aFile.IsDirectory or aFile.IsLinkToDirectory then
ChangePathToChild(aFile)
else
ChooseArchive(frmMain.ActiveFrame, aFile); // TryOpenArchive(aFile);
end;
end;
}
end;
procedure TActs.cm_Open(param:string);
@ -2513,15 +2519,8 @@ begin
end;
procedure TActs.cm_ChangeDirToParent(param: string='');
var
NewPath: String;
begin
with frmMain.ActiveFrame do
begin
NewPath := FileSource.GetParentDir(CurrentPath);
if NewPath <> '' then
CurrentPath := NewPath;
end;
frmMain.ActiveFrame.ChangePathToParent(True);
end;
// Parameters: