Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edb259e6bb | ||
|
|
9e287c3a1d | ||
|
|
5eda68a7a2 |
No files matched your search
@@ -484,6 +484,11 @@ Warning і початковий фокус на No.
|
||||
- Бірюзовий курсор поточного рядка видно в активній панелі. Кожна панель зберігає свою позицію курсора. Коли панелі видимі, F5 і F6 з командного рядка діють на активну панель.
|
||||
- Клік у панелі нижче списку ставить курсор на останній рядок, а клік вище списку — на перший.
|
||||
|
||||
- **Change drive → Recent folders** у меню Alt+F1 або Alt+F2 показує
|
||||
останні відвідані локальні папки. Повторний візит підіймає один запис
|
||||
угору, порядок зберігається після перезапуску. Enter або клік відкриває
|
||||
шлях у панелі, з якої викликали меню. Delete прибирає вибраний запис.
|
||||
|
||||
- У локальному заголовку кнопки ← та → переходять назад і вперед
|
||||
в історії відповідної панелі. Стрілка ↑, Alt+↑ та рядок `..`
|
||||
відкривають безпосередню батьківську папку. На корені стрілка вимкнена,
|
||||
|
||||
@@ -27,25 +27,18 @@ bool saveFolderShortcuts(const FolderShortcuts &shortcuts)
|
||||
{"name",ks::utf8(entry.peerName)},{"title",ks::utf8(entry.title)}});
|
||||
groups.push_back(std::move(rows));
|
||||
}
|
||||
const auto data=groups.dump();
|
||||
return data.size()<=1024*1024 &&
|
||||
RegSetKeyValueW(HKEY_CURRENT_USER,schemeKey,folderShortcutsKey,REG_BINARY,data.data(),
|
||||
static_cast<DWORD>(data.size()))==ERROR_SUCCESS;
|
||||
return writeFilesJsonPreference(folderShortcutsKey,groups);
|
||||
}
|
||||
catch(const std::exception &){return false;}
|
||||
}
|
||||
|
||||
void loadFolderShortcuts()
|
||||
{
|
||||
DWORD bytes{};
|
||||
if(RegGetValueW(HKEY_CURRENT_USER,schemeKey,folderShortcutsKey,RRF_RT_REG_BINARY,nullptr,nullptr,&bytes)!=ERROR_SUCCESS ||
|
||||
!bytes || bytes>1024*1024) return;
|
||||
std::string data(bytes,'\0');
|
||||
if(RegGetValueW(HKEY_CURRENT_USER,schemeKey,folderShortcutsKey,RRF_RT_REG_BINARY,nullptr,data.data(),&bytes)!=ERROR_SUCCESS)
|
||||
return;
|
||||
const auto saved=readFilesJsonPreference(folderShortcutsKey);
|
||||
if(!saved) return;
|
||||
try
|
||||
{
|
||||
const auto groups=Json::parse(data.begin(),data.begin()+bytes);
|
||||
const auto &groups=*saved;
|
||||
if(!groups.is_array() || groups.size()!=folderShortcuts.size()) return;
|
||||
FolderShortcuts loaded;
|
||||
for(size_t digit=0;digit<loaded.size();++digit)
|
||||
|
||||
+56
-7
@@ -331,6 +331,7 @@ FolderSize measureFolder(const fs::path &root,std::stop_token stop,const ListDir
|
||||
}
|
||||
|
||||
constexpr auto schemeKey = L"Software\\KSwitcher\\Files";
|
||||
#include "files_registry_json.inl"
|
||||
#include "files_ftp.inl"
|
||||
|
||||
|
||||
@@ -359,6 +360,8 @@ bool inLocalBranch(const fs::path &ancestor,fs::path directory)
|
||||
return false;
|
||||
}
|
||||
|
||||
#include "files_recent_folders.inl"
|
||||
|
||||
struct LocalNavigation
|
||||
{
|
||||
std::vector<fs::path> history;
|
||||
@@ -554,7 +557,12 @@ std::vector<size_t> commandAccessPositions;
|
||||
std::vector<int> commandActions;
|
||||
int menuIndex{};
|
||||
bool commandPicker{};
|
||||
struct FolderPicker { const wchar_t *caption; std::vector<fs::path> paths; };
|
||||
struct FolderPicker
|
||||
{
|
||||
const wchar_t *caption;
|
||||
std::vector<fs::path> paths;
|
||||
bool recent{};
|
||||
};
|
||||
std::optional<FolderPicker> folderPicker;
|
||||
constexpr int defaultSizeWidth=6, defaultFontPoints=110;
|
||||
constexpr bool defaultWide=false, defaultAlignExtensions=true, defaultShowDetails=true, defaultAlignFolders=false;
|
||||
@@ -2367,7 +2375,11 @@ bool applyDirectoryScan(Panel &panel,Panel::ScanRequest request,Panel::ScanResul
|
||||
panel.findOrigin.reset();
|
||||
}
|
||||
if(peer || request.ftp) panel.navigation={};
|
||||
else if(!finding) panel.navigation.opened(directory,request.navigationPosition);
|
||||
else if(!finding)
|
||||
{
|
||||
panel.navigation.opened(directory,request.navigationPosition);
|
||||
if(!sameDirectory && !panel.directory.empty() && !partial) updateRecentFolders(directory,true);
|
||||
}
|
||||
panel.directory = directory;
|
||||
panel.peer=std::move(peer);
|
||||
panel.ftp=std::move(request.ftp);
|
||||
@@ -2836,6 +2848,8 @@ void runActivePeerAction(HWND owner,bool update)
|
||||
}
|
||||
|
||||
LRESULT ftpDriveRow() {return static_cast<LRESULT>(drivePaths.size())+1;}
|
||||
LRESULT recentDriveRow() {return ftpDriveRow()+1;}
|
||||
void showRecentFolders(int side);
|
||||
|
||||
bool selectablePickerRow(LRESULT row)
|
||||
{
|
||||
@@ -2843,7 +2857,8 @@ bool selectablePickerRow(LRESULT row)
|
||||
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);
|
||||
return row<static_cast<LRESULT>(drivePaths.size()) || row==ftpDriveRow() || row==recentDriveRow() ||
|
||||
remoteDriveRows.contains(row);
|
||||
}
|
||||
|
||||
void selectDrive()
|
||||
@@ -2895,6 +2910,7 @@ void selectDrive()
|
||||
}
|
||||
else setStatus(L"Cannot load saved FTP connections.");
|
||||
}
|
||||
else if(row==recentDriveRow()) showRecentFolders(pickerPanel);
|
||||
else if(remote!=remoteDriveRows.end())
|
||||
{
|
||||
const auto &choice=remote->second;
|
||||
@@ -2905,6 +2921,37 @@ void selectDrive()
|
||||
|
||||
LRESULT CALLBACK pickerKeys(HWND window, UINT msg, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR)
|
||||
{
|
||||
if(folderPicker && folderPicker->recent && msg==WM_KEYDOWN && wp==VK_DELETE)
|
||||
{
|
||||
const auto row=SendMessageW(window,LB_GETCURSEL,0,0);
|
||||
if(!selectablePickerRow(row)) return 0;
|
||||
auto &paths=folderPicker->paths;
|
||||
if(!updateRecentFolders(paths[row],false))
|
||||
{
|
||||
setStatus(L"Could not remove the recent folder.");
|
||||
return 0;
|
||||
}
|
||||
paths.erase(paths.begin()+row);
|
||||
SendMessageW(window,LB_DELETESTRING,row,0);
|
||||
if(paths.empty())
|
||||
{
|
||||
hidePicker();
|
||||
setStatus(L"No recent local folders.");
|
||||
}
|
||||
else SendMessageW(window,LB_SETCURSEL,std::min(row,static_cast<LRESULT>(paths.size()-1)),0);
|
||||
return 0;
|
||||
}
|
||||
if(folderPicker && msg==WM_LBUTTONUP)
|
||||
{
|
||||
const auto hit=SendMessageW(window,LB_ITEMFROMPOINT,0,lp);
|
||||
const auto result=DefSubclassProc(window,msg,wp,lp);
|
||||
if(folderPicker && !HIWORD(hit) && selectablePickerRow(LOWORD(hit)))
|
||||
{
|
||||
SendMessageW(window,LB_SETCURSEL,LOWORD(hit),0);
|
||||
selectDrive();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if(msg==WM_KEYDOWN && (wp==VK_UP || wp==VK_DOWN))
|
||||
{
|
||||
const auto count=SendMessageW(window,LB_GETCOUNT,0,0);
|
||||
@@ -2989,7 +3036,7 @@ LRESULT CALLBACK pickerKeys(HWND window, UINT msg, WPARAM wp, LPARAM lp, UINT_PT
|
||||
if(!HIWORD(hit))
|
||||
{
|
||||
const auto choice=remoteDriveRows.find(LOWORD(hit));
|
||||
if(LOWORD(hit)<drivePaths.size() || LOWORD(hit)==ftpDriveRow() ||
|
||||
if(LOWORD(hit)<drivePaths.size() || LOWORD(hit)==ftpDriveRow() || LOWORD(hit)==recentDriveRow() ||
|
||||
(choice!=remoteDriveRows.end() && !choice->second.path &&
|
||||
driveWakeAction.hit(window,LOWORD(hit),lp,cellWidth)))
|
||||
row=LOWORD(hit);
|
||||
@@ -3113,7 +3160,7 @@ void showRemoteDrives(bool focus=false,int initialRow=0)
|
||||
auto selection=SendMessageW(picker,LB_GETCURSEL,0,0);
|
||||
std::optional<DriveChoice> previous;
|
||||
if(auto row=remoteDriveRows.find(selection);row!=remoteDriveRows.end()) previous=row->second;
|
||||
if(selection>ftpDriveRow()) selection=-1;
|
||||
if(selection>recentDriveRow()) selection=-1;
|
||||
if(focus) selection=initialRow;
|
||||
const auto top=SendMessageW(picker,LB_GETTOPINDEX,0,0);
|
||||
for(auto count=SendMessageW(picker,LB_GETCOUNT,0,0);count>static_cast<LRESULT>(drivePaths.size());--count)
|
||||
@@ -3126,6 +3173,7 @@ void showRemoteDrives(bool focus=false,int initialRow=0)
|
||||
};
|
||||
add(L"");
|
||||
add(L"FTP");
|
||||
add(L"Recent folders");
|
||||
add(L"KSwitcher LAN");
|
||||
if(!drivePeerLookupError.empty()) add(L" "+drivePeerLookupError);
|
||||
else if(driveQueries.empty()) add(L" No paired computers");
|
||||
@@ -7138,7 +7186,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);
|
||||
paintDialogFrameCaptions(item.hDC,item.rcItem,box,folderPicker->caption,teal,colors[Text],mono,
|
||||
folderPicker->recent?L"Del Remove":nullptr);
|
||||
const auto list=item.hwndItem==pickerFrame?picker:completionList;
|
||||
paintScrollPosition(item.hwndItem,item.hDC,list,colors[Dialog]);
|
||||
DeleteObject(border);
|
||||
@@ -7186,7 +7235,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 && !folderPicker && item.itemID==ftpDriveRow()+1)
|
||||
if(item.hwndItem==picker && !commandPicker && !folderPicker && item.itemID==recentDriveRow()+1)
|
||||
{
|
||||
auto row=item.rcItem;
|
||||
FillRect(item.hDC,&row,teal);
|
||||
|
||||
@@ -264,13 +264,13 @@ void editPanelPath(Panel &panel)
|
||||
navigateLocal(panel,prompt.result);
|
||||
}
|
||||
|
||||
void showFolderPicker(HWND owner,int side,const wchar_t *caption,std::vector<fs::path> paths,RECT anchor)
|
||||
void showFolderPicker(HWND owner,int side,const wchar_t *caption,std::vector<fs::path> paths,RECT anchor,bool recent=false)
|
||||
{
|
||||
hidePicker();
|
||||
showMenu(false);
|
||||
commandPicker=false;
|
||||
pickerPanel=side;
|
||||
folderPicker=FolderPicker{caption,std::move(paths)};
|
||||
folderPicker=FolderPicker{caption,std::move(paths),recent};
|
||||
SendMessageW(picker,LB_RESETCONTENT,0,0);
|
||||
size_t longest=wcslen(caption);
|
||||
for(const auto &path:folderPicker->paths)
|
||||
@@ -295,6 +295,21 @@ void showFolderPicker(HWND owner,int side,const wchar_t *caption,std::vector<fs:
|
||||
SetFocus(picker);
|
||||
}
|
||||
|
||||
void showRecentFolders(int side)
|
||||
{
|
||||
auto paths=readRecentFolders();
|
||||
if(paths.empty())
|
||||
{
|
||||
setStatus(L"No recent local folders.");
|
||||
return;
|
||||
}
|
||||
const auto owner=GetParent(picker);
|
||||
RECT anchor{};
|
||||
GetWindowRect(panels[side].path,&anchor);
|
||||
MapWindowPoints(nullptr,owner,reinterpret_cast<POINT *>(&anchor),2);
|
||||
showFolderPicker(owner,side,L"Recent folders",std::move(paths),anchor,true);
|
||||
}
|
||||
|
||||
void showHiddenPathParts(HWND window,int side,const PathPart &part)
|
||||
{
|
||||
const auto owner=GetParent(window);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
constexpr wchar_t recentFoldersKey[]=L"RecentFolders";
|
||||
constexpr size_t recentFoldersLimit=100;
|
||||
|
||||
std::vector<fs::path> readRecentFolders()
|
||||
{
|
||||
const auto saved=readFilesJsonPreference(recentFoldersKey);
|
||||
std::vector<fs::path> folders;
|
||||
if(!saved || !saved->is_array()) return folders;
|
||||
for(const auto &entry:*saved)
|
||||
{
|
||||
if(!entry.is_string()) continue;
|
||||
const auto path=filePath(entry);
|
||||
if(!path.is_absolute() || path.native().find(L'\0')!=std::wstring::npos) continue;
|
||||
if(std::none_of(folders.begin(),folders.end(),[&](const auto &known){return sameLocalFolder(path,known);}))
|
||||
folders.push_back(path);
|
||||
if(folders.size()==recentFoldersLimit) break;
|
||||
}
|
||||
return folders;
|
||||
}
|
||||
|
||||
bool updateRecentFolders(const fs::path &path,bool remember)
|
||||
{
|
||||
const Handle lock{CreateMutexW(nullptr,FALSE,L"Local\\KSwitcher.Files.RecentFolders")};
|
||||
if(!lock.value) return false;
|
||||
const auto wait=WaitForSingleObject(lock.value,100);
|
||||
if(wait!=WAIT_OBJECT_0 && wait!=WAIT_ABANDONED) return false;
|
||||
bool saved=false;
|
||||
try
|
||||
{
|
||||
auto folders=readRecentFolders();
|
||||
std::erase_if(folders,[&](const auto &known){return sameLocalFolder(path,known);});
|
||||
if(remember) folders.insert(folders.begin(),path);
|
||||
if(folders.size()>recentFoldersLimit) folders.resize(recentFoldersLimit);
|
||||
auto data=Json::array();
|
||||
for(const auto &folder:folders) data.push_back(ks::utf8(folder.native()));
|
||||
saved=writeFilesJsonPreference(recentFoldersKey,data);
|
||||
}
|
||||
catch(const std::exception &) {}
|
||||
ReleaseMutex(lock.value);
|
||||
return saved;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
constexpr DWORD maxFilesJsonBytes=1024*1024;
|
||||
|
||||
std::optional<Json> readFilesJsonPreference(const wchar_t *key)
|
||||
{
|
||||
DWORD bytes{};
|
||||
if(RegGetValueW(HKEY_CURRENT_USER,schemeKey,key,RRF_RT_REG_BINARY,nullptr,nullptr,&bytes)!=ERROR_SUCCESS ||
|
||||
!bytes || bytes>maxFilesJsonBytes) return {};
|
||||
std::string data(bytes,'\0');
|
||||
if(RegGetValueW(HKEY_CURRENT_USER,schemeKey,key,RRF_RT_REG_BINARY,nullptr,data.data(),&bytes)!=ERROR_SUCCESS)
|
||||
return {};
|
||||
try {return Json::parse(data.begin(),data.begin()+bytes);}
|
||||
catch(const std::exception &) {return {};}
|
||||
}
|
||||
|
||||
bool writeFilesJsonPreference(const wchar_t *key,const Json &value)
|
||||
{
|
||||
try
|
||||
{
|
||||
const auto data=value.dump();
|
||||
return data.size()<=maxFilesJsonBytes &&
|
||||
RegSetKeyValueW(HKEY_CURRENT_USER,schemeKey,key,REG_BINARY,data.data(),
|
||||
static_cast<DWORD>(data.size()))==ERROR_SUCCESS;
|
||||
}
|
||||
catch(const std::exception &) {return false;}
|
||||
}
|
||||
@@ -89,7 +89,8 @@ try {
|
||||
Open-Picker $side
|
||||
$rows = @(Read-Picker)
|
||||
$row = [Array]::IndexOf($rows, 'FTP')
|
||||
if ($row -lt 2 -or $rows[$row - 1] -cne '' -or $rows[$row + 1] -cne 'KSwitcher LAN') {
|
||||
if ($row -lt 2 -or $rows[$row - 1] -cne '' -or $rows[$row + 1] -cne 'Recent folders' -or
|
||||
$rows[$row + 2] -cne 'KSwitcher LAN') {
|
||||
throw "Source groups are missing separators in panel $side."
|
||||
}
|
||||
[void][FilesDriveShortcutTest]::SendMessage($picker, 390, [IntPtr]$row, $null)
|
||||
@@ -98,12 +99,14 @@ try {
|
||||
[void][FilesDriveShortcutTest]::PostMessage($picker, 256, [IntPtr]40, [IntPtr]::Zero)
|
||||
Wait-Until { [FilesDriveShortcutTest]::SendMessage($picker, 392, [IntPtr]::Zero, $null).ToInt32() -eq $row }
|
||||
[void][FilesDriveShortcutTest]::PostMessage($picker, 256, [IntPtr]40, [IntPtr]::Zero)
|
||||
Wait-Until { [FilesDriveShortcutTest]::SendMessage($picker, 392, [IntPtr]::Zero, $null).ToInt32() -eq $row + 1 }
|
||||
[void][FilesDriveShortcutTest]::PostMessage($picker, 256, [IntPtr]40, [IntPtr]::Zero)
|
||||
Wait-Until {
|
||||
$selected = [FilesDriveShortcutTest]::SendMessage($picker, 392, [IntPtr]::Zero, $null).ToInt32()
|
||||
$selected -ge 0 -and ($selected -lt $row -or $selected -gt $row + 1)
|
||||
$selected -ge 0 -and ($selected -lt $row -or $selected -gt $row + 2)
|
||||
}
|
||||
[void][FilesDriveShortcutTest]::PostMessage($picker, 256, [IntPtr]38, [IntPtr]::Zero)
|
||||
Wait-Until { [FilesDriveShortcutTest]::SendMessage($picker, 392, [IntPtr]::Zero, $null).ToInt32() -eq $row }
|
||||
Wait-Until { [FilesDriveShortcutTest]::SendMessage($picker, 392, [IntPtr]::Zero, $null).ToInt32() -eq $row + 1 }
|
||||
[void][FilesDriveShortcutTest]::SendMessage($picker, 407, [IntPtr]($row - 2), $null)
|
||||
$bitmap = Render-Picker
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user