feat(files): add searchable command history

Persist command recall and align keyboard, mouse, and dialog behavior.

Refs #18
This commit is contained in:
agrynco committed 2026-11-14 14:42:48 +02:00
1 parent 721c3f0f38
commit 46b4b51cea
9 files changed
+914 -127

No files matched your search

+202 -71
View File
@@ -270,7 +270,8 @@ HWND terminalInput{},terminalOutput{},terminalPrompt{};
constexpr UINT_PTR terminalTimer=2;
bool terminalVisible{};
int terminalRows{};
std::vector<std::wstring> terminalHistory;
struct CommandEntry { std::wstring date, command; };
std::vector<CommandEntry> terminalHistory;
size_t terminalHistoryIndex{};
constexpr UINT_PTR transferHighlightTimer=1;
unsigned transferHighlightPhase{};
@@ -369,6 +370,9 @@ void savePreference(const wchar_t *name, DWORD value)
}
#include "files_styles.inl"
void setStatus(const std::wstring &message);
void refreshCommandHistory();
#include "files_command_history.inl"
constexpr const wchar_t *panelPathKeys[]{L"LeftPath",L"RightPath"};
constexpr const wchar_t *panelCursorKeys[]{L"LeftCursor",L"RightCursor"};
@@ -620,7 +624,7 @@ int dialogRowTextInset(int characterWidth,DialogFramePadding padding=dialogFrame
}
void paintDialogListRow(HDC dc,RECT bounds,std::wstring_view label,HFONT font,
COLORREF foreground,COLORREF background,int inset)
COLORREF foreground,COLORREF background,int inset,UINT ellipsis=DT_PATH_ELLIPSIS)
{
const auto saved=SaveDC(dc);
SetBkColor(dc,background);
@@ -631,7 +635,7 @@ void paintDialogListRow(HDC dc,RECT bounds,std::wstring_view label,HFONT font,
InflateRect(&bounds,-inset,0);
if(bounds.right>bounds.left)
DrawTextW(dc,label.data(),static_cast<int>(label.size()),&bounds,
DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX|DT_PATH_ELLIPSIS);
DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX|ellipsis);
if(saved) RestoreDC(dc,saved);
}
@@ -856,6 +860,17 @@ void updateTerminalOutput()
}
LRESULT CALLBACK terminalInputKeys(HWND input,UINT message,WPARAM wp,LPARAM lp,UINT_PTR,DWORD_PTR)
{
if(message==WM_CHAR && wp==VK_ESCAPE)
{
recallCommand(terminalHistory.size());
return 0;
}
if((message==WM_CHAR && wp==22) ||
(message==WM_KEYDOWN && wp==VK_INSERT && (GetKeyState(VK_SHIFT)&0x8000)))
{
SendMessageW(input,WM_PASTE,0,0);
return 0;
}
// The edit control receives Ctrl+Backspace as DEL.
if(message==WM_CHAR && wp==127)
{
@@ -884,11 +899,7 @@ LRESULT CALLBACK terminalInputKeys(HWND input,UINT message,WPARAM wp,LPARAM lp,U
std::wstring value(GetWindowTextLengthW(input)+1,L'\0');
value.resize(GetWindowTextW(input,value.data(),static_cast<int>(value.size())));
if(!terminal.write(value+L"\r")) { setStatus(L"Could not send PowerShell input."); return 0; }
if(!value.empty() && (terminalHistory.empty() || terminalHistory.back()!=value))
{
if(terminalHistory.size()==100) terminalHistory.erase(terminalHistory.begin());
terminalHistory.push_back(value);
}
if(value.find_first_not_of(L" \t\r\n")!=std::wstring::npos) rememberCommand(value);
terminalHistoryIndex=terminalHistory.size();
SetWindowTextW(input,L"");
return 0;
@@ -914,11 +925,8 @@ LRESULT CALLBACK terminalInputKeys(HWND input,UINT message,WPARAM wp,LPARAM lp,U
}
if(message==WM_KEYDOWN && (wp==VK_UP || wp==VK_DOWN))
{
if(wp==VK_UP && terminalHistoryIndex) --terminalHistoryIndex;
if(wp==VK_DOWN && terminalHistoryIndex<terminalHistory.size()) ++terminalHistoryIndex;
SetWindowTextW(input,terminalHistoryIndex<terminalHistory.size()?
terminalHistory[terminalHistoryIndex].c_str():L"");
SendMessageW(input,EM_SETSEL,-2,-1);
if(wp==VK_UP && terminalHistoryIndex) recallCommand(terminalHistoryIndex-1);
if(wp==VK_DOWN && terminalHistoryIndex<terminalHistory.size()) recallCommand(terminalHistoryIndex+1);
return 0;
}
return DefSubclassProc(input,message,wp,lp);
@@ -1451,6 +1459,9 @@ bool directoryExists(const FilesPeer *peer,const fs::path &path)
}
HBRUSH warningBrush{};
RECT previousOwnerBounds{};
#include "files_dialog_input.inl"
LRESULT CALLBACK dialogButtonEnter(HWND button,UINT message,WPARAM wp,LPARAM lp,UINT_PTR,DWORD_PTR);
@@ -1473,15 +1484,8 @@ bool isDialogEdit(HWND control)
return lstrcmpiW(name,L"Edit")==0;
}
void prepareDialogEdit(HWND field)
void centerDialogEditText(HWND field)
{
SendMessageW(field,WM_SETFONT,reinterpret_cast<WPARAM>(mono),FALSE);
const auto margin=MulDiv(2,GetDpiForWindow(field),96);
SendMessageW(field,EM_SETMARGINS,EC_LEFTMARGIN|EC_RIGHTMARGIN,MAKELPARAM(margin,margin));
if(!(GetWindowLongPtrW(field,GWL_STYLE)&ES_MULTILINE)) return;
// A single-line Edit centers its own text. Copy uses a multiline Edit for
// its formatting rectangle and keeps its existing dialog key handling.
RECT edit{};
GetClientRect(field,&edit);
if(const auto dc=GetDC(field))
@@ -1496,6 +1500,25 @@ void prepareDialogEdit(HWND field)
SendMessageW(field,EM_SETRECTNP,0,reinterpret_cast<LPARAM>(&edit));
}
LRESULT CALLBACK dialogEditLayout(HWND field,UINT message,WPARAM wp,LPARAM lp,UINT_PTR,DWORD_PTR)
{
const auto result=DefSubclassProc(field,message,wp,lp);
if(message==WM_SIZE || message==WM_SETFONT) centerDialogEditText(field);
return result;
}
void prepareDialogEdit(HWND field)
{
SendMessageW(field,WM_SETFONT,reinterpret_cast<WPARAM>(mono),FALSE);
const auto margin=MulDiv(2,GetDpiForWindow(field),96);
SendMessageW(field,EM_SETMARGINS,EC_LEFTMARGIN|EC_RIGHTMARGIN,MAKELPARAM(margin,margin));
if(GetWindowLongPtrW(field,GWL_STYLE)&ES_MULTILINE)
{
SetWindowSubclass(field,dialogEditLayout,1,0);
centerDialogEditText(field);
}
}
void prepareCopyDialog(HWND dialog)
{
installDialogButtonKeys(dialog);
@@ -1554,10 +1577,10 @@ LONG dialogDividerY(HWND dialog,int id)
if(id==214)
{
const auto combo=dialogControlBounds(dialog,213);
const auto name=dialogControlBounds(dialog,211);
return bounds.bottom+std::max(0L,(combo.top-name.bottom-1)/2);
const auto validation=dialogControlBounds(dialog,328);
return bounds.bottom+std::max(0L,(combo.top-validation.bottom-1)/2);
}
if(id==213) return (dialogControlBounds(dialog,211).bottom+bounds.top-1)/2;
if(id==213) return (dialogControlBounds(dialog,328).bottom+bounds.top-1)/2;
return bounds.top-4;
}
@@ -1619,11 +1642,12 @@ void paintDialogButton(const DRAWITEMSTRUCT &item,COLORREF surface,COLORREF fore
}
INT_PTR paintCopyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp,
const wchar_t *caption, bool warning, std::initializer_list<int> dividers)
const wchar_t *caption, bool warning, std::initializer_list<int> dividers, bool useDialogPalette=false,
HWND scrollListControl=nullptr)
{
const auto foreground=warning?RGB(255,255,255):RGB(0,0,0);
const auto surface=warning?RGB(128,0,0):RGB(192,192,192);
const auto brush=warning?warningBrush:static_cast<HBRUSH>(GetStockObject(LTGRAY_BRUSH));
const auto foreground=useDialogPalette?colors[Text]:warning?RGB(255,255,255):RGB(0,0,0);
const auto surface=useDialogPalette?colors[Dialog]:warning?RGB(128,0,0):RGB(192,192,192);
const auto brush=useDialogPalette?teal:warning?warningBrush:static_cast<HBRUSH>(GetStockObject(LTGRAY_BRUSH));
if(message==WM_CTLCOLORDLG) return reinterpret_cast<INT_PTR>(brush);
if(message==WM_CTLCOLORSTATIC || message==WM_CTLCOLOREDIT || message==WM_CTLCOLORBTN)
{
@@ -1641,7 +1665,8 @@ INT_PTR paintCopyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp,
RECT bounds{};
GetClientRect(dialog,&bounds);
const auto client=bounds;
const auto black=static_cast<HBRUSH>(GetStockObject(warning?WHITE_BRUSH:BLACK_BRUSH));
const auto black=static_cast<HBRUSH>(GetStockObject(useDialogPalette?DC_BRUSH:warning?WHITE_BRUSH:BLACK_BRUSH));
if(useDialogPalette) SetDCBrushColor(dc,foreground);
bounds=paintDialogFrame(dc,client,dialogFrameMetrics(GetDpiForWindow(dialog)),brush,black);
for(const auto control:dividers)
{
@@ -1650,6 +1675,7 @@ INT_PTR paintCopyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp,
FillRect(dc,&divider,black);
}
paintDialogFrameCaptions(dc,client,bounds,caption,brush,foreground,mono);
if(scrollListControl) paintScrollPosition(dialog,dc,scrollListControl,surface);
EndPaint(dialog,&paint);
return TRUE;
}
@@ -1744,6 +1770,7 @@ INT_PTR CALLBACK copyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp)
SendDlgItemMessageW(dialog,pathField,EM_SETREADONLY,!single && !request.move,0);
if(request.move) SetDlgItemTextW(dialog,IDOK,L"&Rename");
layoutDialogButtons(dialog,214,{IDOK,IDCANCEL});
SendDlgItemMessageW(dialog,328,WM_SETFONT,reinterpret_cast<WPARAM>(mono),FALSE);
SendDlgItemMessageW(dialog,summary,WM_SETFONT,reinterpret_cast<WPARAM>(mono),FALSE);
SendDlgItemMessageW(dialog,conflicts,WM_SETFONT,reinterpret_cast<WPARAM>(mono),FALSE);
for(const auto control:{213,214})
@@ -1765,7 +1792,7 @@ INT_PTR CALLBACK copyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp)
}
if(message==WM_CLOSE || (message==WM_COMMAND && LOWORD(wp)==IDCANCEL))
{
EndDialog(dialog,IDCANCEL);
finishFilesDialog(dialog,IDCANCEL);
return TRUE;
}
if(message!=WM_COMMAND) return FALSE;
@@ -1781,7 +1808,17 @@ INT_PTR CALLBACK copyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp)
InvalidateRect(GetDlgItem(dialog,213),nullptr,FALSE);
return FALSE;
}
if(LOWORD(wp)==pathField && HIWORD(wp)==EN_CHANGE)
{
SetDlgItemTextW(dialog,328,L"");
return TRUE;
}
if(LOWORD(wp)!=IDOK) return FALSE;
const auto showError=[&](const wchar_t *message)
{
SetDlgItemTextW(dialog,328,message);
SetFocus(GetDlgItem(dialog,pathField));
};
try
{
if(request.move)
@@ -1801,9 +1838,7 @@ INT_PTR CALLBACK copyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp)
(!directoryExists(peer,target) &&
(request.sources.size()!=1 || !target.has_filename() || !directoryExists(peer,target.parent_path()))))
{
MessageBoxW(dialog,L"Enter an existing destination folder, or a new name for one item.",
L"Rename/Move",MB_OK|MB_ICONWARNING);
SetFocus(field);
showError(L"Enter an existing destination folder, or a new name for one item.");
return TRUE;
}
request.destinationPeer=peer;
@@ -1829,8 +1864,7 @@ INT_PTR CALLBACK copyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp)
name.find_first_of(L"<>:\"/\\|?*")!=name.npos ||
std::any_of(name.begin(),name.end(),[](wchar_t ch){return ch<32;}))
{
MessageBoxW(dialog,L"Enter a valid name for the copy.",L"Copy",MB_OK|MB_ICONWARNING);
SetFocus(field);
showError(L"Enter a valid name for the copy.");
return TRUE;
}
if(CompareStringOrdinal(name.c_str(),-1,request.sources.front().filename().c_str(),-1,TRUE)!=CSTR_EQUAL)
@@ -1843,7 +1877,7 @@ INT_PTR CALLBACK copyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp)
const auto peer=request.move || request.newName.empty()?request.destinationPeer:request.sourcePeer;
if(!directoryExists(peer,destination))
{
MessageBoxW(dialog,L"The destination folder is unavailable.",L"Copy",MB_OK|MB_ICONWARNING);
showError(L"The destination folder is unavailable.");
return TRUE;
}
const bool sameHost=(!peer && !request.sourcePeer) ||
@@ -1853,22 +1887,21 @@ INT_PTR CALLBACK copyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp)
fs::equivalent(destination,sourceDirectory,error));
if(request.newName.empty() && sameFolder)
{
MessageBoxW(dialog,L"Open a different folder in the other panel, or enter a new name for a single item.",
request.move?L"Rename/Move":L"Copy",MB_OK|MB_ICONWARNING);
showError(L"Open a different folder in the other panel, or enter a new name for a single item.");
return TRUE;
}
const auto mode=SendDlgItemMessageW(dialog,213,CB_GETCURSEL,0,0);
if(mode!=CB_ERR) request.conflictMode=static_cast<ConflictMode>(
request.move && mode==static_cast<int>(ConflictMode::append)?static_cast<int>(ConflictMode::newer):mode);
EndDialog(dialog,IDOK);
finishFilesDialog(dialog,IDOK);
}
catch(const std::system_error &e)
{
MessageBoxW(dialog,fileError(e).c_str(),L"Destination unavailable",MB_OK|MB_ICONWARNING);
showError(fileError(e).c_str());
}
catch(const std::exception &)
{
MessageBoxW(dialog,L"The remote destination is unavailable.",L"Copy",MB_OK|MB_ICONWARNING);
showError(L"The remote destination is unavailable.");
}
return TRUE;
}
@@ -1890,7 +1923,6 @@ struct CopyProgress
};
bool copyInProgress{};
CopyProgress *activeCopy{};
RECT previousOwnerBounds{};
struct OwnedWindowMove
{
@@ -2010,7 +2042,7 @@ INT_PTR CALLBACK cancelOperationDialog(HWND window,UINT message,WPARAM wp,LPARAM
if(message==WM_CLOSE || (message==WM_COMMAND &&
(LOWORD(wp)==IDYES || LOWORD(wp)==IDNO || LOWORD(wp)==IDCANCEL)))
{
EndDialog(window,message==WM_COMMAND && LOWORD(wp)==IDYES?IDYES:IDNO);
finishFilesDialog(window,message==WM_COMMAND && LOWORD(wp)==IDYES?IDYES:IDNO);
return TRUE;
}
return FALSE;
@@ -2020,7 +2052,7 @@ bool confirmOperationCancellation(HWND owner,const wchar_t *question)
{
const auto previous=warningBrush;
if(!previous) warningBrush=CreateSolidBrush(RGB(128,0,0));
const auto answer=DialogBoxParamW(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(105),owner,
const auto answer=runFilesDialog(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(105),owner,
cancelOperationDialog,reinterpret_cast<LPARAM>(question));
if(!previous)
{
@@ -2134,9 +2166,28 @@ struct WarningPrompt
const wchar_t *details;
const wchar_t *accept;
const wchar_t *decline;
FileInfo incoming,existing;
bool remember{};
};
std::wstring conflictFileDetails(const FileInfo &file)
{
const FILETIME stamp{static_cast<DWORD>(file.modified),static_cast<DWORD>(file.modified>>32)};
SYSTEMTIME utc{},local{};
wchar_t date[32]=L"—";
if(file.modified && FileTimeToSystemTime(&stamp,&utc) && SystemTimeToTzSpecificLocalTime(nullptr,&utc,&local))
swprintf_s(date,L"%04u-%02u-%02u %02u:%02u:%02u",unsigned(local.wYear),
unsigned(local.wMonth),unsigned(local.wDay),unsigned(local.wHour),
unsigned(local.wMinute),unsigned(local.wSecond));
auto bytes=std::to_wstring(file.size);
for(auto position=bytes.size();position>3;)
{
position-=3;
bytes.insert(position,1,L'\u202F');
}
return bytes+L" B "+date;
}
LRESULT CALLBACK warningButtonKeys(HWND button,UINT message,WPARAM wp,LPARAM lp,
UINT_PTR,DWORD_PTR index)
{
@@ -2173,7 +2224,7 @@ INT_PTR CALLBACK warningDialog(HWND window,UINT message,WPARAM wp,LPARAM lp)
if(item.itemState&ODS_FOCUS) DrawFocusRect(item.hDC,&item.rcItem);
return TRUE;
}
if(const auto painted=paintCopyDialog(window,message,wp,lp,L" Warning ",true,{233,234}))
if(const auto painted=paintCopyDialog(window,message,wp,lp,L" Warning ",true,{233,333,234}))
return painted;
if(message==WM_INITDIALOG)
{
@@ -2183,11 +2234,13 @@ INT_PTR CALLBACK warningDialog(HWND window,UINT message,WPARAM wp,LPARAM lp)
const auto &warning=*reinterpret_cast<WarningPrompt*>(lp);
SetDlgItemTextW(window,230,warning.message);
SetDlgItemTextW(window,231,warning.details);
SetDlgItemTextW(window,330,conflictFileDetails(warning.incoming).c_str());
SetDlgItemTextW(window,332,conflictFileDetails(warning.existing).c_str());
SetDlgItemTextW(window,IDYES,warning.accept);
SetDlgItemTextW(window,IDNO,warning.decline);
for(const auto control:{230,231,232})
for(const auto control:{230,231,232,329,330,331,332})
SendDlgItemMessageW(window,control,WM_SETFONT,reinterpret_cast<WPARAM>(mono),FALSE);
centerDialogRow(window,233,234,{232});
centerDialogRow(window,333,234,{232});
layoutDialogButtons(window,234,{IDYES,IDNO,IDCANCEL});
SendMessageW(window,DM_SETDEFID,IDNO,0);
constexpr int buttons[]{IDYES,IDNO,IDCANCEL};
@@ -2199,7 +2252,7 @@ INT_PTR CALLBACK warningDialog(HWND window,UINT message,WPARAM wp,LPARAM lp)
}
if(message==WM_CLOSE)
{
EndDialog(window,IDCANCEL);
finishFilesDialog(window,IDCANCEL);
return TRUE;
}
if(message==WM_COMMAND && LOWORD(wp)==232 && HIWORD(wp)==BN_CLICKED)
@@ -2212,7 +2265,7 @@ INT_PTR CALLBACK warningDialog(HWND window,UINT message,WPARAM wp,LPARAM lp)
if(message==WM_COMMAND && (LOWORD(wp)==IDYES || LOWORD(wp)==IDNO || LOWORD(wp)==IDCANCEL))
{
const auto choice=LOWORD(wp);
EndDialog(window,choice);
finishFilesDialog(window,choice);
return TRUE;
}
return FALSE;
@@ -2235,7 +2288,7 @@ bool pumpCopy(CopyProgress &progress)
((message.message>=WM_KEYFIRST && message.message<=WM_KEYLAST) ||
(message.message>=WM_MOUSEFIRST && message.message<=WM_MOUSELAST)))
{
if(message.message==WM_KEYDOWN && message.wParam==VK_ESCAPE)
if(filesMouseDown(message.message) || (message.message==WM_KEYDOWN && message.wParam==VK_ESCAPE))
SendMessageW(progress.window,WM_COMMAND,IDCANCEL,0);
else if(message.message==WM_SYSKEYDOWN && message.wParam==VK_F4)
SendMessageW(owner,WM_CLOSE,0,0);
@@ -2416,9 +2469,9 @@ CopyResult copyItem(const CopyEndpoints &hosts,const fs::path &from,const fs::pa
if(!answer)
{
WarningPrompt warning{readOnly?L"Existing file is read-only":L"File already exists",
to.c_str(),L"&Overwrite",L"&Skip"};
to.c_str(),L"&Overwrite",L"&Skip",*incoming,*existing};
warningBrush=CreateSolidBrush(RGB(128,0,0));
answer=DialogBoxParamW(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(104),progress.window,
answer=runFilesDialog(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(104),progress.window,
warningDialog,reinterpret_cast<LPARAM>(&warning));
if(warning.remember && (answer==IDYES || answer==IDNO))
progress.conflictChoice=static_cast<int>(answer);
@@ -2454,7 +2507,7 @@ void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
if(row<0 || static_cast<size_t>(row)>=source.rows.size() || source.sizes[row]==L"Up") return;
request.sources.push_back(source.rows[row]);
}
const auto result=DialogBoxParamW(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(102),owner,copyDialog,
const auto result=runFilesDialog(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(102),owner,copyDialog,
reinterpret_cast<LPARAM>(&request));
if(result==-1) setStatus(L"Could not open the Copy dialog.");
if(result!=IDOK) return;
@@ -2475,6 +2528,7 @@ void copySelection(HWND owner,Panel &source,Panel &destination,bool move)
setStatus(L"Could not open copy progress.");
return;
}
FilesDialogInput progressInput(progress.window);
copyInProgress=true;
activeCopy=&progress;
for(auto &panel:panels) EnableWindow(panel.list,FALSE);
@@ -2702,14 +2756,14 @@ INT_PTR CALLBACK deleteConfirmationDialog(HWND window,UINT message,WPARAM wp,LPA
}
if(message==WM_CLOSE || (message==WM_COMMAND && LOWORD(wp)==IDCANCEL))
{
EndDialog(window,IDCANCEL);
finishFilesDialog(window,IDCANCEL);
return TRUE;
}
if(message==WM_COMMAND && (LOWORD(wp)==IDYES ||
((data->folderPrompt || data->readOnlyPrompt) && (LOWORD(wp)==244 || LOWORD(wp)==IDNO)) ||
(data->readOnlyPrompt && LOWORD(wp)==249)))
{
EndDialog(window,LOWORD(wp));
finishFilesDialog(window,LOWORD(wp));
return TRUE;
}
return FALSE;
@@ -2751,7 +2805,7 @@ bool pumpDeletion(HWND window,bool &canceled)
canceled=true;
break;
}
if(!IsDialogMessageW(window,&message))
if(!filesDialogHandlesMessage(window,message))
{
TranslateMessage(&message);
DispatchMessageW(&message);
@@ -2801,7 +2855,7 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
}
DeleteConfirmation confirmation{message,entries,static_cast<int>(shown+(shown<paths.size())),
permanent,false};
if(DialogBoxParamW(instance,MAKEINTRESOURCEW(106),owner,deleteConfirmationDialog,
if(runFilesDialog(instance,MAKEINTRESOURCEW(106),owner,deleteConfirmationDialog,
reinterpret_cast<LPARAM>(&confirmation))!=IDYES)
{
DeleteObject(warningBrush);
@@ -2815,7 +2869,8 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
reinterpret_cast<LPARAM>(&canceled));
if(window)
{
EnableWindow(owner,FALSE);
GetWindowRect(owner,&previousOwnerBounds);
FilesDialogInput progressInput(window);
ShowWindow(window,SW_SHOW);
size_t done=0, skipped=0, failed=0, total=0;
bool all=false;
@@ -2879,7 +2934,7 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
if(group.size()>1 && !all)
{
DeleteConfirmation folder{L"The following folder will be deleted:",group.front().wstring(),1,true,true};
const auto answer=DialogBoxParamW(instance,MAKEINTRESOURCEW(106),window,deleteConfirmationDialog,
const auto answer=runFilesDialog(instance,MAKEINTRESOURCEW(106),window,deleteConfirmationDialog,
reinterpret_cast<LPARAM>(&folder));
if(answer==244) all=true;
else if(answer==IDNO)
@@ -2906,7 +2961,7 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
if(!answer)
{
DeleteConfirmation warning{L"Delete this read-only file?",current.wstring(),1,true,false,true};
answer=DialogBoxParamW(instance,MAKEINTRESOURCEW(106),window,deleteConfirmationDialog,
answer=runFilesDialog(instance,MAKEINTRESOURCEW(106),window,deleteConfirmationDialog,
reinterpret_cast<LPARAM>(&warning));
if(answer==244 || answer==249) readOnlyChoice=static_cast<int>(answer);
}
@@ -2950,7 +3005,7 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
catch(const std::system_error &e){++failed;failure=fileError(e);}
catch(const std::exception &){++failed;failure=L"File connection interrupted.";}
RedrawWindow(window,nullptr,nullptr,RDW_UPDATENOW|RDW_ALLCHILDREN);
EnableWindow(owner,TRUE);
DestroyWindow(window);
for(auto &visible:panels)
if(!visible.directory.empty()) open(visible,visible.directory);
@@ -2964,8 +3019,29 @@ void deleteSelection(HWND owner,Panel &panel,bool permanent)
warningBrush=nullptr;
}
void selectPanelEdge(Panel &panel,bool first)
{
SetFocus(panel.list);
const auto count=SendMessageW(panel.list,LB_GETCOUNT,0,0);
if(count<=0) return;
SendMessageW(panel.list,LB_SETCURSEL,first?0:count-1,0);
InvalidateRect(panel.list,nullptr,FALSE);
showFileDetails(panel);
}
LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR index)
{
if(message==WM_LBUTTONDOWN)
{
const auto count=SendMessageW(window,LB_GETCOUNT,0,0);
RECT last{};
if(count>0 && SendMessageW(window,LB_GETITEMRECT,count-1,reinterpret_cast<LPARAM>(&last))!=LB_ERR &&
GET_Y_LPARAM(lp)>=last.bottom)
{
selectPanelEdge(panels[index],false);
return 0;
}
}
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))))
{
@@ -2994,7 +3070,6 @@ LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT
}
if (message == WM_KEYDOWN && (wp == VK_LEFT || wp == VK_RIGHT))
return scrollList(window, message, wp == VK_LEFT ? VK_HOME : VK_END, lp);
if(message==WM_KILLFOCUS || message==WM_SETFOCUS) InvalidateRect(window,nullptr,FALSE);
if (message == WM_SETFOCUS)
{
const auto previous=active;
@@ -3068,6 +3143,7 @@ LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT
}
#include "files_folder_shortcuts.inl"
#include "files_command_history_dialog.inl"
#include "files_options.inl"
void openMenu(HWND window, int index)
@@ -3264,7 +3340,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
0, 0, 0, 0, window, nullptr, instance, nullptr);
terminalInput=CreateWindowW(L"EDIT",L"",WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL,
0,0,0,0,window,nullptr,instance,nullptr);
terminalPrompt=CreateWindowW(L"STATIC",L"",WS_CHILD|WS_VISIBLE|SS_PATHELLIPSIS|SS_CENTERIMAGE,
terminalPrompt=CreateWindowW(L"STATIC",L"",WS_CHILD|WS_VISIBLE|SS_PATHELLIPSIS,
0,0,0,0,window,nullptr,instance,nullptr);
terminalOutput=CreateWindowW(L"STATIC",L"",WS_CHILD|WS_CLIPCHILDREN,
0,0,0,0,window,nullptr,instance,nullptr);
@@ -3325,7 +3401,8 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
return 0;
}
case WM_MOVE:
if(copyInProgress && !IsIconic(window))
layoutOpenCommandHistory(true);
if((copyInProgress || activeFilesDialog) && !IsIconic(window))
{
RECT bounds{};
if(GetWindowRect(window,&bounds))
@@ -3341,6 +3418,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
case WM_SIZE:
hidePicker();
layout(window);
layoutOpenCommandHistory();
return 0;
case WM_GETMINMAXINFO:
reinterpret_cast<MINMAXINFO *>(lp)->ptMinTrackSize = {540, 220};
@@ -3361,6 +3439,20 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
if (message == WM_LBUTTONDOWN) { dragging = true; SetCapture(window); }
return TRUE;
}
if(message==WM_LBUTTONDOWN && !terminalVisible)
{
for(auto &panel:panels)
{
RECT list{};
if(!GetWindowRect(panel.list,&list)) continue;
MapWindowPoints(nullptr,window,reinterpret_cast<POINT*>(&list),2);
if(point.x>=list.left && point.x<list.right && point.y>=0 && point.y<list.top)
{
selectPanelEdge(panel,true);
return 0;
}
}
}
break;
}
case WM_MOUSEMOVE:
@@ -3548,17 +3640,19 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
}
if(item.CtlID>=130 && item.CtlID<=134 && static_cast<int>(item.CtlID)-130==menuIndex)
background=Selection;
if(item.CtlID==102 || item.CtlID==103)
const bool panelRow=item.CtlID==102 || item.CtlID==103;
const bool activePanelRow=panelRow && item.hwndItem==panels[active].list;
if(panelRow)
{
const auto cursor=SendMessageW(item.hwndItem,LB_GETCURSEL,0,0);
if(GetFocus()==item.hwndItem && cursor!=LB_ERR &&
if(activePanelRow && cursor!=LB_ERR &&
static_cast<UINT>(cursor)==item.itemID) background=PanelCursor;
}
else if(item.itemState&(ODS_SELECTED|ODS_FOCUS))
background=Selection;
COLORREF rowBackground=colors[background];
HFONT rowFont{};
if(item.CtlID==102 || item.CtlID==103)
if(panelRow)
{
const auto &panel=panels[item.CtlID-102];
if(item.itemID<panel.rows.size() && panel.sizes[item.itemID]!=L"Up")
@@ -3567,7 +3661,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
const bool transferred=transferHighlightPhase%2==0 && panel.transferResults.contains(panel.rows[item.itemID]);
const bool cursor=SendMessageW(panel.list,LB_GETCURSEL,0,0)==item.itemID;
const auto state=marked?FileRowState::Marked:!cursor?FileRowState::Normal:
GetFocus()==panel.list?FileRowState::Focused:FileRowState::Unfocused;
activePanelRow?FileRowState::Focused:FileRowState::Unfocused;
const auto resolved=resolveFileStyle(panel.rows[item.itemID].extension().native(),
panel.sizes[item.itemID]!=L"Folder",panel.dimmed[item.itemID],
background==PanelCursor || marked || transferred,foreground,rowBackground,fileStyles,state,transferred);
@@ -3697,7 +3791,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
return TRUE;
}
case WM_COMMAND:
if(copyInProgress) return 0;
if(copyInProgress || commandHistoryWindow || activeFilesDialog) return 0;
if(LOWORD(wp)==121 && HIWORD(wp)==LBN_DBLCLK) selectDrive();
if(LOWORD(wp)>=130 && LOWORD(wp)<=134 && HIWORD(wp)==BN_CLICKED)
{
@@ -3720,9 +3814,14 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
}
return 0;
case WM_CLOSE:
if(activeFilesDialog && !activeCopy)
{
PostMessageW(activeFilesDialog,WM_CLOSE,0,0);
return 0;
}
if(activeCopy)
{
if(!IsWindowEnabled(activeCopy->window))
if(activeFilesDialog!=activeCopy->window)
{
setStatus(L"Resolve the copy prompt before closing.");
return 0;
@@ -3780,8 +3879,9 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
}
LocalFree(args);
}
INITCOMMONCONTROLSEX controls{sizeof(controls), ICC_STANDARD_CLASSES|ICC_PROGRESS_CLASS|ICC_TREEVIEW_CLASSES};
INITCOMMONCONTROLSEX controls{sizeof(controls), ICC_STANDARD_CLASSES|ICC_PROGRESS_CLASS|ICC_TREEVIEW_CLASSES|ICC_HOTKEY_CLASS};
InitCommonControlsEx(&controls);
loadCommandHistory();
WNDCLASSW type{};
type.hInstance = instance;
type.lpfnWndProc = filesWindow;
@@ -3799,6 +3899,21 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
MSG message{};
while (GetMessageW(&message, nullptr, 0, 0) > 0)
{
if(commandHistoryWindow)
{
if(message.message==WM_KEYDOWN && (message.wParam==VK_RETURN || message.wParam==VK_ESCAPE) &&
(message.hwnd==commandHistoryWindow || IsChild(commandHistoryWindow,message.hwnd)))
{
SendMessageW(commandHistoryWindow,WM_COMMAND,message.wParam==VK_RETURN?IDOK:IDCANCEL,0);
continue;
}
if(IsDialogMessageW(commandHistoryWindow,&message)) continue;
const bool ownerClient=message.hwnd==window || IsChild(window,message.hwnd);
const bool clientInput=(message.message>=WM_KEYFIRST && message.message<=WM_KEYLAST) ||
(message.message>=WM_MOUSEFIRST && message.message<=WM_MOUSELAST) ||
message.message==WM_CONTEXTMENU;
if(ownerClient && clientInput) continue;
}
if(message.message==WM_KEYDOWN && (message.wParam==VK_UP || message.wParam==VK_DOWN) &&
(GetKeyState(VK_CONTROL)&0x8000) && !(GetKeyState(VK_MENU)&0x8000) &&
(message.hwnd==window || IsChild(window,message.hwnd)) && !terminalVisible && !copyInProgress)
@@ -3839,6 +3954,22 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
continue;
}
const bool filesMessage=message.hwnd==window || IsChild(window,message.hwnd);
const bool panelFocused=message.hwnd==panels[0].list || message.hwnd==panels[1].list;
if(panelFocused && !copyInProgress && message.message==WM_KEYDOWN &&
!(GetKeyState(VK_MENU)&0x8000) &&
!(GetKeyState(VK_LWIN)&0x8000) && !(GetKeyState(VK_RWIN)&0x8000))
{
const bool ctrl=(GetKeyState(VK_CONTROL)&0x8000)!=0;
const bool shift=(GetKeyState(VK_SHIFT)&0x8000)!=0;
if((message.wParam=='V' && ctrl && !shift) ||
(message.wParam==VK_INSERT && shift && !ctrl))
{
SetFocus(terminalInput);
SendMessageW(terminalInput,WM_PASTE,0,0);
continue;
}
}
if(filesMessage && !copyInProgress && handleCommandHistoryKey(window,message)) continue;
const bool modified=(GetKeyState(VK_CONTROL)&0x8000) || (GetKeyState(VK_SHIFT)&0x8000) ||
(GetKeyState(VK_LWIN)&0x8000) || (GetKeyState(VK_RWIN)&0x8000);
if(filesMessage && !copyInProgress &&