Skip to content

Commit

Permalink
Properly cancel operations when !?<title>?<init>! dialog is cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Dec 21, 2024
1 parent 029e057 commit 7535e04
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
drkns 2024-12-21 23:08:36+00:00 - build 6404

1. Properly cancel operations when !?<title>?<init>! dialog is cancelled.

--------------------------------------------------------------------------------
MZK 2024-12-19 16:56:14-05:00 - build 6403

Expand Down
12 changes: 9 additions & 3 deletions far/filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1937,8 +1937,10 @@ bool FileList::ProcessKey(const Manager::Key& Key)
{
if (EnableExternal)
{
ProcessExternal(Global->Opt->strExternalEditor, strFileName, strShortFileName, PluginMode, TemporaryDirectory);
UploadFile = file_state::get(strFileName) != SavedState;
UploadFile =
ProcessExternal(Global->Opt->strExternalEditor, strFileName, strShortFileName, PluginMode, TemporaryDirectory) &&
file_state::get(strFileName) != SavedState;

Modaling = PluginMode; // External editor from plugin panel is Modal!
}
else if (PluginMode)
Expand Down Expand Up @@ -5178,7 +5180,11 @@ bool FileList::ApplyCommand()
break;

bool PreserveLFN = false;
if (string strConvertedCommand = strCommand; SubstFileName(strConvertedCommand, { i.FileName, i.AlternateFileName() }, &PreserveLFN) && !strConvertedCommand.empty())
string strConvertedCommand = strCommand;
if (!SubstFileName(strConvertedCommand, { i.FileName, i.AlternateFileName() }, &PreserveLFN))
break;

if (strConvertedCommand.empty())
{
SCOPED_ACTION(PreserveLongName)(i.FileName, PreserveLFN);

Expand Down
18 changes: 12 additions & 6 deletions far/filetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ bool ProcessLocalFileTypes(string_view const Name, string_view const ShortName,
else
strDescription = std::move(strCommandText);

MenuItemEx TypesMenuItem(strDescription);
MenuData.emplace_back(std::move(NewMenuData));
MenuItems.emplace_back(std::move(TypesMenuItem));
MenuItems.emplace_back(strDescription);
}

if (!CommandCount)
Expand Down Expand Up @@ -209,7 +208,10 @@ bool ProcessLocalFileTypes(string_view const Name, string_view const ShortName,
AddMatches(ItemData);

bool PreserveLFN = false;
if (SubstFileName(ItemData.Command, Context, &PreserveLFN) && !ItemData.Command.empty())
if (!SubstFileName(ItemData.Command, Context, &PreserveLFN))
return false;

if (!ItemData.Command.empty())
{
if (AddToHistory && !(Global->Opt->ExcludeCmdHistory & EXCLUDECMDHISTORY_NOTFARASS) && !AlwaysWaitFinish) //AN
{
Expand Down Expand Up @@ -305,7 +307,7 @@ bool GetFiletypeOpenMode(int keyPressed, FILETYPE_MODE& mode, bool& shouldForceI
/*
Используется для запуска внешнего редактора и вьювера
*/
void ProcessExternal(string_view const Command, string_view const Name, string_view const ShortName, bool const AlwaysWaitFinish, string_view const CurrentDirectory)
bool ProcessExternal(string_view const Command, string_view const Name, string_view const ShortName, bool const AlwaysWaitFinish, string_view const CurrentDirectory)
{
std::optional<os::fs::current_directory_guard> Guard;
// We have to set it - users can have associations like !.! which will work funny without this
Expand All @@ -314,8 +316,11 @@ void ProcessExternal(string_view const Command, string_view const Name, string_v

string strExecStr(Command);
bool PreserveLFN = false;
if (!SubstFileName(strExecStr, { Name, ShortName }, &PreserveLFN) || strExecStr.empty())
return;
if (!SubstFileName(strExecStr, { Name, ShortName }, &PreserveLFN))
return false;

if (strExecStr.empty())
return false;

// If you want your history to be usable - use full paths yourself. We cannot reliably substitute them.
Global->CtrlObject->ViewHistory->AddToHistory(strExecStr, AlwaysWaitFinish? HR_EXTERNAL_WAIT : HR_EXTERNAL);
Expand All @@ -329,6 +334,7 @@ void ProcessExternal(string_view const Command, string_view const Name, string_v
Info.WaitMode = AlwaysWaitFinish? execute_info::wait_mode::wait_finish : execute_info::wait_mode::if_needed;

Global->CtrlObject->CmdLine()->ExecString(Info);
return true;
}

static auto FillFileTypesMenu(VMenu2* TypesMenu, int MenuPos)
Expand Down
2 changes: 1 addition & 1 deletion far/filetype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ enum FILETYPE_MODE
bool GetFiletypeOpenMode(int keyPressed, FILETYPE_MODE& mode, bool& shouldForceInternal);

bool ProcessLocalFileTypes(string_view Name, string_view ShortName, FILETYPE_MODE Mode, bool AlwaysWaitFinish, string_view CurrentDirectory, bool AddToHistory = true, bool RunAs = false, function_ref<void(struct execute_info&)> Launcher = nullptr);
void ProcessExternal(string_view Command, string_view Name, string_view ShortName, bool AlwaysWaitFinish, string_view CurrentDirectory);
bool ProcessExternal(string_view Command, string_view Name, string_view ShortName, bool AlwaysWaitFinish, string_view CurrentDirectory);
void EditFileTypes();

#endif // FILETYPE_HPP_E08E6BC3_545B_4343_9D79_A72830AC30F0
5 changes: 4 additions & 1 deletion far/usermenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,10 @@ int UserMenu::ProcessSingleMenu(std::list<UserMenuItem>& Menu, int MenuPos, std:
*/

bool PreserveLFN = false;
if (SubstFileName(strCommand, Context, &PreserveLFN, false, CurrentLabel) && !strCommand.empty())
if (!SubstFileName(strCommand, Context, &PreserveLFN, false, CurrentLabel))
return EC_CLOSE_MENU;

if (!strCommand.empty())
{
SCOPED_ACTION(PreserveLongName)(strName, PreserveLFN);

Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6403
6404

0 comments on commit 7535e04

Please sign in to comment.