Compare commits

...
2 Commits
5 changed files with 301 additions and 12 deletions

No files matched your search

+10
View File
@@ -429,6 +429,16 @@ Warning і початковий фокус на No.
## Панелі
- **F9 → Commands → Find files** або **Alt+F7** запускає фоновий пошук
файлів у поточній локальній папці та її підпапках. Поле приймає повне
ім’я або маску без урахування регістру. `*` відповідає довільній
послідовності символів, `?` — одному символу. Приховані та системні
елементи можна включити прапорцем. Пошук не обходить junction та інші
посилання на каталоги. Esc під час пошуку зупиняє обхід і показує знайдене.
Результати відкриваються в тій самій панелі з відносними шляхами.
Enter або подвійний клік відкриває папку й ставить курсор на файл.
Esc у результатах повертає вихідну папку, курсор і позначки.
- Обидві панелі автоматично підхоплюють створення, зміну й видалення файлів
у відкритих локальних папках. Фокус залишається там, де був, а курсор
лишається на поточному елементі, якщо той ще існує.
+13
View File
@@ -407,3 +407,16 @@ BEGIN
LTEXT "Reading and comparing files...", -1, 14, 15, 262, 13
CONTROL "&Cancel", IDCANCEL, "Button", BS_OWNERDRAW | WS_TABSTOP, 101, 31, 88, 17
END
116 DIALOGEX 0, 0, 300, 98
STYLE DS_SETFONT | DS_CENTER | WS_POPUP
CAPTION "Find files"
FONT 10, "Consolas"
BEGIN
LTEXT "File &name or mask", 483, 16, 18, 268, 12
FAR_EDIT(480, 0, 16, 32, 268, 15)
AUTOCHECKBOX "Include &hidden and system files", 481, 16, 53, 268, 12
LTEXT "", 482, 10, 69, 1, 1, NOT WS_VISIBLE
CONTROL "&Find", IDOK, "Button", BS_OWNERDRAW | WS_TABSTOP, 68, 73, 80, 17
CONTROL "&Cancel", IDCANCEL, "Button", BS_OWNERDRAW | WS_TABSTOP, 152, 73, 80, 17
END
+75
View File
@@ -0,0 +1,75 @@
constexpr int findMask=480, findHidden=481, findFooter=482, findLabel=483;
INT_PTR CALLBACK findFilesDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
{
if(message==WM_DRAWITEM)
{
paintDialogButton(*reinterpret_cast<const DRAWITEMSTRUCT *>(lp),RGB(192,192,192),RGB(0,0,0),true);
return TRUE;
}
if(const auto painted=paintCopyDialog(dialog,message,wp,lp,L" Find files ",false,{findFooter}))
return painted;
if(message==WM_INITDIALOG)
{
const auto &options=*reinterpret_cast<Panel::FindOptions *>(lp);
SetWindowLongPtrW(dialog,DWLP_USER,lp);
prepareTextDialog(dialog);
layoutDialogContent(dialog,findLabel);
for(const auto id:{IDOK,IDCANCEL})
{
const auto button=GetDlgItem(dialog,id);
SetWindowPos(button,nullptr,0,0,farDialogButtonWidth(button),textHeight,
SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
}
layoutDialogButtons(dialog,findFooter,{IDOK,IDCANCEL});
installFarCheckbox(GetDlgItem(dialog,findHidden),FarCheckboxSurface::gray);
SendDlgItemMessageW(dialog,findMask,EM_SETLIMITTEXT,255,0);
SetDlgItemTextW(dialog,findMask,options.mask.c_str());
CheckDlgButton(dialog,findHidden,options.includeHidden?BST_CHECKED:BST_UNCHECKED);
SetFocus(GetDlgItem(dialog,findMask));
SendDlgItemMessageW(dialog,findMask,EM_SETSEL,0,-1);
return FALSE;
}
if(message==WM_COMMAND && LOWORD(wp)==IDOK)
{
auto &options=*reinterpret_cast<Panel::FindOptions *>(GetWindowLongPtrW(dialog,DWLP_USER));
wchar_t mask[256]{};
GetDlgItemTextW(dialog,findMask,mask,static_cast<int>(std::size(mask)));
if(std::wstring_view(mask).find_first_of(L"/\\:")!=std::wstring_view::npos)
{
showFilesNotice(dialog,L"Enter a file name or mask without a path.",L"Find files");
SetFocus(GetDlgItem(dialog,findMask));
return TRUE;
}
options.mask=*mask?mask:L"*";
options.includeHidden=IsDlgButtonChecked(dialog,findHidden)==BST_CHECKED;
FilesModalDialog::finish(dialog,IDOK);
return TRUE;
}
if(message==WM_CLOSE || (message==WM_COMMAND && LOWORD(wp)==IDCANCEL))
{
FilesModalDialog::finish(dialog,IDCANCEL);
return TRUE;
}
return FALSE;
}
void findLocalFiles(HWND owner,Panel &panel)
{
if(panel.peer || panel.ftp || panel.directory.empty())
{
setStatus(L"Find files requires a local folder.");
return;
}
if(panel.scanRequest)
{
setStatus(L"Wait for the current scan to finish.");
return;
}
Panel::FindOptions options;
if(FilesModalDialog::run(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(116),owner,
findFilesDialog,reinterpret_cast<LPARAM>(&options))!=IDOK) return;
cancelFolderSizes(panel);
panel.scanRequest=Panel::ScanRequest{.directory=panel.directory,.statusRevision=statusRevision,.find=std::move(options)};
startDirectoryScan(panel);
}
+74
View File
@@ -0,0 +1,74 @@
bool matchesFileMask(std::wstring_view name,std::wstring_view mask)
{
size_t fileIndex=0, maskIndex=0, star=mask.npos, afterStar=0;
while(fileIndex<name.size())
{
if(maskIndex<mask.size() && mask[maskIndex]==L'*')
{
star=maskIndex++;
afterStar=fileIndex;
}
else if(maskIndex<mask.size() &&
(mask[maskIndex]==L'?' || CompareStringOrdinal(name.data()+fileIndex,1,
mask.data()+maskIndex,1,TRUE)==CSTR_EQUAL))
{
++fileIndex;
++maskIndex;
}
else if(star!=mask.npos)
{
maskIndex=star+1;
fileIndex=++afterStar;
}
else return false;
}
return mask.find_first_not_of(L'*',maskIndex)==mask.npos;
}
std::unique_ptr<Panel::ScanResult> scanFileMatches(const Panel::ScanRequest &request,
std::atomic_size_t &entriesRead,std::stop_token stop)
{
auto result=std::make_unique<Panel::ScanResult>();
FilesConnection local(nullptr);
std::vector<fs::path> pending{request.directory};
size_t visited=0;
while(!pending.empty() && !stop.stop_requested())
{
const auto directory=std::move(pending.back());
pending.pop_back();
try
{
listFiles(local,directory,[&](const fs::path &path,const FileInfo &entry)
{
if(stop.stop_requested()) return false;
entriesRead.store(++visited,std::memory_order_relaxed);
if(!request.find->includeHidden && (entry.attributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
return true;
if(entry.attributes&FILE_ATTRIBUTE_DIRECTORY)
{
if(!(entry.attributes&FILE_ATTRIBUTE_REPARSE_POINT)) pending.push_back(path);
}
else if(matchesFileMask(path.filename().native(),request.find->mask))
{
result->files.push_back(path);
result->metadata.emplace(path,FolderEntryMetadata{entry.attributes,entry.size});
result->timestamps.emplace(path,entry.modified);
}
return true;
});
}
catch(const std::system_error &)
{
if(directory==request.directory)
{
result->failure=L"Cannot search folder: "+directory.native();
return result;
}
result->error=ERROR_PARTIAL_COPY;
}
}
if(stop.stop_requested()) result->error=ERROR_CANCELLED;
result->opened=true;
std::sort(result->files.begin(),result->files.end());
return result;
}
+129 -12
View File
@@ -367,6 +367,15 @@ struct Panel
FILE_NOTIFY_CHANGE_ATTRIBUTES|FILE_NOTIFY_CHANGE_SIZE|FILE_NOTIFY_CHANGE_LAST_WRITE);
}
} watch;
struct FindOptions { std::wstring mask=L"*"; bool includeHidden{}; };
struct FindOrigin
{
fs::path cursor;
std::set<fs::path> marks;
LRESULT row{}, top{};
DWORD error{};
};
std::optional<FindOrigin> findOrigin;
struct ScanRequest
{
fs::path directory, selection, fallback;
@@ -375,6 +384,7 @@ struct Panel
uint64_t statusRevision{};
std::shared_ptr<ElevatedHelper> elevated;
std::optional<FtpProfile> ftp;
std::optional<FindOptions> find;
};
struct ScanResult
{
@@ -418,6 +428,16 @@ std::wstring panelLocation(const Panel &panel)
return (panel.peer?panel.peer->name+L" · ":std::wstring{})+panel.directory.native();
}
bool hasPanelSizeColumn(const Panel &panel)
{
return panel.wide && !panel.findOrigin;
}
std::wstring panelCaption(const Panel &panel)
{
return panel.findOrigin?L"Search results":panelLocation(panel);
}
Panel panels[2];
FilesTerminal terminal;
std::mutex pendingTerminalOutputMutex;
@@ -1207,7 +1227,7 @@ bool showDirectoryScanProgress(Panel &panel)
const auto entries=panel.scanEntriesRead ? panel.scanEntriesRead->load(std::memory_order_relaxed) : 0;
auto message=panel.scanSuperseded ? std::wstring(L"Waiting to read…") :
panel.scanStop.stop_requested() ? L"Stopping… "+std::to_wstring(entries) :
L"Reading "+std::to_wstring(entries)+L" [Esc]";
(panel.scanRequest->find?L"Searching ":L"Reading ")+std::to_wstring(entries)+L" [Esc]";
wchar_t displayed[96]{};
GetWindowTextW(status,displayed,std::size(displayed));
if(message!=displayed) setStatus(message);
@@ -1999,6 +2019,14 @@ void updateSelectionSummary(const Panel &panel)
void showFileDetails(const Panel &panel)
{
if(&panel==&panels[active] && showDirectoryScanProgress(panels[active])) return;
if(panel.findOrigin)
{
const auto error=panel.findOrigin->error;
setStatus(std::to_wstring(panel.rows.size())+(error==ERROR_CANCELLED?L" matches (stopped)":
error?L" matches (some folders could not be read)":L" matches")+
L" · Enter: Go · Esc: Back");
return;
}
if(ftpProfileList(panel))
{
setStatus(ftpProfiles.empty()?L"Shift+F4 New connection":L"Shift+F4 New F4 Edit Enter Connect");
@@ -2045,9 +2073,12 @@ void showFileDetails(const Panel &panel)
setStatus(details);
}
#include "files_find_scan.inl"
std::unique_ptr<Panel::ScanResult> scanDirectory(const Panel::ScanRequest &request,
std::atomic_size_t &entriesRead,std::stop_token stop)
{
if(request.find) return scanFileMatches(request,entriesRead,stop);
auto result=std::make_unique<Panel::ScanResult>();
auto &[watch,folders,files,metadata,timestamps,error,opened,failure,ftpInitialDirectory]=*result;
const auto &directory=request.directory;
@@ -2240,6 +2271,28 @@ bool applyDirectoryScan(Panel &panel,Panel::ScanRequest request,Panel::ScanResul
for(size_t i=0;i<panel.rows.size();++i)
if(panel.marked[i]) markedPaths.insert(panel.rows[i]);
}
const bool finding=request.find.has_value();
const bool viewChanged=finding!=panel.findOrigin.has_value();
if(finding)
{
if(!panel.findOrigin)
panel.findOrigin=Panel::FindOrigin{previousSelection,std::move(markedPaths),previousRow,previousTop};
panel.findOrigin->error=error;
previousSelection.clear();
previousRow=previousTop=0;
markedPaths.clear();
}
else if(panel.findOrigin)
{
if(sameDirectory)
{
previousSelection=std::move(panel.findOrigin->cursor);
markedPaths=std::move(panel.findOrigin->marks);
previousRow=panel.findOrigin->row;
previousTop=panel.findOrigin->top;
}
panel.findOrigin.reset();
}
panel.directory = directory;
panel.peer=std::move(peer);
panel.ftp=std::move(request.ftp);
@@ -2248,7 +2301,7 @@ bool applyDirectoryScan(Panel &panel,Panel::ScanRequest request,Panel::ScanResul
cancelFolderSizes(panel);
panel.folderSizes.clear();
}
if(partial) panel.watch.reset();
if(partial || finding) panel.watch.reset();
else if(!sameDirectory || panel.watch.handle==INVALID_HANDLE_VALUE)
{
panel.watch.reset();
@@ -2261,7 +2314,7 @@ bool applyDirectoryScan(Panel &panel,Panel::ScanRequest request,Panel::ScanResul
panel.marked.clear();
panel.fileExtensionLength=panel.folderExtensionLength=0;
const bool profiles=ftpProfileList(panel);
const bool hasParent=directory.has_relative_path();
const bool hasParent=!finding && directory.has_relative_path();
const auto rowCount=profiles?ftpProfiles.size():folders.size()+files.size()+hasParent;
panel.rows.reserve(rowCount);
panel.sizes.reserve(rowCount);
@@ -2298,11 +2351,16 @@ bool applyDirectoryScan(Panel &panel,Panel::ScanRequest request,Panel::ScanResul
{
if(hasParent) add(directory.parent_path(),L"..",true);
for(const auto &folder:folders) add(folder,L"["+folder.filename().wstring()+L"]",true);
for(const auto &file:files) add(file,file.filename().wstring(),false);
for(const auto &file:files) add(file,finding?file.lexically_relative(directory).native():file.filename().native(),false);
}
const auto label=panelLocation(panel);
const auto label=panelCaption(panel);
SetWindowTextW(panel.path,label.c_str());
InvalidateRect(panel.path,nullptr,FALSE);
if(viewChanged)
{
InvalidateRect(panel.heading,nullptr,FALSE);
InvalidateRect(GetParent(panel.list),nullptr,FALSE);
}
if(&panel==&panels[active] && !sameDirectory)
layout(GetParent(panel.list),true);
auto selected=std::find(panel.rows.begin(),panel.rows.end(),previousSelection);
@@ -2326,7 +2384,8 @@ bool applyDirectoryScan(Panel &panel,Panel::ScanRequest request,Panel::ScanResul
if(visible) SendMessageW(panel.list,WM_SETREDRAW,TRUE,0);
InvalidateRect(panel.list,nullptr,FALSE);
updateSelectionSummary(panel);
if(partial && &panel==&panels[active])
if(finding && &panel==&panels[active]) showFileDetails(panel);
else if(partial && &panel==&panels[active])
setStatus(L"Partial: "+std::to_wstring(folders.size()+files.size()));
else if(!partial && error!=ERROR_SUCCESS && error!=ERROR_NO_MORE_FILES && error!=ERROR_FILE_NOT_FOUND)
setStatus(L"Some entries could not be read.");
@@ -2595,6 +2654,7 @@ void collectFolderSizes(Panel &panel)
}
void openSelectedText(const Panel &panel, bool edit, bool external);
void findLocalFiles(HWND owner,Panel &panel);
void compareSelectedFiles(HWND owner);
INT_PTR confirmTextSave(HWND owner,bool draft);
bool chooseTextSaveOptions(HWND owner,fs::path &destination,ks::files::TextSaveFormat &format);
@@ -2730,6 +2790,7 @@ void selectDrive()
else if(menuIndex==2 && (row==4 || row==5)) openSelectedText(panels[active],row==5,true);
else if(menuIndex==2 && (row==6 || row==7)) runActivePeerAction(owner,row==7);
else if(menuIndex==2 && row==8) compareSelectedFiles(owner);
else if(menuIndex==2 && row==9) findLocalFiles(owner,panels[active]);
else
{
const int command=menuIndex==1?113+static_cast<int>(row):110+static_cast<int>(row);
@@ -3280,6 +3341,11 @@ void enter(Panel &panel)
return;
}
auto target = panel.rows[row];
if(panel.findOrigin)
{
openOn(panel,target.parent_path(),false,{},target);
return;
}
if(panel.sizes[row]==L"Folder" || panel.sizes[row]==L"Up") open(panel,target,true);
else if(panel.ftp) openSelectedText(panel,false,false);
else openPanelFile(panel, target, nullptr, L"Cannot open the selected file.");
@@ -5104,6 +5170,11 @@ CopyResult copyItem(const CopyEndpoints &hosts,const fs::path &from,const fs::pa
void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
{
if(source.findOrigin || destination.findOrigin)
{
setStatus(L"Open the folder before copying or moving files.");
return;
}
const auto sourceFtp=source.ftp;
const bool ftpRename=move && sourceFtp && !ftpProfileList(source);
const auto destinationFtp=ftpRename?sourceFtp:destination.ftp;
@@ -5461,6 +5532,11 @@ INT_PTR CALLBACK deleteProgressDialog(HWND window,UINT message,WPARAM wp,LPARAM
void deleteSelection(HWND owner,Panel &panel,bool permanent)
{
if(panel.findOrigin)
{
setStatus(L"Open the folder before making changes.");
return;
}
if(ftpProfileList(panel)) return;
if(copyInProgress) return;
const auto ftp=panel.ftp;
@@ -5881,6 +5957,11 @@ INT_PTR CALLBACK makeFolderDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
void makeFolder(HWND owner,Panel &panel)
{
if(panel.findOrigin)
{
setStatus(L"Open the folder before making changes.");
return;
}
if(panel.ftp) return;
if(panel.directory.empty()) return;
const auto directory=panel.directory;
@@ -6067,6 +6148,11 @@ bool chooseTextSaveOptions(HWND owner,fs::path &destination,ks::files::TextSaveF
void openOrCreateText(HWND owner,const Panel &panel)
{
if(panel.findOrigin)
{
setStatus(L"Open the folder before making changes.");
return;
}
if(panel.ftp) return;
if(panel.peer)
{
@@ -6232,7 +6318,7 @@ LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT
auto result=DefSubclassProc(window,message,wp,lp);
if(movesCursor) invalidatePanelCursorChange(window,previous);
if(message==WM_LBUTTONUP && GetFocus()==window) restoreCommandFocus();
if(message==WM_PAINT && panels[index].wide)
if(message==WM_PAINT && hasPanelSizeColumn(panels[index]))
{
auto dc=GetDC(window);
if(dc)
@@ -6274,6 +6360,7 @@ bool loadFilesPreferences(HWND window)
return true;
}
#include "files_find.inl"
#include "files_options.inl"
void openMenu(HWND window, int index)
@@ -6302,12 +6389,14 @@ 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"Hibernate remote PC",L"Update remote KSwitcher",L"Compare files\t"+comparisonShortcutLabel(),
L"Find files\tAlt+F7"};
}
commandActions.clear();
if(index==2)
{
commandActions={0,3,-1,1,2,4,5,8};
if(!panels[active].peer && !panels[active].ftp) commandActions.insert(commandActions.begin()+1,9);
if(panels[active].peer) commandActions.insert(commandActions.end(),{-1,6,7});
}
else
@@ -6771,7 +6860,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
InflateRect(&box,-3,-3);
FrameRect(dc,&box,border);
FillRect(dc,&divider,border);
if(panel.wide)
if(hasPanelSizeColumn(panel))
{
RECT column{columnX,box.top+1,columnX+1,pathBounds.bottom+6};
FillRect(dc,&column,border);
@@ -6822,7 +6911,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
auto bounds=item.rcItem;
FillRect(item.hDC,&bounds,blue);
const auto &panel=panels[item.CtlID-142];
const auto path=panelLocation(panel);
const auto path=panelCaption(panel);
const auto middle=bounds.top+(bounds.bottom-bounds.top)/2;
SetDCBrushColor(item.hDC,colors[Frame]);
const auto lineBrush=static_cast<HBRUSH>(GetStockObject(DC_BRUSH));
@@ -6830,7 +6919,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
RECT lower{bounds.left,middle+1,bounds.right,middle+2};
FillRect(item.hDC,&upper,lineBrush);
FillRect(item.hDC,&lower,lineBrush);
if(panels[item.CtlID-142].wide)
if(hasPanelSizeColumn(panel))
{
const auto index=item.CtlID-142;
RECT list{};
@@ -6861,6 +6950,11 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
}
if(item.CtlID==140 || item.CtlID==141)
{
if(panels[item.CtlID-140].findOrigin)
{
paintText(item.hDC,item.rcItem,L"Relative path",RGB(255,255,0),colors[PanelBlue]);
return TRUE;
}
auto name=item.rcItem, size=item.rcItem;
size.left=panelSizeColumn(size);
name.right=size.left;
@@ -7092,7 +7186,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
if(item.CtlID==102 || item.CtlID==103)
{
const auto &panel=panels[item.CtlID-102];
if(panel.wide && !ftpProfileList(panel) && item.itemID<panel.sizes.size())
if(hasPanelSizeColumn(panel) && !ftpProfileList(panel) && item.itemID<panel.sizes.size())
{
auto name=item.rcItem, size=item.rcItem;
size.left=panelSizeColumn(size);
@@ -7322,6 +7416,16 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
(message.hwnd==terminalInput || message.hwnd==panels[0].list || message.hwnd==panels[1].list))
{
auto &panel=panels[active];
if(panel.scanRequest && panel.scanRequest->find)
{
if(!panel.scanSuperseded) stopDirectoryScan();
continue;
}
if(panel.findOrigin && !panel.scanRequest)
{
openOn(panel,panel.directory,false,{});
continue;
}
if(panel.folderSizeJob)
{
collectFolderSizes(panel);
@@ -7333,6 +7437,19 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
continue;
}
}
if(!terminalVisible && !copyInProgress && !commandHistoryWindow && !FilesModalDialog::activeFor(window) &&
message.message==WM_SYSKEYDOWN && message.wParam==VK_F7 &&
(message.lParam & (1LL<<29)) &&
!((GetKeyState(VK_CONTROL)|GetKeyState(VK_SHIFT)|GetKeyState(VK_LWIN)|GetKeyState(VK_RWIN))&0x8000))
{
if(!(message.lParam & (1LL<<30)))
{
hidePicker();
showMenu(false);
findLocalFiles(window,panels[active]);
}
continue;
}
if(!copyInProgress && !commandHistoryWindow && !FilesModalDialog::activeFor(window) && !terminalVisible &&
message.message==WM_SYSKEYDOWN && (message.wParam==VK_F3 || message.wParam==VK_F4) &&
(message.lParam & (1LL<<29)) &&