Compare commits

..
5 changed files with 209 additions and 16 deletions

No files matched your search

+11
View File
@@ -204,6 +204,17 @@ Warning і початковий фокус на No.
Незбережені зміни у примусово закритих вікнах втрачаються.
Закриття процесів і результат записуються до `kswitcher.log`.
- У файловій панелі Ctrl+C копіює позначені або поточний локальний
елемент у файловий буфер Windows. Ctrl+V вставляє файли й папки в
поточний локальний каталог через звичайний діалог Copy і показує
конфлікти та прогрес. Клік або навігація у файловій панелі вибирають
файловий контекст. Клік у командному рядку або введення тексту
повертають текстовий контекст Ctrl+C / Ctrl+V.
- **Commands → Copy full path** або **Ctrl+Shift+C** копіює повний шлях
файла чи папки під курсором як текст. У LAN- і FTP-панелях текст включає
адресу віддаленого джерела. Для рядка `..` команда не змінює буфер.
- Ctrl+F вставляє повний шлях елемента під курсором активної панелі в позицію
курсора командного рядка або замінює виділення. Подвійні лапки додаються
лише до шляхів із пробілами. На рядку `..` вставляється шлях папки,
+123 -16
View File
@@ -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))
+1
View File
@@ -331,6 +331,7 @@ LRESULT CALLBACK pathBarInput(HWND window,UINT message,WPARAM wp,LPARAM lp,UINT_
ReleaseCapture();
const int index=GetDlgCtrlID(window)-142;
if(index<0 || index>=2) return 0;
panelClipboardContext=true;
auto &panel=panels[index];
if(!localNavigationAvailable(panel))
{
+71
View File
@@ -486,6 +486,77 @@ Clip textClip(const std::wstring &text)
memcpy(f.data.data(), text.c_str(), f.data.size());
return Clip{{std::move(f)}};
}
Clip fileDropClip(std::span<const std::filesystem::path> paths)
{
std::wstring names;
for(const auto &path:paths)
{
if(!path.is_absolute() || path.native().find(L'\0')!=std::wstring::npos)
throw std::invalid_argument("A file clipboard path must be absolute and contain no nulls.");
names+=path.native();
names+=L'\0';
}
if(paths.empty()) names+=L'\0';
names+=L'\0';
DROPFILES header{};
header.pFiles=sizeof(header);
header.fWide=TRUE;
Format files{CF_HDROP,{},Bytes(sizeof(header)+names.size()*sizeof(wchar_t))};
memcpy(files.data.data(),&header,sizeof(header));
memcpy(files.data.data()+sizeof(header),names.data(),names.size()*sizeof(wchar_t));
const DWORD effect=DROPEFFECT_COPY;
Format preferred{0,CFSTR_PREFERREDDROPEFFECT,Bytes(sizeof(effect))};
memcpy(preferred.data.data(),&effect,sizeof(effect));
return Clip{{std::move(files),std::move(preferred)}};
}
std::vector<std::filesystem::path> fileDropPaths(HANDLE medium)
{
const auto size=medium?GlobalSize(medium):0;
if(size<sizeof(DROPFILES)) return {};
const auto bytes=static_cast<const unsigned char *>(GlobalLock(medium));
if(!bytes) return {};
DROPFILES header{};
memcpy(&header,bytes,sizeof(header));
bool terminated=false;
if(header.pFiles>=sizeof(header) && header.pFiles<size)
{
const auto start=bytes+header.pFiles;
if(!header.fWide)
terminated=std::search_n(start,bytes+size,2,static_cast<unsigned char>(0))!=bytes+size;
else if(header.pFiles%alignof(wchar_t)==0)
{
const auto names=reinterpret_cast<const wchar_t *>(start);
const auto end=names+(size-header.pFiles)/sizeof(wchar_t);
terminated=std::search_n(names,end,2,L'\0')!=end;
}
}
GlobalUnlock(medium);
if(!terminated) return {};
const auto drop=reinterpret_cast<HDROP>(medium);
const UINT count=DragQueryFileW(drop,UINT(-1),nullptr,0);
std::vector<std::filesystem::path> paths;
std::set<std::filesystem::path> seen;
for(UINT index=0;index<count;++index)
{
const UINT length=DragQueryFileW(drop,index,nullptr,0);
if(!length || length>32767) continue;
std::wstring name(length+1,L'\0');
if(DragQueryFileW(drop,index,name.data(),length+1)!=length) continue;
name.resize(length);
auto path=std::filesystem::path(std::move(name)).lexically_normal();
if(path.is_absolute() && seen.insert(path).second) paths.push_back(std::move(path));
}
return paths;
}
std::vector<std::filesystem::path> readClipboardFilePaths(HWND window)
{
ClipboardLock lock(window);
return fileDropPaths(GetClipboardData(CF_HDROP));
}
std::wstring Clip::text() const
{
for (const auto &f : formats)
+3
View File
@@ -59,6 +59,9 @@ Clip readClipboard(HWND, size_t limit = 32 * 1024 * 1024,
DWORD writeClipboard(HWND, const Clip &);
DWORD writeClipboardGuarded(HWND, const Clip &, std::optional<DWORD> expected);
Clip textClip(const std::wstring &);
Clip fileDropClip(std::span<const std::filesystem::path> paths);
std::vector<std::filesystem::path> fileDropPaths(HANDLE medium);
std::vector<std::filesystem::path> readClipboardFilePaths(HWND window);
bool chord(WORD key, UINT modifiers = 0);
bool chord(std::span<const WORD> keys);
struct SystemVolume