Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cbb0639a1 | ||
|
|
2a6f9c7841 | ||
|
|
94b22fdd52 | ||
|
|
0d293429df | ||
|
|
83a099ab25 |
No files matched your search
+26
-1
@@ -429,6 +429,21 @@ Warning і початковий фокус на No.
|
||||
|
||||
## Панелі
|
||||
|
||||
- **F9 → Commands → Find files** або **Alt+F7** запускає фоновий пошук
|
||||
файлів у поточній локальній папці та її підпапках. Поле приймає повне
|
||||
ім’я або маску без урахування регістру. `*` відповідає довільній
|
||||
послідовності символів, `?` — одному символу. Приховані та системні
|
||||
елементи можна включити прапорцем. Пошук не обходить junction та інші
|
||||
посилання на каталоги. Esc під час пошуку зупиняє обхід і показує знайдене.
|
||||
Результати відкриваються в тій самій панелі з відносними шляхами.
|
||||
Enter або подвійний клік відкриває папку й ставить курсор на файл.
|
||||
Esc у результатах повертає вихідну папку, курсор і позначки.
|
||||
У результатах F3/F4 відкривають файл, а F5/F6 працюють із позначеними
|
||||
або поточним файлом, використовуючи папку іншої панелі як призначення.
|
||||
F8 і Shift+Delete використовують звичайні підтвердження. Успішно
|
||||
переміщені та видалені файли зникають зі списку. Ctrl+R повторює пошук
|
||||
з тією самою маскою й видимістю прихованих файлів.
|
||||
|
||||
- Обидві панелі автоматично підхоплюють створення, зміну й видалення файлів
|
||||
у відкритих локальних папках. Фокус залишається там, де був, а курсор
|
||||
лишається на поточному елементі, якщо той ще існує.
|
||||
@@ -469,7 +484,17 @@ Warning і початковий фокус на No.
|
||||
- Бірюзовий курсор поточного рядка видно в активній панелі. Кожна панель зберігає свою позицію курсора. Коли панелі видимі, F5 і F6 з командного рядка діють на активну панель.
|
||||
- Клік у панелі нижче списку ставить курсор на останній рядок, а клік вище списку — на перший.
|
||||
|
||||
- Поточний шлях відображається по центру верхньої подвійної лінії панелі. Лінію видно з обох боків напису. Бірюзове тло активної панелі охоплює лише напис шляху з невеликими відступами. Довгий шлях скорочується в межах панелі.
|
||||
- У локальному заголовку кнопки ← та → переходять назад і вперед
|
||||
в історії відповідної панелі. Стрілка ↑, Alt+↑ та рядок `..`
|
||||
відкривають безпосередню батьківську папку. На корені стрілка вимкнена,
|
||||
а рядка немає. Alt+← і Alt+→ працюють з історією активної панелі.
|
||||
- Сегменти шляху відкривають папки. Якщо шлях не вміщується, ліва
|
||||
трикрапка відкриває прихованих предків, а права — приховані папки
|
||||
попередньої гілки. Клік по поточній папці або кнопці редагування та Ctrl+L
|
||||
відкривають поле шляху. Tab доповнює назву папки, Enter відкриває шлях,
|
||||
а Esc повертає до тих самих панелей і курсора.
|
||||
|
||||
- Для LAN і FTP поточний шлях відображається по центру верхньої подвійної лінії панелі. Довгий шлях скорочується в межах панелі.
|
||||
|
||||
## Спільні елементи діалогів
|
||||
|
||||
|
||||
@@ -407,3 +407,28 @@ 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
|
||||
|
||||
117 DIALOGEX 0, 0, 290, 83
|
||||
STYLE DS_SETFONT | DS_CENTER | WS_POPUP
|
||||
CAPTION "Go to folder"
|
||||
FONT 10, "Consolas"
|
||||
BEGIN
|
||||
LTEXT "Folder &path (Tab completes)", 486, 16, 18, 258, 12
|
||||
FAR_EDIT(485, 0, 16, 32, 258, 15)
|
||||
LTEXT "", 487, 10, 54, 1, 1, NOT WS_VISIBLE
|
||||
CONTROL "&Open", IDOK, "Button", BS_OWNERDRAW | WS_TABSTOP, 63, 59, 80, 17
|
||||
CONTROL "&Cancel", IDCANCEL, "Button", BS_OWNERDRAW | WS_TABSTOP, 147, 59, 80, 17
|
||||
END
|
||||
@@ -0,0 +1,81 @@
|
||||
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 startFileSearch(Panel &panel,Panel::FindOptions options)
|
||||
{
|
||||
if(panel.scanRequest) return;
|
||||
cancelFolderSizes(panel);
|
||||
panel.scanRequest=Panel::ScanRequest{.directory=panel.directory,.statusRevision=statusRevision,.find=std::move(options)};
|
||||
startDirectoryScan(panel);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
auto options=panel.findOrigin?panel.findOrigin->options:Panel::FindOptions{};
|
||||
if(FilesModalDialog::run(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(116),owner,
|
||||
findFilesDialog,reinterpret_cast<LPARAM>(&options))!=IDOK) return;
|
||||
startFileSearch(panel,std::move(options));
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
+312
-42
@@ -333,10 +333,72 @@ FolderSize measureFolder(const fs::path &root,std::stop_token stop,const ListDir
|
||||
constexpr auto schemeKey = L"Software\\KSwitcher\\Files";
|
||||
#include "files_ftp.inl"
|
||||
|
||||
|
||||
fs::path panelParentPath(const fs::path &directory,bool local)
|
||||
{
|
||||
if(!directory.has_relative_path()) return {};
|
||||
const auto parent=directory.parent_path();
|
||||
if(parent==directory) return {};
|
||||
if(local && directory.root_name().native().starts_with(L"\\\\") && !parent.has_relative_path())
|
||||
return {}; // A UNC share is a browsing root.
|
||||
return parent;
|
||||
}
|
||||
|
||||
bool sameLocalFolder(const fs::path &a,const fs::path &b)
|
||||
{
|
||||
return CompareStringOrdinal(a.c_str(),-1,b.c_str(),-1,TRUE)==CSTR_EQUAL;
|
||||
}
|
||||
|
||||
bool inLocalBranch(const fs::path &ancestor,fs::path directory)
|
||||
{
|
||||
while(!directory.empty())
|
||||
{
|
||||
if(sameLocalFolder(ancestor,directory)) return true;
|
||||
directory=panelParentPath(directory,true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct LocalNavigation
|
||||
{
|
||||
std::vector<fs::path> history;
|
||||
size_t current{};
|
||||
fs::path previousBranch;
|
||||
|
||||
void opened(const fs::path &directory,std::optional<size_t> position)
|
||||
{
|
||||
if(!history.empty())
|
||||
{
|
||||
const auto &previous=history[current];
|
||||
if(sameLocalFolder(previous,directory)) return;
|
||||
if(inLocalBranch(directory,previous))
|
||||
{
|
||||
if(!inLocalBranch(previous,previousBranch)) previousBranch=previous;
|
||||
}
|
||||
else if(!inLocalBranch(directory,previousBranch)) previousBranch.clear();
|
||||
}
|
||||
if(position && *position<history.size() && sameLocalFolder(history[*position],directory))
|
||||
{
|
||||
current=*position;
|
||||
return;
|
||||
}
|
||||
if(!history.empty()) history.erase(history.begin()+current+1,history.end());
|
||||
history.push_back(directory);
|
||||
current=history.size()-1;
|
||||
}
|
||||
|
||||
std::optional<size_t> neighbor(int direction) const
|
||||
{
|
||||
if(direction<0) return current?std::optional<size_t>(current-1):std::nullopt;
|
||||
return current+1<history.size()?std::optional<size_t>(current+1):std::nullopt;
|
||||
}
|
||||
};
|
||||
|
||||
struct Panel
|
||||
{
|
||||
HWND path{}, list{}, heading{};
|
||||
fs::path directory;
|
||||
LocalNavigation navigation;
|
||||
std::optional<FilesPeer> peer;
|
||||
std::optional<FtpProfile> ftp;
|
||||
struct DirectoryWatch
|
||||
@@ -367,6 +429,16 @@ 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
|
||||
{
|
||||
FindOptions options;
|
||||
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 +447,8 @@ struct Panel
|
||||
uint64_t statusRevision{};
|
||||
std::shared_ptr<ElevatedHelper> elevated;
|
||||
std::optional<FtpProfile> ftp;
|
||||
std::optional<FindOptions> find;
|
||||
std::optional<size_t> navigationPosition;
|
||||
};
|
||||
struct ScanResult
|
||||
{
|
||||
@@ -418,6 +492,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;
|
||||
@@ -470,6 +554,8 @@ std::vector<size_t> commandAccessPositions;
|
||||
std::vector<int> commandActions;
|
||||
int menuIndex{};
|
||||
bool commandPicker{};
|
||||
struct FolderPicker { const wchar_t *caption; std::vector<fs::path> paths; };
|
||||
std::optional<FolderPicker> folderPicker;
|
||||
constexpr int defaultSizeWidth=6, defaultFontPoints=110;
|
||||
constexpr bool defaultWide=false, defaultAlignExtensions=true, defaultShowDetails=true, defaultAlignFolders=false;
|
||||
constexpr DWORD defaultStatusFields=15;
|
||||
@@ -882,6 +968,7 @@ void showMenu(bool show);
|
||||
void hidePicker()
|
||||
{
|
||||
if (!picker || !IsWindowVisible(picker)) return;
|
||||
folderPicker.reset();
|
||||
KillTimer(GetParent(picker),driveQueryTimer);
|
||||
driveQueries.clear();
|
||||
ShowWindow(picker,SW_HIDE);
|
||||
@@ -1207,7 +1294,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);
|
||||
@@ -1606,12 +1693,15 @@ void copyCommandLineOrPanelNames(HWND owner)
|
||||
else copyPanelNames(owner);
|
||||
}
|
||||
|
||||
void startFileSearch(Panel &panel,Panel::FindOptions options);
|
||||
|
||||
void refreshPanel(Panel &panel)
|
||||
{
|
||||
cancelFolderSizes(panel);
|
||||
panel.folderSizes.clear();
|
||||
updateSelectionSummary(panel);
|
||||
open(panel,panel.directory,false);
|
||||
if(panel.findOrigin) startFileSearch(panel,panel.findOrigin->options);
|
||||
else open(panel,panel.directory,false);
|
||||
}
|
||||
|
||||
std::wstring powerShellPath(const fs::path &path)
|
||||
@@ -1999,6 +2089,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 +2143,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 +2341,33 @@ 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{*request.find,previousSelection,std::move(markedPaths),previousRow,previousTop};
|
||||
previousSelection.clear();
|
||||
previousRow=previousTop=0;
|
||||
markedPaths.clear();
|
||||
}
|
||||
panel.findOrigin->options=std::move(*request.find);
|
||||
panel.findOrigin->error=error;
|
||||
}
|
||||
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();
|
||||
}
|
||||
if(peer || request.ftp) panel.navigation={};
|
||||
else if(!finding) panel.navigation.opened(directory,request.navigationPosition);
|
||||
panel.directory = directory;
|
||||
panel.peer=std::move(peer);
|
||||
panel.ftp=std::move(request.ftp);
|
||||
@@ -2248,7 +2376,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 +2389,8 @@ 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 auto parent=finding?fs::path{}:panelParentPath(directory,!panel.peer && !panel.ftp);
|
||||
const bool hasParent=!parent.empty();
|
||||
const auto rowCount=profiles?ftpProfiles.size():folders.size()+files.size()+hasParent;
|
||||
panel.rows.reserve(rowCount);
|
||||
panel.sizes.reserve(rowCount);
|
||||
@@ -2296,13 +2425,18 @@ bool applyDirectoryScan(Panel &panel,Panel::ScanRequest request,Panel::ScanResul
|
||||
}
|
||||
else
|
||||
{
|
||||
if(hasParent) add(directory.parent_path(),L"..",true);
|
||||
if(hasParent) add(parent,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 +2460,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.");
|
||||
@@ -2356,13 +2491,14 @@ void startDirectoryScan(Panel &panel)
|
||||
}
|
||||
|
||||
void openOn(Panel &panel,const fs::path &directory,bool offerElevation,std::optional<FilesPeer> peer,
|
||||
fs::path selection={},fs::path fallback={},std::optional<FtpProfile> ftp={})
|
||||
fs::path selection={},fs::path fallback={},std::optional<FtpProfile> ftp={},
|
||||
std::optional<size_t> navigationPosition={})
|
||||
{
|
||||
if(directory.empty() && !ftp) return;
|
||||
if(directory!=panel.directory || !samePanelSource(panel,peer,ftp))
|
||||
cancelFolderSizes(panel);
|
||||
panel.scanRequest=Panel::ScanRequest{directory,std::move(selection),std::move(fallback),
|
||||
std::move(peer),offerElevation,statusRevision,{},std::move(ftp)};
|
||||
std::move(peer),offerElevation,statusRevision,{},std::move(ftp),{},navigationPosition};
|
||||
if(panel.scan.valid())
|
||||
{
|
||||
panel.scanSuperseded=true;
|
||||
@@ -2595,6 +2731,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);
|
||||
@@ -2703,6 +2840,7 @@ LRESULT ftpDriveRow() {return static_cast<LRESULT>(drivePaths.size())+1;}
|
||||
bool selectablePickerRow(LRESULT row)
|
||||
{
|
||||
if(row<0) return false;
|
||||
if(folderPicker) return static_cast<size_t>(row)<folderPicker->paths.size();
|
||||
if(commandPicker)
|
||||
return static_cast<size_t>(row)<commandActions.size() && commandActions[row]>=0;
|
||||
return row<static_cast<LRESULT>(drivePaths.size()) || row==ftpDriveRow() || remoteDriveRows.contains(row);
|
||||
@@ -2712,6 +2850,14 @@ void selectDrive()
|
||||
{
|
||||
auto row=SendMessageW(picker,LB_GETCURSEL,0,0);
|
||||
if(!selectablePickerRow(row)) return;
|
||||
if(folderPicker)
|
||||
{
|
||||
const auto path=folderPicker->paths[row];
|
||||
auto &panel=panels[pickerPanel];
|
||||
hidePicker();
|
||||
openOn(panel,path,true,{});
|
||||
return;
|
||||
}
|
||||
if(commandPicker) row=commandActions[row];
|
||||
const auto remote=remoteDriveRows.find(row);
|
||||
hidePicker();
|
||||
@@ -2730,6 +2876,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);
|
||||
@@ -2785,7 +2932,7 @@ LRESULT CALLBACK pickerKeys(HWND window, UINT msg, WPARAM wp, LPARAM lp, UINT_PT
|
||||
if(!HIWORD(hit) && !selectablePickerRow(LOWORD(hit))) return 0;
|
||||
}
|
||||
if(msg==WM_CAPTURECHANGED) driveWakeAction.cancel();
|
||||
if(!commandPicker && (msg==WM_LBUTTONDOWN || msg==WM_LBUTTONUP || msg==WM_LBUTTONDBLCLK))
|
||||
if(!commandPicker && !folderPicker && (msg==WM_LBUTTONDOWN || msg==WM_LBUTTONUP || msg==WM_LBUTTONDBLCLK))
|
||||
{
|
||||
const auto hit=SendMessageW(window,LB_ITEMFROMPOINT,0,lp);
|
||||
const int row=HIWORD(hit)?-1:LOWORD(hit);
|
||||
@@ -2807,7 +2954,7 @@ LRESULT CALLBACK pickerKeys(HWND window, UINT msg, WPARAM wp, LPARAM lp, UINT_PT
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(!commandPicker && msg==WM_CHAR)
|
||||
if(!commandPicker && !folderPicker && msg==WM_CHAR)
|
||||
{
|
||||
const auto key=towupper(static_cast<wchar_t>(wp));
|
||||
LRESULT row=LB_ERR;
|
||||
@@ -2831,7 +2978,7 @@ LRESULT CALLBACK pickerKeys(HWND window, UINT msg, WPARAM wp, LPARAM lp, UINT_PT
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(!commandPicker && (msg==WM_MOUSEMOVE || msg==WM_MOUSELEAVE))
|
||||
if(!commandPicker && !folderPicker && (msg==WM_MOUSEMOVE || msg==WM_MOUSELEAVE))
|
||||
{
|
||||
int row=-1;
|
||||
if(msg==WM_MOUSEMOVE)
|
||||
@@ -3021,7 +3168,7 @@ void showRemoteDrives(bool focus=false,int initialRow=0)
|
||||
|
||||
void pollDriveQueries(HWND owner)
|
||||
{
|
||||
if(commandPicker || !IsWindowVisible(picker))
|
||||
if(commandPicker || folderPicker || !IsWindowVisible(picker))
|
||||
{
|
||||
KillTimer(owner,driveQueryTimer);
|
||||
driveQueries.clear();
|
||||
@@ -3089,6 +3236,7 @@ void pollDriveQueries(HWND owner)
|
||||
|
||||
void chooseDrive(int index,bool fromMenu)
|
||||
{
|
||||
folderPicker.reset();
|
||||
commandPicker=false;
|
||||
if (!fromMenu) showMenu(false);
|
||||
pickerPanel=index;
|
||||
@@ -3280,6 +3428,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.");
|
||||
@@ -3928,10 +4081,14 @@ CopyDestination validateCopyDestination(CopyRequest request,const std::wstring &
|
||||
throw std::runtime_error(ks::utf8(L"The destination folder is unavailable."));
|
||||
const bool sameHost=(!peer && !request.sourcePeer) ||
|
||||
(peer && request.sourcePeer && peer->id==request.sourcePeer->id);
|
||||
const bool sameFolder=sameHost && (peer?
|
||||
CompareStringOrdinal(destination.c_str(),-1,sourceDirectory.c_str(),-1,TRUE)==CSTR_EQUAL:
|
||||
fs::equivalent(destination,sourceDirectory,error));
|
||||
if(request.newName.empty() && sameFolder)
|
||||
const bool containsDestination=sameHost && request.newName.empty() &&
|
||||
std::any_of(request.sources.begin(),request.sources.end(),[&](const auto &path)
|
||||
{
|
||||
const auto parent=path.parent_path();
|
||||
return peer?CompareStringOrdinal(destination.c_str(),-1,parent.c_str(),-1,TRUE)==CSTR_EQUAL:
|
||||
fs::equivalent(destination,parent,error);
|
||||
});
|
||||
if(containsDestination)
|
||||
throw std::runtime_error(ks::utf8(L"Open a different folder in the other panel, or enter a new name for a single item."));
|
||||
return {std::move(request.destination),std::move(request.newName),useSourcePeer};
|
||||
}
|
||||
@@ -4167,7 +4324,7 @@ struct CopyProgress
|
||||
HWND window{};
|
||||
std::atomic_bool canceled{};
|
||||
bool closeOwner{};
|
||||
bool move{};
|
||||
bool move{}, fileSourcesOnly{};
|
||||
int conflictChoice{};
|
||||
ConflictMode conflictMode{};
|
||||
bool askReadOnly=true;
|
||||
@@ -4913,6 +5070,8 @@ bool countCopy(CopyHost &host,const fs::path &path,CopyProgress &progress)
|
||||
const auto info=host.stat(path,progress.canceled);
|
||||
if(!info || (info->attributes&FILE_ATTRIBUTE_REPARSE_POINT))
|
||||
throw std::system_error(info?ERROR_NOT_SUPPORTED:ERROR_FILE_NOT_FOUND,std::system_category());
|
||||
if(progress.fileSourcesOnly && (info->attributes&FILE_ATTRIBUTE_DIRECTORY))
|
||||
throw std::system_error(ERROR_FILE_INVALID,std::system_category());
|
||||
if(!(info->attributes&FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
++progress.totalFiles;
|
||||
@@ -4979,6 +5138,8 @@ CopyResult copyItem(const CopyEndpoints &hosts,const fs::path &from,const fs::pa
|
||||
const auto incoming=hosts.source.stat(from,progress.canceled);
|
||||
if(!incoming || (incoming->attributes&FILE_ATTRIBUTE_REPARSE_POINT))
|
||||
throw std::system_error(incoming?ERROR_NOT_SUPPORTED:ERROR_FILE_NOT_FOUND,std::system_category());
|
||||
if(progress.fileSourcesOnly && (incoming->attributes&FILE_ATTRIBUTE_DIRECTORY))
|
||||
throw std::system_error(ERROR_FILE_INVALID,std::system_category());
|
||||
|
||||
const auto moveOnHost=[&](const fs::path &target,bool replace)
|
||||
{
|
||||
@@ -5102,10 +5263,48 @@ CopyResult copyItem(const CopyEndpoints &hosts,const fs::path &from,const fs::pa
|
||||
return transfer(to,true,mode==ConflictMode::append);
|
||||
}
|
||||
|
||||
void pruneSearchResults(Panel &panel,const std::set<fs::path> &removed)
|
||||
{
|
||||
if(!panel.findOrigin || removed.empty()) return;
|
||||
const bool visible=IsWindowVisible(panel.list);
|
||||
if(visible) SendMessageW(panel.list,WM_SETREDRAW,FALSE,0);
|
||||
const auto cursor=currentPanelRow(panel);
|
||||
LRESULT next=cursor;
|
||||
for(size_t row=panel.rows.size();row>0;)
|
||||
{
|
||||
--row;
|
||||
const auto &path=panel.rows[row];
|
||||
if(!removed.contains(path)) continue;
|
||||
panel.timestamps.erase(path);
|
||||
SendMessageW(panel.list,LB_DELETESTRING,row,0);
|
||||
panel.rows.erase(panel.rows.begin()+row);
|
||||
panel.sizes.erase(panel.sizes.begin()+row);
|
||||
panel.dimmed.erase(panel.dimmed.begin()+row);
|
||||
panel.marked.erase(panel.marked.begin()+row);
|
||||
if(static_cast<LRESULT>(row)<cursor) --next;
|
||||
}
|
||||
if(cursor!=LB_ERR && !panel.rows.empty())
|
||||
SendMessageW(panel.list,LB_SETCURSEL,std::min(next,static_cast<LRESULT>(panel.rows.size()-1)),0);
|
||||
if(visible) SendMessageW(panel.list,WM_SETREDRAW,TRUE,0);
|
||||
InvalidateRect(panel.list,nullptr,FALSE);
|
||||
updateSelectionSummary(panel);
|
||||
}
|
||||
|
||||
void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
|
||||
{
|
||||
const auto sourceFtp=source.ftp;
|
||||
const bool ftpRename=move && sourceFtp && !ftpProfileList(source);
|
||||
if(destination.findOrigin && !ftpRename)
|
||||
{
|
||||
setStatus(L"Open a destination folder in the other panel before copying or moving files.");
|
||||
return;
|
||||
}
|
||||
if(source.findOrigin && source.scanRequest)
|
||||
{
|
||||
setStatus(L"Wait for the search to finish.");
|
||||
return;
|
||||
}
|
||||
const bool fromSearch=source.findOrigin.has_value();
|
||||
const auto destinationFtp=ftpRename?sourceFtp:destination.ftp;
|
||||
const bool ftp=sourceFtp || destinationFtp;
|
||||
if(ftp && !ftpRename && (move || (sourceFtp && destinationFtp) || source.peer || destination.peer ||
|
||||
@@ -5150,6 +5349,7 @@ void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
|
||||
const bool sameHost=!ftp && peerId(request.sourcePeer)==peerId(targetPeer);
|
||||
CopyProgress progress;
|
||||
progress.move=move;
|
||||
progress.fileSourcesOnly=fromSearch;
|
||||
progress.conflictMode=request.conflictMode;
|
||||
progress.askReadOnly=request.askReadOnly;
|
||||
FilesModalDialog progressDialog(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(103),owner,
|
||||
@@ -5167,7 +5367,7 @@ void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
|
||||
progressDialog.show();
|
||||
bool failed=false, skipped=false;
|
||||
size_t copied=0;
|
||||
std::set<fs::path> results;
|
||||
std::set<fs::path> results, removed;
|
||||
std::wstring failure;
|
||||
std::vector<fs::path> lockPaths;
|
||||
try
|
||||
@@ -5232,6 +5432,7 @@ void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
|
||||
if(outcome==CopyResult::failed) { failed=true; break; }
|
||||
if(outcome==CopyResult::skipped) { skipped=true; continue; }
|
||||
++copied;
|
||||
if(move && fromSearch) removed.insert(path);
|
||||
results.insert(progress.renamedTarget.empty()?to:progress.renamedTarget);
|
||||
progress.ui.invoke([&] {
|
||||
const auto row=std::find(source.rows.begin(),source.rows.end(),path);
|
||||
@@ -5270,9 +5471,10 @@ void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
|
||||
}
|
||||
if(move)
|
||||
{
|
||||
open(source,source.directory);
|
||||
if(fromSearch) pruneSearchResults(source,removed);
|
||||
else open(source,source.directory);
|
||||
if(!ftpRename) open(destination,destination.directory);
|
||||
if(renamed && copied && (sameHost || ftpRename))
|
||||
if(!fromSearch && renamed && copied && (sameHost || ftpRename))
|
||||
{
|
||||
const auto renamedPath=progress.renamedTarget.empty()?
|
||||
targetDirectory/request.newName:progress.renamedTarget;
|
||||
@@ -5282,7 +5484,7 @@ void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
|
||||
else
|
||||
{
|
||||
auto &updated=renameInSource?source:destination;
|
||||
if(updated.directory==targetDirectory)
|
||||
if(!updated.findOrigin && updated.directory==targetDirectory)
|
||||
open(updated,updated.directory);
|
||||
}
|
||||
if(!results.empty())
|
||||
@@ -5461,6 +5663,12 @@ INT_PTR CALLBACK deleteProgressDialog(HWND window,UINT message,WPARAM wp,LPARAM
|
||||
|
||||
void deleteSelection(HWND owner,Panel &panel,bool permanent)
|
||||
{
|
||||
const bool fromSearch=panel.findOrigin.has_value();
|
||||
if(fromSearch && panel.scanRequest)
|
||||
{
|
||||
setStatus(L"Wait for the search to finish.");
|
||||
return;
|
||||
}
|
||||
if(ftpProfileList(panel)) return;
|
||||
if(copyInProgress) return;
|
||||
const auto ftp=panel.ftp;
|
||||
@@ -5472,7 +5680,7 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
|
||||
for(size_t i=0;i<shown;++i)
|
||||
{
|
||||
if(i) entries+=L"\r\n";
|
||||
entries+=paths[i].filename().wstring();
|
||||
entries+=fromSearch?paths[i].lexically_relative(panel.directory).native():paths[i].filename().native();
|
||||
}
|
||||
if(shown<paths.size()) entries+=L"\r\n…and "+std::to_wstring(paths.size()-shown)+L" more";
|
||||
const auto instance=GetModuleHandleW(nullptr);
|
||||
@@ -5511,7 +5719,7 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
|
||||
int readOnlyChoice=0;
|
||||
std::vector<std::vector<fs::path>> groups;
|
||||
std::wstring failure, sharingFailure;
|
||||
std::set<fs::path> lockPaths;
|
||||
std::set<fs::path> lockPaths, removed;
|
||||
const auto recordFailure=[&](const std::system_error &error,const fs::path &path)
|
||||
{
|
||||
++failed;
|
||||
@@ -5541,7 +5749,7 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
|
||||
{
|
||||
if(canceled) break;
|
||||
auto &group=groups.emplace_back(1,path);
|
||||
if(permanent)
|
||||
if(permanent && !fromSearch)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -5603,7 +5811,9 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
|
||||
bool readOnly=false;
|
||||
try
|
||||
{
|
||||
const auto info=permanent?host.stat(current,canceled):std::optional<FileInfo>{};
|
||||
const auto info=(permanent || fromSearch)?host.stat(current,canceled):std::optional<FileInfo>{};
|
||||
if(fromSearch && info && (info->attributes&FILE_ATTRIBUTE_DIRECTORY))
|
||||
throw std::system_error(ERROR_FILE_INVALID,std::system_category());
|
||||
const auto attributes=info?info->attributes:INVALID_FILE_ATTRIBUTES;
|
||||
if(attributes!=INVALID_FILE_ATTRIBUTES && (attributes&FILE_ATTRIBUTE_READONLY) &&
|
||||
!(attributes&FILE_ATTRIBUTE_DIRECTORY))
|
||||
@@ -5648,6 +5858,7 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
|
||||
}
|
||||
else host.remove(current,permanent,attributes,readOnly);
|
||||
++done;
|
||||
if(!panel.peer && !ftp) removed.insert(current);
|
||||
}
|
||||
catch(const std::system_error &e)
|
||||
{
|
||||
@@ -5666,7 +5877,10 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
|
||||
|
||||
progressDialog.close();
|
||||
for(auto &visible:panels)
|
||||
if(!visible.directory.empty()) open(visible,visible.directory);
|
||||
{
|
||||
if(visible.findOrigin) pruneSearchResults(visible,removed);
|
||||
else if(!visible.directory.empty()) open(visible,visible.directory);
|
||||
}
|
||||
SetFocus(panel.list);
|
||||
const auto summary=(canceled?L"Deletion canceled. ":L"Deletion finished. ")+
|
||||
std::to_wstring(done)+(permanent?L" deleted, ":L" moved to Recycle Bin, ")+
|
||||
@@ -5881,6 +6095,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 +6286,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 +6456,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 +6498,7 @@ bool loadFilesPreferences(HWND window)
|
||||
return true;
|
||||
}
|
||||
|
||||
#include "files_find.inl"
|
||||
#include "files_options.inl"
|
||||
|
||||
void openMenu(HWND window, int index)
|
||||
@@ -6287,6 +6512,7 @@ void openMenu(HWND window, int index)
|
||||
return;
|
||||
}
|
||||
menuIndex=index;
|
||||
folderPicker.reset();
|
||||
commandPicker=true;
|
||||
SendMessageW(picker,LB_RESETCONTENT,0,0);
|
||||
std::vector<std::wstring> rows;
|
||||
@@ -6302,12 +6528,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
|
||||
@@ -6512,6 +6740,8 @@ void submitTerminalReturn(HWND owner,bool shift)
|
||||
handleFilesReturn(shift);
|
||||
}
|
||||
|
||||
#include "files_path_navigation.inl"
|
||||
|
||||
LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
if(message==filesPreferencesChanged)
|
||||
@@ -6648,7 +6878,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
auto &panel = panels[i];
|
||||
panel.path = CreateWindowW(L"STATIC", L"", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SS_OWNERDRAW,
|
||||
panel.path = CreateWindowW(L"STATIC", L"", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SS_OWNERDRAW | SS_NOTIFY,
|
||||
0, 0, 0, 0, window, reinterpret_cast<HMENU>(142 + static_cast<INT_PTR>(i)), instance, nullptr);
|
||||
panel.list = CreateWindowExW(0, L"LISTBOX", L"",
|
||||
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS,
|
||||
@@ -6668,6 +6898,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
openOn(panel,saved.is_absolute()?saved:root,false,{},savedPanelPath(panelCursorKeys[i]),
|
||||
saved.is_absolute() && saved!=root?root:fs::path{});
|
||||
SetWindowSubclass(panel.list, panelKeys, 1, 0);
|
||||
SetWindowSubclass(panel.path,pathBarInput,1,0);
|
||||
installScrollBar(panel.list,window,firstPanelScrollBar+i);
|
||||
}
|
||||
SetFocus(panels[0].list);
|
||||
@@ -6771,7 +7002,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
InflateRect(&box,-3,-3);
|
||||
FrameRect(dc,&box,border);
|
||||
FillRect(dc,÷r,border);
|
||||
if(panel.wide)
|
||||
if(hasPanelSizeColumn(panel))
|
||||
{
|
||||
RECT column{columnX,box.top+1,columnX+1,pathBounds.bottom+6};
|
||||
FillRect(dc,&column,border);
|
||||
@@ -6822,7 +7053,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 +7061,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{};
|
||||
@@ -6840,6 +7071,12 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
RECT column{x,middle,x+1,bounds.bottom};
|
||||
FillRect(item.hDC,&column,lineBrush);
|
||||
}
|
||||
const bool highlighted=static_cast<int>(item.CtlID)-142==active;
|
||||
if(localNavigationAvailable(panel))
|
||||
{
|
||||
paintLocalPath(item.hDC,bounds,panel,highlighted);
|
||||
return TRUE;
|
||||
}
|
||||
if(path.empty()) return TRUE;
|
||||
const int saved=SaveDC(item.hDC);
|
||||
SelectObject(item.hDC,mono);
|
||||
@@ -6848,7 +7085,6 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
const auto width=std::min(bounds.right-bounds.left,text.cx+2L*cellWidth);
|
||||
bounds.left+=(bounds.right-bounds.left-width)/2;
|
||||
bounds.right=bounds.left+width;
|
||||
const bool highlighted=static_cast<int>(item.CtlID)-142==active;
|
||||
FillRect(item.hDC,&bounds,highlighted?teal:blue);
|
||||
const auto padding=std::min(static_cast<LONG>(cellWidth),width/4);
|
||||
InflateRect(&bounds,-padding,0);
|
||||
@@ -6861,6 +7097,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;
|
||||
@@ -6873,7 +7114,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
}
|
||||
if(item.hwndItem==pickerFrame || item.hwndItem==completionFrame)
|
||||
{
|
||||
const bool driveFrame=item.hwndItem==pickerFrame && !commandPicker;
|
||||
const bool driveFrame=item.hwndItem==pickerFrame && !commandPicker && !folderPicker;
|
||||
auto border=CreateSolidBrush(driveFrame?RGB(255,255,255):colors[Frame]);
|
||||
const auto box=paintDialogFrame(item.hDC,item.rcItem,
|
||||
dialogFrameMetrics(GetDpiForWindow(window)),teal,border);
|
||||
@@ -6896,6 +7137,8 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
}
|
||||
paintDialogFrameCaptions(item.hDC,item.rcItem,box,L"Change drive",teal,colors[Text],mono);
|
||||
}
|
||||
if(item.hwndItem==pickerFrame && folderPicker)
|
||||
paintDialogFrameCaptions(item.hDC,item.rcItem,box,folderPicker->caption,teal,colors[Text],mono);
|
||||
const auto list=item.hwndItem==pickerFrame?picker:completionList;
|
||||
paintScrollPosition(item.hwndItem,item.hDC,list,colors[Dialog]);
|
||||
DeleteObject(border);
|
||||
@@ -6933,7 +7176,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
const bool popupRow=item.hwndItem==picker || item.hwndItem==completionList;
|
||||
auto background=item.CtlType==ODT_BUTTON?Footer:popupRow?Dialog:PanelBlue;
|
||||
auto foreground=colors[Text];
|
||||
if(item.hwndItem==picker && ((commandPicker && item.itemID<commandActions.size() && commandActions[item.itemID]<0) ||
|
||||
if(item.hwndItem==picker && !folderPicker && ((commandPicker && item.itemID<commandActions.size() && commandActions[item.itemID]<0) ||
|
||||
(!commandPicker && item.itemID==drivePaths.size())))
|
||||
{
|
||||
FillRect(item.hDC,&item.rcItem,teal);
|
||||
@@ -6943,7 +7186,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
FillRect(item.hDC,&line,static_cast<HBRUSH>(GetStockObject(DC_BRUSH)));
|
||||
return TRUE;
|
||||
}
|
||||
if(item.hwndItem==picker && !commandPicker && item.itemID==ftpDriveRow()+1)
|
||||
if(item.hwndItem==picker && !commandPicker && !folderPicker && item.itemID==ftpDriveRow()+1)
|
||||
{
|
||||
auto row=item.rcItem;
|
||||
FillRect(item.hDC,&row,teal);
|
||||
@@ -6986,7 +7229,10 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
}
|
||||
}
|
||||
auto shortcut=text.find(L'\t');
|
||||
if(item.hwndItem==picker && commandPicker && item.itemID<commandAccessPositions.size())
|
||||
if(item.hwndItem==picker && folderPicker)
|
||||
paintDialogListRow(item.hDC,item.rcItem,text.c_str(),mono,foreground,rowBackground,
|
||||
dialogRowTextInset(cellWidth),DT_PATH_ELLIPSIS|DT_END_ELLIPSIS);
|
||||
else if(item.hwndItem==picker && commandPicker && item.itemID<commandAccessPositions.size())
|
||||
{
|
||||
auto labelRect=item.rcItem, keyRect=item.rcItem;
|
||||
SelectObject(item.hDC,mono);
|
||||
@@ -7002,7 +7248,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
paintMenuLabel(item.hDC,labelRect,text.substr(0,shortcut),commandAccessPositions[item.itemID],
|
||||
colors[Text],colors[background]);
|
||||
}
|
||||
else if(item.hwndItem==picker && !commandPicker && item.itemID<drivePaths.size())
|
||||
else if(item.hwndItem==picker && !commandPicker && !folderPicker && item.itemID<drivePaths.size())
|
||||
{
|
||||
SelectObject(item.hDC,mono);
|
||||
SetTextColor(item.hDC,foreground);
|
||||
@@ -7042,7 +7288,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
}
|
||||
SetBkMode(item.hDC,OPAQUE);
|
||||
}
|
||||
else if(item.hwndItem==picker && !commandPicker && item.itemID>=drivePaths.size())
|
||||
else if(item.hwndItem==picker && !commandPicker && !folderPicker && item.itemID>=drivePaths.size())
|
||||
{
|
||||
auto bounds=item.rcItem;
|
||||
RECT button{};
|
||||
@@ -7092,7 +7338,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);
|
||||
@@ -7301,6 +7547,7 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
|
||||
if(message.hwnd==window && message.message>=WM_KEYFIRST && message.message<=WM_KEYLAST &&
|
||||
GetFocus()==terminalInput)
|
||||
message.hwnd=terminalInput;
|
||||
if(handleLocalPathKey(window,message)) continue;
|
||||
if(message.hwnd==terminalInput && message.message==WM_KEYDOWN &&
|
||||
!(GetKeyState(VK_CONTROL)&0x8000) && !(GetKeyState(VK_SHIFT)&0x8000) &&
|
||||
!(GetKeyState(VK_MENU)&0x8000) && !(GetKeyState(VK_LWIN)&0x8000) &&
|
||||
@@ -7322,6 +7569,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 +7590,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)) &&
|
||||
|
||||
@@ -0,0 +1,368 @@
|
||||
|
||||
bool localNavigationAvailable(const Panel &panel)
|
||||
{
|
||||
return !panel.peer && !panel.ftp && !panel.findOrigin && !panel.directory.empty();
|
||||
}
|
||||
|
||||
enum class PathAction { back, forward, up, edit, ancestors, previous, folder };
|
||||
|
||||
void navigateLocal(Panel &panel,const fs::path &path,std::optional<size_t> position={})
|
||||
{
|
||||
if(path.empty() || sameLocalFolder(path,panel.directory)) return;
|
||||
closePanelSearch();
|
||||
openOn(panel,path,true,{},{},{},{},position);
|
||||
}
|
||||
|
||||
void navigateLocalHistory(Panel &panel,int direction)
|
||||
{
|
||||
if(const auto next=panel.navigation.neighbor(direction))
|
||||
navigateLocal(panel,panel.navigation.history[*next],next);
|
||||
}
|
||||
|
||||
struct PathPart
|
||||
{
|
||||
PathAction action{};
|
||||
std::wstring label;
|
||||
fs::path target;
|
||||
std::vector<fs::path> hidden;
|
||||
RECT rect{};
|
||||
bool current{}, dim{}, enabled=true;
|
||||
};
|
||||
|
||||
std::wstring pathSegmentLabel(const fs::path &path)
|
||||
{
|
||||
return panelParentPath(path,true).empty()?path.native():path.filename().native();
|
||||
}
|
||||
|
||||
LONG segmentWidth(const fs::path &path)
|
||||
{
|
||||
return static_cast<LONG>(pathSegmentLabel(path).size()+2)*cellWidth;
|
||||
}
|
||||
|
||||
std::vector<PathPart> localPathParts(const Panel &panel,RECT bounds)
|
||||
{
|
||||
const LONG total=bounds.right-bounds.left;
|
||||
if(total<=0) return {};
|
||||
const LONG width=std::max(1L,std::min(2L*cellWidth,total/7));
|
||||
std::vector<PathPart> parts;
|
||||
const auto add=[&](PathPart part,LONG length)
|
||||
{
|
||||
if(length<=0 || bounds.left>=bounds.right) return;
|
||||
part.rect={bounds.left,bounds.top,std::min(bounds.right,bounds.left+length),bounds.bottom};
|
||||
bounds.left=part.rect.right;
|
||||
parts.push_back(std::move(part));
|
||||
};
|
||||
const auto parent=panelParentPath(panel.directory,true);
|
||||
add({.action=PathAction::back,.label=L"←",.enabled=panel.navigation.neighbor(-1).has_value()},width);
|
||||
add({.action=PathAction::forward,.label=L"→",.enabled=panel.navigation.neighbor(1).has_value()},width);
|
||||
add({.action=PathAction::up,.label=L"↑",.target=parent,.enabled=!parent.empty()},width);
|
||||
add({.action=PathAction::edit,.label=L"✎"},width);
|
||||
|
||||
std::vector<fs::path> ancestors, previous;
|
||||
for(auto path=parent;!path.empty();path=panelParentPath(path,true)) ancestors.push_back(path);
|
||||
std::reverse(ancestors.begin(),ancestors.end());
|
||||
if(inLocalBranch(panel.directory,panel.navigation.previousBranch))
|
||||
{
|
||||
for(auto path=panel.navigation.previousBranch;!sameLocalFolder(path,panel.directory);
|
||||
path=panelParentPath(path,true))
|
||||
previous.push_back(path);
|
||||
std::reverse(previous.begin(),previous.end());
|
||||
}
|
||||
|
||||
const LONG room=bounds.right-bounds.left;
|
||||
LONG required=segmentWidth(panel.directory);
|
||||
for(const auto &path:ancestors) required+=segmentWidth(path);
|
||||
for(const auto &path:previous) required+=segmentWidth(path);
|
||||
size_t firstAncestor=0,visiblePrevious=previous.size();
|
||||
LONG currentWidth=segmentWidth(panel.directory);
|
||||
if(required>room)
|
||||
{
|
||||
const LONG reserved=(!ancestors.empty()?width:0)+(!previous.empty()?width:0);
|
||||
currentWidth=std::min(currentWidth,std::max(1L,room-reserved));
|
||||
LONG remaining=room-currentWidth-reserved;
|
||||
firstAncestor=ancestors.size();
|
||||
while(firstAncestor && remaining>=segmentWidth(ancestors[firstAncestor-1]))
|
||||
remaining-=segmentWidth(ancestors[--firstAncestor]);
|
||||
visiblePrevious=0;
|
||||
while(visiblePrevious<previous.size() && remaining>=segmentWidth(previous[visiblePrevious]))
|
||||
remaining-=segmentWidth(previous[visiblePrevious++]);
|
||||
}
|
||||
|
||||
if(firstAncestor)
|
||||
add({.action=PathAction::ancestors,.label=L"…",
|
||||
.hidden={ancestors.begin(),ancestors.begin()+firstAncestor}},width);
|
||||
for(size_t i=firstAncestor;i<ancestors.size();++i)
|
||||
add({.action=PathAction::folder,.label=pathSegmentLabel(ancestors[i]),.target=ancestors[i]},
|
||||
segmentWidth(ancestors[i]));
|
||||
add({.action=PathAction::edit,.label=pathSegmentLabel(panel.directory),.current=true},currentWidth);
|
||||
for(size_t i=0;i<visiblePrevious;++i)
|
||||
add({.action=PathAction::folder,.label=pathSegmentLabel(previous[i]),.target=previous[i],.dim=true},
|
||||
segmentWidth(previous[i]));
|
||||
if(visiblePrevious<previous.size())
|
||||
add({.action=PathAction::previous,.label=L"…",
|
||||
.hidden={previous.begin()+visiblePrevious,previous.end()},.dim=true},width);
|
||||
return parts;
|
||||
}
|
||||
|
||||
void paintLocalPath(HDC dc,RECT bounds,const Panel &panel,bool activePanel)
|
||||
{
|
||||
const int saved=SaveDC(dc);
|
||||
SelectObject(dc,mono);
|
||||
SetBkMode(dc,TRANSPARENT);
|
||||
for(const auto &part:localPathParts(panel,bounds))
|
||||
{
|
||||
const bool current=activePanel && part.current;
|
||||
FillRect(dc,&part.rect,current?teal:blue);
|
||||
SetTextColor(dc,!part.enabled || part.dim?RGB(160,170,190):colors[current?Text:Frame]);
|
||||
auto text=part.rect;
|
||||
DrawTextW(dc,part.label.c_str(),static_cast<int>(part.label.size()),&text,
|
||||
DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|DT_NOPREFIX);
|
||||
}
|
||||
if(saved) RestoreDC(dc,saved);
|
||||
}
|
||||
|
||||
constexpr int addressField=485,addressLabel=486,addressFooter=487;
|
||||
|
||||
struct PathPrompt
|
||||
{
|
||||
fs::path base, result;
|
||||
std::wstring completionInput;
|
||||
std::future<std::wstring> completion;
|
||||
};
|
||||
|
||||
constexpr UINT addressComplete=WM_APP+29;
|
||||
constexpr UINT_PTR addressCompletionTimer=1;
|
||||
|
||||
fs::path enteredPanelPath(const fs::path &base,std::wstring text)
|
||||
{
|
||||
if(text.size()>=2 && text.front()==L'"' && text.back()==L'"')
|
||||
text=text.substr(1,text.size()-2);
|
||||
return fs::path(text).is_absolute()?fs::path(std::move(text)):base/fs::path(std::move(text));
|
||||
}
|
||||
|
||||
std::wstring panelPathCompletion(const fs::path &base,const std::wstring &text)
|
||||
{
|
||||
const auto path=enteredPanelPath(base,text);
|
||||
const auto directory=path.has_filename()?path.parent_path():path;
|
||||
const auto prefix=path.filename().native();
|
||||
fs::path best;
|
||||
std::error_code error;
|
||||
for(fs::directory_iterator it(directory,error),end;!error && it!=end;it.increment(error))
|
||||
{
|
||||
const auto name=it->path().filename().native();
|
||||
if(name.size()<prefix.size() || (!prefix.empty() && CompareStringOrdinal(name.data(),
|
||||
static_cast<int>(prefix.size()),prefix.data(),static_cast<int>(prefix.size()),TRUE)!=CSTR_EQUAL))
|
||||
continue;
|
||||
std::error_code typeError;
|
||||
if(it->is_directory(typeError) && (best.empty() || it->path()<best)) best=it->path();
|
||||
}
|
||||
return best.empty()?std::wstring{}:best.native()+L"\\";
|
||||
}
|
||||
|
||||
LRESULT CALLBACK addressFieldKeys(HWND field,UINT message,WPARAM wp,LPARAM lp,UINT_PTR,DWORD_PTR)
|
||||
{
|
||||
if(message==WM_GETDLGCODE)
|
||||
{
|
||||
const auto *key=reinterpret_cast<const MSG *>(lp);
|
||||
if(key && key->wParam==VK_TAB && !(GetKeyState(VK_SHIFT)&0x8000))
|
||||
return DefSubclassProc(field,message,wp,lp)|DLGC_WANTTAB;
|
||||
}
|
||||
if(message==WM_KEYDOWN && wp==VK_TAB && !(GetKeyState(VK_SHIFT)&0x8000))
|
||||
{
|
||||
SendMessageW(GetParent(field),addressComplete,0,0);
|
||||
return 0;
|
||||
}
|
||||
if(message==WM_CHAR && wp==VK_TAB) return 0;
|
||||
return DefSubclassProc(field,message,wp,lp);
|
||||
}
|
||||
|
||||
INT_PTR CALLBACK editPathDialog(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" Go to folder ",false,{addressFooter}))
|
||||
return painted;
|
||||
if(message==WM_INITDIALOG)
|
||||
{
|
||||
auto &prompt=*reinterpret_cast<PathPrompt *>(lp);
|
||||
SetWindowLongPtrW(dialog,DWLP_USER,lp);
|
||||
prepareTextDialog(dialog);
|
||||
layoutDialogContent(dialog,addressLabel);
|
||||
layoutDialogButtons(dialog,addressFooter,{IDOK,IDCANCEL});
|
||||
const auto field=GetDlgItem(dialog,addressField);
|
||||
SendMessageW(field,EM_SETLIMITTEXT,32767,0);
|
||||
SetWindowTextW(field,(prompt.base/fs::path{}).c_str());
|
||||
SetWindowSubclass(field,addressFieldKeys,4,0);
|
||||
SetFocus(field);
|
||||
SendMessageW(field,EM_SETSEL,0,-1);
|
||||
return FALSE;
|
||||
}
|
||||
if(message==addressComplete)
|
||||
{
|
||||
auto &prompt=*reinterpret_cast<PathPrompt *>(GetWindowLongPtrW(dialog,DWLP_USER));
|
||||
if(prompt.completion.valid()) return TRUE;
|
||||
prompt.completionInput=shortcutField(dialog,addressField);
|
||||
std::packaged_task<std::wstring()> task([base=prompt.base,text=prompt.completionInput]
|
||||
{
|
||||
return panelPathCompletion(base,text);
|
||||
});
|
||||
if(!SetTimer(dialog,addressCompletionTimer,30,nullptr)) return TRUE;
|
||||
prompt.completion=task.get_future();
|
||||
std::thread(std::move(task)).detach();
|
||||
return TRUE;
|
||||
}
|
||||
if(message==WM_TIMER && wp==addressCompletionTimer)
|
||||
{
|
||||
auto &prompt=*reinterpret_cast<PathPrompt *>(GetWindowLongPtrW(dialog,DWLP_USER));
|
||||
if(!prompt.completion.valid() ||
|
||||
prompt.completion.wait_for(std::chrono::seconds(0))!=std::future_status::ready) return TRUE;
|
||||
KillTimer(dialog,addressCompletionTimer);
|
||||
try
|
||||
{
|
||||
const auto value=prompt.completion.get();
|
||||
if(!value.empty() && shortcutField(dialog,addressField)==prompt.completionInput)
|
||||
{
|
||||
const auto field=GetDlgItem(dialog,addressField);
|
||||
SetWindowTextW(field,value.c_str());
|
||||
SendMessageW(field,EM_SETSEL,value.size(),value.size());
|
||||
SendMessageW(field,EM_SCROLLCARET,0,0);
|
||||
}
|
||||
}
|
||||
catch(const std::exception &) {}
|
||||
return TRUE;
|
||||
}
|
||||
if(message==WM_COMMAND && LOWORD(wp)==IDOK)
|
||||
{
|
||||
auto &prompt=*reinterpret_cast<PathPrompt *>(GetWindowLongPtrW(dialog,DWLP_USER));
|
||||
auto path=enteredPanelPath(prompt.base,shortcutField(dialog,addressField)).lexically_normal();
|
||||
if(!path.is_absolute())
|
||||
{
|
||||
showFilesNotice(dialog,L"Enter a folder path.",L"Go to folder");
|
||||
return TRUE;
|
||||
}
|
||||
if(!path.has_filename() && path.has_relative_path()) path=path.parent_path();
|
||||
prompt.result=std::move(path);
|
||||
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 editPanelPath(Panel &panel)
|
||||
{
|
||||
PathPrompt prompt{panel.directory};
|
||||
if(FilesModalDialog::run(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(117),GetParent(panel.list),
|
||||
editPathDialog,reinterpret_cast<LPARAM>(&prompt))==IDOK)
|
||||
navigateLocal(panel,prompt.result);
|
||||
}
|
||||
|
||||
void showFolderPicker(HWND owner,int side,const wchar_t *caption,std::vector<fs::path> paths,RECT anchor)
|
||||
{
|
||||
hidePicker();
|
||||
showMenu(false);
|
||||
commandPicker=false;
|
||||
pickerPanel=side;
|
||||
folderPicker=FolderPicker{caption,std::move(paths)};
|
||||
SendMessageW(picker,LB_RESETCONTENT,0,0);
|
||||
size_t longest=wcslen(caption);
|
||||
for(const auto &path:folderPicker->paths)
|
||||
{
|
||||
longest=std::max(longest,path.native().size());
|
||||
SendMessageW(picker,LB_ADDSTRING,0,reinterpret_cast<LPARAM>(path.c_str()));
|
||||
}
|
||||
RECT client{};
|
||||
GetClientRect(owner,&client);
|
||||
const int inset=dialogFrameMetrics(GetDpiForWindow(owner)).content();
|
||||
const int width=std::max(1,std::min(static_cast<int>(client.right)-2*inset,static_cast<int>(longest+3)*cellWidth));
|
||||
const int x=std::clamp(static_cast<int>(anchor.left),inset,std::max(inset,static_cast<int>(client.right)-width-inset));
|
||||
const int y=anchor.bottom+inset;
|
||||
const int row=std::max(1,static_cast<int>(SendMessageW(picker,LB_GETITEMHEIGHT,0,0)));
|
||||
RECT input{};
|
||||
GetWindowRect(terminalInput,&input);
|
||||
MapWindowPoints(nullptr,owner,reinterpret_cast<POINT *>(&input),2);
|
||||
const int bottom=std::min(client.bottom,input.top);
|
||||
const int shown=std::clamp((bottom-y-inset)/row,1,static_cast<int>(folderPicker->paths.size()));
|
||||
showFramedList(picker,pickerFrame,x,y,width,row*shown,inset);
|
||||
SendMessageW(picker,LB_SETCURSEL,0,0);
|
||||
SetFocus(picker);
|
||||
}
|
||||
|
||||
void showHiddenPathParts(HWND window,int side,const PathPart &part)
|
||||
{
|
||||
const auto owner=GetParent(window);
|
||||
auto anchor=part.rect;
|
||||
MapWindowPoints(window,owner,reinterpret_cast<POINT*>(&anchor),2);
|
||||
showFolderPicker(owner,side,part.action==PathAction::ancestors?L"Parent folders":L"Previous path",
|
||||
part.hidden,anchor);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK pathBarInput(HWND window,UINT message,WPARAM wp,LPARAM lp,UINT_PTR,DWORD_PTR)
|
||||
{
|
||||
if(message==WM_LBUTTONDOWN)
|
||||
{
|
||||
SetCapture(window);
|
||||
return 0;
|
||||
}
|
||||
if(message==WM_LBUTTONUP && GetCapture()==window)
|
||||
{
|
||||
ReleaseCapture();
|
||||
const int index=GetDlgCtrlID(window)-142;
|
||||
if(index<0 || index>=2) return 0;
|
||||
auto &panel=panels[index];
|
||||
if(!localNavigationAvailable(panel))
|
||||
{
|
||||
selectPanelEdge(panel,true);
|
||||
return 0;
|
||||
}
|
||||
activatePanel(index);
|
||||
RECT bounds{};
|
||||
GetClientRect(window,&bounds);
|
||||
const POINT mouse{GET_X_LPARAM(lp),GET_Y_LPARAM(lp)};
|
||||
const auto parts=localPathParts(panel,bounds);
|
||||
for(const auto &part:parts)
|
||||
{
|
||||
if(!part.enabled || !PtInRect(&part.rect,mouse)) continue;
|
||||
switch(part.action)
|
||||
{
|
||||
case PathAction::back: navigateLocalHistory(panel,-1); break;
|
||||
case PathAction::forward: navigateLocalHistory(panel,1); break;
|
||||
case PathAction::up: case PathAction::folder: navigateLocal(panel,part.target); break;
|
||||
case PathAction::edit: editPanelPath(panel); break;
|
||||
case PathAction::ancestors: case PathAction::previous: showHiddenPathParts(window,index,part); break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return DefSubclassProc(window,message,wp,lp);
|
||||
}
|
||||
|
||||
bool handleLocalPathKey(HWND owner,const MSG &message)
|
||||
{
|
||||
if(!commandLineAvailable(owner) || terminalVisible || !localNavigationAvailable(panels[active]) ||
|
||||
(message.hwnd!=terminalInput && message.hwnd!=panels[active].list) ||
|
||||
((GetKeyState(VK_SHIFT)|GetKeyState(VK_LWIN)|GetKeyState(VK_RWIN))&0x8000)) return false;
|
||||
auto &panel=panels[active];
|
||||
if(message.message==WM_KEYDOWN && message.wParam=='L' &&
|
||||
(GetKeyState(VK_CONTROL)&0x8000) && !(GetKeyState(VK_MENU)&0x8000))
|
||||
{
|
||||
if(!(message.lParam&(1LL<<30))) editPanelPath(panel);
|
||||
return true;
|
||||
}
|
||||
if(message.message!=WM_SYSKEYDOWN || !(message.lParam&(1LL<<29)) ||
|
||||
(GetKeyState(VK_CONTROL)&0x8000)) return false;
|
||||
if(message.wParam==VK_UP)
|
||||
navigateLocal(panel,panelParentPath(panel.directory,true));
|
||||
else if(message.wParam==VK_LEFT || message.wParam==VK_RIGHT)
|
||||
navigateLocalHistory(panel,message.wParam==VK_LEFT?-1:1);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user