Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ac6501b21 | ||
|
|
b6b7164742 | ||
|
|
8870d8c3d9 | ||
|
|
eb0f6ead72 | ||
|
|
d26eec3c98 |
No files matched your search
@@ -741,6 +741,8 @@ Warning і початковий фокус на No.
|
||||
|
||||
- При перенесенні вікна між моніторами з різним DPI оновлюй шрифт, висоту рядків панелей і компонування відкритого прогресу копіювання. Перевір перенесення під час активного копіювання.
|
||||
- Для власних діалогів і списків Far використовуй спільні метрики та малювання подвійної рамки. Еталон Delete задає 8 px від краю тла до першої лінії та 14 px від внутрішньої лінії до бічної межі вмісту при 96 DPI. Обидва відступи масштабуються за DPI. Вертикальний відступ враховує висоту заголовка та нижніх підказок. Діалоги й списки зберігають свою палітру та поведінку.
|
||||
- Options → Import JSON / Export JSON переносить вибрані групи збережених параметрів Files. Окремо доступні кольори панелей і порівняння разом зі стилями файлів, режими й компонування панелей та іменовані схеми клавіш. Перед заміною відмінних схем з однаковою назвою Files запитує підтвердження. Імпорт спочатку оновлює чернетку Options. Apply або OK зберігає зміни, Cancel відкидає їх. Формат містить лише ці параметри. Невідомі поля і групи пропускаються.
|
||||
- Commands → Keyboard shortcuts відкриває іменовані схеми для команд файлових панелей та історії команд. У схемі можна задати кілька клавіш, вибрати основну, вилучити прив’язку, скопіювати схему під новим іменем, перемкнути чи скинути її. OK зберігає активну схему. Меню показує всі прив’язки, нижній ряд і текстові підказки відображають основну. Діалог відхиляє дублікати в контекстах, що перетинаються, і клавіші, зайняті навігацією. Попередні прив’язки історії та порівняння завантажуються як схема Previous settings.
|
||||
- Appearance → Dialog frame налаштовує зовнішній і внутрішній відступи від 0 до 24 px при 96 DPI. Row text padding додає від 0 до 4 ширин символу з кожного боку тексту в рядках Folder shortcuts. Inner padding задає відстань від рамки до краю списку. Ширина попапа враховує обидва текстові відступи, а довгі шляхи скорочуються в межах доступної ширини. Живий зразок показує чернетку. Apply зберігає значення, Cancel відкидає незастосовані зміни, Reset selected to defaults повертає 8 px, 14 px і 0 символів. Профілі без цих параметрів використовують ті самі значення.
|
||||
- У ресурсі чи виклику задавай назву кнопки й клавішу доступу. Спільна функція `paintDialogButton` центрує текст, підсвічує фокус і додає фігурні дужки для дії за замовчуванням та квадратні для решти кнопок.
|
||||
- Модальні діалоги редактора й переглядача використовують той самий шрифт, що й діалоги операцій Files. Розміри полів і кнопок враховують метрики цього шрифту.
|
||||
|
||||
+49
-6
@@ -156,6 +156,51 @@ BEGIN
|
||||
PUSHBUTTON "Cancel", IDCANCEL, 162, 44, 50, 14
|
||||
END
|
||||
|
||||
615 DIALOGEX 0, 0, 371, 214
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Keyboard shortcuts"
|
||||
FONT 9, "Segoe UI"
|
||||
BEGIN
|
||||
LTEXT "Active &scheme", -1, 9, 9, 160, 11
|
||||
COMBOBOX 610, 9, 22, 194, 120, CBS_DROPDOWNLIST | WS_TABSTOP | WS_VSCROLL
|
||||
PUSHBUTTON "&Copy as…", 611, 211, 22, 69, 15
|
||||
PUSHBUTTON "Rese&t scheme", 612, 288, 22, 74, 15
|
||||
LTEXT "&Command", -1, 9, 49, 166, 11
|
||||
LISTBOX 613, 9, 63, 166, 117, LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "", 614, 184, 49, 178, 11
|
||||
LISTBOX 615, 184, 63, 178, 80, LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
|
||||
CONTROL "", 616, "msctls_hotkey32", WS_TABSTOP | WS_BORDER, 184, 152, 74, 15
|
||||
PUSHBUTTON "&Add", 617, 264, 152, 44, 15
|
||||
PUSHBUTTON "&Remove", 618, 314, 152, 48, 15
|
||||
PUSHBUTTON "Make &primary", 619, 184, 172, 75, 15
|
||||
DEFPUSHBUTTON "OK", IDOK, 250, 192, 52, 15
|
||||
PUSHBUTTON "Cancel", IDCANCEL, 310, 192, 52, 15
|
||||
END
|
||||
|
||||
616 DIALOGEX 0, 0, 233, 73
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Copy keyboard scheme"
|
||||
FONT 9, "Segoe UI"
|
||||
BEGIN
|
||||
LTEXT "Scheme &name", -1, 9, 9, 214, 11
|
||||
EDITTEXT 620, 9, 23, 215, 15, ES_AUTOHSCROLL
|
||||
DEFPUSHBUTTON "Copy", IDOK, 112, 49, 52, 15
|
||||
PUSHBUTTON "Cancel", IDCANCEL, 172, 49, 52, 15
|
||||
END
|
||||
|
||||
617 DIALOGEX 0, 0, 240, 124
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Files settings"
|
||||
FONT 9, "Segoe UI"
|
||||
BEGIN
|
||||
LTEXT "", 624, 9, 9, 222, 24
|
||||
AUTOCHECKBOX "Colors and file styles", 621, 9, 39, 222, 13
|
||||
AUTOCHECKBOX "Panel modes and layout", 622, 9, 55, 222, 13
|
||||
AUTOCHECKBOX "Keyboard schemes", 623, 9, 71, 222, 13
|
||||
DEFPUSHBUTTON "Load", IDOK, 118, 99, 52, 15
|
||||
PUSHBUTTON "Cancel", IDCANCEL, 179, 99, 52, 15
|
||||
END
|
||||
|
||||
101 DIALOGEX 0, 0, 397, 310
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPCHILDREN
|
||||
CAPTION "KSwitcher Files Options"
|
||||
@@ -194,10 +239,7 @@ BEGIN
|
||||
COMBOBOX 305, 311, 51, 56, 125, CBS_DROPDOWNLIST | WS_TABSTOP | WS_VSCROLL
|
||||
LTEXT "&Row text padding (characters)", 306, 131, 77, 173, 12
|
||||
COMBOBOX 307, 311, 74, 56, 76, CBS_DROPDOWNLIST | WS_TABSTOP | WS_VSCROLL
|
||||
LTEXT "Previous command", 320, 131, 30, 120, 12
|
||||
CONTROL "", 321, "msctls_hotkey32", WS_TABSTOP | WS_BORDER, 260, 27, 110, 15
|
||||
LTEXT "Open command history", 322, 131, 53, 120, 12
|
||||
CONTROL "", 323, "msctls_hotkey32", WS_TABSTOP | WS_BORDER, 260, 50, 110, 15
|
||||
PUSHBUTTON "&Keyboard shortcuts…", 321, 131, 30, 127, 15
|
||||
AUTOCHECKBOX "Allow &paired PCs to run PowerShell commands here", 370, 131, 79, 250, 14
|
||||
AUTOCHECKBOX "Allow paired PCs to &hibernate this PC", 371, 131, 95, 250, 14
|
||||
AUTOCHECKBOX "Allow paired PCs to &update KSwitcher here", 372, 131, 111, 250, 14
|
||||
@@ -250,8 +292,9 @@ BEGIN
|
||||
COMBOBOX 411, 250, 76, 132, 126, CBS_DROPDOWNLIST | WS_TABSTOP | WS_VSCROLL
|
||||
PUSHBUTTON "Change color…", 412, 250, 97, 82, 15
|
||||
LTEXT "", 413, 338, 100, 45, 12
|
||||
LTEXT "Compare files &shortcut", 414, 131, 130, 117, 12
|
||||
CONTROL "", 415, "msctls_hotkey32", WS_TABSTOP | WS_BORDER, 250, 127, 132, 15
|
||||
PUSHBUTTON "&Keyboard shortcuts…", 415, 131, 127, 127, 15
|
||||
PUSHBUTTON "&Import JSON…", 525, 8, 289, 70, 14
|
||||
PUSHBUTTON "&Export JSON…", 526, 84, 289, 70, 14
|
||||
DEFPUSHBUTTON "OK", IDOK, 222, 289, 50, 14
|
||||
PUSHBUTTON "Cancel", IDCANCEL, 280, 289, 50, 14
|
||||
PUSHBUTTON "&Apply", 283, 338, 289, 50, 14
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
constexpr std::array<WORD,2> defaultHistoryKeys{MAKEWORD('E',HOTKEYF_CONTROL),MAKEWORD(VK_F8,HOTKEYF_ALT)};
|
||||
auto commandHistoryKeys=defaultHistoryKeys;
|
||||
constexpr size_t commandHistoryLimit=1000;
|
||||
|
||||
std::wstring commandHistoryLabel(const std::wstring &command)
|
||||
@@ -19,41 +17,6 @@ std::wstring commandHistoryLabel(const std::wstring &command)
|
||||
return fs::path(path).is_absolute()?path:command;
|
||||
}
|
||||
|
||||
bool validHistoryKeys(const std::array<WORD,2> &keys)
|
||||
{
|
||||
if(keys[0]==keys[1]) return false;
|
||||
return std::all_of(keys.begin(),keys.end(),[](WORD binding)
|
||||
{
|
||||
const auto key=LOBYTE(binding), modifiers=HIBYTE(binding);
|
||||
const bool letter=key>='A' && key<='Z';
|
||||
const bool function=key>=VK_F1 && key<=VK_F12;
|
||||
if(!letter && !function) return false;
|
||||
if(modifiers==HOTKEYF_CONTROL)
|
||||
return letter && key!='C' && key!='F' && key!='R' && key!='V' && key!='X' && key!='A' && key!='Z' && key!='Y';
|
||||
if(modifiers==HOTKEYF_ALT) return function && key!=VK_F1 && key!=VK_F2 && key!=VK_F4 && key!=VK_F10;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
std::array<WORD,2> optionHistoryKeys(HWND dialog)
|
||||
{
|
||||
return {static_cast<WORD>(SendDlgItemMessageW(dialog,321,HKM_GETHOTKEY,0,0)),
|
||||
static_cast<WORD>(SendDlgItemMessageW(dialog,323,HKM_GETHOTKEY,0,0))};
|
||||
}
|
||||
|
||||
void setOptionHistoryKeys(HWND dialog,const std::array<WORD,2> &keys)
|
||||
{
|
||||
SendDlgItemMessageW(dialog,321,HKM_SETHOTKEY,keys[0],0);
|
||||
SendDlgItemMessageW(dialog,323,HKM_SETHOTKEY,keys[1],0);
|
||||
}
|
||||
|
||||
void loadCommandHistoryKeys()
|
||||
{
|
||||
const std::array<WORD,2> keys{static_cast<WORD>(preference(L"PreviousCommandKey",defaultHistoryKeys[0])),
|
||||
static_cast<WORD>(preference(L"CommandHistoryKey",defaultHistoryKeys[1]))};
|
||||
commandHistoryKeys=validHistoryKeys(keys)?keys:defaultHistoryKeys;
|
||||
}
|
||||
|
||||
void loadCommandHistory()
|
||||
{
|
||||
|
||||
@@ -107,23 +70,3 @@ void recallPreviousCommand()
|
||||
if(terminalHistoryIndex==terminalHistory.size()) terminalHistoryDraft=terminalInputText();
|
||||
recallCommand(terminalHistoryIndex-1);
|
||||
}
|
||||
|
||||
void showCommandHistory(HWND owner);
|
||||
|
||||
bool handleCommandHistoryKey(HWND window,const MSG &message)
|
||||
{
|
||||
if(message.message!=WM_KEYDOWN && message.message!=WM_SYSKEYDOWN) return false;
|
||||
if((GetKeyState(VK_LWIN)&0x8000) || (GetKeyState(VK_RWIN)&0x8000)) return false;
|
||||
const BYTE modifiers=((GetKeyState(VK_CONTROL)&0x8000)?HOTKEYF_CONTROL:0) |
|
||||
((GetKeyState(VK_MENU)&0x8000)?HOTKEYF_ALT:0) | ((GetKeyState(VK_SHIFT)&0x8000)?HOTKEYF_SHIFT:0);
|
||||
const auto binding=MAKEWORD(message.wParam,modifiers);
|
||||
if(binding==commandHistoryKeys[0] && (message.hwnd==terminalInput ||
|
||||
message.hwnd==panels[0].list || message.hwnd==panels[1].list))
|
||||
{
|
||||
recallPreviousCommand();
|
||||
return true;
|
||||
}
|
||||
if(binding!=commandHistoryKeys[1]) return false;
|
||||
if(!(message.lParam&(1LL<<30))) showCommandHistory(window);
|
||||
return true;
|
||||
}
|
||||
@@ -4,31 +4,8 @@ enum ComparisonColor { CompareBackground, CompareText, CompareInsert, CompareDel
|
||||
constexpr const wchar_t *comparisonColorNames[]{L"Background",L"Text",L"Insertion",L"Deletion",L"Replacement",
|
||||
L"Changed fragment",L"Alignment padding",L"Divider",L"Text on changed lines"};
|
||||
constexpr wchar_t comparisonAppearanceKey[]=L"ComparisonAppearance";
|
||||
constexpr wchar_t comparisonShortcutKey[]=L"ComparisonShortcut";
|
||||
constexpr WORD defaultComparisonShortcut=MAKEWORD(VK_F11,HOTKEYF_SHIFT);
|
||||
WORD comparisonShortcut=defaultComparisonShortcut;
|
||||
constexpr int comparisonSplitScale=10000;
|
||||
|
||||
bool validComparisonShortcut(WORD shortcut)
|
||||
{
|
||||
const auto key=LOBYTE(shortcut),modifiers=HIBYTE(shortcut);
|
||||
return key>=VK_F1 && key<=VK_F12 &&
|
||||
(modifiers==(HOTKEYF_CONTROL|HOTKEYF_SHIFT) ||
|
||||
(modifiers==HOTKEYF_SHIFT && key!=VK_F4 && key!=VK_F8));
|
||||
}
|
||||
|
||||
void loadComparisonShortcut()
|
||||
{
|
||||
const auto shortcut=static_cast<WORD>(preference(comparisonShortcutKey,defaultComparisonShortcut));
|
||||
comparisonShortcut=validComparisonShortcut(shortcut)?shortcut:defaultComparisonShortcut;
|
||||
}
|
||||
|
||||
std::wstring comparisonShortcutLabel()
|
||||
{
|
||||
return std::wstring(HIBYTE(comparisonShortcut)&HOTKEYF_CONTROL?L"Ctrl+Shift+F":L"Shift+F")+
|
||||
std::to_wstring(LOBYTE(comparisonShortcut)-VK_F1+1);
|
||||
}
|
||||
|
||||
struct ComparisonAppearance
|
||||
{
|
||||
LOGFONTW font=defaultFilesFont();
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
enum KeyContext : unsigned { panelKeyContext=1, terminalKeyContext=2 };
|
||||
enum class FilesKey
|
||||
{
|
||||
Refresh, View, Edit, Copy, Move, Mkdir, Delete, Exit, Compare, Previous, History,
|
||||
Pack, Find, ExternalView, ExternalEdit, QuickView, FullPath, HexView, Swap, Properties, Next, Count
|
||||
};
|
||||
constexpr size_t keyIndex(FilesKey command) { return static_cast<size_t>(command); }
|
||||
constexpr unsigned bothKeyContexts=panelKeyContext|terminalKeyContext;
|
||||
constexpr WORD chord(BYTE key,BYTE modifiers=0) { return MAKEWORD(key,modifiers); }
|
||||
constexpr BYTE keyCtrl=HOTKEYF_CONTROL,keyShift=HOTKEYF_SHIFT,keyAlt=HOTKEYF_ALT;
|
||||
constexpr struct
|
||||
{
|
||||
const char *id;
|
||||
const wchar_t *label;
|
||||
unsigned contexts;
|
||||
std::array<WORD,2> defaults;
|
||||
} filesKeyCommands[]{
|
||||
{"refresh",L"Refresh panel",bothKeyContexts,{chord('R',keyCtrl),chord(VK_F2)}},
|
||||
{"view",L"View",panelKeyContext,{chord(VK_F3)}},
|
||||
{"edit",L"Edit",panelKeyContext,{chord(VK_F4)}},
|
||||
{"copy",L"Copy",panelKeyContext,{chord(VK_F5)}},
|
||||
{"move",L"Move",panelKeyContext,{chord(VK_F6)}},
|
||||
{"mkdir",L"Make folder",panelKeyContext,{chord(VK_F7)}},
|
||||
{"delete",L"Delete to Recycle Bin",panelKeyContext,{chord(VK_F8)}},
|
||||
{"exit",L"Exit",bothKeyContexts,{chord(VK_F10)}},
|
||||
{"compare",L"Compare files",panelKeyContext,{chord(VK_F11,keyShift)}},
|
||||
{"previous",L"Previous command",bothKeyContexts,{chord('E',keyCtrl)}},
|
||||
{"history",L"Command history",bothKeyContexts,{chord(VK_F8,keyAlt)}},
|
||||
{"pack",L"Pack files",panelKeyContext,{chord(VK_F5,keyAlt)}},
|
||||
{"find",L"Find files",panelKeyContext,{chord(VK_F7,keyAlt)}},
|
||||
{"externalView",L"View externally",panelKeyContext,{chord(VK_F3,keyAlt)}},
|
||||
{"externalEdit",L"Edit externally",panelKeyContext,{chord(VK_F4,keyAlt)}},
|
||||
{"quickView",L"Quick View",panelKeyContext,{chord('Q',keyCtrl)}},
|
||||
{"fullPath",L"Copy full path",panelKeyContext,{chord('C',keyCtrl|keyShift)}},
|
||||
{"hexView",L"View as hex",panelKeyContext,{chord(VK_F3,keyShift)}},
|
||||
{"swap",L"Swap panels",panelKeyContext,{chord('U',keyCtrl)}},
|
||||
{"properties",L"Properties",panelKeyContext,{chord('A',keyCtrl)}},
|
||||
{"next",L"Next command",terminalKeyContext,{chord(VK_DOWN)}},
|
||||
};
|
||||
static_assert(std::size(filesKeyCommands)==keyIndex(FilesKey::Count));
|
||||
constexpr size_t filesKeySchemeLimit=24,filesKeysPerCommand=8;
|
||||
constexpr wchar_t filesKeySchemePreference[]=L"KeySchemesV1";
|
||||
|
||||
struct FilesKeyScheme
|
||||
{
|
||||
std::wstring name;
|
||||
std::array<std::vector<WORD>,keyIndex(FilesKey::Count)> keys;
|
||||
bool operator==(const FilesKeyScheme &) const=default;
|
||||
};
|
||||
|
||||
struct FilesKeySettings
|
||||
{
|
||||
std::vector<FilesKeyScheme> schemes;
|
||||
size_t active{};
|
||||
bool operator==(const FilesKeySettings &) const=default;
|
||||
};
|
||||
|
||||
std::wstring filesKeyLabel(WORD binding)
|
||||
{
|
||||
if(!binding) return {};
|
||||
std::wstring label;
|
||||
if(HIBYTE(binding)&keyCtrl) label+=L"Ctrl+";
|
||||
if(HIBYTE(binding)&keyAlt) label+=L"Alt+";
|
||||
if(HIBYTE(binding)&keyShift) label+=L"Shift+";
|
||||
const auto key=LOBYTE(binding);
|
||||
if(key>=VK_F1 && key<=VK_F24) label+=L"F"+std::to_wstring(key-VK_F1+1);
|
||||
else if(key==VK_DOWN) label+=L"Down";
|
||||
else label+=static_cast<wchar_t>(key);
|
||||
return label;
|
||||
}
|
||||
|
||||
FilesKeyScheme defaultFilesKeyScheme(std::wstring name=L"Default")
|
||||
{
|
||||
FilesKeyScheme scheme{std::move(name),{}};
|
||||
for(size_t command=0;command<scheme.keys.size();++command)
|
||||
for(const auto binding:filesKeyCommands[command].defaults)
|
||||
if(binding) scheme.keys[command].push_back(binding);
|
||||
return scheme;
|
||||
}
|
||||
|
||||
FilesKeySettings filesKeySettings{{defaultFilesKeyScheme()},0};
|
||||
|
||||
bool sameFilesKeySchemeName(std::wstring_view first,std::wstring_view second)
|
||||
{
|
||||
return CompareStringOrdinal(first.data(),static_cast<int>(first.size()),
|
||||
second.data(),static_cast<int>(second.size()),TRUE)==CSTR_EQUAL;
|
||||
}
|
||||
|
||||
bool validFilesKeySchemeName(std::wstring_view name)
|
||||
{
|
||||
return !name.empty() && name.size()<=48 && !iswspace(name.front()) && !iswspace(name.back()) &&
|
||||
std::ranges::none_of(name,[](wchar_t character){return iswcntrl(character);});
|
||||
}
|
||||
|
||||
unsigned reservedFilesKeyContexts(WORD binding)
|
||||
{
|
||||
const auto key=LOBYTE(binding),mods=HIBYTE(binding);
|
||||
if(key>=VK_F1 && key<=VK_F24)
|
||||
{
|
||||
if(mods==keyAlt && key==VK_F4) return terminalKeyContext;
|
||||
if((!mods && key==VK_F9) || (mods==keyAlt && (key==VK_F1 || key==VK_F2 || key==VK_F10)) ||
|
||||
(mods==keyShift && key==VK_F4) || (mods==keyShift && key==VK_F10) ||
|
||||
(mods==keyCtrl && key<=VK_F12))
|
||||
return panelKeyContext;
|
||||
return 0;
|
||||
}
|
||||
if(key==VK_DOWN && !mods) return panelKeyContext;
|
||||
if(key>='A' && key<='Z' && (mods&keyCtrl) && !(mods&keyAlt))
|
||||
{
|
||||
constexpr std::wstring_view editing=L"CFOPVXYZ";
|
||||
if(mods==keyCtrl && editing.find(key)!=editing.npos) return bothKeyContexts;
|
||||
if((mods==keyCtrl && key=='A') || (mods==(keyCtrl|keyShift) && (key=='C' || key=='V')))
|
||||
return terminalKeyContext;
|
||||
return 0;
|
||||
}
|
||||
return bothKeyContexts;
|
||||
}
|
||||
|
||||
std::wstring filesKeyConflict(const FilesKeyScheme &scheme,size_t command,WORD binding)
|
||||
{
|
||||
if(!binding || (HIBYTE(binding)&~(keyCtrl|keyShift|keyAlt)))
|
||||
return L"Use a function key or a letter with Ctrl.";
|
||||
const auto contexts=filesKeyCommands[command].contexts;
|
||||
if(reservedFilesKeyContexts(binding)&contexts)
|
||||
return filesKeyLabel(binding)+L" is reserved or unavailable in this context.";
|
||||
for(size_t i=0;i<scheme.keys.size();++i)
|
||||
if((filesKeyCommands[i].contexts&contexts) && std::ranges::find(scheme.keys[i],binding)!=scheme.keys[i].end())
|
||||
return filesKeyLabel(binding)+L" is already assigned to "+filesKeyCommands[i].label+L".";
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<FilesKeySettings> parseFilesKeySettings(const Json &stored)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(stored.at("version")!=1 || !stored.at("schemes").is_array()) return {};
|
||||
const auto &rows=stored.at("schemes");
|
||||
if(rows.empty() || rows.size()>filesKeySchemeLimit) return {};
|
||||
FilesKeySettings settings;
|
||||
const auto active=stored.at("active").get<std::string>();
|
||||
for(const auto &row:rows)
|
||||
{
|
||||
auto name=ks::wide(row.at("name").get<std::string>());
|
||||
if(!validFilesKeySchemeName(name) ||
|
||||
std::ranges::any_of(settings.schemes,[&](const auto &other)
|
||||
{ return sameFilesKeySchemeName(other.name,name); })) return {};
|
||||
FilesKeyScheme scheme{std::move(name),{}};
|
||||
const auto &commands=row.at("commands");
|
||||
if(!commands.is_object()) return {};
|
||||
for(size_t i=0;i<scheme.keys.size();++i)
|
||||
{
|
||||
const auto found=commands.find(filesKeyCommands[i].id);
|
||||
if(found==commands.end()) continue;
|
||||
if(!found->is_array() || found->size()>filesKeysPerCommand) return {};
|
||||
for(const auto &entry:*found)
|
||||
{
|
||||
if(!entry.is_number_unsigned() || entry>0xffff) return {};
|
||||
const auto binding=entry.get<WORD>();
|
||||
if(!filesKeyConflict(scheme,i,binding).empty()) return {};
|
||||
scheme.keys[i].push_back(binding);
|
||||
}
|
||||
}
|
||||
for(size_t i=0;i<scheme.keys.size();++i)
|
||||
if(!commands.contains(filesKeyCommands[i].id))
|
||||
for(const auto binding:filesKeyCommands[i].defaults)
|
||||
if(binding && filesKeyConflict(scheme,i,binding).empty()) scheme.keys[i].push_back(binding);
|
||||
if(active==ks::utf8(scheme.name)) settings.active=settings.schemes.size();
|
||||
settings.schemes.push_back(std::move(scheme));
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
catch(const std::exception &) { return {}; }
|
||||
}
|
||||
|
||||
Json serializeFilesKeySettings(const FilesKeySettings &settings)
|
||||
{
|
||||
Json schemes=Json::array();
|
||||
for(const auto &scheme:settings.schemes)
|
||||
{
|
||||
Json commands=Json::object();
|
||||
for(size_t i=0;i<scheme.keys.size();++i) commands[filesKeyCommands[i].id]=scheme.keys[i];
|
||||
schemes.push_back({{"name",ks::utf8(scheme.name)},{"commands",std::move(commands)}});
|
||||
}
|
||||
return {{"version",1},{"active",ks::utf8(settings.schemes[settings.active].name)},{"schemes",std::move(schemes)}};
|
||||
}
|
||||
|
||||
void loadFilesKeySettings()
|
||||
{
|
||||
if(const auto json=readFilesJsonPreference(filesKeySchemePreference))
|
||||
if(auto settings=parseFilesKeySettings(*json))
|
||||
{
|
||||
filesKeySettings=std::move(*settings);
|
||||
return;
|
||||
}
|
||||
auto migrated=defaultFilesKeyScheme(L"Previous settings");
|
||||
constexpr struct { FilesKey command; const wchar_t *name; } legacy[]{
|
||||
{FilesKey::Previous,L"PreviousCommandKey"},{FilesKey::History,L"CommandHistoryKey"},
|
||||
{FilesKey::Compare,L"ComparisonShortcut"},
|
||||
};
|
||||
for(const auto &item:legacy)
|
||||
{
|
||||
const auto index=keyIndex(item.command);
|
||||
auto &keys=migrated.keys[index];
|
||||
const auto fallback=filesKeyCommands[index].defaults.front();
|
||||
const auto binding=static_cast<WORD>(preference(item.name,fallback));
|
||||
const auto context=filesKeyCommands[index].contexts;
|
||||
if(binding==fallback || (HIBYTE(binding)&~(keyCtrl|keyShift|keyAlt)) ||
|
||||
(reservedFilesKeyContexts(binding)&context)) continue;
|
||||
for(size_t i=0;i<migrated.keys.size();++i)
|
||||
if(filesKeyCommands[i].contexts&context) std::erase(migrated.keys[i],binding);
|
||||
keys={binding};
|
||||
}
|
||||
filesKeySettings={{defaultFilesKeyScheme()},0};
|
||||
if(migrated.keys!=filesKeySettings.schemes.front().keys)
|
||||
{
|
||||
filesKeySettings.schemes.push_back(std::move(migrated));
|
||||
filesKeySettings.active=1;
|
||||
}
|
||||
}
|
||||
|
||||
WORD currentFilesChord(WPARAM key)
|
||||
{
|
||||
if(key>0xff || ((GetKeyState(VK_LWIN)|GetKeyState(VK_RWIN))&0x8000)) return 0;
|
||||
return chord(static_cast<BYTE>(key),((GetKeyState(VK_CONTROL)&0x8000)?keyCtrl:0) |
|
||||
((GetKeyState(VK_SHIFT)&0x8000)?keyShift:0) | ((GetKeyState(VK_MENU)&0x8000)?keyAlt:0));
|
||||
}
|
||||
|
||||
std::optional<FilesKey> boundFilesCommand(WORD binding,unsigned context)
|
||||
{
|
||||
const auto &keys=filesKeySettings.schemes[filesKeySettings.active].keys;
|
||||
for(size_t i=0;i<keys.size();++i)
|
||||
if((filesKeyCommands[i].contexts&context) && std::ranges::find(keys[i],binding)!=keys[i].end())
|
||||
return static_cast<FilesKey>(i);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::wstring filesKeyHint(FilesKey command,bool all=false)
|
||||
{
|
||||
std::wstring text;
|
||||
for(const auto binding:filesKeySettings.schemes[filesKeySettings.active].keys[keyIndex(command)])
|
||||
{
|
||||
if(!text.empty()) text+=L", ";
|
||||
text+=filesKeyLabel(binding);
|
||||
if(!all) break;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
std::wstring filesKeyMenuLabel(FilesKey command,std::wstring label={})
|
||||
{
|
||||
if(label.empty()) label=filesKeyCommands[keyIndex(command)].label;
|
||||
const auto keys=filesKeyHint(command,true);
|
||||
if(!keys.empty()) label+=L"\t"+keys;
|
||||
return label;
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
constexpr int keySchemeChoice=610,keySchemeCopy=611,keySchemeReset=612,keySchemeCommand=613,
|
||||
keySchemeContext=614,keySchemeBindings=615,keySchemeCapture=616,keySchemeAdd=617,keySchemeRemove=618,
|
||||
keySchemePrimary=619,keySchemeName=620;
|
||||
|
||||
struct FilesKeySchemeDraft
|
||||
{
|
||||
FilesKeySettings base=filesKeySettings,settings=base;
|
||||
FilesKey initial;
|
||||
FilesKeySettings *pending{};
|
||||
};
|
||||
|
||||
INT_PTR CALLBACK copyKeySchemeDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
{
|
||||
if(message==WM_INITDIALOG)
|
||||
{
|
||||
SetWindowLongPtrW(dialog,DWLP_USER,lp);
|
||||
auto &name=*reinterpret_cast<std::wstring*>(lp);
|
||||
SendDlgItemMessageW(dialog,keySchemeName,EM_SETLIMITTEXT,48,0);
|
||||
SetDlgItemTextW(dialog,keySchemeName,name.c_str());
|
||||
return TRUE;
|
||||
}
|
||||
if(message==WM_CLOSE || (message==WM_COMMAND && LOWORD(wp)==IDCANCEL))
|
||||
{
|
||||
FilesModalDialog::finish(dialog,IDCANCEL);
|
||||
return TRUE;
|
||||
}
|
||||
if(message!=WM_COMMAND || LOWORD(wp)!=IDOK) return FALSE;
|
||||
auto &name=*reinterpret_cast<std::wstring*>(GetWindowLongPtrW(dialog,DWLP_USER));
|
||||
wchar_t entry[49]{};
|
||||
GetDlgItemTextW(dialog,keySchemeName,entry,std::size(entry));
|
||||
name=entry;
|
||||
FilesModalDialog::finish(dialog,IDOK);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void refreshFilesKeyBindings(HWND dialog,const FilesKeyScheme &scheme,size_t command,size_t selection=0)
|
||||
{
|
||||
const auto &descriptor=filesKeyCommands[command];
|
||||
SetDlgItemTextW(dialog,keySchemeContext,
|
||||
descriptor.contexts==bothKeyContexts?L"Keys · panels and command output":
|
||||
descriptor.contexts==terminalKeyContext?L"Keys · command output":L"Keys · file panels");
|
||||
const auto list=GetDlgItem(dialog,keySchemeBindings);
|
||||
SendMessageW(list,LB_RESETCONTENT,0,0);
|
||||
const auto &keys=scheme.keys[command];
|
||||
for(size_t i=0;i<keys.size();++i)
|
||||
{
|
||||
auto label=filesKeyLabel(keys[i]);
|
||||
if(!i) label+=L" (primary)";
|
||||
SendMessageW(list,LB_ADDSTRING,0,reinterpret_cast<LPARAM>(label.c_str()));
|
||||
}
|
||||
if(!keys.empty()) SendMessageW(list,LB_SETCURSEL,std::min(selection,keys.size()-1),0);
|
||||
EnableWindow(GetDlgItem(dialog,keySchemeRemove),!keys.empty());
|
||||
EnableWindow(GetDlgItem(dialog,keySchemePrimary),keys.size()>1 && selection>0 && selection<keys.size());
|
||||
EnableWindow(GetDlgItem(dialog,keySchemeAdd),keys.size()<filesKeysPerCommand);
|
||||
}
|
||||
|
||||
void refreshFilesKeySchemes(HWND dialog,const FilesKeySettings &settings)
|
||||
{
|
||||
const auto choice=GetDlgItem(dialog,keySchemeChoice);
|
||||
SendMessageW(choice,CB_RESETCONTENT,0,0);
|
||||
for(const auto &scheme:settings.schemes)
|
||||
SendMessageW(choice,CB_ADDSTRING,0,reinterpret_cast<LPARAM>(scheme.name.c_str()));
|
||||
SendMessageW(choice,CB_SETCURSEL,settings.active,0);
|
||||
EnableWindow(GetDlgItem(dialog,keySchemeCopy),settings.schemes.size()<filesKeySchemeLimit);
|
||||
}
|
||||
|
||||
std::wstring filesKeyBarLabel(FilesKey command,const wchar_t *action)
|
||||
{
|
||||
return filesKeyHint(command)+L" "+action;
|
||||
}
|
||||
|
||||
void refreshFilesKeyBar()
|
||||
{
|
||||
for(size_t i=0;i<std::size(keyBar);++i)
|
||||
{
|
||||
SetWindowTextW(commands[i],filesKeyBarLabel(keyBar[i].command,keyBar[i].label).c_str());
|
||||
InvalidateRect(commands[i],nullptr,FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
INT_PTR CALLBACK filesKeySchemesDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
{
|
||||
if(message==WM_INITDIALOG)
|
||||
{
|
||||
auto &draft=*reinterpret_cast<FilesKeySchemeDraft*>(lp);
|
||||
SetWindowLongPtrW(dialog,DWLP_USER,lp);
|
||||
refreshFilesKeySchemes(dialog,draft.settings);
|
||||
for(const auto &item:filesKeyCommands)
|
||||
SendDlgItemMessageW(dialog,keySchemeCommand,LB_ADDSTRING,0,reinterpret_cast<LPARAM>(item.label));
|
||||
const auto index=keyIndex(draft.initial);
|
||||
SendDlgItemMessageW(dialog,keySchemeCommand,LB_SETCURSEL,index,0);
|
||||
refreshFilesKeyBindings(dialog,draft.settings.schemes[draft.settings.active],index);
|
||||
return TRUE;
|
||||
}
|
||||
if(message==WM_CLOSE || (message==WM_COMMAND && LOWORD(wp)==IDCANCEL))
|
||||
{
|
||||
FilesModalDialog::finish(dialog,IDCANCEL);
|
||||
return TRUE;
|
||||
}
|
||||
if(message!=WM_COMMAND) return FALSE;
|
||||
auto &draft=*reinterpret_cast<FilesKeySchemeDraft*>(GetWindowLongPtrW(dialog,DWLP_USER));
|
||||
auto &settings=draft.settings;
|
||||
auto &scheme=settings.schemes[settings.active];
|
||||
const auto row=SendDlgItemMessageW(dialog,keySchemeCommand,LB_GETCURSEL,0,0);
|
||||
if(row==LB_ERR) return FALSE;
|
||||
const auto command=static_cast<size_t>(row);
|
||||
const auto position=static_cast<size_t>(SendDlgItemMessageW(dialog,keySchemeBindings,LB_GETCURSEL,0,0));
|
||||
auto &keys=scheme.keys[command];
|
||||
switch(LOWORD(wp))
|
||||
{
|
||||
case keySchemeChoice:
|
||||
if(HIWORD(wp)==CBN_SELCHANGE)
|
||||
{
|
||||
const auto chosen=SendDlgItemMessageW(dialog,keySchemeChoice,CB_GETCURSEL,0,0);
|
||||
if(chosen!=CB_ERR) settings.active=static_cast<size_t>(chosen);
|
||||
refreshFilesKeyBindings(dialog,settings.schemes[settings.active],command);
|
||||
}
|
||||
return TRUE;
|
||||
case keySchemeCommand:
|
||||
if(HIWORD(wp)==LBN_SELCHANGE) refreshFilesKeyBindings(dialog,scheme,command);
|
||||
return TRUE;
|
||||
case keySchemeBindings:
|
||||
if(HIWORD(wp)==LBN_SELCHANGE)
|
||||
EnableWindow(GetDlgItem(dialog,keySchemePrimary),position>0 && position<keys.size());
|
||||
return TRUE;
|
||||
case keySchemeCopy:
|
||||
{
|
||||
if(settings.schemes.size()>=filesKeySchemeLimit) return TRUE;
|
||||
std::wstring name=scheme.name.substr(0,43)+L" copy";
|
||||
FilesModalDialog copyName(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(616),dialog,
|
||||
copyKeySchemeDialog,reinterpret_cast<LPARAM>(&name),false);
|
||||
if(copyName.runModal()!=IDOK) return TRUE;
|
||||
if(!validFilesKeySchemeName(name) || std::ranges::any_of(settings.schemes,[&](const auto &other)
|
||||
{ return sameFilesKeySchemeName(other.name,name); }))
|
||||
{
|
||||
showFilesNotice(dialog,L"Enter a unique name with no leading or trailing spaces.",L"Keyboard shortcuts");
|
||||
return TRUE;
|
||||
}
|
||||
auto copy=scheme;
|
||||
copy.name=std::move(name);
|
||||
settings.schemes.push_back(std::move(copy));
|
||||
settings.active=settings.schemes.size()-1;
|
||||
refreshFilesKeySchemes(dialog,settings);
|
||||
refreshFilesKeyBindings(dialog,settings.schemes.back(),command);
|
||||
return TRUE;
|
||||
}
|
||||
case keySchemeReset:
|
||||
{
|
||||
FilesNoticeOptions notice;
|
||||
notice.confirm=true;
|
||||
notice.accept=L"&Reset";
|
||||
const auto prompt=L"Reset all keys in “"+scheme.name+L"” to defaults?";
|
||||
if(showFilesNotice(dialog,prompt.c_str(),L"Keyboard shortcuts",notice)!=IDYES) return TRUE;
|
||||
scheme=defaultFilesKeyScheme(scheme.name);
|
||||
refreshFilesKeyBindings(dialog,scheme,command);
|
||||
return TRUE;
|
||||
}
|
||||
case keySchemeAdd:
|
||||
{
|
||||
if(keys.size()>=filesKeysPerCommand) return TRUE;
|
||||
const auto binding=static_cast<WORD>(SendDlgItemMessageW(dialog,keySchemeCapture,HKM_GETHOTKEY,0,0));
|
||||
if(const auto conflict=filesKeyConflict(scheme,command,binding);!conflict.empty())
|
||||
{
|
||||
showFilesNotice(dialog,conflict.c_str(),L"Keyboard shortcuts");
|
||||
SetFocus(GetDlgItem(dialog,keySchemeCapture));
|
||||
return TRUE;
|
||||
}
|
||||
keys.push_back(binding);
|
||||
SendDlgItemMessageW(dialog,keySchemeCapture,HKM_SETHOTKEY,0,0);
|
||||
refreshFilesKeyBindings(dialog,scheme,command,keys.size()-1);
|
||||
return TRUE;
|
||||
}
|
||||
case keySchemeRemove:
|
||||
if(position<keys.size())
|
||||
{
|
||||
keys.erase(keys.begin()+position);
|
||||
refreshFilesKeyBindings(dialog,scheme,command,position<keys.size()?position:0);
|
||||
}
|
||||
return TRUE;
|
||||
case keySchemePrimary:
|
||||
if(position>0 && position<keys.size())
|
||||
{
|
||||
std::rotate(keys.begin(),keys.begin()+position,keys.begin()+position+1);
|
||||
refreshFilesKeyBindings(dialog,scheme,command);
|
||||
}
|
||||
return TRUE;
|
||||
case IDOK:
|
||||
if(draft.pending) *draft.pending=settings;
|
||||
else if(settings!=draft.base)
|
||||
{
|
||||
const OptionsWriteLock writeLock;
|
||||
if(!writeLock.acquired())
|
||||
{
|
||||
showFilesNotice(dialog,L"Another window is saving Files settings. Try again.",L"Keyboard shortcuts");
|
||||
return TRUE;
|
||||
}
|
||||
loadFilesKeySettings();
|
||||
if(filesKeySettings!=draft.base && filesKeySettings!=settings)
|
||||
{
|
||||
showFilesNotice(dialog,L"Keyboard schemes were changed in another window. Reopen this dialog.",
|
||||
L"Keyboard shortcuts");
|
||||
return TRUE;
|
||||
}
|
||||
if(!writeFilesJsonPreference(filesKeySchemePreference,serializeFilesKeySettings(settings)))
|
||||
{
|
||||
showFilesNotice(dialog,L"Could not save the keyboard schemes.",L"Keyboard shortcuts");
|
||||
return TRUE;
|
||||
}
|
||||
filesKeySettings=settings;
|
||||
refreshFilesKeyBar();
|
||||
showFileDetails(panels[active]);
|
||||
notifyFilesPreferences(GetAncestor(dialog,GA_ROOTOWNER));
|
||||
}
|
||||
FilesModalDialog::finish(dialog,IDOK);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void editFilesKeySchemes(HWND owner,FilesKey initial,FilesKeySettings *pending)
|
||||
{
|
||||
if(!pending) loadFilesKeySettings();
|
||||
const auto &base=pending?*pending:filesKeySettings;
|
||||
FilesKeySchemeDraft draft{base,base,initial,pending};
|
||||
FilesModalDialog dialog(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(615),owner,
|
||||
filesKeySchemesDialog,reinterpret_cast<LPARAM>(&draft),false);
|
||||
dialog.runModal();
|
||||
}
|
||||
+123
-136
@@ -805,10 +805,12 @@ size_t terminalHistoryIndex{};
|
||||
std::wstring terminalHistoryDraft;
|
||||
constexpr UINT_PTR transferHighlightTimer=1;
|
||||
unsigned transferHighlightPhase{};
|
||||
constexpr struct KeyBarCommand { int id; WPARAM key; const wchar_t *label; } keyBar[]{
|
||||
{110,VK_F2,L"Ctrl+R Refresh"}, {111,VK_F3,L"F3 View"}, {112,VK_F4,L"F4 Edit"},
|
||||
{113,VK_F5,L"F5 Copy"}, {114,VK_F6,L"F6 Move"}, {115,VK_F7,L"F7 Mkdir"},
|
||||
{117,VK_F8,L"F8 Delete"}, {116,VK_F10,L"F10 Exit"}
|
||||
DWORD preference(const wchar_t *name,DWORD fallback);
|
||||
#include "files_key_schemes.inl"
|
||||
constexpr struct KeyBarCommand { int id; FilesKey command; const wchar_t *label; } keyBar[]{
|
||||
{110,FilesKey::Refresh,L"Refresh"}, {111,FilesKey::View,L"View"}, {112,FilesKey::Edit,L"Edit"},
|
||||
{113,FilesKey::Copy,L"Copy"}, {114,FilesKey::Move,L"Move"}, {115,FilesKey::Mkdir,L"Mkdir"},
|
||||
{117,FilesKey::Delete,L"Delete"}, {116,FilesKey::Exit,L"Exit"}
|
||||
};
|
||||
HWND status{}, commands[std::size(keyBar)]{};
|
||||
int active{}, split{};
|
||||
@@ -2724,10 +2726,9 @@ LRESULT CALLBACK terminalInputKeys(HWND input,UINT message,WPARAM wp,LPARAM lp,U
|
||||
SendMessageW(panels[active].list,WM_KEYDOWN,wp,lp);
|
||||
return 0;
|
||||
}
|
||||
if(message==WM_KEYDOWN && (wp==VK_UP || wp==VK_DOWN))
|
||||
if(message==WM_KEYDOWN && wp==VK_UP)
|
||||
{
|
||||
if(wp==VK_UP) recallPreviousCommand();
|
||||
if(wp==VK_DOWN && terminalHistoryIndex<terminalHistory.size()) recallCommand(terminalHistoryIndex+1);
|
||||
recallPreviousCommand();
|
||||
return 0;
|
||||
}
|
||||
return DefSubclassProc(input,message,wp,lp);
|
||||
@@ -2827,9 +2828,11 @@ void showFileDetails(const Panel &panel)
|
||||
if(&panel==&panels[active])
|
||||
for(const auto key:commands) InvalidateRect(key,nullptr,FALSE);
|
||||
if(&panel==&panels[active] && showDirectoryScanProgress(panels[active])) return;
|
||||
const auto refreshKey=filesKeyHint(FilesKey::Refresh);
|
||||
if(panel.remoteRetry)
|
||||
{
|
||||
setStatus(L"Ctrl+R to retry · "+panel.remoteRetry->failure,true);
|
||||
setStatus((refreshKey.empty()?L"Refresh to retry":refreshKey+L" to retry")+
|
||||
L" · "+panel.remoteRetry->failure,true);
|
||||
return;
|
||||
}
|
||||
if(panel.findOrigin)
|
||||
@@ -2838,7 +2841,7 @@ void showFileDetails(const Panel &panel)
|
||||
const auto count=std::to_wstring(panel.rows.size());
|
||||
if(error==ERROR_CONNECTION_ABORTED)
|
||||
setStatus(count+(panel.rows.size()==1?L" match":L" matches")+
|
||||
L" · Connection interrupted · Ctrl+R Retry · Esc Back");
|
||||
L" · Connection interrupted · "+(refreshKey.empty()?L"Refresh to retry":refreshKey+L" Retry")+L" · Esc Back");
|
||||
else setStatus(count+(error==ERROR_CANCELLED?L" matches (stopped)":
|
||||
error?L" matches (some folders could not be read)":L" matches")+
|
||||
L" · Enter: Go · Esc: Back");
|
||||
@@ -2847,7 +2850,8 @@ void showFileDetails(const Panel &panel)
|
||||
if(transferProfileList(panel))
|
||||
{
|
||||
setStatus(transferProfiles(panel.ftp->protocol).rows.empty()?L"Shift+F4 New connection":
|
||||
L"Shift+F4 New F4 Edit Enter Connect");
|
||||
L"Shift+F4 New "+(filesKeyHint(FilesKey::Edit).empty()?L"":filesKeyHint(FilesKey::Edit)+L" Edit ")+
|
||||
L"Enter Connect");
|
||||
return;
|
||||
}
|
||||
auto row=SendMessageW(panel.list,LB_GETCURSEL,0,0);
|
||||
@@ -3891,6 +3895,8 @@ void showProcesses(HWND owner,std::vector<fs::path> paths={});
|
||||
bool gitChangesAvailable(const Panel &panel);
|
||||
void openGitChanges(HWND owner,const Panel &panel);
|
||||
void showEnvironmentPanel(HWND owner);
|
||||
void editFilesKeySchemes(HWND owner,FilesKey initial,FilesKeySettings *pending=nullptr);
|
||||
void showCommandHistory(HWND owner);
|
||||
|
||||
bool selectablePickerRow(LRESULT row)
|
||||
{
|
||||
@@ -3942,6 +3948,8 @@ void selectDrive()
|
||||
else if(menuIndex==2 && row==16) openGitChanges(owner,panels[active]);
|
||||
else if(menuIndex==2 && row==17) showEnvironmentPanel(owner);
|
||||
else if(menuIndex==2 && row==18) swapPanels(owner);
|
||||
else if(menuIndex==2 && row==19) showCommandHistory(owner);
|
||||
else if(menuIndex==2 && row==20) editFilesKeySchemes(owner,FilesKey::Refresh);
|
||||
else if(menuIndex==1 && row==4) createArchive(owner,panels[active]);
|
||||
else if(menuIndex==1 && row==5) showPanelItemProperties(owner,panels[active]);
|
||||
else if(menuIndex==1 && row==6) showPanelLockProcesses(owner,panels[active]);
|
||||
@@ -4578,17 +4586,6 @@ void toggleQuickView(HWND owner)
|
||||
layout(owner);
|
||||
}
|
||||
|
||||
bool handleQuickViewKey(HWND window,const MSG &message)
|
||||
{
|
||||
if(message.message!=WM_KEYDOWN || message.wParam!='Q' || terminalVisible ||
|
||||
!commandLineAvailable(window) ||
|
||||
!(GetKeyState(VK_CONTROL)&0x8000) ||
|
||||
((GetKeyState(VK_MENU)|GetKeyState(VK_SHIFT)|GetKeyState(VK_LWIN)|GetKeyState(VK_RWIN))&0x8000))
|
||||
return false;
|
||||
if(!(message.lParam&(1LL<<30))) toggleQuickView(window);
|
||||
return true;
|
||||
}
|
||||
|
||||
ks::files::RemoteTextSource transferTextSource(const TransferProfile &profile);
|
||||
|
||||
void openPanelImage(const Panel &panel,const fs::path &path,const ks::files::RemoteTextSource *source=nullptr)
|
||||
@@ -7919,6 +7916,72 @@ void editTransferProfile(Panel &panel,bool create);
|
||||
#include "files_properties.inl"
|
||||
#include "files_context_menu.inl"
|
||||
|
||||
void runFilesKeyCommand(HWND owner,int side,FilesKey command)
|
||||
{
|
||||
auto &panel=panels[side];
|
||||
switch(command)
|
||||
{
|
||||
case FilesKey::Refresh: refreshPanel(panel); break;
|
||||
case FilesKey::View:
|
||||
case FilesKey::Edit:
|
||||
{
|
||||
const bool edit=command==FilesKey::Edit;
|
||||
if(transferProfileList(panel))
|
||||
{
|
||||
if(edit) editTransferProfile(panel,false);
|
||||
break;
|
||||
}
|
||||
const auto row=currentPanelRow(panel);
|
||||
if(edit || row==LB_ERR || !calculateFolderSizes(panel,row)) openSelectedText(panel,edit,false);
|
||||
break;
|
||||
}
|
||||
case FilesKey::Copy:
|
||||
case FilesKey::Move: copySelection(owner,panel,panels[1-side],command==FilesKey::Move); break;
|
||||
case FilesKey::Mkdir: makeFolder(owner,panel); break;
|
||||
case FilesKey::Delete: deleteSelection(owner,panel,false); break;
|
||||
case FilesKey::Exit: SendMessageW(owner,WM_CLOSE,0,0); break;
|
||||
case FilesKey::Compare: compareSelectedFiles(owner); break;
|
||||
case FilesKey::Previous: recallPreviousCommand(); break;
|
||||
case FilesKey::Next:
|
||||
if(terminalHistoryIndex<terminalHistory.size()) recallCommand(terminalHistoryIndex+1);
|
||||
break;
|
||||
case FilesKey::History: showCommandHistory(owner); break;
|
||||
case FilesKey::Pack: createArchive(owner,panel); break;
|
||||
case FilesKey::Find: findPanelFiles(owner,panel); break;
|
||||
case FilesKey::ExternalView:
|
||||
case FilesKey::ExternalEdit: openSelectedText(panel,command==FilesKey::ExternalEdit,true); break;
|
||||
case FilesKey::QuickView: toggleQuickView(owner); break;
|
||||
case FilesKey::FullPath: copyFullPanelPath(owner,panel); break;
|
||||
case FilesKey::HexView: openSelectedText(panel,false,false,true); break;
|
||||
case FilesKey::Swap: swapPanels(owner); break;
|
||||
case FilesKey::Properties: showPanelItemProperties(owner,panel); break;
|
||||
case FilesKey::Count: break;
|
||||
}
|
||||
}
|
||||
|
||||
bool handleFilesKeyChord(HWND owner,const MSG &message)
|
||||
{
|
||||
if(message.message!=WM_KEYDOWN && message.message!=WM_SYSKEYDOWN) return false;
|
||||
if(copyInProgress || FilesModalDialog::activeFor(owner) ||
|
||||
(message.hwnd!=owner && message.hwnd!=terminalInput && message.hwnd!=panels[0].list &&
|
||||
message.hwnd!=panels[1].list && !IsChild(owner,message.hwnd))) return false;
|
||||
const bool input=message.hwnd==terminalInput || message.hwnd==panels[0].list || message.hwnd==panels[1].list;
|
||||
const auto binding=currentFilesChord(message.wParam);
|
||||
if(!binding) return false;
|
||||
const auto command=boundFilesCommand(binding,terminalVisible?terminalKeyContext:panelKeyContext);
|
||||
if(!command || (!input && *command!=FilesKey::History && *command!=FilesKey::Exit)) return false;
|
||||
if(!commandLineAvailable(owner) && *command!=FilesKey::History && *command!=FilesKey::Exit) return false;
|
||||
if(*command==FilesKey::Properties && (!panelItemPropertiesAvailable(panels[active]) ||
|
||||
(message.hwnd==terminalInput && GetWindowTextLengthW(terminalInput)))) return false;
|
||||
if(!(message.lParam&(1LL<<30)) || *command==FilesKey::Previous || *command==FilesKey::Next)
|
||||
{
|
||||
hidePicker();
|
||||
showMenu(false);
|
||||
runFilesKeyCommand(owner,message.hwnd==panels[1].list?1:message.hwnd==panels[0].list?0:active,*command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR)
|
||||
{
|
||||
const auto index=GetDlgCtrlID(window)-102;
|
||||
@@ -8077,7 +8140,7 @@ LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT
|
||||
SetFocus(terminalInput);
|
||||
return SendMessageW(terminalInput,message,wp,lp);
|
||||
}
|
||||
if (message == WM_KEYDOWN)
|
||||
if (message == WM_KEYDOWN || message==WM_SYSKEYDOWN)
|
||||
{
|
||||
if(wp==VK_TAB)
|
||||
{
|
||||
@@ -8090,38 +8153,14 @@ LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT
|
||||
return 0;
|
||||
}
|
||||
if (wp == VK_RETURN) { enter(panels[index]); return 0; }
|
||||
if (wp == VK_F2)
|
||||
if(const auto command=boundFilesCommand(currentFilesChord(wp),panelKeyContext))
|
||||
{
|
||||
refreshPanel(panels[index]);
|
||||
runFilesKeyCommand(GetParent(window),static_cast<int>(index),*command);
|
||||
return 0;
|
||||
}
|
||||
if (wp == VK_F10) { SendMessageW(GetParent(window), WM_CLOSE, 0, 0); return 0; }
|
||||
if (wp == VK_F3 || wp == VK_F4)
|
||||
if(wp==VK_DELETE && (GetKeyState(VK_SHIFT)&0x8000))
|
||||
{
|
||||
auto &panel=panels[index];
|
||||
if(transferProfileList(panel))
|
||||
{
|
||||
if(wp==VK_F4) editTransferProfile(panel,false);
|
||||
return 0;
|
||||
}
|
||||
const auto row=currentPanelRow(panel);
|
||||
if(wp==VK_F3 && row!=LB_ERR && calculateFolderSizes(panel,row)) return 0;
|
||||
openSelectedText(panel,wp==VK_F4,false);
|
||||
return 0;
|
||||
}
|
||||
if (wp == VK_F5 || wp == VK_F6)
|
||||
{
|
||||
copySelection(GetParent(window),panels[index],panels[1-index],wp==VK_F6);
|
||||
return 0;
|
||||
}
|
||||
if(wp==VK_F7)
|
||||
{
|
||||
makeFolder(GetParent(window),panels[index]);
|
||||
return 0;
|
||||
}
|
||||
if(wp==VK_F8 || (wp==VK_DELETE && (GetKeyState(VK_SHIFT)&0x8000)))
|
||||
{
|
||||
deleteSelection(GetParent(window),panels[index],wp==VK_DELETE);
|
||||
deleteSelection(GetParent(window),panels[index],true);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -8180,12 +8219,25 @@ bool loadFilesPreferences(HWND window)
|
||||
compactLayout=preference(compactLayoutKey,0)!=0;
|
||||
restoreDocuments=preference(restoreDocumentsKey,0)!=0;
|
||||
statusFields=preference(L"StatusFields",defaultStatusFields)&15;
|
||||
loadCommandHistoryKeys();
|
||||
loadComparisonShortcut();
|
||||
loadFilesKeySettings();
|
||||
return true;
|
||||
}
|
||||
|
||||
#include "files_find.inl"
|
||||
struct OptionsWriteLock
|
||||
{
|
||||
HANDLE mutex=CreateMutexW(nullptr,FALSE,L"Local\\KSwitcher.Files.OptionsWrite");
|
||||
DWORD result=mutex?WaitForSingleObject(mutex,2000):WAIT_FAILED;
|
||||
|
||||
bool acquired() const { return result==WAIT_OBJECT_0 || result==WAIT_ABANDONED; }
|
||||
~OptionsWriteLock()
|
||||
{
|
||||
if(acquired()) ReleaseMutex(mutex);
|
||||
if(mutex) CloseHandle(mutex);
|
||||
}
|
||||
};
|
||||
|
||||
#include "files_key_schemes_dialog.inl"
|
||||
#include "files_options.inl"
|
||||
#include "files_panel_columns_dialog.inl"
|
||||
#include "files_space_analyzer.inl"
|
||||
@@ -8235,16 +8287,18 @@ void openMenu(HWND window, int index)
|
||||
if(detailedPanel(panel)) rows.push_back(L" Columns…");
|
||||
}
|
||||
}
|
||||
else if(index==1) rows={L"Copy\tF5",L"Move\tF6",L"Make folder\tF7",L"Exit\tF10",L"Pack files…\tAlt+F5",
|
||||
L"Properties…\tCtrl+A",L"Locking processes…"};
|
||||
else if(index==1) rows={filesKeyMenuLabel(FilesKey::Copy),filesKeyMenuLabel(FilesKey::Move),
|
||||
filesKeyMenuLabel(FilesKey::Mkdir),filesKeyMenuLabel(FilesKey::Exit),filesKeyMenuLabel(FilesKey::Pack,L"Pack files…"),
|
||||
filesKeyMenuLabel(FilesKey::Properties,L"Properties…"),L"Locking processes…"};
|
||||
else if(index==2)
|
||||
{
|
||||
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"Find files\tAlt+F7",quickViewWindow?L"Close Quick View\tCtrl+Q":L"Quick View\tCtrl+Q",
|
||||
L"Copy full path\tCtrl+Shift+C",L"Space Analyzer",L"View as hex\tShift+F3",L"Viewer bookmarks…",L"Processes…",
|
||||
L"Git Changes…",L"Environment Variables…",L"Swap panels\tCtrl+U"};
|
||||
rows={filesKeyMenuLabel(FilesKey::Refresh),filesKeyMenuLabel(FilesKey::View),filesKeyMenuLabel(FilesKey::Edit),
|
||||
L"Folder shortcuts",filesKeyMenuLabel(FilesKey::ExternalView),filesKeyMenuLabel(FilesKey::ExternalEdit),
|
||||
L"Hibernate remote PC",L"Update remote KSwitcher",filesKeyMenuLabel(FilesKey::Compare),
|
||||
filesKeyMenuLabel(FilesKey::Find),filesKeyMenuLabel(FilesKey::QuickView,quickViewWindow?L"Close Quick View":L"Quick View"),
|
||||
filesKeyMenuLabel(FilesKey::FullPath),L"Space Analyzer",filesKeyMenuLabel(FilesKey::HexView),
|
||||
L"Viewer bookmarks…",L"Processes…",L"Git Changes…",L"Environment Variables…",filesKeyMenuLabel(FilesKey::Swap),
|
||||
filesKeyMenuLabel(FilesKey::History),L"Keyboard shortcuts…"};
|
||||
}
|
||||
const auto &panel=panels[active];
|
||||
const bool remoteResults=remoteSearchResults(panel);
|
||||
@@ -8255,7 +8309,7 @@ void openMenu(HWND window, int index)
|
||||
if(remoteSearchActionAvailable(113)) commandActions.push_back(0);
|
||||
if(remoteSearchActionAvailable(114))
|
||||
{
|
||||
if(panel.ftp) rows[1]=L"Rename\tF6";
|
||||
if(panel.ftp) rows[1]=filesKeyMenuLabel(FilesKey::Move,L"Rename");
|
||||
commandActions.push_back(1);
|
||||
}
|
||||
commandActions.push_back(3);
|
||||
@@ -8291,6 +8345,7 @@ void openMenu(HWND window, int index)
|
||||
}
|
||||
if(quickViewWindow || (!panels[active].peer && !panels[active].ftp)) commandActions.push_back(10);
|
||||
if(panels[active].peer) commandActions.insert(commandActions.end(),{-1,6,7});
|
||||
commandActions.insert(commandActions.end(),{-1,19,20});
|
||||
}
|
||||
else
|
||||
for(size_t i=0;i<rows.size();++i) commandActions.push_back(static_cast<int>(i));
|
||||
@@ -8510,6 +8565,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
if(reinterpret_cast<HWND>(wp)!=window)
|
||||
{
|
||||
loadFilesPreferences(window);
|
||||
refreshFilesKeyBar();
|
||||
layout(window);
|
||||
layoutOpenCommandHistory();
|
||||
showFileDetails(panels[active]);
|
||||
@@ -8647,7 +8703,8 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
if (!mono || !blue || !teal || !menuBar || !picker || !pickerFrame || !status || !panelSearchPopup) return -1;
|
||||
SendMessageW(status, WM_SETFONT, reinterpret_cast<WPARAM>(mono), FALSE);
|
||||
for (int i = 0; i < static_cast<int>(std::size(commands)); ++i)
|
||||
commands[i] = CreateWindowW(L"BUTTON", keyBar[i].label, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
|
||||
commands[i] = CreateWindowW(L"BUTTON", filesKeyBarLabel(keyBar[i].command,keyBar[i].label).c_str(),
|
||||
WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
|
||||
0, 0, 0, 0, window, reinterpret_cast<HMENU>(static_cast<INT_PTR>(keyBar[i].id)), instance, nullptr);
|
||||
for(int i=0;i<static_cast<int>(driveButtons.size());++i)
|
||||
{
|
||||
@@ -8976,7 +9033,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
if(std::find(std::begin(commands),std::end(commands),item.hwndItem)!=std::end(commands))
|
||||
{
|
||||
if(item.CtlID==114 && remoteSearchResults(panels[active]) && panels[active].ftp)
|
||||
text=L"F6 Rename";
|
||||
text=filesKeyBarLabel(FilesKey::Move,L"Rename");
|
||||
const auto separator=text.find(L' ');
|
||||
auto key=text.substr(0,separator);
|
||||
if(key.starts_with(L'F') && key.size()>1) key.erase(0,1);
|
||||
@@ -9284,7 +9341,7 @@ LRESULT CALLBACK filesWindow(HWND window, UINT message, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
for(const auto &command:keyBar)
|
||||
if(LOWORD(wp)==command.id && remoteSearchActionAvailable(command.id))
|
||||
SendMessageW(panels[active].list,WM_KEYDOWN,command.key,0);
|
||||
runFilesKeyCommand(window,active,command.command);
|
||||
}
|
||||
if (LOWORD(wp) >= 102 && LOWORD(wp) <= 103 && HIWORD(wp) == LBN_DBLCLK)
|
||||
enter(panels[LOWORD(wp) - 102]);
|
||||
@@ -9447,7 +9504,7 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(handleQuickViewKey(window,message) || handlePanelPathKey(window,message)) continue;
|
||||
if(handlePanelPathKey(window,message) || handleFilesKeyChord(window,message)) continue;
|
||||
if((message.message==WM_KEYDOWN || message.message==WM_SYSKEYDOWN) &&
|
||||
!terminalVisible && commandLineAvailable(window) &&
|
||||
(message.hwnd==terminalInput || message.hwnd==panels[0].list || message.hwnd==panels[1].list) &&
|
||||
@@ -9505,34 +9562,6 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(!terminalVisible && !copyInProgress && !commandHistoryWindow && !FilesModalDialog::activeFor(window) &&
|
||||
message.message==WM_SYSKEYDOWN && (message.wParam==VK_F5 || 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);
|
||||
if(message.wParam==VK_F5) createArchive(window,panels[active]);
|
||||
else findPanelFiles(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)) &&
|
||||
!(GetKeyState(VK_CONTROL)&0x8000) && !(GetKeyState(VK_SHIFT)&0x8000) &&
|
||||
(message.hwnd==window || IsChild(window,message.hwnd)))
|
||||
{
|
||||
if(!(message.lParam & (1LL<<30)))
|
||||
{
|
||||
hidePicker();
|
||||
showMenu(false);
|
||||
openSelectedText(panels[active],message.wParam==VK_F4,true);
|
||||
}
|
||||
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)
|
||||
@@ -9586,21 +9615,6 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
|
||||
continue;
|
||||
}
|
||||
const bool filesMessage=message.hwnd==window || IsChild(window,message.hwnd);
|
||||
if(filesMessage && !terminalVisible && !copyInProgress && !commandHistoryWindow &&
|
||||
!FilesModalDialog::activeFor(window) && message.message==WM_KEYDOWN &&
|
||||
!(GetKeyState(VK_MENU)&0x8000) && !(GetKeyState(VK_LWIN)&0x8000) &&
|
||||
!(GetKeyState(VK_RWIN)&0x8000) && (GetKeyState(VK_SHIFT)&0x8000) &&
|
||||
MAKEWORD(message.wParam,HOTKEYF_SHIFT|((GetKeyState(VK_CONTROL)&0x8000)?HOTKEYF_CONTROL:0))==
|
||||
comparisonShortcut)
|
||||
{
|
||||
if(!(message.lParam & (1LL<<30)))
|
||||
{
|
||||
hidePicker();
|
||||
showMenu(false);
|
||||
compareSelectedFiles(window);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(mainInput && !terminalVisible && !copyInProgress &&
|
||||
(message.message==WM_KEYDOWN || (message.message==WM_SYSKEYDOWN && message.wParam==VK_F10)) &&
|
||||
message.wParam>=VK_F1 && message.wParam<=VK_F12 &&
|
||||
@@ -9635,17 +9649,6 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(ctrl && shift && message.wParam=='C' && !terminalVisible && commandLineAvailable(window))
|
||||
{
|
||||
if(!(message.lParam & (1LL<<30))) copyFullPanelPath(window,panels[active]);
|
||||
continue;
|
||||
}
|
||||
if(ctrl && !shift && message.wParam=='A' && !terminalVisible && commandLineAvailable(window) &&
|
||||
(!GetWindowTextLengthW(terminalInput) || panelFocused) && panelItemPropertiesAvailable(panels[active]))
|
||||
{
|
||||
if(!(message.lParam&(1LL<<30))) showPanelItemProperties(window,panels[active]);
|
||||
continue;
|
||||
}
|
||||
if(shift && !ctrl && message.wParam==VK_F4 && !terminalVisible)
|
||||
{
|
||||
if(!(message.lParam & (1LL<<30)) && commandLineAvailable(window))
|
||||
@@ -9656,21 +9659,13 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(shift && !ctrl && message.wParam==VK_F3 && !terminalVisible && commandLineAvailable(window))
|
||||
{
|
||||
if(!(message.lParam&(1LL<<30))) openSelectedText(panels[active],false,false,true);
|
||||
continue;
|
||||
}
|
||||
if(ctrl && !shift &&
|
||||
(message.wParam=='F' || message.wParam=='C' || message.wParam=='R' ||
|
||||
(message.wParam=='U' && !terminalVisible) ||
|
||||
(message.wParam=='F' || message.wParam=='C' ||
|
||||
message.wParam==VK_RETURN || message.wParam==VK_INSERT))
|
||||
{
|
||||
if(!(message.lParam & (1LL<<30)))
|
||||
{
|
||||
if(message.wParam=='F') insertCurrentPanelPath();
|
||||
else if(message.wParam=='R') refreshPanel(panels[active]);
|
||||
else if(message.wParam=='U') swapPanels(window);
|
||||
else if(message.wParam==VK_RETURN) insertCurrentPanelPath(true);
|
||||
else if(message.wParam==VK_INSERT) copyCommandLineOrPanelNames(window);
|
||||
else copyOrInterruptTerminal();
|
||||
@@ -9685,7 +9680,6 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
|
||||
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 &&
|
||||
@@ -9751,13 +9745,6 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (message.message == WM_SYSKEYDOWN && message.wParam == VK_F10 &&
|
||||
!(GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000) &&
|
||||
!(GetKeyState(VK_SHIFT) & 0x8000))
|
||||
{
|
||||
SendMessageW(window, WM_CLOSE, 0, 0);
|
||||
continue;
|
||||
}
|
||||
if (message.message == WM_SYSKEYDOWN && (message.wParam == VK_F1 || message.wParam == VK_F2))
|
||||
{
|
||||
chooseDrive(static_cast<int>(message.wParam - VK_F1));
|
||||
|
||||
+46
-60
@@ -1,12 +1,13 @@
|
||||
constexpr int optionsSearch=270,optionsTree=271,optionsTitle=272,optionsApply=283,optionsReset=284,optionsProperty=285,optionsResetProperty=286,
|
||||
optionsImport=525,optionsExport=526,
|
||||
optionsRemoteTerminal=370,optionsRemoteHibernate=371,optionsRemoteUpdate=372;
|
||||
enum OptionsPage { PanelModes, PanelColors, Appearance, CommandLine, TextViewer, TextEditor, allOptions, CompareFiles };
|
||||
constexpr const wchar_t *optionsTitles[]{L"File panel modes",L"Colors",L"Appearance",L"Command line",
|
||||
L"Viewer",L"Editor",L"All settings",L"File comparison"};
|
||||
constexpr int comparisonFontLabel=408,comparisonChooseFont=409,comparisonColorCombo=411,
|
||||
comparisonChooseColor=412,comparisonColorValue=413,comparisonShortcutControl=415;
|
||||
comparisonChooseColor=412,comparisonColorValue=413,comparisonKeySchemesButton=415;
|
||||
constexpr int comparisonControls[]{comparisonFontLabel,comparisonChooseFont,410,comparisonColorCombo,
|
||||
comparisonChooseColor,comparisonColorValue,414,comparisonShortcutControl};
|
||||
comparisonChooseColor,comparisonColorValue,comparisonKeySchemesButton};
|
||||
constexpr const wchar_t *colorNames[]{L"Panel background",L"Text",L"Frame",L"Popup background",
|
||||
L"Menu selection",L"Command bar",L"File cursor"};
|
||||
enum PanelSection { PanelLayout, WideColumns, StatusColumns };
|
||||
@@ -53,7 +54,7 @@ constexpr struct
|
||||
{innerFramePadding,&DialogFramePadding::inner,maxDialogFramePadding},
|
||||
{rowTextPadding,&DialogFramePadding::rowText,maxDialogRowTextPadding}};
|
||||
|
||||
enum class OptionsAnchor { StretchWidth, StretchHeight, BottomRight };
|
||||
enum class OptionsAnchor { StretchWidth, StretchHeight, BottomRight, BottomLeft };
|
||||
struct OptionsControl
|
||||
{
|
||||
int id;
|
||||
@@ -106,7 +107,6 @@ struct OptionsBaseline
|
||||
DialogFramePadding padding=dialogFramePadding;
|
||||
std::array<COLORREF,ColorCount> palette=colors;
|
||||
std::vector<FileStyle> styles=fileStyles;
|
||||
std::array<WORD,2> keys=commandHistoryKeys;
|
||||
bool remoteTerminal=ks::lan::remoteTerminalAllowed();
|
||||
bool remoteHibernate=ks::lan::remoteHibernateAllowed();
|
||||
bool remoteUpdate=ks::lan::remoteUpdateAllowed();
|
||||
@@ -117,7 +117,7 @@ struct OptionsBaseline
|
||||
std::array<PanelMode,2> modes{panels[0].mode,panels[1].mode};
|
||||
ks::files::TextSettings text=ks::files::loadTextPreferences();
|
||||
ComparisonAppearance comparison=readComparisonAppearance();
|
||||
WORD compareShortcut=comparisonShortcut;
|
||||
FilesKeySettings keySettings=filesKeySettings;
|
||||
};
|
||||
|
||||
struct OptionsDraft
|
||||
@@ -125,6 +125,7 @@ struct OptionsDraft
|
||||
OptionsBaseline baseline;
|
||||
ks::files::TextSettings text=baseline.text;
|
||||
ComparisonAppearance comparison=baseline.comparison;
|
||||
FilesKeySettings keySettings=baseline.keySettings;
|
||||
HWND filesWindow{};
|
||||
LOGFONTW font=displayFont;
|
||||
int points=fontPoints;
|
||||
@@ -140,13 +141,14 @@ struct OptionsDraft
|
||||
HTREEITEM wideColumnsNode{},markdownNode{};
|
||||
RECT initialClient{};
|
||||
UINT initialDpi=96;
|
||||
OptionsControl controls[8]{
|
||||
OptionsControl controls[10]{
|
||||
{optionsTree,OptionsAnchor::StretchHeight},
|
||||
{optionsTitle,OptionsAnchor::StretchWidth},
|
||||
{275,OptionsAnchor::StretchWidth},{277,OptionsAnchor::StretchWidth},
|
||||
{281,OptionsAnchor::StretchWidth},
|
||||
{IDOK,OptionsAnchor::BottomRight},{IDCANCEL,OptionsAnchor::BottomRight},
|
||||
{optionsApply,OptionsAnchor::BottomRight}};
|
||||
{optionsApply,OptionsAnchor::BottomRight},
|
||||
{optionsImport,OptionsAnchor::BottomLeft},{optionsExport,OptionsAnchor::BottomLeft}};
|
||||
|
||||
};
|
||||
|
||||
@@ -164,19 +166,6 @@ bool optionsFontChanged(const OptionsDraft &draft)
|
||||
_wcsicmp(pending.lfFaceName,applied.lfFaceName)!=0;
|
||||
}
|
||||
|
||||
struct OptionsWriteLock
|
||||
{
|
||||
HANDLE mutex=CreateMutexW(nullptr,FALSE,L"Local\\KSwitcher.Files.OptionsWrite");
|
||||
DWORD result=mutex?WaitForSingleObject(mutex,2000):WAIT_FAILED;
|
||||
|
||||
bool acquired() const { return result==WAIT_OBJECT_0 || result==WAIT_ABANDONED; }
|
||||
~OptionsWriteLock()
|
||||
{
|
||||
if(acquired()) ReleaseMutex(mutex);
|
||||
if(mutex) CloseHandle(mutex);
|
||||
}
|
||||
};
|
||||
|
||||
void updateOptionsApply(HWND dialog,const OptionsDraft &draft)
|
||||
{
|
||||
BOOL valid{};
|
||||
@@ -192,11 +181,10 @@ void updateOptionsApply(HWND dialog,const OptionsDraft &draft)
|
||||
checked(compactLayoutControl)!=base.compact || checked(restoreDocumentsControl)!=base.restoreLocal ||
|
||||
fields!=base.fields || draft.palette!=base.palette || draft.styles!=base.styles ||
|
||||
draft.framePadding!=base.padding || optionsFontChanged(draft) ||
|
||||
optionHistoryKeys(dialog)!=base.keys || checked(optionsRemoteTerminal)!=base.remoteTerminal ||
|
||||
checked(optionsRemoteTerminal)!=base.remoteTerminal ||
|
||||
checked(optionsRemoteHibernate)!=base.remoteHibernate ||
|
||||
checked(optionsRemoteUpdate)!=base.remoteUpdate ||
|
||||
draft.text!=base.text || draft.comparison!=base.comparison ||
|
||||
SendDlgItemMessageW(dialog,comparisonShortcutControl,HKM_GETHOTKEY,0,0)!=base.compareShortcut;
|
||||
draft.text!=base.text || draft.comparison!=base.comparison || draft.keySettings!=base.keySettings;
|
||||
EnableWindow(GetDlgItem(dialog,optionsApply),dirty);
|
||||
InvalidateRect(GetDlgItem(dialog,fileStylePreview),nullptr,FALSE);
|
||||
}
|
||||
@@ -254,6 +242,7 @@ void layoutOptions(HWND dialog,const OptionsDraft &draft)
|
||||
case OptionsAnchor::StretchWidth: width+=dx;break;
|
||||
case OptionsAnchor::StretchHeight: height+=dy;break;
|
||||
case OptionsAnchor::BottomRight: x+=dx;y+=dy;break;
|
||||
case OptionsAnchor::BottomLeft: y+=dy;break;
|
||||
}
|
||||
SetWindowPos(GetDlgItem(dialog,control.id),nullptr,x,y,width,height,
|
||||
SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOREDRAW);
|
||||
@@ -506,7 +495,7 @@ void showOptionsPage(HWND dialog,OptionsDraft &draft,int page,int section)
|
||||
for(const auto &option:frameOptions)
|
||||
SendDlgItemMessageW(dialog,option.id,CB_SETCURSEL,draft.framePadding.*option.value,0);
|
||||
}
|
||||
constexpr int commandLineControls[]{320,321,322,323,optionsRemoteTerminal,optionsRemoteHibernate,optionsRemoteUpdate};
|
||||
constexpr int commandLineControls[]{321,optionsRemoteTerminal,optionsRemoteHibernate,optionsRemoteUpdate};
|
||||
show(commandLineControls,page==CommandLine && section==0);
|
||||
show(markdownControls,markdown);
|
||||
show(textControls,textOptionsPage(page) && !markdown);
|
||||
@@ -611,10 +600,10 @@ void filterOptions(HWND dialog,OptionsDraft &draft)
|
||||
matches(L"Underline") || matches(L"Strikethrough") || matches(L"Foreground"));
|
||||
}
|
||||
else if(page==CommandLine) addSection(L"Command history",0,
|
||||
matches(L"Previous command") || matches(L"Allow paired PCs to run PowerShell commands here") ||
|
||||
matches(L"Previous command") || matches(L"Keyboard shortcuts") || matches(L"Allow paired PCs to run PowerShell commands here") ||
|
||||
matches(L"Allow paired PCs to hibernate this PC") || matches(L"Allow paired PCs to update KSwitcher here"));
|
||||
else if(page==CompareFiles)
|
||||
addSection(L"Font and colors",0,matches(L"Compare files shortcut") || std::any_of(std::begin(comparisonColorNames),
|
||||
addSection(L"Font and colors",0,matches(L"Compare files shortcut") || matches(L"Keyboard shortcuts") || std::any_of(std::begin(comparisonColorNames),
|
||||
std::end(comparisonColorNames),matches));
|
||||
else if(textOptionsPage(page))
|
||||
{
|
||||
@@ -642,6 +631,8 @@ void filterOptions(HWND dialog,OptionsDraft &draft)
|
||||
if(!first) SetDlgItemTextW(dialog,optionsTitle,L"No matching settings");
|
||||
}
|
||||
|
||||
#include "files_options_transfer.inl"
|
||||
|
||||
INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
{
|
||||
if(message==WM_INITDIALOG)
|
||||
@@ -672,8 +663,6 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
for(const auto label:comparisonColorNames)
|
||||
SendDlgItemMessageW(dialog,comparisonColorCombo,CB_ADDSTRING,0,reinterpret_cast<LPARAM>(label));
|
||||
SendDlgItemMessageW(dialog,comparisonColorCombo,CB_SETCURSEL,0,0);
|
||||
SendDlgItemMessageW(dialog,comparisonShortcutControl,HKM_SETRULES,HKCOMB_NONE,HOTKEYF_SHIFT);
|
||||
SendDlgItemMessageW(dialog,comparisonShortcutControl,HKM_SETHOTKEY,comparisonShortcut,0);
|
||||
SendDlgItemMessageW(dialog,optionsSearch,EM_SETLIMITTEXT,255,0);
|
||||
for(const auto &option:frameOptions)
|
||||
for(DWORD value=0;value<=option.maximum;++value)
|
||||
@@ -696,7 +685,6 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
CheckDlgButton(dialog,restoreDocumentsControl,restoreDocuments);
|
||||
showPanelModeOptions(dialog);
|
||||
for(int i=0;i<4;++i) CheckDlgButton(dialog,205+i,(statusFields>>i)&1u);
|
||||
setOptionHistoryKeys(dialog,commandHistoryKeys);
|
||||
CheckDlgButton(dialog,optionsRemoteTerminal,ks::lan::remoteTerminalAllowed());
|
||||
CheckDlgButton(dialog,optionsRemoteHibernate,ks::lan::remoteHibernateAllowed());
|
||||
CheckDlgButton(dialog,optionsRemoteUpdate,ks::lan::remoteUpdateAllowed());
|
||||
@@ -862,13 +850,9 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
return TRUE;
|
||||
case optionsReset:
|
||||
if(draft->page==allOptions || draft->page==CompareFiles)
|
||||
{
|
||||
draft->comparison=ComparisonAppearance{};
|
||||
SendDlgItemMessageW(dialog,comparisonShortcutControl,HKM_SETHOTKEY,defaultComparisonShortcut,0);
|
||||
}
|
||||
if(draft->page==allOptions || draft->page==CommandLine)
|
||||
{
|
||||
setOptionHistoryKeys(dialog,defaultHistoryKeys);
|
||||
CheckDlgButton(dialog,optionsRemoteTerminal,BST_UNCHECKED);
|
||||
CheckDlgButton(dialog,optionsRemoteHibernate,BST_UNCHECKED);
|
||||
CheckDlgButton(dialog,optionsRemoteUpdate,BST_UNCHECKED);
|
||||
@@ -920,22 +904,16 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
case optionsRemoteTerminal: case optionsRemoteHibernate: case optionsRemoteUpdate:
|
||||
updateOptionsApply(dialog,*draft);
|
||||
return TRUE;
|
||||
case 321: case 323: case comparisonShortcutControl:
|
||||
case 321: case comparisonKeySchemesButton:
|
||||
editFilesKeySchemes(dialog,LOWORD(wp)==321?FilesKey::Previous:FilesKey::Compare,&draft->keySettings);
|
||||
updateOptionsApply(dialog,*draft);
|
||||
return TRUE;
|
||||
case optionsImport: case optionsExport:
|
||||
transferFilesOptions(dialog,*draft,LOWORD(wp)==optionsImport);
|
||||
return TRUE;
|
||||
case optionsApply:
|
||||
case IDOK:
|
||||
{
|
||||
const auto compareShortcut=static_cast<WORD>(
|
||||
SendDlgItemMessageW(dialog,comparisonShortcutControl,HKM_GETHOTKEY,0,0));
|
||||
if(!validComparisonShortcut(compareShortcut))
|
||||
{
|
||||
showFilesNotice(dialog,L"Choose Shift or Ctrl+Shift with a function key. Shift+F4 and Shift+F8 are reserved.",
|
||||
optionsTitles[CompareFiles]);
|
||||
if(IsWindowVisible(GetDlgItem(dialog,comparisonShortcutControl)))
|
||||
SetFocus(GetDlgItem(dialog,comparisonShortcutControl));
|
||||
return TRUE;
|
||||
}
|
||||
if(draft->markdownError)
|
||||
{
|
||||
if(!draft->markdownNode) SetDlgItemTextW(dialog,optionsSearch,L"");
|
||||
@@ -963,6 +941,14 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
return TRUE;
|
||||
}
|
||||
const auto &base=draft->baseline;
|
||||
const bool keysChanged=draft->keySettings!=base.keySettings;
|
||||
loadFilesKeySettings();
|
||||
if(keysChanged && filesKeySettings!=base.keySettings && filesKeySettings!=draft->keySettings)
|
||||
{
|
||||
showFilesNotice(dialog,L"Keyboard schemes changed in another window. Reopen Options before editing them again.",
|
||||
L"Keyboard shortcuts");
|
||||
return TRUE;
|
||||
}
|
||||
const auto storedComparison=readComparisonAppearance();
|
||||
const bool comparisonChanged=draft->comparison!=base.comparison;
|
||||
if(comparisonChanged && storedComparison!=base.comparison && storedComparison!=draft->comparison)
|
||||
@@ -972,7 +958,8 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
return TRUE;
|
||||
}
|
||||
const bool textChanged=draft->text!=base.text;
|
||||
auto textSettings=ks::files::loadTextPreferences();
|
||||
const auto storedText=ks::files::loadTextPreferences();
|
||||
auto textSettings=storedText;
|
||||
if(draft->text.markdown!=base.text.markdown)
|
||||
{
|
||||
if(textSettings.markdown!=base.text.markdown && textSettings.markdown!=draft->text.markdown)
|
||||
@@ -1004,15 +991,6 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
}
|
||||
textSettings.schemes=draft->text.schemes;
|
||||
}
|
||||
auto keys=optionHistoryKeys(dialog);
|
||||
loadCommandHistoryKeys();
|
||||
for(size_t i=0;i<keys.size();++i)
|
||||
if(keys[i]==base.keys[i]) keys[i]=commandHistoryKeys[i];
|
||||
if(!validHistoryKeys(keys))
|
||||
{
|
||||
showFilesNotice(dialog,L"Choose distinct shortcuts using Ctrl or Alt that are free in Files.",L"Command history");
|
||||
return TRUE;
|
||||
}
|
||||
const bool stylesChanged=draft->styles!=base.styles;
|
||||
loadFileStyles();
|
||||
if(stylesChanged && fileStyles!=base.styles && fileStyles!=draft->styles)
|
||||
@@ -1053,15 +1031,22 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
if(keysChanged && !writeFilesJsonPreference(filesKeySchemePreference,serializeFilesKeySettings(draft->keySettings)))
|
||||
{
|
||||
if(textChanged)
|
||||
try {ks::files::saveTextPreferences(storedText);}
|
||||
catch(const std::exception &) {setStatus(L"Could not restore earlier text settings.",true);}
|
||||
if(comparisonChanged) saveComparisonAppearance(storedComparison);
|
||||
if(fontChanged) applyFont(owner,base.font,base.points);
|
||||
if(stylesChanged) saveFileStyles(fileStyles);
|
||||
showFilesNotice(dialog,L"Could not save the keyboard schemes.",L"Keyboard shortcuts");
|
||||
return TRUE;
|
||||
}
|
||||
const auto saveChanged=[](const wchar_t *name,DWORD value,DWORD initial)
|
||||
{
|
||||
if(value!=initial) savePreference(name,value);
|
||||
};
|
||||
const auto checked=[&](int id){return IsDlgButtonChecked(dialog,id)==BST_CHECKED;};
|
||||
const auto inputKeys=optionHistoryKeys(dialog);
|
||||
saveChanged(L"PreviousCommandKey",inputKeys[0],base.keys[0]);
|
||||
saveChanged(L"CommandHistoryKey",inputKeys[1],base.keys[1]);
|
||||
saveChanged(comparisonShortcutKey,compareShortcut,base.compareShortcut);
|
||||
saveChanged(ks::lan::remoteTerminalPreference,checked(optionsRemoteTerminal),base.remoteTerminal);
|
||||
saveChanged(ks::lan::remoteHibernatePreference,checked(optionsRemoteHibernate),base.remoteHibernate);
|
||||
saveChanged(ks::lan::remoteUpdatePreference,checked(optionsRemoteUpdate),base.remoteUpdate);
|
||||
@@ -1097,6 +1082,7 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
if(mode!=base.modes[index]) savePanelMode(index,mode);
|
||||
}
|
||||
loadFilesPreferences(owner);
|
||||
refreshFilesKeyBar();
|
||||
notifyFilesPreferences(owner);
|
||||
const auto dialogOwner=GetWindow(dialog,GW_OWNER);
|
||||
if(dialogOwner!=owner)
|
||||
@@ -1104,6 +1090,7 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
draft->baseline=OptionsBaseline{};
|
||||
draft->text=draft->baseline.text;
|
||||
draft->comparison=draft->baseline.comparison;
|
||||
draft->keySettings=draft->baseline.keySettings;
|
||||
showMarkdownOptions(dialog,draft->text.markdown);
|
||||
populateTextSchemes(dialog,draft->text);
|
||||
draft->font=displayFont;
|
||||
@@ -1121,8 +1108,6 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
CheckDlgButton(dialog,restoreDocumentsControl,restoreDocuments);
|
||||
showPanelModeOptions(dialog);
|
||||
for(int i=0;i<4;++i) CheckDlgButton(dialog,205+i,(statusFields>>i)&1u);
|
||||
setOptionHistoryKeys(dialog,commandHistoryKeys);
|
||||
SendDlgItemMessageW(dialog,comparisonShortcutControl,HKM_SETHOTKEY,comparisonShortcut,0);
|
||||
CheckDlgButton(dialog,optionsRemoteTerminal,ks::lan::remoteTerminalAllowed());
|
||||
CheckDlgButton(dialog,optionsRemoteHibernate,ks::lan::remoteHibernateAllowed());
|
||||
CheckDlgButton(dialog,optionsRemoteUpdate,ks::lan::remoteUpdateAllowed());
|
||||
@@ -1142,6 +1127,7 @@ INT_PTR CALLBACK optionsDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
|
||||
void runOptions(HWND owner,int page)
|
||||
{
|
||||
loadFilesKeySettings();
|
||||
OptionsDraft draft;
|
||||
draft.filesWindow=GetAncestor(owner,GA_ROOTOWNER);
|
||||
const DWORD initial=static_cast<DWORD>((page<<8)|1);
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
constexpr struct
|
||||
{
|
||||
const char *id;
|
||||
const wchar_t *label;
|
||||
int control;
|
||||
} filesTransferGroups[]{
|
||||
{"colors",L"&Colors and file styles",621},
|
||||
{"panels",L"&Panel modes and layout",622},
|
||||
{"keys",L"&Keyboard schemes",623},
|
||||
};
|
||||
|
||||
constexpr struct
|
||||
{
|
||||
const char *id;
|
||||
int control;
|
||||
bool OptionsBaseline::*value;
|
||||
} transferablePanelChecks[]{
|
||||
{"alignFileExtensions",202,&OptionsBaseline::extensions},
|
||||
{"alignFolderExtensions",204,&OptionsBaseline::folders},
|
||||
{"showDetails",203,&OptionsBaseline::details},
|
||||
{"rightClickMarks",rightClickMarksControl,&OptionsBaseline::mouseMarks},
|
||||
{"driveButtons",driveButtonsControl,&OptionsBaseline::drives},
|
||||
{"compactLayout",compactLayoutControl,&OptionsBaseline::compact},
|
||||
};
|
||||
|
||||
struct FilesTransferDraft
|
||||
{
|
||||
bool importing{};
|
||||
Json groups=Json::object();
|
||||
std::array<bool,std::size(filesTransferGroups)> chosen{};
|
||||
};
|
||||
|
||||
INT_PTR CALLBACK filesTransferDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
|
||||
{
|
||||
if(message==WM_INITDIALOG)
|
||||
{
|
||||
auto &draft=*reinterpret_cast<FilesTransferDraft*>(lp);
|
||||
SetWindowLongPtrW(dialog,DWLP_USER,lp);
|
||||
SetWindowTextW(dialog,draft.importing?L"Import Files settings":L"Export Files settings");
|
||||
SetDlgItemTextW(dialog,624,draft.importing?
|
||||
L"Choose groups to load into Options. Apply saves the changes.":
|
||||
L"Choose groups to export from your saved Files settings.");
|
||||
SetDlgItemTextW(dialog,IDOK,draft.importing?L"&Load":L"&Export");
|
||||
for(const auto &group:filesTransferGroups)
|
||||
{
|
||||
const bool available=draft.groups.contains(group.id);
|
||||
const auto control=GetDlgItem(dialog,group.control);
|
||||
SetWindowTextW(control,group.label);
|
||||
ShowWindow(control,available?SW_SHOW:SW_HIDE);
|
||||
CheckDlgButton(dialog,group.control,available?BST_CHECKED:BST_UNCHECKED);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
if(message==WM_CLOSE || (message==WM_COMMAND && LOWORD(wp)==IDCANCEL))
|
||||
{
|
||||
FilesModalDialog::finish(dialog,IDCANCEL);
|
||||
return TRUE;
|
||||
}
|
||||
if(message!=WM_COMMAND) return FALSE;
|
||||
auto &draft=*reinterpret_cast<FilesTransferDraft*>(GetWindowLongPtrW(dialog,DWLP_USER));
|
||||
for(size_t i=0;i<draft.chosen.size();++i)
|
||||
{
|
||||
const auto &group=filesTransferGroups[i];
|
||||
draft.chosen[i]=draft.groups.contains(group.id) && IsDlgButtonChecked(dialog,group.control)==BST_CHECKED;
|
||||
}
|
||||
const bool any=std::ranges::any_of(draft.chosen,[](bool chosen){return chosen;});
|
||||
if(LOWORD(wp)==IDOK && any) FilesModalDialog::finish(dialog,IDOK);
|
||||
else EnableWindow(GetDlgItem(dialog,IDOK),any);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
fs::path chooseFilesTransferPath(HWND owner,bool importing)
|
||||
{
|
||||
std::array<wchar_t,32768> file{};
|
||||
if(!importing) wcscpy_s(file.data(),file.size(),L"KSwitcher.Files.settings.json");
|
||||
OPENFILENAMEW pick{sizeof(pick)};
|
||||
pick.hwndOwner=owner;
|
||||
pick.lpstrTitle=importing?L"Open Files settings JSON":L"Save Files settings JSON";
|
||||
pick.lpstrFilter=L"JSON files (*.json)\0*.json\0All files (*.*)\0*.*\0";
|
||||
pick.lpstrFile=file.data();
|
||||
pick.nMaxFile=static_cast<DWORD>(file.size());
|
||||
pick.lpstrDefExt=L"json";
|
||||
pick.Flags=OFN_EXPLORER|OFN_NOCHANGEDIR|OFN_PATHMUSTEXIST|
|
||||
(importing?OFN_FILEMUSTEXIST:OFN_OVERWRITEPROMPT);
|
||||
if(importing?GetOpenFileNameW(&pick):GetSaveFileNameW(&pick)) return file.data();
|
||||
if(CommDlgExtendedError()) throw std::runtime_error("Could not open the file picker.");
|
||||
return {};
|
||||
}
|
||||
|
||||
Json exportFilesOptionGroups(const OptionsBaseline &saved)
|
||||
{
|
||||
Json colors{{"panels",saved.palette},{"comparison",saved.comparison.palette},{"fileStyles",serializeFileStyles(saved.styles)}};
|
||||
Json panels{{"leftMode",static_cast<DWORD>(saved.modes[0])},
|
||||
{"rightMode",static_cast<DWORD>(saved.modes[1])},{"sizeWidth",saved.width},{"statusFields",saved.fields}};
|
||||
for(const auto &check:transferablePanelChecks) panels[check.id]=saved.*check.value;
|
||||
return {{"colors",std::move(colors)},{"panels",std::move(panels)},{"keys",serializeFilesKeySettings(saved.keySettings)}};
|
||||
}
|
||||
|
||||
template<typename Palette>
|
||||
void importFilesColors(const Json &value,Palette &palette)
|
||||
{
|
||||
if(!value.is_array()) throw std::runtime_error("Expected an array of colors.");
|
||||
for(size_t i=0;i<std::min(value.size(),palette.size());++i)
|
||||
{
|
||||
if(!value[i].is_number_unsigned() || value[i]>0xffffff)
|
||||
throw std::runtime_error("A color is outside the RGB range.");
|
||||
palette[i]=value[i].template get<COLORREF>();
|
||||
}
|
||||
}
|
||||
|
||||
DWORD importFilesOptionNumber(const Json &value,DWORD minimum,DWORD maximum)
|
||||
{
|
||||
if(!value.is_number_unsigned() || value<minimum || value>maximum)
|
||||
throw std::runtime_error("A panel setting is outside its supported range.");
|
||||
return value.get<DWORD>();
|
||||
}
|
||||
|
||||
std::optional<FilesKeySettings> mergeImportedFilesKeySchemes(HWND owner,const FilesKeySettings &local,const Json &value)
|
||||
{
|
||||
const auto imported=parseFilesKeySettings(value);
|
||||
if(!imported) throw std::runtime_error("The keyboard schemes contain invalid or conflicting bindings.");
|
||||
auto result=local;
|
||||
size_t replacements{};
|
||||
for(size_t i=0;i<imported->schemes.size();++i)
|
||||
{
|
||||
const auto &scheme=imported->schemes[i];
|
||||
const auto existing=std::ranges::find_if(result.schemes,[&](const auto &candidate)
|
||||
{ return sameFilesKeySchemeName(candidate.name,scheme.name); });
|
||||
const auto position=static_cast<size_t>(existing-result.schemes.begin());
|
||||
if(i==imported->active) result.active=position;
|
||||
if(existing==result.schemes.end()) result.schemes.push_back(scheme);
|
||||
else if(existing->keys!=scheme.keys)
|
||||
{
|
||||
++replacements;
|
||||
auto name=existing->name;
|
||||
*existing=scheme;
|
||||
existing->name=std::move(name);
|
||||
}
|
||||
}
|
||||
if(result.schemes.size()>filesKeySchemeLimit)
|
||||
throw std::runtime_error("The imported keyboard schemes exceed the number Files can store.");
|
||||
if(replacements)
|
||||
{
|
||||
const auto prompt=L"Replace "+std::to_wstring(replacements)+
|
||||
(replacements==1?L" keyboard scheme with the same name?":L" keyboard schemes with the same names?");
|
||||
if(showFilesNotice(owner,prompt.c_str(),L"Import Files settings",
|
||||
{.confirm=true,.accept=L"&Replace"})!=IDYES) return {};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void stageImportedFilesOptions(HWND dialog,OptionsDraft &draft,const Json &groups)
|
||||
{
|
||||
auto palette=draft.palette;
|
||||
auto comparison=draft.comparison.palette;
|
||||
auto styles=draft.styles;
|
||||
auto options=OptionsBaseline{};
|
||||
options.modes={panelModeOption(dialog,0),panelModeOption(dialog,1)};
|
||||
options.width=GetDlgItemInt(dialog,201,nullptr,FALSE);
|
||||
options.fields=0;
|
||||
for(int i=0;i<4;++i)
|
||||
if(IsDlgButtonChecked(dialog,205+i)==BST_CHECKED) options.fields|=1u<<i;
|
||||
for(const auto &check:transferablePanelChecks)
|
||||
options.*check.value=IsDlgButtonChecked(dialog,check.control)==BST_CHECKED;
|
||||
|
||||
const auto colorGroup=groups.find("colors");
|
||||
if(colorGroup!=groups.end())
|
||||
{
|
||||
if(!colorGroup->is_object()) throw std::runtime_error("Invalid colors group.");
|
||||
if(colorGroup->contains("panels")) importFilesColors(colorGroup->at("panels"),palette);
|
||||
if(colorGroup->contains("comparison")) importFilesColors(colorGroup->at("comparison"),comparison);
|
||||
if(colorGroup->contains("fileStyles"))
|
||||
{
|
||||
auto parsed=parseFileStyles(colorGroup->at("fileStyles"));
|
||||
if(!parsed) throw std::runtime_error("Invalid file styles.");
|
||||
styles=std::move(*parsed);
|
||||
}
|
||||
}
|
||||
const auto panelGroup=groups.find("panels");
|
||||
if(panelGroup!=groups.end())
|
||||
{
|
||||
if(!panelGroup->is_object()) throw std::runtime_error("Invalid panel modes and layout group.");
|
||||
for(const auto &check:transferablePanelChecks)
|
||||
if(panelGroup->contains(check.id)) options.*check.value=panelGroup->at(check.id).get<bool>();
|
||||
constexpr const char *modeKeys[]{"leftMode","rightMode"};
|
||||
for(size_t i=0;i<options.modes.size();++i)
|
||||
if(panelGroup->contains(modeKeys[i]))
|
||||
options.modes[i]=static_cast<PanelMode>(importFilesOptionNumber(
|
||||
panelGroup->at(modeKeys[i]),0,std::size(panelModeNames)-1));
|
||||
if(panelGroup->contains("sizeWidth"))
|
||||
options.width=importFilesOptionNumber(panelGroup->at("sizeWidth"),6,16);
|
||||
if(panelGroup->contains("statusFields"))
|
||||
options.fields=importFilesOptionNumber(panelGroup->at("statusFields"),0,15);
|
||||
}
|
||||
if(groups.contains("keys"))
|
||||
{
|
||||
auto keys=mergeImportedFilesKeySchemes(dialog,draft.keySettings,groups.at("keys"));
|
||||
if(!keys) return;
|
||||
draft.keySettings=std::move(*keys);
|
||||
}
|
||||
if(colorGroup!=groups.end())
|
||||
{
|
||||
draft.palette=palette;
|
||||
draft.comparison.palette=comparison;
|
||||
draft.styles=std::move(styles);
|
||||
}
|
||||
if(panelGroup!=groups.end())
|
||||
{
|
||||
if(panelGroup->contains("sizeWidth")) SetDlgItemInt(dialog,201,options.width,FALSE);
|
||||
for(int index=0;index<2;++index)
|
||||
SendDlgItemMessageW(dialog,273+index,CB_SETCURSEL,static_cast<WPARAM>(options.modes[index]),0);
|
||||
for(const auto &check:transferablePanelChecks)
|
||||
CheckDlgButton(dialog,check.control,options.*check.value?BST_CHECKED:BST_UNCHECKED);
|
||||
for(int i=0;i<4;++i) CheckDlgButton(dialog,205+i,options.fields&(1u<<i)?BST_CHECKED:BST_UNCHECKED);
|
||||
}
|
||||
if(draft.page==PanelColors && draft.section==fileStyleSection) updateFileStyleEditor(dialog,draft,true);
|
||||
showOptionsPage(dialog,draft,draft.page,draft.section);
|
||||
updateOptionsApply(dialog,draft);
|
||||
}
|
||||
|
||||
void transferFilesOptions(HWND dialog,OptionsDraft &options,bool importing)
|
||||
{
|
||||
try
|
||||
{
|
||||
FilesTransferDraft transfer{.importing=importing};
|
||||
if(importing)
|
||||
{
|
||||
const auto path=chooseFilesTransferPath(dialog,true);
|
||||
if(path.empty()) return;
|
||||
const auto data=ks::readFile(path,maxFilesJsonBytes);
|
||||
const auto document=Json::parse(data,[](int depth,Json::parse_event_t,Json &)
|
||||
{
|
||||
if(depth>32) throw std::runtime_error("The JSON contains too many nested levels.");
|
||||
return true;
|
||||
});
|
||||
if(document.value("format",std::string{})!="kswitcher-files-settings" || document.at("version")!=1)
|
||||
throw std::runtime_error("This Files settings format or version is unsupported.");
|
||||
const auto &groups=document.at("groups");
|
||||
if(!groups.is_object()) throw std::runtime_error("The document does not contain settings groups.");
|
||||
for(const auto &group:filesTransferGroups)
|
||||
if(groups.contains(group.id)) transfer.groups[group.id]=groups.at(group.id);
|
||||
if(transfer.groups.empty()) throw std::runtime_error("The file does not contain any supported settings groups.");
|
||||
}
|
||||
else transfer.groups=exportFilesOptionGroups(options.baseline);
|
||||
if(FilesModalDialog::run(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(617),dialog,filesTransferDialog,
|
||||
reinterpret_cast<LPARAM>(&transfer))!=IDOK) return;
|
||||
for(size_t i=0;i<transfer.chosen.size();++i)
|
||||
if(!transfer.chosen[i]) transfer.groups.erase(filesTransferGroups[i].id);
|
||||
if(importing) stageImportedFilesOptions(dialog,options,transfer.groups);
|
||||
else
|
||||
{
|
||||
const auto path=chooseFilesTransferPath(dialog,false);
|
||||
if(path.empty()) return;
|
||||
const auto output=Json{{"format","kswitcher-files-settings"},{"version",1},
|
||||
{"groups",std::move(transfer.groups)}}.dump(2)+"\n";
|
||||
const auto temporary=ks::files::temporaryPath(path.parent_path());
|
||||
const bool replace=GetFileAttributesW(path.c_str())!=INVALID_FILE_ATTRIBUTES;
|
||||
ks::atomicWrite(temporary,ks::Bytes(output.begin(),output.end()));
|
||||
if(!MoveFileExW(temporary.c_str(),path.c_str(),MOVEFILE_WRITE_THROUGH|(replace?MOVEFILE_REPLACE_EXISTING:0)))
|
||||
{
|
||||
DeleteFileW(temporary.c_str());
|
||||
throw std::runtime_error("Could not publish the settings file.");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const Json::exception &)
|
||||
{
|
||||
showFilesNotice(dialog,L"The JSON is damaged or contains an invalid value.",L"Files settings");
|
||||
}
|
||||
catch(const std::exception &error)
|
||||
{
|
||||
const auto message=ks::wide(error.what());
|
||||
showFilesNotice(dialog,message.c_str(),L"Files settings");
|
||||
}
|
||||
}
|
||||
+31
-34
@@ -48,60 +48,54 @@ bool sameFileExtension(std::wstring_view left,std::wstring_view right)
|
||||
right.data(),static_cast<int>(right.size()),TRUE)==CSTR_EQUAL;
|
||||
}
|
||||
|
||||
void loadFileStyles()
|
||||
std::optional<std::vector<FileStyle>> parseFileStyles(const Json &rows)
|
||||
{
|
||||
DWORD bytes{};
|
||||
if(RegGetValueW(HKEY_CURRENT_USER,schemeKey,fileStyleKey,RRF_RT_REG_BINARY,nullptr,nullptr,&bytes)!=ERROR_SUCCESS ||
|
||||
!bytes || bytes>256*1024) return;
|
||||
std::string data(bytes,'\0');
|
||||
if(RegGetValueW(HKEY_CURRENT_USER,schemeKey,fileStyleKey,RRF_RT_REG_BINARY,nullptr,data.data(),&bytes)!=ERROR_SUCCESS)
|
||||
return;
|
||||
try
|
||||
{
|
||||
const auto rows=Json::parse(data.begin(),data.begin()+bytes);
|
||||
if(!rows.is_array() || rows.size()>64) return;
|
||||
if(!rows.is_array() || rows.size()>64) return {};
|
||||
std::vector<FileStyle> parsed;
|
||||
for(const auto &row:rows)
|
||||
{
|
||||
FileStyle style{ks::wide(row.at("extension").get<std::string>())};
|
||||
if(style.extension!=L"@system-hidden" && fileStyleExtension(style.extension)!=style.extension) return;
|
||||
if(std::any_of(parsed.begin(),parsed.end(),[&](const auto &existing){return existing.extension==style.extension;}))
|
||||
return;
|
||||
const auto color=[&](const char *key)->std::optional<COLORREF>
|
||||
if(style.extension!=L"@system-hidden" && fileStyleExtension(style.extension)!=style.extension) return {};
|
||||
if(std::ranges::any_of(parsed,[&](const auto &existing){return existing.extension==style.extension;}))
|
||||
return {};
|
||||
const auto color=[](const Json &entry,const char *key)->std::optional<COLORREF>
|
||||
{
|
||||
if(!row.contains(key)) return {};
|
||||
const auto value=row.at(key).get<DWORD>();
|
||||
if(value>0xffffff) throw std::runtime_error("Invalid file style color");
|
||||
return value;
|
||||
if(!entry.contains(key)) return {};
|
||||
const auto &value=entry.at(key);
|
||||
if(!value.is_number_unsigned() || value>0xffffff) throw std::runtime_error("Invalid file style color");
|
||||
return value.get<DWORD>();
|
||||
};
|
||||
style.foreground=color("foreground");
|
||||
style.background=color("background");
|
||||
style.foreground=color(row,"foreground");
|
||||
style.background=color(row,"background");
|
||||
style.underline=row.value("underline",false);
|
||||
style.strikeout=row.value("strikeout",false);
|
||||
if(row.contains("states"))
|
||||
{
|
||||
const auto &states=row.at("states");
|
||||
if(!states.is_array() || states.size()!=style.states.size()) return;
|
||||
if(!states.is_array() || states.size()!=style.states.size()) return {};
|
||||
for(size_t i=0;i<style.states.size();++i)
|
||||
{
|
||||
const auto read=[&](const char *key)->std::optional<COLORREF>
|
||||
{
|
||||
if(!states[i].contains(key)) return {};
|
||||
const auto value=states[i].at(key).get<DWORD>();
|
||||
if(value>0xffffff) throw std::runtime_error("Invalid state color");
|
||||
return value;
|
||||
};
|
||||
style.states[i]={read("foreground"),read("background")};
|
||||
if(!states[i].is_object()) return {};
|
||||
style.states[i]={color(states[i],"foreground"),color(states[i],"background")};
|
||||
}
|
||||
}
|
||||
parsed.push_back(std::move(style));
|
||||
}
|
||||
fileStyles=std::move(parsed);
|
||||
return parsed;
|
||||
}
|
||||
catch(const std::exception &) {}
|
||||
catch(const std::exception &) {return {};}
|
||||
}
|
||||
|
||||
bool saveFileStyles(const std::vector<FileStyle> &styles)
|
||||
void loadFileStyles()
|
||||
{
|
||||
fileStyles=defaultFileStyles;
|
||||
if(const auto rows=readFilesJsonPreference(fileStyleKey))
|
||||
if(auto parsed=parseFileStyles(*rows)) fileStyles=std::move(*parsed);
|
||||
}
|
||||
|
||||
Json serializeFileStyles(const std::vector<FileStyle> &styles)
|
||||
{
|
||||
auto rows=Json::array();
|
||||
for(const auto &style:styles)
|
||||
@@ -119,9 +113,12 @@ bool saveFileStyles(const std::vector<FileStyle> &styles)
|
||||
}
|
||||
rows.push_back(std::move(row));
|
||||
}
|
||||
const auto data=rows.dump();
|
||||
return RegSetKeyValueW(HKEY_CURRENT_USER,schemeKey,fileStyleKey,REG_BINARY,data.data(),
|
||||
static_cast<DWORD>(data.size()))==ERROR_SUCCESS;
|
||||
return rows;
|
||||
}
|
||||
|
||||
bool saveFileStyles(const std::vector<FileStyle> &styles)
|
||||
{
|
||||
return writeFilesJsonPreference(fileStyleKey,serializeFileStyles(styles));
|
||||
}
|
||||
|
||||
struct FileRowStyle
|
||||
|
||||
Reference in new issue
Block a user