Skip to content

Commit

Permalink
Bug 1758: Copy (to clipboard) command in file context menu
Browse files Browse the repository at this point in the history
https://winscp.net/tracker/1758

Source commit: 2c3c49532235a347dfb97670fb763cfc3ba0ddfa
  • Loading branch information
martinprikryl committed Jun 20, 2019
1 parent eb20ae2 commit 0e79b99
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 40 deletions.
4 changes: 2 additions & 2 deletions source/forms/CustomScpExplorer.cpp
Expand Up @@ -10257,7 +10257,7 @@ void __fastcall TCustomScpExplorerForm::SessionsPageControlCloseButtonClick(TPag
CloseSessionTab(Index);
}
//---------------------------------------------------------------------------
void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side)
void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
{
if (DebugAlwaysTrue(!IsSideLocalBrowser(Side)))
{
Expand All @@ -10284,7 +10284,7 @@ void __fastcall TCustomScpExplorerForm::CopyFilesToClipboard(TOperationSide Side
FClipboardTerminal = FTerminal;

// Need full paths, as cwd can be different once files are pasted
FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(false, true)));
FClipboardFileList.reset(TRemoteFileList::CloneStrings(RemoteDirView->CreateFileList(OnFocused, true)));
for (int Index = 0; Index < FClipboardFileList->Count; Index++)
{
FClipboardFileList->Strings[Index] = UnixExcludeTrailingBackslash(FClipboardFileList->Strings[Index]);
Expand Down
2 changes: 1 addition & 1 deletion source/forms/CustomScpExplorer.h
Expand Up @@ -778,7 +778,7 @@ friend class TAutoBatch;
void __fastcall StandaloneEdit(const UnicodeString & FileName);
bool __fastcall CanPasteFromClipBoard();
virtual void __fastcall PasteFromClipBoard();
virtual void __fastcall CopyFilesToClipboard(TOperationSide Side);
virtual void __fastcall CopyFilesToClipboard(TOperationSide Side, bool OnFocused);
void __fastcall ToggleQueueVisibility();
virtual UnicodeString __fastcall PathForCaption();
void __fastcall FileListFromClipboard();
Expand Down
4 changes: 3 additions & 1 deletion source/forms/NonVisual.cpp
Expand Up @@ -158,6 +158,7 @@ void __fastcall TNonVisualDataModule::ExplorerActionsUpdate(
!WinConfiguration->DisableOpenEdit)
UPD(CurrentEditInternalFocusedAction, EnabledFocusedFileOperation &&
!WinConfiguration->DisableOpenEdit)
UPD(CurrentCopyToClipboardFocusedAction, EnabledFocusedOperation)
// file operation
UPD(CurrentRenameAction, EnabledFocusedOperation &&
((ScpExplorer->HasDirView[osLocal] && DirView(osLocal) == DirView(osCurrent)) ||
Expand Down Expand Up @@ -509,6 +510,7 @@ void __fastcall TNonVisualDataModule::ExplorerActionsExecute(
EXE(CurrentSystemMenuFocusedAction, ScpExplorer->DisplaySystemContextMenu())
EXE(CurrentEditWithFocusedAction, ScpExplorer->ExecuteCurrentFileWith(true))
EXE(CurrentEditInternalFocusedAction, ScpExplorer->ExecuteFile(osCurrent, efInternalEditor, NULL, true, true))
EXE(CurrentCopyToClipboardFocusedAction, ScpExplorer->CopyFilesToClipboard(osCurrent, true))
// operation
EXE(CurrentEditAction, ScpExplorer->ExecuteFile(osCurrent, efDefaultEditor, NULL, true, false))
EXE(CurrentEditInternalAction, ScpExplorer->ExecuteFile(osCurrent, efInternalEditor, NULL, true, false))
Expand All @@ -521,7 +523,7 @@ void __fastcall TNonVisualDataModule::ExplorerActionsExecute(
EXE(CurrentDeleteAction, ScpExplorer->ExecuteFileOperationCommand(foDelete, osCurrent, false))
EXE(CurrentDeleteAlternativeAction, ScpExplorer->ExecuteFileOperationCommand(foDelete, osCurrent, false, false, (void*)true))
EXE(CurrentPropertiesAction, ScpExplorer->ExecuteFileOperationCommand(foSetProperties, osCurrent, false))
EXE(CurrentCopyToClipboardAction, ScpExplorer->CopyFilesToClipboard(osCurrent))
EXE(CurrentCopyToClipboardAction, ScpExplorer->CopyFilesToClipboard(osCurrent, false))
EXE(FileListToCommandLineAction, ScpExplorer->PanelExport(osCurrent, peFileList, pedCommandLine))
EXE(FileListToClipboardAction, ScpExplorer->PanelExport(osCurrent, peFileList, pedClipboard))
EXE(FullFileListToClipboardAction, ScpExplorer->PanelExport(osCurrent, peFullFileList, pedClipboard))
Expand Down
18 changes: 18 additions & 0 deletions source/forms/NonVisual.dfm
Expand Up @@ -45,6 +45,11 @@ object NonVisualDataModule: TNonVisualDataModule
object Rename1: TTBXItem
Action = CurrentRenameAction
end
object TBXSeparatorItem12: TTBXSeparatorItem
end
object TBXItem82: TTBXItem
Action = CurrentCopyToClipboardFocusedAction
end
object N45: TTBXSeparatorItem
end
object RemoteFilePopupCustomCommandsMenu: TTBXSubmenuItem
Expand Down Expand Up @@ -2274,6 +2279,14 @@ object NonVisualDataModule: TNonVisualDataModule
HelpKeyword = 'ui_pref_file_colors'
Hint = 'Configure file color rules'
end
object CurrentCopyToClipboardFocusedAction: TAction
Tag = 12
Category = 'Focused Operation'
Caption = '&Copy'
Hint = 'Copy|Copy the selected files to clipboard'
ImageIndex = 111
ShortCut = 16451
end
end
object ExplorerBarPopup: TTBXPopupMenu
Images = GlyphsModule.ExplorerImages
Expand Down Expand Up @@ -3107,6 +3120,11 @@ object NonVisualDataModule: TNonVisualDataModule
object TBXItem58: TTBXItem
Action = CurrentRenameAction
end
object TBXSeparatorItem11: TTBXSeparatorItem
end
object TBXItem81: TTBXItem
Action = CurrentCopyToClipboardFocusedAction
end
object TBXSeparatorItem3: TTBXSeparatorItem
end
object LocalFilePopupCustomCommandsMenu: TTBXSubmenuItem
Expand Down
5 changes: 5 additions & 0 deletions source/forms/NonVisual.h
Expand Up @@ -624,6 +624,11 @@ class TNonVisualDataModule : public TDataModule
TTBXItem *TBXItem79;
TAction *ReconnectSessionAction;
TTBXItem *TBXItem80;
TAction *CurrentCopyToClipboardFocusedAction;
TTBXSeparatorItem *TBXSeparatorItem11;
TTBXItem *TBXItem81;
TTBXSeparatorItem *TBXSeparatorItem12;
TTBXItem *TBXItem82;
void __fastcall ExplorerActionsUpdate(TBasicAction *Action, bool &Handled);
void __fastcall ExplorerActionsExecute(TBasicAction *Action, bool &Handled);
void __fastcall SessionIdleTimerTimer(TObject *Sender);
Expand Down
6 changes: 3 additions & 3 deletions source/forms/ScpCommander.cpp
Expand Up @@ -2249,16 +2249,16 @@ void __fastcall TScpCommanderForm::RemoteOpenDirButtonPopup(TTBCustomItem * /*Se
CreateOpenDirMenu(RemoteOpenDirButton, osRemote);
}
//---------------------------------------------------------------------------
void __fastcall TScpCommanderForm::CopyFilesToClipboard(TOperationSide Side)
void __fastcall TScpCommanderForm::CopyFilesToClipboard(TOperationSide Side, bool OnFocused)
{
if (IsSideLocalBrowser(Side))
{
TInstantOperationVisualizer Visualizer;
dynamic_cast<TDirView *>(DirView(Side))->CopyToClipBoard();
dynamic_cast<TDirView *>(DirView(Side))->CopyToClipBoard(OnFocused);
}
else
{
TCustomScpExplorerForm::CopyFilesToClipboard(Side);
TCustomScpExplorerForm::CopyFilesToClipboard(Side, OnFocused);
}
}
//---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion source/forms/ScpCommander.h
Expand Up @@ -620,7 +620,7 @@ class TScpCommanderForm : public TCustomScpExplorerForm
virtual void __fastcall HistoryGo(TOperationSide Side, int Index);
virtual void __fastcall DisplaySystemContextMenu();
virtual void __fastcall GoToAddress();
virtual void __fastcall CopyFilesToClipboard(TOperationSide Side);
virtual void __fastcall CopyFilesToClipboard(TOperationSide Side, bool OnFocused);
virtual void __fastcall PasteFromClipBoard();

__property double LeftPanelWidth = { read = GetLeftPanelWidth, write = SetLeftPanelWidth };
Expand Down
11 changes: 9 additions & 2 deletions source/packages/filemng/CustomDirView.pas
Expand Up @@ -250,6 +250,7 @@ TCustomDirView = class(TCustomIEListView)
procedure ColClick(Column: TListColumn); override;
procedure CreateWnd; override;
procedure DestroyWnd; override;
function OperateOnFocusedFile(Focused: Boolean; OnlyFocused: Boolean = False): Boolean;
function CustomCreateFileList(Focused, OnlyFocused: Boolean;
FullPath: Boolean; FileList: TStrings = nil; ItemObject: Boolean = False): TStrings;
function CustomDrawItem(Item: TListItem; State: TCustomDrawState;
Expand Down Expand Up @@ -2202,6 +2203,13 @@ function TCustomDirView.ItemData(Item: TListItem): TObject;
Result := nil;
end;

function TCustomDirView.OperateOnFocusedFile(Focused, OnlyFocused: Boolean): Boolean;
begin
Result :=
Assigned(ItemFocused) and
((Focused and (not ItemFocused.Selected)) or (SelCount = 0) or OnlyFocused);
end;

function TCustomDirView.CustomCreateFileList(Focused, OnlyFocused: Boolean;
FullPath: Boolean; FileList: TStrings; ItemObject: Boolean): TStrings;

Expand All @@ -2224,8 +2232,7 @@ function TCustomDirView.CustomCreateFileList(Focused, OnlyFocused: Boolean;
else Result := TStringList.Create;

try
if Assigned(ItemFocused) and
((Focused and (not ItemFocused.Selected)) or (SelCount = 0) or OnlyFocused) then
if OperateOnFocusedFile(Focused, OnlyFocused) then
begin
AddItem(ItemFocused)
end
Expand Down
57 changes: 27 additions & 30 deletions source/packages/filemng/DirView.pas
Expand Up @@ -236,6 +236,7 @@ TDirView = class(TCustomDirView)
procedure CMRecreateWnd(var Message: TMessage); message CM_RECREATEWND;
procedure Load(DoFocusSomething: Boolean); override;
function GetFileInfo(pszPath: LPCWSTR; dwFileAttributes: DWORD; var psfi: TSHFileInfoW; cbFileInfo, uFlags: UINT): DWORD_PTR;
function DoCopyToClipboard(Focused: Boolean; Cut: Boolean; Operation: TClipBoardOperation): Boolean;

function HiddenCount: Integer; override;
function FilteredCount: Integer; override;
Expand All @@ -255,8 +256,8 @@ TDirView = class(TCustomDirView)
function UndoCopyMove: Boolean; dynamic;
{Clipboard fileoperation methods (requires drag&drop enabled):}
procedure EmptyClipboard; dynamic;
function CopyToClipBoard: Boolean; dynamic;
function CutToClipBoard: Boolean; dynamic;
function CopyToClipBoard(Focused: Boolean): Boolean; dynamic;
function CutToClipBoard(Focused: Boolean): Boolean; dynamic;
function PasteFromClipBoard(TargetPath: string = ''): Boolean; override;
function DuplicateSelectedFiles: Boolean; dynamic;
procedure DisplayPropertiesMenu; override;
Expand Down Expand Up @@ -3328,7 +3329,7 @@ procedure TDirView.EmptyClipboard;
end;
end; {EmptyClipBoard}

function TDirView.CopyToClipBoard : Boolean;
function TDirView.DoCopyToClipboard(Focused: Boolean; Cut: Boolean; Operation: TClipBoardOperation): Boolean;
var
Item: TListItem;
SaveCursor: TCursor;
Expand All @@ -3339,44 +3340,40 @@ function TDirView.CopyToClipBoard : Boolean;
Result := False;
EmptyClipBoard;
DragDropFilesEx.FileList.Clear;
if SelCount > 0 then
if OperateOnFocusedFile(Focused) or (SelCount > 0) then
begin
Item := GetNextItem(nil, sdAll, [isSelected]);
while Assigned(Item) do
if OperateOnFocusedFile(Focused) then
begin
DragDropFilesEx.FileList.AddItem(nil, ItemFullFileName(Item));
Item := GetNextItem(Item, sdAll, [isSelected]);
DragDropFilesEx.FileList.AddItem(nil, ItemFullFileName(ItemFocused));
end
else
begin
Item := GetNextItem(nil, sdAll, [isSelected]);
while Assigned(Item) do
begin
DragDropFilesEx.FileList.AddItem(nil, ItemFullFileName(Item));
Item.Cut := Cut;
Item := GetNextItem(Item, sdAll, [isSelected]);
end;
end;

Result := DragDropFilesEx.CopyToClipBoard;
LastClipBoardOperation := cboCopy;
LastClipBoardOperation := Operation;
end;
finally
Screen.Cursor := SaveCursor;
end;
end; {CopyToClipBoard}
end; {DoCopyToClipBoard}

function TDirView.CutToClipBoard : Boolean;
var
Item: TListItem;
function TDirView.CopyToClipBoard(Focused: Boolean): Boolean;
begin
Result := False;
EmptyClipBoard;
DragDropFilesEx.FileList.Clear;
if SelCount > 0 then
begin
Item := GetNextItem(nil, sdAll, [isSelected]);
while Assigned(Item) do
begin
DragDropFilesEx.FileList.AddItem(nil, ItemFullFileName(Item));
Item.Cut := True;
Item := GetNextItem(Item, sdAll, [isSelected]);
end;
Result := DoCopyToClipboard(Focused, False, cboCopy);
end;

Result := DragDropFilesEx.CopyToClipBoard;
LastClipBoardOperation := cboCut;
end;
end; {CutToClipBoard}
function TDirView.CutToClipBoard(Focused: Boolean): Boolean;
begin
Result := DoCopyToClipboard(Focused, True, cboCut);
end;

function TDirView.PasteFromClipBoard(TargetPath: string): Boolean;
begin
Expand Down Expand Up @@ -3421,7 +3418,7 @@ function TDirView.DuplicateSelectedFiles: Boolean;
Result := False;
if SelCount > 0 then
begin
Result := CopyToClipBoard;
Result := CopyToClipBoard(False);
if Result then
try
SelectNewFiles := True;
Expand Down

0 comments on commit 0e79b99

Please sign in to comment.