|
|
|
@@ -508,6 +508,7 @@ std::wstring panelCaption(const Panel &panel)
|
|
|
|
|
Panel panels[2];
|
|
|
|
|
HWND quickViewWindow{};
|
|
|
|
|
int quickViewSource{};
|
|
|
|
|
bool panelClipboardContext=true;
|
|
|
|
|
void refreshQuickView(const Panel &panel);
|
|
|
|
|
void toggleQuickView(HWND owner);
|
|
|
|
|
FilesTerminal terminal;
|
|
|
|
@@ -1661,12 +1662,18 @@ void clearTerminalSelection()
|
|
|
|
|
terminalView.post(L"clear-selection");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool copyFilesText(HWND owner,const std::wstring &value,const wchar_t *failure)
|
|
|
|
|
{
|
|
|
|
|
try {ks::writeClipboard(owner,ks::textClip(value));}
|
|
|
|
|
catch(const std::exception &) {setStatus(failure);return false;}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void copyTerminalText(HWND owner)
|
|
|
|
|
{
|
|
|
|
|
const auto value=terminalSelection.empty()?terminalInputText():terminalSelection;
|
|
|
|
|
if(value.empty()) return;
|
|
|
|
|
try { ks::writeClipboard(owner,ks::textClip(value)); }
|
|
|
|
|
catch(const std::exception &) { setStatus(L"Could not copy terminal text."); }
|
|
|
|
|
copyFilesText(owner,value,L"Could not copy terminal text.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LRESULT currentPanelRow(const Panel &panel)
|
|
|
|
@@ -1703,8 +1710,46 @@ void copyPanelNames(HWND owner)
|
|
|
|
|
names+=path.filename().native();
|
|
|
|
|
}
|
|
|
|
|
if(names.empty()) return;
|
|
|
|
|
try { ks::writeClipboard(owner,ks::textClip(names)); }
|
|
|
|
|
catch(const std::exception &) { setStatus(L"Could not copy file names."); }
|
|
|
|
|
copyFilesText(owner,names,L"Could not copy file names.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void copyPanelFiles(HWND owner,const Panel &panel)
|
|
|
|
|
{
|
|
|
|
|
if(panel.peer || panel.ftp)
|
|
|
|
|
{
|
|
|
|
|
setStatus(L"File clipboard copy requires local files.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const auto paths=selectedPanelPaths(panel);
|
|
|
|
|
if(paths.empty()) return;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ks::writeClipboard(owner,ks::fileDropClip(paths));
|
|
|
|
|
setStatus(std::to_wstring(paths.size())+(paths.size()==1?L" item copied":L" items copied")+L" to the file clipboard.");
|
|
|
|
|
}
|
|
|
|
|
catch(const std::exception &) {setStatus(L"Could not copy files to the clipboard.");}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void copyFullPanelPath(HWND owner,const Panel &panel)
|
|
|
|
|
{
|
|
|
|
|
const auto row=currentPanelRow(panel);
|
|
|
|
|
if(row==LB_ERR || panel.sizes[row]==L"Up" || ftpProfileList(panel)) return;
|
|
|
|
|
const auto &path=panel.rows[row];
|
|
|
|
|
auto value=path.native();
|
|
|
|
|
if(panel.ftp)
|
|
|
|
|
{
|
|
|
|
|
const auto &profile=*panel.ftp;
|
|
|
|
|
const auto host=profile.host.find(L':')!=std::wstring::npos && !profile.host.starts_with(L"[")?
|
|
|
|
|
L"["+profile.host+L"]":profile.host;
|
|
|
|
|
value=L"FTP "+host+L":"+std::to_wstring(profile.port)+L" · "+ftpPath(path);
|
|
|
|
|
}
|
|
|
|
|
else if(panel.peer)
|
|
|
|
|
{
|
|
|
|
|
auto host=panel.peer->name;
|
|
|
|
|
if(!panel.peer->address.empty()) host+=L" ("+ks::wide(panel.peer->address)+L")";
|
|
|
|
|
value=host+L" · "+value;
|
|
|
|
|
}
|
|
|
|
|
if(copyFilesText(owner,value,L"Could not copy the full path.")) setStatus(L"Full path copied.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void copyCommandLineOrPanelNames(HWND owner)
|
|
|
|
@@ -1996,6 +2041,7 @@ LRESULT CALLBACK terminalInputKeys(HWND input,UINT message,WPARAM wp,LPARAM lp,U
|
|
|
|
|
if(message==WM_KILLFOCUS) resetCompletion();
|
|
|
|
|
if(message==WM_LBUTTONDOWN || message==WM_RBUTTONDOWN)
|
|
|
|
|
{
|
|
|
|
|
panelClipboardContext=false;
|
|
|
|
|
clearTerminalSelection();
|
|
|
|
|
hideCompletion();
|
|
|
|
|
}
|
|
|
|
@@ -2040,7 +2086,11 @@ LRESULT CALLBACK terminalInputKeys(HWND input,UINT message,WPARAM wp,LPARAM lp,U
|
|
|
|
|
}
|
|
|
|
|
if(message==WM_KEYDOWN && !terminalVisible && wp==VK_TAB)
|
|
|
|
|
{
|
|
|
|
|
if(plainPanelTab()) activatePanel(1-active);
|
|
|
|
|
if(plainPanelTab())
|
|
|
|
|
{
|
|
|
|
|
panelClipboardContext=true;
|
|
|
|
|
activatePanel(1-active);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if(message==WM_KEYDOWN && !terminalVisible &&
|
|
|
|
@@ -2907,6 +2957,7 @@ void selectDrive()
|
|
|
|
|
else if(menuIndex==2 && row==8) compareSelectedFiles(owner);
|
|
|
|
|
else if(menuIndex==2 && row==9) findLocalFiles(owner,panels[active]);
|
|
|
|
|
else if(menuIndex==2 && row==10) toggleQuickView(owner);
|
|
|
|
|
else if(menuIndex==2 && row==11) copyFullPanelPath(owner,panels[active]);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int command=menuIndex==1?113+static_cast<int>(row):110+static_cast<int>(row);
|
|
|
|
@@ -3571,7 +3622,7 @@ struct CopyRequest
|
|
|
|
|
std::future<CopyDestination> validation;
|
|
|
|
|
std::wstring ftpDestination;
|
|
|
|
|
bool upload{};
|
|
|
|
|
bool ftpRename{};
|
|
|
|
|
bool ftpRename{}, externalSources{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool directoryExists(const FilesPeer *peer,const fs::path &path)
|
|
|
|
@@ -4185,9 +4236,10 @@ CopyDestination validateCopyDestination(CopyRequest request,const std::wstring &
|
|
|
|
|
else request.newName.clear();
|
|
|
|
|
}
|
|
|
|
|
const auto sourceDirectory=request.sources.front().parent_path();
|
|
|
|
|
const auto destination=request.move || request.newName.empty()?request.destination:sourceDirectory;
|
|
|
|
|
const bool renameInSource=!request.externalSources && !request.move && !request.newName.empty();
|
|
|
|
|
const auto destination=renameInSource?sourceDirectory:request.destination;
|
|
|
|
|
std::error_code error;
|
|
|
|
|
const auto peer=request.move || request.newName.empty()?request.destinationPeer:request.sourcePeer;
|
|
|
|
|
const auto peer=renameInSource?request.sourcePeer:request.destinationPeer;
|
|
|
|
|
if(!directoryExists(peer,destination))
|
|
|
|
|
throw std::runtime_error(ks::utf8(L"The destination folder is unavailable."));
|
|
|
|
|
const bool sameHost=(!peer && !request.sourcePeer) ||
|
|
|
|
@@ -4345,6 +4397,7 @@ INT_PTR CALLBACK copyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp)
|
|
|
|
|
snapshot.move=request.move;
|
|
|
|
|
snapshot.ftpDestination=request.ftpDestination;
|
|
|
|
|
snapshot.upload=request.upload;
|
|
|
|
|
snapshot.externalSources=request.externalSources;
|
|
|
|
|
std::packaged_task<CopyDestination()> validation(
|
|
|
|
|
[snapshot=std::move(snapshot),value=std::move(value),
|
|
|
|
|
source=peer(request.sourcePeer),other=peer(request.otherPeer)]() mutable {
|
|
|
|
@@ -5401,7 +5454,7 @@ void pruneSearchResults(Panel &panel,const std::set<fs::path> &removed)
|
|
|
|
|
updateSelectionSummary(panel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
|
|
|
|
|
void copySelection(HWND owner,Panel &source,Panel &destination,bool move,std::vector<fs::path> external={})
|
|
|
|
|
{
|
|
|
|
|
const auto sourceFtp=source.ftp;
|
|
|
|
|
const bool ftpRename=move && sourceFtp && !ftpProfileList(source);
|
|
|
|
@@ -5437,6 +5490,7 @@ void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
|
|
|
|
|
CopyRequest request{{},ftpRename?source.directory:destination.directory};
|
|
|
|
|
request.move=move;
|
|
|
|
|
request.ftpRename=ftpRename;
|
|
|
|
|
request.externalSources=!external.empty();
|
|
|
|
|
if(ftp)
|
|
|
|
|
{
|
|
|
|
|
request.ftpDestination=panelLocation(destination);
|
|
|
|
@@ -5445,7 +5499,7 @@ void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
|
|
|
|
|
request.otherDirectory=destination.directory;
|
|
|
|
|
request.sourcePeer=source.peer?&*source.peer:nullptr;
|
|
|
|
|
request.otherPeer=request.destinationPeer=destination.peer?&*destination.peer:nullptr;
|
|
|
|
|
request.sources=selectedPanelPaths(source);
|
|
|
|
|
request.sources=request.externalSources?std::move(external):selectedPanelPaths(source);
|
|
|
|
|
if(request.sources.empty()) return;
|
|
|
|
|
if(ftpRename && request.sources.size()!=1)
|
|
|
|
|
{
|
|
|
|
@@ -5458,7 +5512,7 @@ void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
|
|
|
|
|
if(result!=IDOK) return;
|
|
|
|
|
|
|
|
|
|
const bool renamed=!request.newName.empty();
|
|
|
|
|
const bool renameInSource=renamed && !move && !ftp;
|
|
|
|
|
const bool renameInSource=renamed && !move && !ftp && !request.externalSources;
|
|
|
|
|
const auto targetDirectory=renameInSource?request.sources.front().parent_path():request.destination;
|
|
|
|
|
const auto *targetPeer=renameInSource?request.sourcePeer:request.destinationPeer;
|
|
|
|
|
const auto peerId=[](const FilesPeer *peer){return peer?peer->id:std::string{};};
|
|
|
|
@@ -5550,7 +5604,7 @@ void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
|
|
|
|
|
++copied;
|
|
|
|
|
if(move && fromSearch) removed.insert(path);
|
|
|
|
|
results.insert(progress.renamedTarget.empty()?to:progress.renamedTarget);
|
|
|
|
|
progress.ui.invoke([&] {
|
|
|
|
|
if(!request.externalSources) progress.ui.invoke([&] {
|
|
|
|
|
const auto row=std::find(source.rows.begin(),source.rows.end(),path);
|
|
|
|
|
if(row!=source.rows.end()) source.marked[row-source.rows.begin()]=false;
|
|
|
|
|
InvalidateRect(source.list,nullptr,FALSE);
|
|
|
|
@@ -6014,8 +6068,33 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
|
|
|
|
|
warningBrush=nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool pastePanelFiles(HWND owner,Panel &panel)
|
|
|
|
|
{
|
|
|
|
|
if(!IsClipboardFormatAvailable(CF_HDROP)) return false;
|
|
|
|
|
if(panel.peer || panel.ftp || panel.findOrigin)
|
|
|
|
|
{
|
|
|
|
|
setStatus(L"Open a local folder before pasting files.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
std::vector<fs::path> paths;
|
|
|
|
|
try {paths=ks::readClipboardFilePaths(owner);}
|
|
|
|
|
catch(const std::exception &)
|
|
|
|
|
{
|
|
|
|
|
setStatus(L"Could not read file paths from the clipboard.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if(paths.empty())
|
|
|
|
|
{
|
|
|
|
|
setStatus(L"The clipboard has no usable file paths.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
copySelection(owner,panel,panel,false,std::move(paths));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void selectPanelEdge(Panel &panel,bool first)
|
|
|
|
|
{
|
|
|
|
|
panelClipboardContext=true;
|
|
|
|
|
activatePanel(static_cast<int>(&panel-panels));
|
|
|
|
|
const auto count=SendMessageW(panel.list,LB_GETCOUNT,0,0);
|
|
|
|
|
if(count<=0) return;
|
|
|
|
@@ -6431,7 +6510,11 @@ LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT
|
|
|
|
|
if(message==WM_LBUTTONDOWN || message==WM_LBUTTONDBLCLK ||
|
|
|
|
|
(message==WM_MOUSEMOVE && (wp&MK_LBUTTON) && GetCapture()==window))
|
|
|
|
|
{
|
|
|
|
|
if(message==WM_LBUTTONDOWN) clearTerminalSelection();
|
|
|
|
|
if(message==WM_LBUTTONDOWN)
|
|
|
|
|
{
|
|
|
|
|
panelClipboardContext=true;
|
|
|
|
|
clearTerminalSelection();
|
|
|
|
|
}
|
|
|
|
|
auto &panel=panels[index];
|
|
|
|
|
const auto count=SendMessageW(window,LB_GETCOUNT,0,0);
|
|
|
|
|
if(count<=0)
|
|
|
|
@@ -6484,6 +6567,7 @@ LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT
|
|
|
|
|
const bool rangeKey=wp==VK_UP || wp==VK_DOWN || wp==VK_LEFT || wp==VK_RIGHT;
|
|
|
|
|
if(message==WM_KEYDOWN && (wp==VK_INSERT || (rangeKey && (GetKeyState(VK_SHIFT)&0x8000))))
|
|
|
|
|
{
|
|
|
|
|
panelClipboardContext=true;
|
|
|
|
|
auto &panel=panels[index];
|
|
|
|
|
const auto row=SendMessageW(window,LB_GETCURSEL,0,0);
|
|
|
|
|
if(row<0 || static_cast<size_t>(row)>=panel.marked.size()) return 0;
|
|
|
|
@@ -6525,6 +6609,7 @@ LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT
|
|
|
|
|
{
|
|
|
|
|
if(plainPanelTab())
|
|
|
|
|
{
|
|
|
|
|
panelClipboardContext=true;
|
|
|
|
|
activatePanel(1-index);
|
|
|
|
|
SetFocus(terminalInput);
|
|
|
|
|
}
|
|
|
|
@@ -6570,7 +6655,11 @@ LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT
|
|
|
|
|
(wp==VK_UP || wp==VK_DOWN || wp==VK_PRIOR || wp==VK_NEXT || wp==VK_HOME || wp==VK_END);
|
|
|
|
|
const auto previous=movesCursor?SendMessageW(window,LB_GETCURSEL,0,0):LB_ERR;
|
|
|
|
|
auto result=DefSubclassProc(window,message,wp,lp);
|
|
|
|
|
if(movesCursor) invalidatePanelCursorChange(window,previous);
|
|
|
|
|
if(movesCursor)
|
|
|
|
|
{
|
|
|
|
|
panelClipboardContext=true;
|
|
|
|
|
invalidatePanelCursorChange(window,previous);
|
|
|
|
|
}
|
|
|
|
|
if(message==WM_LBUTTONUP && GetFocus()==window) restoreCommandFocus();
|
|
|
|
|
if(message==WM_PAINT && hasPanelSizeColumn(panels[index]))
|
|
|
|
|
{
|
|
|
|
@@ -6645,12 +6734,13 @@ void openMenu(HWND window, int index)
|
|
|
|
|
rows={L"Refresh panel\tCtrl+R",L"View\tF3",L"Edit\tF4",L"Folder shortcuts",
|
|
|
|
|
L"View externally\tAlt+F3",L"Edit externally\tAlt+F4",
|
|
|
|
|
L"Hibernate remote PC",L"Update remote KSwitcher",L"Compare files\t"+comparisonShortcutLabel(),
|
|
|
|
|
L"Find files\tAlt+F7",quickViewWindow?L"Close Quick View\tCtrl+Q":L"Quick View\tCtrl+Q"};
|
|
|
|
|
L"Find files\tAlt+F7",quickViewWindow?L"Close Quick View\tCtrl+Q":L"Quick View\tCtrl+Q",
|
|
|
|
|
L"Copy full path\tCtrl+Shift+C"};
|
|
|
|
|
}
|
|
|
|
|
commandActions.clear();
|
|
|
|
|
if(index==2)
|
|
|
|
|
{
|
|
|
|
|
commandActions={0,3,-1,1,2,4,5,8};
|
|
|
|
|
commandActions={0,3,11,-1,1,2,4,5,8};
|
|
|
|
|
if(!panels[active].peer && !panels[active].ftp) commandActions.insert(commandActions.begin()+1,9);
|
|
|
|
|
if(quickViewWindow || (!panels[active].peer && !panels[active].ftp)) commandActions.push_back(10);
|
|
|
|
|
if(panels[active].peer) commandActions.insert(commandActions.end(),{-1,6,7});
|
|
|
|
@@ -7516,6 +7606,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
|
if(reinterpret_cast<HWND>(lp)==terminalInput && HIWORD(wp)==EN_CHANGE)
|
|
|
|
|
{
|
|
|
|
|
panelClipboardContext=false;
|
|
|
|
|
clearTerminalSelection();
|
|
|
|
|
resetCompletion();
|
|
|
|
|
}
|
|
|
|
@@ -7829,6 +7920,22 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
|
|
|
|
|
{
|
|
|
|
|
const bool ctrl=(GetKeyState(VK_CONTROL)&0x8000)!=0;
|
|
|
|
|
const bool shift=(GetKeyState(VK_SHIFT)&0x8000)!=0;
|
|
|
|
|
const bool fileClipboard=!terminalVisible && (panelFocused || panelClipboardContext) &&
|
|
|
|
|
commandLineAvailable(window);
|
|
|
|
|
if(fileClipboard && ctrl && !shift && (message.wParam=='C' || message.wParam=='V'))
|
|
|
|
|
{
|
|
|
|
|
if(!(message.lParam&(1LL<<30)))
|
|
|
|
|
{
|
|
|
|
|
if(message.wParam=='C') copyPanelFiles(window,panels[active]);
|
|
|
|
|
else if(!pastePanelFiles(window,panels[active])) SendMessageW(terminalInput,WM_PASTE,0,0);
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(ctrl && shift && message.wParam=='C' && !terminalVisible && commandLineAvailable(window))
|
|
|
|
|
{
|
|
|
|
|
if(!(message.lParam & (1LL<<30))) copyFullPanelPath(window,panels[active]);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if(shift && !ctrl && message.wParam==VK_F4 && !terminalVisible)
|
|
|
|
|
{
|
|
|
|
|
if(!(message.lParam & (1LL<<30)) && commandLineAvailable(window))
|
|
|
|
|