From f78bdca7bad63588afe497d533603c4e4685cc51 Mon Sep 17 00:00:00 2001 From: Ivan Date: Mon, 2 Dec 2024 21:05:57 +0400 Subject: [PATCH 1/3] tmppanel: tweak open/execute logic in ShowMenuFromList() --- tmppanel/src/TmpPanel.cpp | 63 ++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/tmppanel/src/TmpPanel.cpp b/tmppanel/src/TmpPanel.cpp index e7987b1bd..e8327ba2c 100644 --- a/tmppanel/src/TmpPanel.cpp +++ b/tmppanel/src/TmpPanel.cpp @@ -341,29 +341,56 @@ void ReadFileLines(int fd, DWORD FileSizeLow, TCHAR **argv, TCHAR *args, UINT *n ExpandEnvStrs(p, TMP); p = TMP; - int bShellExecute = BreakCode != -1; - - if (!bShellExecute) { - FAR_FIND_DATA FindData = {}; - if (TmpPanel::GetFileInfoAndValidate(p, &FindData, FALSE)) { - if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - Info.Control(INVALID_HANDLE_VALUE, FCTL_SETPANELDIR, 0, (LONG_PTR)p); - } else { - bShellExecute = TRUE; - } + bool bShellExecute = BreakCode != -1; + + enum { ACTION_NOP, ACTION_SETPANELDIR, ACTION_SETCMDLINE, ACTION_OPEN, + ACTION_EXECUTE} Action = ACTION_NOP; + + FAR_FIND_DATA FindData = {}; + + if (TmpPanel::GetFileInfoAndValidate(p, &FindData, FALSE)) { + if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + Action = bShellExecute ? ACTION_OPEN : ACTION_SETPANELDIR; + } else if (FindData.dwFileAttributes & FILE_ATTRIBUTE_EXECUTABLE) { + Action = ACTION_EXECUTE; } else { + Action = ACTION_OPEN; + } + } else { + Action = bShellExecute ? ACTION_OPEN : ACTION_SETCMDLINE; + } + + if (FindData.lpwszFileName) { + free((void *)FindData.lpwszFileName); + } + + switch (Action) { + case ACTION_SETPANELDIR: { + Info.Control(INVALID_HANDLE_VALUE, FCTL_SETPANELDIR, 0, (LONG_PTR)p); + break; + } + + case ACTION_SETCMDLINE: { Info.Control(PANEL_ACTIVE, FCTL_SETCMDLINE, 0, (LONG_PTR)p); + break; } - if (FindData.lpwszFileName) { - free((void *)FindData.lpwszFileName); + + case ACTION_OPEN: { + std::wstring cmd = p; + QuoteCmdArgIfNeed(cmd); + FSF.Execute(cmd.c_str(), EF_OPEN | EF_NOCMDPRINT | EF_NOWAIT); + break; + } + + case ACTION_EXECUTE: { + std::wstring cmd = p; + QuoteCmdArgIfNeed(cmd); + FSF.Execute(cmd.c_str(), bShellExecute ? EF_NOWAIT : 0); + break; } - } - if (bShellExecute) { - DWORD flags = EF_OPEN | EF_NOCMDPRINT | EF_NOWAIT; - std::wstring cmd = p; - QuoteCmdArgIfNeed(cmd); - FSF.Execute(cmd.c_str(), flags); + default: + ; } } } From fa8aae95f281efa51f40a5307d8a9edda111bd6f Mon Sep 17 00:00:00 2001 From: Ivan Date: Mon, 2 Dec 2024 22:01:39 +0400 Subject: [PATCH 2/3] tmppanel: added keyboard shortcut help in ShowMenuFromList() --- tmppanel/src/TmpPanel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmppanel/src/TmpPanel.cpp b/tmppanel/src/TmpPanel.cpp index e8327ba2c..fd0193662 100644 --- a/tmppanel/src/TmpPanel.cpp +++ b/tmppanel/src/TmpPanel.cpp @@ -326,7 +326,7 @@ void ReadFileLines(int fd, DWORD FileSizeLow, TCHAR **argv, TCHAR *args, UINT *n int BreakCode; static const int BreakKeys[2] = {MAKELONG(VK_RETURN, PKF_SHIFT), 0}; - int ExitCode = Info.Menu(Info.ModuleNumber, -1, -1, 0, FMENU_WRAPMODE, Title, NULL, + int ExitCode = Info.Menu(Info.ModuleNumber, -1, -1, 0, FMENU_WRAPMODE, Title, L"Enter Shift+Enter Esc Ctrl+Alt+F", _T("Contents"), &BreakKeys[0], &BreakCode, fmi, argc); for (int i = 0; i < argc; ++i) From 034b0049400d86bc1ad73b02010eaebe54ab5043 Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 3 Dec 2024 17:24:57 +0400 Subject: [PATCH 3/3] new flag in EXECUTEFLAGS to run command in external terminal + some more open/execute tuning in ShowMenuFromList() --- far2l/far2sdk/farplug-mb.h | 3 ++- far2l/far2sdk/farplug-wide.h | 3 ++- far2l/src/execute.cpp | 7 +++++++ tmppanel/src/TmpPanel.cpp | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/far2l/far2sdk/farplug-mb.h b/far2l/far2sdk/farplug-mb.h index 88b78b91f..02808cd3e 100644 --- a/far2l/far2sdk/farplug-mb.h +++ b/far2l/far2sdk/farplug-mb.h @@ -1574,7 +1574,8 @@ namespace oldfar EF_NOTIFY = 0x08, // notify when command completed (if such notifications enabled in settings) EF_NOCMDPRINT = 0x10, // dont print command in command line nor include it to history EF_OPEN = 0x20, // use desktop shell (if present) to open command (e.g. URLs, documents..) - EF_MAYBGND = 0x40 // allow put command to background mode + EF_MAYBGND = 0x40, // allow put command to background mode + EF_EXTERNALTERM = 0x80 // execute command in configured external terminal }; typedef int (WINAPI *FAREXECUTE)(const char *CmdStr, unsigned int ExecFlags); diff --git a/far2l/far2sdk/farplug-wide.h b/far2l/far2sdk/farplug-wide.h index 8db905e5f..a0b9909aa 100644 --- a/far2l/far2sdk/farplug-wide.h +++ b/far2l/far2sdk/farplug-wide.h @@ -1984,7 +1984,8 @@ enum EXECUTEFLAGS EF_NOTIFY = 0x08, // notify when command completed (if such notifications enabled in settings) EF_NOCMDPRINT = 0x10, // dont print command in command line nor include it to history EF_OPEN = 0x20, // use desktop shell (if present) to open command (e.g. URLs, documents..) - EF_MAYBGND = 0x40 // allow put command to background mode + EF_MAYBGND = 0x40, // allow put command to background mode + EF_EXTERNALTERM = 0x80 // execute command in configured external terminal }; typedef int (WINAPI *FAREXECUTE)(const wchar_t *CmdStr, unsigned int ExecFlags); diff --git a/far2l/src/execute.cpp b/far2l/src/execute.cpp index 8f521540c..742bed4bb 100644 --- a/far2l/src/execute.cpp +++ b/far2l/src/execute.cpp @@ -298,6 +298,13 @@ static int farExecuteASynched(const char *CmdStr, unsigned int ExecFlags) return farExecuteASynched(OpenCmd.c_str(), ExecFlags & (~EF_OPEN)); } + if (ExecFlags & EF_EXTERNALTERM) { + std::string OpenCmd = GetOpenShVerb("exec"); + OpenCmd+= ' '; + OpenCmd+= CmdStr; + return farExecuteASynched(OpenCmd.c_str(), ExecFlags & (~EF_EXTERNALTERM)); + } + const bool may_notify = (ExecFlags & (EF_NOTIFY | EF_NOWAIT)) == EF_NOTIFY && Opt.NotifOpt.OnConsole; if (ExecFlags & (EF_HIDEOUT | EF_NOWAIT)) { r = NotVTExecute(CmdStr, (ExecFlags & EF_NOWAIT) != 0, (ExecFlags & EF_SUDO) != 0); diff --git a/tmppanel/src/TmpPanel.cpp b/tmppanel/src/TmpPanel.cpp index fd0193662..c41d7a507 100644 --- a/tmppanel/src/TmpPanel.cpp +++ b/tmppanel/src/TmpPanel.cpp @@ -385,7 +385,7 @@ void ReadFileLines(int fd, DWORD FileSizeLow, TCHAR **argv, TCHAR *args, UINT *n case ACTION_EXECUTE: { std::wstring cmd = p; QuoteCmdArgIfNeed(cmd); - FSF.Execute(cmd.c_str(), bShellExecute ? EF_NOWAIT : 0); + FSF.Execute(cmd.c_str(), bShellExecute ? EF_EXTERNALTERM | EF_NOCMDPRINT | EF_HIDEOUT: EF_MAYBGND); break; }