Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hotkey problems #453

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NetBox/FarDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ bool TFarDialog::HotKey(uint32_t Key, uint32_t ControlState) const
{
bool Result = false;
char HotKey = 0;
if ((ControlState & ALTMASK) &&
if (CheckControlMaskSet(ControlState, ALTMASK) &&
('A' <= Key) && (Key <= 'Z'))
{
Result = true;
Expand Down
3 changes: 2 additions & 1 deletion src/NetBox/FarPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2269,7 +2269,8 @@ TFarPanelInfo ** TCustomFarFileSystem::GetPanelInfo(int32_t Another)
{
DebugAssert(false);
}
FPanelInfo[bAnother] = new TFarPanelInfo(Info, !bAnother ? this : nullptr);
const bool SetOwner = !bAnother || (GetOppositeFileSystem() == this);
FPanelInfo[bAnother] = new TFarPanelInfo(Info, SetOwner ? this : nullptr);
}
return &FPanelInfo[bAnother];
}
Expand Down
9 changes: 9 additions & 0 deletions src/NetBox/FarPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ constexpr const DWORD CTRLMASK = (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED);
constexpr const DWORD SHIFTMASK = (SHIFT_PRESSED);
constexpr const wchar_t * SHORTCUT_DELIMITER = L"\1";

template<typename... TMasks>
bool CheckControlMaskSet(DWORD State, TMasks... Masks)
{
const auto CtlState = State & RMASK;
// 1) check all individual masks are present in the ctl state
// 2) check all bits that are not in any mask are cleared
return ((CtlState & Masks) && ...) && !(CtlState & ~(Masks | ...));
}

class TCustomFarFileSystem;
class TFarPanelModes;
class TFarKeyBarTitles;
Expand Down
20 changes: 10 additions & 10 deletions src/NetBox/WinSCPDialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ bool TTabbedDialog::Key(TFarDialogItem * /*Item*/, intptr_t KeyCode)
bool Result = false;
const WORD Key = KeyCode & 0xFFFF;
const WORD ControlState = nb::ToWord(KeyCode >> 16);
if ((((Key == VK_NEXT) || (Key == VK_NUMPAD3)) && (ControlState & CTRLMASK) != 0) ||
(((Key == VK_PRIOR) || (Key == VK_NUMPAD9)) && (ControlState & CTRLMASK) != 0))
if ((((Key == VK_NEXT) || (Key == VK_NUMPAD3)) && CheckControlMaskSet(ControlState, CTRLMASK)) ||
(((Key == VK_PRIOR) || (Key == VK_NUMPAD9)) && CheckControlMaskSet(ControlState, CTRLMASK)))
{
int32_t NewTab = FTab;
do
Expand Down Expand Up @@ -7518,7 +7518,7 @@ void TSynchronizeChecklistDialog::AddColumn(UnicodeString & List,
Width--;
}
List += Value.SubString(Scroll + 1, Width);
if (!Header && (Len - Scroll > Width))
if (!AHeader && (Len - Scroll > Width))
{
List += L'}';
FCanScrollRight = true;
Expand Down Expand Up @@ -7875,10 +7875,10 @@ bool TSynchronizeChecklistDialog::Key(TFarDialogItem * Item, intptr_t KeyCode)
const WORD ControlState = nb::ToWord(KeyCode >> 16);
if (ListBox->Focused())
{
if (((Key == VK_ADD) && (ControlState & SHIFTMASK) != 0) ||
((Key == VK_SUBTRACT) && (ControlState & SHIFTMASK) != 0))
if (((Key == VK_ADD) && CheckControlMaskSet(ControlState, SHIFTMASK)) ||
((Key == VK_SUBTRACT) && CheckControlMaskSet(ControlState, SHIFTMASK)))
{
CheckAll((Key == VK_ADD) && (ControlState & SHIFTMASK) != 0);
CheckAll((Key == VK_ADD) && CheckControlMaskSet(ControlState, SHIFTMASK));
Result = true;
}
else if ((Key == VK_SPACE) || (Key == VK_INSERT) ||
Expand Down Expand Up @@ -7907,7 +7907,7 @@ bool TSynchronizeChecklistDialog::Key(TFarDialogItem * Item, intptr_t KeyCode)
}
Result = true;
}
else if ((Key == VK_LEFT) && (ControlState & ALTMASK) != 0)
else if ((Key == VK_LEFT) && CheckControlMaskSet(ControlState, ALTMASK))
{
if (FScroll > 0)
{
Expand All @@ -7916,7 +7916,7 @@ bool TSynchronizeChecklistDialog::Key(TFarDialogItem * Item, intptr_t KeyCode)
}
Result = true;
}
else if (Key == VK_RIGHT)
else if ((Key == VK_RIGHT) && CheckControlMaskSet(ControlState, ALTMASK))
{
if (FCanScrollRight)
{
Expand Down Expand Up @@ -8642,15 +8642,15 @@ bool TQueueDialog::Key(TFarDialogItem * /*Item*/, intptr_t KeyCode)
}
Result = true;
}
else if ((Key == VK_UP) && (ControlState & CTRLMASK) != 0)
else if ((Key == VK_UP) && CheckControlMaskSet(ControlState, CTRLMASK))
{
if (MoveUpButton->GetEnabled())
{
DoButton = MoveUpButton;
}
Result = true;
}
else if ((Key == VK_DOWN) && (ControlState & CTRLMASK) != 0)
else if ((Key == VK_DOWN) && CheckControlMaskSet(ControlState, CTRLMASK))
{
if (MoveDownButton->GetEnabled())
{
Expand Down
53 changes: 24 additions & 29 deletions src/NetBox/WinSCPFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,7 @@ bool TWinSCPFileSystem::ProcessKeyEx(int32_t Key, uint32_t ControlState)
TFarPanelInfo * const * PanelInfo = GetPanelInfo();
const TFarPanelItem * Focused = PanelInfo && *PanelInfo ? (*PanelInfo)->GetFocusedItem() : nullptr;

if ((Key == 'W') && (ControlState & SHIFTMASK) &&
(ControlState & ALTMASK))
if ((Key == 'W') && CheckControlMaskSet(ControlState, SHIFTMASK, ALTMASK))
{
GetWinSCPPlugin()->CommandsMenu(true);
Handled = true;
Expand All @@ -930,13 +929,13 @@ bool TWinSCPFileSystem::ProcessKeyEx(int32_t Key, uint32_t ControlState)
Data = cast_to<TSessionData>(ToObj(Focused->GetUserData()));
}

if ((Key == 'F') && (ControlState & CTRLMASK))
if ((Key == 'F') && CheckControlMaskSet(ControlState, CTRLMASK))
{
InsertSessionNameOnCommandLine();
Handled = true;
}

if ((Key == VK_RETURN) && (ControlState & CTRLMASK))
if ((Key == VK_RETURN) && CheckControlMaskSet(ControlState, CTRLMASK))
{
InsertSessionNameOnCommandLine();
Handled = true;
Expand All @@ -957,14 +956,14 @@ bool TWinSCPFileSystem::ProcessKeyEx(int32_t Key, uint32_t ControlState)
Handled = true;
}

if (Key == VK_F4 && (ControlState & SHIFTMASK))
if (Key == VK_F4 && CheckControlMaskSet(ControlState, SHIFTMASK))
{
EditConnectSession(nullptr, true);
Handled = true;
}

if (((Key == VK_F5) || (Key == VK_F6)) &&
(ControlState & SHIFTMASK))
CheckControlMaskSet(ControlState, SHIFTMASK))
{
if (Data != nullptr)
{
Expand All @@ -973,7 +972,7 @@ bool TWinSCPFileSystem::ProcessKeyEx(int32_t Key, uint32_t ControlState)
Handled = true;
}

if (Key == 'R' && (ControlState & CTRLMASK))
if (Key == 'R' && CheckControlMaskSet(ControlState, CTRLMASK))
{
DeleteStoredSessions();
if (UpdatePanel())
Expand All @@ -985,78 +984,74 @@ bool TWinSCPFileSystem::ProcessKeyEx(int32_t Key, uint32_t ControlState)
}
else if (Connected())
{
if ((Key == 'F') && (ControlState & CTRLMASK))
if ((Key == 'F') && CheckControlMaskSet(ControlState, CTRLMASK, ALTMASK))
{
InsertFileNameOnCommandLine(true);
Handled = true;
}

if ((Key == VK_RETURN) && (ControlState & CTRLMASK))
if ((Key == VK_RETURN) && CheckControlMaskSet(ControlState, CTRLMASK))
{
InsertFileNameOnCommandLine(false);
Handled = true;
}

if ((Key == 'R') && (ControlState & CTRLMASK))
if ((Key == 'R') && CheckControlMaskSet(ControlState, CTRLMASK))
{
FReloadDirectory = true;
}

if ((Key == 'A') && (ControlState & CTRLMASK))
if ((Key == 'A') && CheckControlMaskSet(ControlState, CTRLMASK))
{
FileProperties();
Handled = true;
}

if ((Key == 'G') && (ControlState & CTRLMASK))
if ((Key == 'G') && CheckControlMaskSet(ControlState, CTRLMASK))
{
ApplyCommand();
Handled = true;
}

if ((Key == 'Q') && (ControlState & SHIFTMASK) &&
(ControlState & ALTMASK))
if ((Key == 'Q') && CheckControlMaskSet(ControlState, SHIFTMASK, ALTMASK))
{
QueueShow(false);
Handled = true;
}

if ((Key == 'B') && (ControlState & CTRLMASK) &&
(ControlState & ALTMASK))
if ((Key == 'B') && CheckControlMaskSet(ControlState, CTRLMASK, ALTMASK))
{
ToggleSynchronizeBrowsing();
Handled = true;
}

if ((Key == VK_INSERT) && (((ControlState & ALTMASK) && (ControlState & SHIFTMASK)) ||
(((ControlState & CTRLMASK) && (ControlState & ALTMASK)))))
if ((Key == VK_INSERT) && CheckControlMaskSet(ControlState, ALTMASK, SHIFTMASK))
{
CopyFullFileNamesToClipboard();
Handled = true;
}

if ((Key == VK_F6) && (ControlState & ALTMASK) && !(ControlState & SHIFTMASK))
if ((Key == VK_F6) && CheckControlMaskSet(ControlState, ALTMASK))
{
RemoteCreateLink();
Handled = true;
}

if (Focused && ((Key == VK_F5) || (Key == VK_F6)) &&
(ControlState & SHIFTMASK) && !(ControlState & ALTMASK))
CheckControlMaskSet(ControlState, SHIFTMASK))
{
TransferFiles((Key == VK_F6));
Handled = true;
}

if (Focused && (Key == VK_F6) &&
((ControlState & SHIFTMASK) && (ControlState & ALTMASK)))
CheckControlMaskSet(ControlState, SHIFTMASK, ALTMASK))
{
RenameFile();
Handled = true;
}

if ((Key == VK_F12) && (ControlState & SHIFTMASK) &&
(ControlState & ALTMASK))
if ((Key == VK_F12) && CheckControlMaskSet(ControlState, SHIFTMASK, ALTMASK))
{
OpenDirectory(false);
Handled = true;
Expand All @@ -1071,8 +1066,8 @@ bool TWinSCPFileSystem::ProcessKeyEx(int32_t Key, uint32_t ControlState)

// Return to session panel
if (Focused && !Handled && !IsConnectedDirectly() &&
((Key == VK_RETURN) && (Focused->GetFileName() == PARENTDIRECTORY) ||
(Key == VK_PRIOR) && (ControlState & CTRLMASK)) && FLastPath == ROOTDIRECTORY)
((Key == VK_RETURN) && (ControlState == 0) && (Focused->GetFileName() == PARENTDIRECTORY) ||
(Key == VK_PRIOR) && CheckControlMaskSet(ControlState, CTRLMASK)) && FLastPath == ROOTDIRECTORY)
{
SetDirectoryEx(PARENTDIRECTORY, 0);
if (UpdatePanel())
Expand Down Expand Up @@ -1937,7 +1932,7 @@ void TWinSCPFileSystem::InsertTokenOnCommandLine(const UnicodeString & Token, bo

void TWinSCPFileSystem::InsertSessionNameOnCommandLine()
{
TFarPanelInfo * const * PanelInfo = GetPanelInfo();
TFarPanelInfo * const * PanelInfo = IsActiveFileSystem() ? GetPanelInfo(): GetAnotherPanelInfo();
const TFarPanelItem * Focused = PanelInfo && *PanelInfo ? (*PanelInfo)->GetFocusedItem() : nullptr;

if (Focused != nullptr)
Expand All @@ -1962,7 +1957,7 @@ void TWinSCPFileSystem::InsertSessionNameOnCommandLine()

void TWinSCPFileSystem::InsertFileNameOnCommandLine(bool Full)
{
TFarPanelInfo * const * PanelInfo = GetPanelInfo();
TFarPanelInfo * const * PanelInfo = IsActiveFileSystem() ? GetPanelInfo(): GetAnotherPanelInfo();
const TFarPanelItem * Focused = PanelInfo && *PanelInfo ? (*PanelInfo)->GetFocusedItem() : nullptr;

if (Focused != nullptr)
Expand Down Expand Up @@ -4118,8 +4113,8 @@ void TWinSCPFileSystem::MultipleEdit()
}
}

void TWinSCPFileSystem::MultipleEdit(const UnicodeString & Directory,
const UnicodeString & AFileName, const TRemoteFile * AFile)
void TWinSCPFileSystem::MultipleEdit(const UnicodeString Directory,
const UnicodeString AFileName, const TRemoteFile * AFile)
{
DebugAssert(AFile);
TEditHistory EditHistory;
Expand Down
2 changes: 1 addition & 1 deletion src/NetBox/WinSCPFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class TWinSCPFileSystem final : public TCustomFarFileSystem
const UnicodeString & RealFileName, UnicodeString & DestPath);
void LogAuthentication(TTerminal * Terminal, const UnicodeString & Msg);
void MultipleEdit();
void MultipleEdit(const UnicodeString & Directory, const UnicodeString & AFileName, const TRemoteFile * AFile);
void MultipleEdit(const UnicodeString Directory, const UnicodeString AFileName, const TRemoteFile * AFile);
void EditViewCopyParam(TCopyParamType & CopyParam);
bool SynchronizeBrowsing(const UnicodeString & NewPath);
bool IsEditHistoryEmpty() const;
Expand Down
3 changes: 1 addition & 2 deletions src/NetBox/WinSCPPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ int32_t TWinSCPPlugin::ProcessEditorInputEx(const INPUT_RECORD * Rec)
if ((Rec->EventType == KEY_EVENT) &&
Rec->Event.KeyEvent.bKeyDown &&
(Rec->Event.KeyEvent.uChar.AsciiChar == 'W') &&
(FLAGSET(Rec->Event.KeyEvent.dwControlKeyState, ALTMASK)) &&
(FLAGSET(Rec->Event.KeyEvent.dwControlKeyState, SHIFTMASK)))
CheckControlMaskSet(Rec->Event.KeyEvent.dwControlKeyState, ALTMASK, SHIFTMASK))
{
CommandsMenu(false);
Result = 1;
Expand Down
3 changes: 1 addition & 2 deletions src/core/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9634,9 +9634,8 @@ void TLocalFileHandle::Close()
UnicodeString GetSessionUrl(const TTerminal * Terminal, bool WithUserName)
{
UnicodeString Result;
const TSessionInfo & SessionInfo = Terminal->GetSessionInfo();
const TSessionData * SessionData = Terminal->GetSessionData();
UnicodeString Protocol = SessionInfo.ProtocolBaseName;
UnicodeString Protocol = SessionData->FSProtocolStr;
const UnicodeString HostName = SessionData->GetHostNameExpanded();
const UnicodeString UserName = SessionData->GetUserNameExpanded();
const int32_t Port = Terminal->GetSessionData()->GetPortNumber();
Expand Down