From 2a4df70079d4e85572075c1e9c64a91fe2b1684a Mon Sep 17 00:00:00 2001 From: Anatolii Hrynchuk Date: Wed, 25 Nov 2026 13:36:50 +0200 Subject: [PATCH] Copy the full path of the current file panel item Refs #90 --- FILES-UI.md | 4 ++++ src/files_main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/FILES-UI.md b/FILES-UI.md index 07ef715..3d781d0 100644 --- a/FILES-UI.md +++ b/FILES-UI.md @@ -204,6 +204,10 @@ Warning і початковий фокус на No. Незбережені зміни у примусово закритих вікнах втрачаються. Закриття процесів і результат записуються до `kswitcher.log`. +- **Commands → Copy full path** або **Ctrl+Shift+C** копіює повний шлях + файла чи папки під курсором як текст. У LAN- і FTP-панелях текст включає + адресу віддаленого джерела. Для рядка `..` команда не змінює буфер. + - Ctrl+F вставляє повний шлях елемента під курсором активної панелі в позицію курсора командного рядка або замінює виділення. Подвійні лапки додаються лише до шляхів із пробілами. На рядку `..` вставляється шлях папки, diff --git a/src/files_main.cpp b/src/files_main.cpp index edcd69a..9c2b306 100644 --- a/src/files_main.cpp +++ b/src/files_main.cpp @@ -1661,12 +1661,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 +1709,29 @@ 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 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) @@ -2907,6 +2934,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(row):110+static_cast(row); @@ -6645,12 +6673,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}); @@ -7829,6 +7858,11 @@ 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; + 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))