Release KSwitcher v0.6.90

This commit is contained in:
agrynco committed 2026-11-16 00:46:06 +02:00
1 parent 84d911ae9e
commit 7698ea040d
12 files changed
+303 -135

No files matched your search

+158 -55
View File
@@ -316,6 +316,7 @@ HWND picker{}, pickerFrame{}, menuBar{};
HWND menuItems[5]{};
constexpr std::wstring_view menuAccessKeys=L"LFCOR";
std::vector<size_t> commandAccessPositions;
std::vector<int> commandActions;
int menuIndex{};
bool commandPicker{};
constexpr int defaultSizeWidth=6, defaultFontPoints=110;
@@ -388,8 +389,14 @@ void savePlacement(HWND window)
&placement,sizeof(placement));
}
void chooseDrive(int index, bool fromMenu = false);
INT_PTR showFilesNotice(HWND owner,const wchar_t *text,const wchar_t *title,bool confirm=false,
bool *remember=nullptr,bool warning=false);
enum class FilesNoticeTone { dialog, neutral, warning };
struct FilesNoticeOptions
{
bool confirm{};
bool *remember{};
FilesNoticeTone tone{FilesNoticeTone::dialog};
};
INT_PTR showFilesNotice(HWND owner,const wchar_t *text,const wchar_t *title,FilesNoticeOptions options={});
void openMenu(HWND window, int index);
void showFileDetails(const Panel &panel);
void editOptions(HWND owner);
@@ -1279,7 +1286,7 @@ void openOn(Panel &panel,const fs::path &directory,bool offerElevation,std::opti
const auto question=L"Windows denied access to this folder.\r\n"+path+
L"\r\n\r\nTry opening as administrator? Windows may still ask for UAC.";
if(rememberElevationApproval || showFilesNotice(owner,question.c_str(),
L"KSwitcher Files",true,&remember)==IDYES)
L"KSwitcher Files",{.confirm=true,.remember=&remember})==IDYES)
{
const auto result=requestElevatedFolder(owner,directory,folders,files,metadata);
SetForegroundWindow(owner);
@@ -1431,7 +1438,8 @@ void runActivePeerAction(HWND owner,bool update)
const auto question=update
? L"Update KSwitcher on "+peer.name+L"? Open KSwitcher windows there will close if an update is available."
: L"Hibernate "+peer.name+L"?";
if(showFilesNotice(owner,question.c_str(),update?L"Update remote KSwitcher":L"Hibernate remote PC",true)!=IDYES)
if(showFilesNotice(owner,question.c_str(),update?L"Update remote KSwitcher":L"Hibernate remote PC",
{.confirm=true,.tone=FilesNoticeTone::warning})!=IDYES)
return;
std::packaged_task<std::wstring()> task([peer,update]
@@ -1481,6 +1489,11 @@ void runActivePeerAction(HWND owner,bool update)
void selectDrive()
{
auto row=SendMessageW(picker,LB_GETCURSEL,0,0);
if(commandPicker)
{
if(row<0 || static_cast<size_t>(row)>=commandActions.size() || commandActions[row]<0) return;
row=commandActions[row];
}
if(!commandPicker && (row<0 || static_cast<size_t>(row)==drivePaths.size())) return;
const auto remote=remoteDriveRows.find(row);
if(commandPicker || row<static_cast<LRESULT>(drivePaths.size()) || remote!=remoteDriveRows.end())
@@ -1516,6 +1529,26 @@ void selectDrive()
LRESULT CALLBACK pickerKeys(HWND window, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR)
{
if(commandPicker)
{
const auto separator=[](LRESULT row)
{
return row>=0 && static_cast<size_t>(row)<commandActions.size() && commandActions[row]<0;
};
if(msg==WM_KEYDOWN && (wp==VK_UP || wp==VK_DOWN || wp==VK_PRIOR || wp==VK_NEXT))
{
const auto result=DefSubclassProc(window,msg,wp,lp);
const auto row=SendMessageW(window,LB_GETCURSEL,0,0);
if(separator(row))
SendMessageW(window,LB_SETCURSEL,row+((wp==VK_UP || wp==VK_PRIOR)?-1:1),0);
return result;
}
if(msg==WM_LBUTTONDOWN || msg==WM_LBUTTONDBLCLK || (msg==WM_MOUSEMOVE && (wp&MK_LBUTTON)))
{
const auto hit=SendMessageW(window,LB_ITEMFROMPOINT,0,lp);
if(!HIWORD(hit) && separator(LOWORD(hit))) return 0;
}
}
if(!commandPicker && msg==WM_CHAR)
{
const auto key=towupper(static_cast<wchar_t>(wp));
@@ -1881,7 +1914,8 @@ void openSelectedText(const Panel &panel, bool edit, bool external)
farDropDownPalette,FilesModalDialog::run,FilesModalDialog::finish,FilesModalDialog::dismissOwned,
[](HWND owner)
{
return showFilesNotice(owner,L"This file is already open. Switch to its window?",L"Files",true)==IDYES;
return showFilesNotice(owner,L"This file is already open. Switch to its window?",L"Files",
{.confirm=true})==IDYES;
}},panel.peer?&*panel.peer:nullptr);
}
@@ -2514,7 +2548,7 @@ INT_PTR CALLBACK copyDialog(HWND dialog, UINT message, WPARAM wp, LPARAM lp)
if(LOWORD(wp)!=IDOK) return FALSE;
const auto showError=[&](const wchar_t *message)
{
showFilesNotice(dialog,message,L"Error",false,nullptr,true);
showFilesNotice(dialog,message,L"Error",{.tone=FilesNoticeTone::warning});
SetFocus(GetDlgItem(dialog,pathField));
};
try
@@ -2904,11 +2938,55 @@ struct FilesNotice
{
const wchar_t *text;
std::wstring title;
bool confirm;
bool *remember;
bool warning;
FilesNoticeOptions options;
};
void layoutFilesNotice(HWND dialog)
{
const auto &notice=*reinterpret_cast<const FilesNotice *>(GetWindowLongPtrW(dialog,DWLP_USER));
const auto frame=dialogFrameMetrics(GetDpiForWindow(dialog));
const auto inset=frame.content();
const auto top=dialogListInset(frame,textHeight);
const auto field=GetDlgItem(dialog,100);
RECT client{};
GetClientRect(dialog,&client);
const auto contentWidth=std::max(1L,client.right-2*inset);
TEXTMETRICW metrics{};
if(const auto dc=GetDC(field))
{
const auto previous=SelectObject(dc,mono);
GetTextMetricsW(dc,&metrics);
SelectObject(dc,previous);
ReleaseDC(field,dc);
}
const auto lineHeight=std::max(1L,metrics.tmHeight);
const auto place=[&](int id,int y,int height)
{
SetWindowPos(GetDlgItem(dialog,id),nullptr,inset,y,contentWidth,height,SWP_NOZORDER|SWP_NOACTIVATE);
};
constexpr LRESULT maxLines=8;
ShowScrollBar(field,SB_VERT,FALSE);
place(100,top,maxLines*lineHeight);
const auto lines=SendMessageW(field,EM_GETLINECOUNT,0,0);
const bool overflow=lines>maxLines;
const auto height=static_cast<int>(std::clamp<LRESULT>(lines,1,maxLines))*lineHeight;
place(100,top,height);
ShowScrollBar(field,SB_VERT,overflow);
const auto style=GetWindowLongPtrW(field,GWL_STYLE);
SetWindowLongPtrW(field,GWL_STYLE,overflow?style|WS_TABSTOP:style&~WS_TABSTOP);
if(!overflow) SendMessageW(field,EM_LINESCROLL,0,-SendMessageW(field,EM_GETFIRSTVISIBLELINE,0,0));
auto bottom=top+height;
if(notice.options.remember)
{
bottom+=dialogRowGap();
place(101,bottom,textHeight);
bottom+=textHeight;
}
place(102,bottom+dialogRowGap()+4,1);
if(notice.options.confirm) layoutDialogButtons(dialog,102,{IDYES,IDNO});
else layoutDialogButtons(dialog,102,{IDOK});
}
INT_PTR CALLBACK filesNoticeDialog(HWND window,UINT message,WPARAM wp,LPARAM lp)
{
if(message==WM_INITDIALOG)
@@ -2916,70 +2994,73 @@ INT_PTR CALLBACK filesNoticeDialog(HWND window,UINT message,WPARAM wp,LPARAM lp)
SetWindowLongPtrW(window,DWLP_USER,lp);
const auto &notice=*reinterpret_cast<const FilesNotice *>(lp);
prepareTextDialog(window);
SetDlgItemTextW(window,100,notice.text);
if(notice.warning)
const auto field=GetDlgItem(window,100);
SendMessageW(field,EM_SETMARGINS,EC_LEFTMARGIN|EC_RIGHTMARGIN,0);
SetWindowTextW(field,notice.text);
if(notice.options.remember)
{
const auto bounds=dialogControlBounds(window,100);
const auto divider=dialogControlBounds(window,102);
RECT text{0,0,bounds.right-bounds.left,0};
if(const auto dc=GetDC(window))
{
const auto previous=SelectObject(dc,mono);
DrawTextW(dc,notice.text,-1,&text,DT_CALCRECT|DT_WORDBREAK|DT_NOPREFIX);
SelectObject(dc,previous);
ReleaseDC(window,dc);
}
const auto height=std::max<LONG>(text.bottom,textHeight);
SetWindowPos(GetDlgItem(window,100),nullptr,bounds.left,bounds.top,bounds.right-bounds.left,height,
SWP_NOZORDER|SWP_NOACTIVATE);
SetWindowPos(GetDlgItem(window,102),nullptr,divider.left,bounds.top+height+dialogRowGap()+4,0,0,
SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
layoutDialogButtons(window,102,{IDOK});
const auto checkbox=GetDlgItem(window,101);
installFarCheckbox(checkbox,notice.options.tone==FilesNoticeTone::warning?FarCheckboxSurface::warning:
notice.options.tone==FilesNoticeTone::neutral?FarCheckboxSurface::gray:FarCheckboxSurface::dialog);
ShowWindow(checkbox,SW_SHOW);
}
if(notice.remember)
{
const auto field=GetDlgItem(window,100);
RECT bounds{};
GetWindowRect(field,&bounds);
SetWindowPos(field,nullptr,0,0,bounds.right-bounds.left,
(bounds.bottom-bounds.top)*3/4,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
ShowWindow(GetDlgItem(window,101),SW_SHOW);
}
if(notice.confirm)
if(notice.options.confirm)
{
ShowWindow(GetDlgItem(window,IDOK),SW_HIDE);
ShowWindow(GetDlgItem(window,IDYES),SW_SHOW);
ShowWindow(GetDlgItem(window,IDNO),SW_SHOW);
groupDialogButtons(window,{IDYES,IDNO});
}
else if(!notice.warning) groupDialogButtons(window,{IDOK});
const auto defaultButton=notice.confirm?IDNO:IDOK;
RECT caption{},text{};
if(const auto dc=GetDC(window))
{
const auto previous=SelectObject(dc,mono);
DrawTextW(dc,notice.title.c_str(),-1,&caption,DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
DrawTextW(dc,notice.text,-1,&text,DT_CALCRECT|DT_NOPREFIX|DT_EXPANDTABS);
SelectObject(dc,previous);
ReleaseDC(window,dc);
}
const auto inset=dialogFrameMetrics(GetDpiForWindow(window)).content();
const auto minimum=std::max({24L*cellWidth,caption.right+6*cellWidth,
notice.options.remember?30L*cellWidth:0L})+2*inset;
const auto width=std::clamp(text.right+cellWidth+2*inset,minimum,std::max(minimum,60L*cellWidth+2*inset));
SetWindowPos(window,nullptr,0,0,width,1,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
layoutFilesNotice(window);
FilesModalDialog::fitWidthToOwner(window,minimum,layoutFilesNotice);
const auto defaultButton=notice.options.confirm?IDNO:IDOK;
SendMessageW(window,DM_SETDEFID,defaultButton,0);
SetFocus(GetDlgItem(window,defaultButton));
return FALSE;
}
const auto *notice=reinterpret_cast<const FilesNotice *>(GetWindowLongPtrW(window,DWLP_USER));
if(!notice) return FALSE;
if(const auto painted=paintCopyDialog(window,message,wp,lp,notice->title.c_str(),
notice->warning,notice->warning?std::initializer_list<int>{102}:std::initializer_list<int>{},
!notice->warning)) return painted;
const bool warning=notice->options.tone==FilesNoticeTone::warning;
const bool palette=notice->options.tone==FilesNoticeTone::dialog;
if(message==WM_CTLCOLORSTATIC && reinterpret_cast<HWND>(lp)==GetDlgItem(window,100) && !palette)
{
const auto dc=reinterpret_cast<HDC>(wp);
SetTextColor(dc,warning?RGB(255,255,255):RGB(0,0,0));
SetBkColor(dc,warning?RGB(128,0,0):RGB(192,192,192));
return reinterpret_cast<INT_PTR>(warning?warningBrush:GetStockObject(LTGRAY_BRUSH));
}
if(const auto painted=paintCopyDialog(window,message,wp,lp,notice->title.c_str(),warning,{102},palette))
return painted;
const auto command=LOWORD(wp);
if(message==WM_COMMAND && (command==IDOK || command==IDCANCEL || command==IDYES || command==IDNO))
{
if(command==IDYES && notice->remember)
*notice->remember=IsDlgButtonChecked(window,101)==BST_CHECKED;
if(command==IDYES && notice->options.remember)
*notice->options.remember=IsDlgButtonChecked(window,101)==BST_CHECKED;
FilesModalDialog::finish(window,command);
return TRUE;
}
return FALSE;
}
INT_PTR showFilesNotice(HWND owner,const wchar_t *text,const wchar_t *title,bool confirm,bool *remember,bool warning)
INT_PTR showFilesNotice(HWND owner,const wchar_t *text,const wchar_t *title,FilesNoticeOptions options)
{
const bool createBrush=warning && !warningBrush;
const bool createBrush=options.tone==FilesNoticeTone::warning && !warningBrush;
if(createBrush) warningBrush=CreateSolidBrush(RGB(128,0,0));
FilesNotice notice{text,std::wstring(L" ")+title+L" ",confirm,remember,warning};
const auto result=FilesModalDialog::run(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(warning?609:607),owner,filesNoticeDialog,
FilesNotice notice{text,std::wstring(L" ")+title+L" ",options};
const auto result=FilesModalDialog::run(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(607),owner,filesNoticeDialog,
reinterpret_cast<LPARAM>(&notice));
if(createBrush)
{
@@ -4092,7 +4173,7 @@ INT_PTR CALLBACK makeFolderDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
if(command!=IDOK) return FALSE;
const auto error=[&](const wchar_t *text,HWND focus)
{
showFilesNotice(dialog,text,L"Error",false,nullptr,true);
showFilesNotice(dialog,text,L"Error",{.tone=FilesNoticeTone::warning});
SetFocus(focus);
};
const auto entered=dialogFieldText(input);
@@ -4307,15 +4388,23 @@ void openMenu(HWND window, int index)
rows.push_back(L"Update remote KSwitcher");
}
}
commandActions.clear();
if(index==2)
{
commandActions={0,3,-1,1,2,4,5};
if(panels[active].peer) commandActions.insert(commandActions.end(),{-1,6,7});
}
else
for(size_t i=0;i<rows.size();++i) commandActions.push_back(static_cast<int>(i));
std::set<wchar_t> used;
commandAccessPositions.assign(rows.size(),std::wstring::npos);
std::vector<size_t> accessPositions(rows.size(),std::wstring::npos);
const auto reserve=[&](size_t row,wchar_t key)
{
const auto &text=rows[row];
for(size_t pos=0;pos<text.size() && text[pos]!=L'\t';++pos)
if(towupper(text[pos])==key && used.insert(key).second)
{
commandAccessPositions[row]=pos;
accessPositions[row]=pos;
return true;
}
return false;
@@ -4326,14 +4415,19 @@ void openMenu(HWND window, int index)
for(size_t i=0;i<rows.size();++i)
{
const auto &text=rows[i];
if(commandAccessPositions[i]==std::wstring::npos)
if(accessPositions[i]==std::wstring::npos)
for(const auto ch:text)
{
if(ch==L'\t') break;
const auto key=towupper(ch);
if(key>=L'A' && key<=L'Z' && reserve(i,static_cast<wchar_t>(key))) break;
}
SendMessageW(picker,LB_ADDSTRING,0,reinterpret_cast<LPARAM>(text.c_str()));
}
commandAccessPositions.clear();
for(const auto action:commandActions)
{
commandAccessPositions.push_back(action<0?std::wstring::npos:accessPositions[action]);
SendMessageW(picker,LB_ADDSTRING,0,reinterpret_cast<LPARAM>(action<0?L"":rows[action].c_str()));
}
RECT anchor{}, client{};
GetWindowRect(menuItems[index],&anchor);
@@ -4344,7 +4438,7 @@ void openMenu(HWND window, int index)
const int x=std::clamp(static_cast<int>(anchor.left)+inset,inset,
std::max(inset,static_cast<int>(client.right)-width-inset));
const int y=anchor.bottom+5;
const int height=static_cast<int>(rows.size())*static_cast<int>(SendMessageW(picker,LB_GETITEMHEIGHT,0,0));
const int height=static_cast<int>(commandActions.size())*static_cast<int>(SendMessageW(picker,LB_GETITEMHEIGHT,0,0));
SetWindowPos(pickerFrame,HWND_TOP,x-inset,y-inset,width+2*inset,height+2*inset,SWP_SHOWWINDOW);
SetWindowPos(picker,HWND_TOP,x,y,width,height,SWP_SHOWWINDOW);
SendMessageW(picker,LB_SETCURSEL,0,0);
@@ -4850,6 +4944,15 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
}
auto background=item.CtlType==ODT_BUTTON?Footer:item.hwndItem==picker?Dialog:PanelBlue;
auto foreground=colors[Text];
if(item.hwndItem==picker && commandPicker && item.itemID<commandActions.size() && commandActions[item.itemID]<0)
{
FillRect(item.hDC,&item.rcItem,teal);
const auto y=(item.rcItem.top+item.rcItem.bottom)/2;
const RECT line{item.rcItem.left,y,item.rcItem.right,y+1};
SetDCBrushColor(item.hDC,colors[Frame]);
FillRect(item.hDC,&line,static_cast<HBRUSH>(GetStockObject(DC_BRUSH)));
return TRUE;
}
if(item.hwndItem==picker && !commandPicker && item.itemID==drivePaths.size())
{
auto row=item.rcItem;