ADD: Patch [2784488] "Delete to Windows Recycle bin" from sash0k

This commit is contained in:
Alexander Koblov 2009-05-04 06:00:40 +00:00
commit 7eaa4f17bc
4 changed files with 86 additions and 15 deletions

View file

@ -1,4 +1,4 @@
{
{
Double Commander
-------------------------------------------------------------------------
Licence : GNU GPL v 2.0
@ -1343,19 +1343,25 @@ var
pfri : PFileRecItem;
begin
Result:=True;
// ---- 30.04.2009 - переписал для удаления в корзину. ----
If (Key = VK_F8) or (Key = VK_DELETE) then
begin
if ((not edtCommand.Focused) and (edtCommand.Tag = 0)) or (Key = VK_F8) then
begin
if Shift=[] then
Actions.cm_Delete('recycle')
else
if Shift=[ssShift] then
Actions.cm_Delete('');
//actDelete.Execute;
Exit;
end;
end;
// ---------------------------------------------------------
if Shift=[] then
begin
case Key of
VK_F8, VK_DELETE:
begin
if ((not edtCommand.Focused) and (edtCommand.Tag = 0)) or (Key = VK_F8) then
begin
Actions.cm_Delete('');
//actDelete.Execute;
Exit;
end;
end;
VK_APPS:
begin
Actions.cm_ContextMenu('');

View file

@ -1,4 +1,4 @@
{
{
Double Commander
-------------------------------------------------------------------------
This unit contains platform depended functions.
@ -224,6 +224,11 @@ function mbFileGetAttr(const FileName: UTF8String): LongInt;
function mbFileSetAttr (const FileName: UTF8String; Attr: LongInt) : LongInt;
function mbFileSetReadOnly(const FileName: UTF8String; ReadOnly: Boolean): Boolean;
function mbDeleteFile(const FileName: UTF8String): Boolean;
// 30.04.2009 -----
// Функция удаляет файлы и и папки в корзину (пока только Windows)
// This function move files and folders to trash can (only Windows implemented)
function mbDeleteToTrash(const FileName: UTF8String): Boolean;
// ----------------
function mbRenameFile(const OldName, NewName : UTF8String): Boolean;
function mbFileSize(const FileName: UTF8String): Int64;
function FileFlush(Handle: Integer): Boolean;
@ -259,7 +264,12 @@ var
implementation
uses
FileUtil;
FileUtil
// 30.04.2009 - для удаления в корзину
{$IFDEF MSWINDOWS}
, Win32Int, InterfaceBase
{$ENDIF}
;
{$IFDEF UNIX}
type
@ -1245,6 +1255,32 @@ begin
end;
{$ENDIF}
// 30.04.2009 ---------------------------------------------------------------------
function mbDeleteToTrash(const FileName: UTF8String): Boolean;
{$IFDEF MSWINDOWS}
var
wFileName: WideString;
FileOp: TSHFileOpStructW;
begin
wFileName:= UTF8Decode(FileName);
wFileName:= wFileName + #0;
FillChar(FileOp, SizeOf(FileOp), 0);
FileOp.Wnd := TWin32Widgetset(Widgetset).AppHandle;
FileOp.wFunc := FO_DELETE;
FileOp.pFrom := PWideChar(wFileName);
// удаляем без подтвержения
FileOp.fFlags := FOF_ALLOWUNDO or FOF_NOERRORUI or FOF_SILENT or FOF_NOCONFIRMATION;
Result := (SHFileOperationW(@FileOp) = 0) and (not FileOp.fAnyOperationsAborted);
end;
{$ELSE}
begin
// Хотелось бы реализовать удаление в корзину Nautilus/Gnome,
// велосипеды в виде собственных корзин городить не хочется.
// Корзины, работающие с libc не поддерживаются (проверено с libtrash).
end;
{$ENDIF}
// --------------------------------------------------------------------------------
function mbRenameFile(const OldName, NewName: UTF8String): Boolean;
{$IFDEF MSWINDOWS}
var

View file

@ -1,4 +1,4 @@
{
{
Double Commander
-------------------------------------------------------------------------
This unit contains all DC actions
@ -1150,6 +1150,11 @@ begin
(* Delete files *)
try
DT := TDeleteThread.Create(fl);
// 30.04.2009 - передаем параметр корзины в поток.
If (param = 'recycle') then
DT.Recycle := true
else
If (param = '') then DT.Recycle := false;
DT.sDstPath:= NotActiveFrame.ActiveDir;
//DT.sDstMask:=sDstMaskTemp;
DT.Resume;

View file

@ -1,4 +1,4 @@
{
{
Seksi Commander
----------------------------
Implementing of Delete thread
@ -25,12 +25,18 @@ type
{ TDeleteThread }
TDeleteThread = class(TFileOpThread)
private
// 30.04.2009 - поле, показывающее удаление в корзину
FRecycle : boolean;
protected
constructor Create(aFileList:TFileList); override;
procedure MainExecute; override;
function DeleteFile(fr:PFileRecItem):Boolean;
function GetCaptionLng: String; override;
function CheckFile(FileRecItem: PFileRecItem): Boolean; override;
public
// 30.04.2009 - свойство для удаления в корзину
property Recycle : boolean read FRecycle write FRecycle default false;
end;
implementation
@ -74,6 +80,8 @@ end;
function TDeleteThread.DeleteFile (fr:PFileRecItem):Boolean;
begin
try
If (FRecycle = false) then
begin
if FPS_ISDIR(fr^.iMode) then // directory
begin
Result := mbRemoveDir(fr^.sName);
@ -104,6 +112,22 @@ begin
logWrite(Self, Format(rsMsgLogError+rsMsgLogDelete, [fr^.sName]), lmtError);
end;
end;
end
else
begin // 30.04.2009 - Вызов удаления в корзину. Файлы и папки удаляются одной функцией.
Result := mbDeleteToTrash(fr^.sName);
// write log
if Result then
begin
if (log_delete in gLogOptions) and (log_success in gLogOptions) then
logWrite(Self, Format(rsMsgLogSuccess+rsMsgLogDelete, [fr^.sName]), lmtSuccess);
end
else
begin
if (log_delete in gLogOptions) and (log_errors in gLogOptions) then
logWrite(Self, Format(rsMsgLogError+rsMsgLogDelete, [fr^.sName]), lmtError);
end;
end;
// process comments if need
if Result and gProcessComments and Assigned(FDescr) then
FDescr.DeleteDescription(fr^.sName);