Skip to content

Commit

Permalink
1. Продолжение экспериментальных изменений в запускателе.
Browse files Browse the repository at this point in the history
   Должны лучше работать Ctrl-G и многострочные команды в User Menu.
  • Loading branch information
alabuzhev committed Jun 26, 2016
1 parent 195fdd1 commit 4ae9399
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 75 deletions.
5 changes: 5 additions & 0 deletions far/changelog
@@ -1,3 +1,8 @@
drkns 27.06.2016 00:46:22 +0200 - build 4727

1. Продолжение экспериментальных изменений в запускателе.
Должны лучше работать Ctrl-G и многострочные команды в User Menu.

shmuel 26.06.2016 16:37:24 +0200 - build 4726

1. Расширение возможностей функции Panel.SetCustomSortMode().
Expand Down
140 changes: 96 additions & 44 deletions far/cmdline.cpp
Expand Up @@ -873,44 +873,47 @@ void CommandLine::SetPromptSize(int NewSize)
PromptSize = NewSize? std::max(5, std::min(95, NewSize)) : DEFAULT_CMDLINE_WIDTH;
}

class execution_context: noncopyable
class execution_context: noncopyable, public i_execution_context
{
public:
execution_context(const string& Command, bool ShowCommand = true):
m_CurrentWindow(Global->WindowManager->GetCurrentWindow()),
m_Command(Command),
m_ShowCommand(ShowCommand),
m_Activated(),
m_Consolised()
{
}

void Activate()
void Activate() override
{
if (m_Activated)
return;

m_Activated = true;
++Global->SuppressClock;

m_CurrentWindow = Global->WindowManager->GetCurrentWindow();

Global->WindowManager->ActivateWindow(Global->CtrlObject->Desktop);
Global->WindowManager->PluginCommit();

// ShowCommand is false when there is no "command" - class instantiated by FCTL_GETUSERSCREEN.
if (m_ShowCommand)
{
Global->CtrlObject->CmdLine()->DrawFakeCommand(m_Command);
ScrollScreen(1);
}
Global->CtrlObject->Desktop->TakeSnapshot();
int X1, Y1, X2, Y2;
Global->CtrlObject->CmdLine()->GetPosition(X1, Y1, X2, Y2);
GotoXY(0, Y1);
}

void DrawCommand(const string& Command) override
{
Global->CtrlObject->CmdLine()->DrawFakeCommand(Command);
ScrollScreen(1);

m_Command = Command;
m_ShowCommand = true;
m_Finalised = false;

Global->CtrlObject->Desktop->TakeSnapshot();
int X1, Y1, X2, Y2;
Global->CtrlObject->CmdLine()->GetPosition(X1, Y1, X2, Y2);
GotoXY(0, Y1);
}

void ConsoleContext()
void Consolise() override
{
Activate();
assert(m_Activated);

if (m_Consolised)
return;
m_Consolised = true;
Expand All @@ -930,16 +933,14 @@ class execution_context: noncopyable
Console().SetTextAttributes(colors::PaletteColorToFarColor(COL_COMMANDLINEUSERSCREEN));
}

const string& Command() const
{
return m_Command;
}

~execution_context()
void DrawEpilog() override
{
if (!m_Activated)
return;

if (m_Finalised)
return;

if (m_Consolised)
{
if (Global->Opt->ShowKeyBar)
Expand All @@ -948,6 +949,8 @@ class execution_context: noncopyable
}
Console().Commit();
Global->ScrBuf->FillBuf();

m_Consolised = false;
}

// Empty command means that user simply pressed Enter in command line, in this case we don't want additional scrolling
Expand All @@ -958,20 +961,31 @@ class execution_context: noncopyable
}

Global->CtrlObject->Desktop->TakeSnapshot();

m_Finalised = true;
}

~execution_context() override
{
if (!m_Activated)
return;

Global->WindowManager->SubmergeWindow(Global->CtrlObject->Desktop);
Global->WindowManager->ActivateWindow(m_CurrentWindow);
Global->WindowManager->ResizeAllWindows();
--Global->SuppressClock;
}

private:
const window_ptr m_CurrentWindow;
const string m_Command;
const bool m_ShowCommand;
bool m_Activated;
bool m_Consolised;
window_ptr m_CurrentWindow;
string m_Command;
bool m_ShowCommand{};
bool m_Activated{};
bool m_Finalised{};
bool m_Consolised{};
};

static bool ProcessFarCommands(const string& Command, execution_context& ExecutionContext)
static bool ProcessFarCommands(const string& Command, const std::function<void(bool)>& ConsoleActivatior)
{
if (!StrCmpI(Command.data(), L"far:config"))
{
Expand Down Expand Up @@ -1008,7 +1022,7 @@ static bool ProcessFarCommands(const string& Command, execution_context& Executi
}
}

ExecutionContext.ConsoleContext();
ConsoleActivatior(true);
Console().Write(strOut);

return true;
Expand All @@ -1022,8 +1036,12 @@ void CommandLine::ExecString(execute_info& Info)
bool Silent = false;
bool IsUpdateNeeded = false;

const auto ExecutionContext = GetExecutionContext();

SCOPE_EXIT
{
ExecutionContext->DrawEpilog();

if (!IsUpdateNeeded)
return;

Expand All @@ -1044,12 +1062,20 @@ void CommandLine::ExecString(execute_info& Info)
}
};

execution_context ExecutionContext(Info.Command);
bool CommandDrawn = false;
auto DrawCommand = [&]
{
if (CommandDrawn)
return;
ExecutionContext->DrawCommand(Info.Command);
CommandDrawn = true;
};

if (Info.Command.empty())
{
// Just scroll the screen
ExecutionContext.Activate();
ExecutionContext->Activate();
DrawCommand();
return;
}

Expand All @@ -1072,30 +1098,39 @@ void CommandLine::ExecString(execute_info& Info)

if (!Info.NewWindow && !Info.RunAs)
{
if (ProcessFarCommands(Info.Command, ExecutionContext))
auto Activator = [&](bool DoConsolise)
{
ExecutionContext->Activate();
DrawCommand();
if (DoConsolise)
ExecutionContext->Consolise();
};

if (ProcessFarCommands(Info.Command, Activator))
return;

if (Global->CtrlObject->Plugins->ProcessCommandLine(Info.Command))
return;

if (ProcessOSCommands(Info.Command, ExecutionContext))
if (ProcessOSCommands(Info.Command, Activator))
return;
}
}

if (!Silent)
{
ConsoleTitle::SetFarTitle(ExecutionContext.Command());
ConsoleTitle::SetFarTitle(Info.Command);
}

ExecutionContext.Activate();
Execute(Info, false, Silent, [&ExecutionContext](){ ExecutionContext.ConsoleContext(); });

ExecutionContext->Activate();
DrawCommand();
Execute(Info, false, Silent, [&ExecutionContext](){ ExecutionContext->Consolise(); });

// BUGBUG do we really need to update panels at all?
IsUpdateNeeded = true;
}

bool CommandLine::ProcessOSCommands(const string& CmdLine, class execution_context& ExecutionContext)
bool CommandLine::ProcessOSCommands(const string& CmdLine, const std::function<void(bool)>& ConsoleActivatior)
{
auto SetPanel = Global->CtrlObject->Cp()->ActivePanel();

Expand All @@ -1122,7 +1157,7 @@ bool CommandLine::ProcessOSCommands(const string& CmdLine, class execution_conte

const auto FindHelpKey = [&FindKey]() { return FindKey(L'?'); };

ExecutionContext.Activate();
ConsoleActivatior(false);

if (CmdLine.size() > 1 && CmdLine[1] == L':' && (CmdLine.size() == 2 || !CmdLine.find_first_not_of(L' ', 2)))
{
Expand Down Expand Up @@ -1174,7 +1209,7 @@ bool CommandLine::ProcessOSCommands(const string& CmdLine, class execution_conte

if (!strOut.empty())
{
ExecutionContext.ConsoleContext();
ConsoleActivatior(true);
Console().Write(strOut);
}

Expand Down Expand Up @@ -1407,10 +1442,27 @@ void CommandLine::LockUpdatePanel(bool Mode)

void CommandLine::EnterPluginExecutionContext()
{
(m_PluginExecutionContext = std::make_unique<execution_context>(string(), false))->ConsoleContext();
m_PluginExecutionContext = GetExecutionContext();
m_PluginExecutionContext->Activate();
m_PluginExecutionContext->Consolise();
}

void CommandLine::LeavePluginExecutionContext()
{
m_PluginExecutionContext->DrawEpilog();
m_PluginExecutionContext.reset();
}

const std::shared_ptr<i_execution_context> CommandLine::GetExecutionContext()
{
if (auto Result = m_ExecutionContext.lock())
{
return Result;
}
else
{
Result = std::make_shared<execution_context>();
m_ExecutionContext = Result;
return Result;
}
}
16 changes: 13 additions & 3 deletions far/cmdline.hpp
Expand Up @@ -52,7 +52,15 @@ struct execute_info
bool RunAs{};
};

class execution_context;
class i_execution_context
{
public:
virtual void Activate() = 0;
virtual void DrawCommand(const string& Command) = 0;
virtual void DrawEpilog() = 0;
virtual void Consolise() = 0;
virtual ~i_execution_context() = default;
};

class CommandLine:public SimpleScreenObject
{
Expand Down Expand Up @@ -86,11 +94,12 @@ class CommandLine:public SimpleScreenObject
void DrawFakeCommand(const string& FakeCommand);
void EnterPluginExecutionContext();
void LeavePluginExecutionContext();
const std::shared_ptr<i_execution_context> GetExecutionContext();

private:
virtual void DisplayObject() override;
size_t DrawPrompt();
bool ProcessOSCommands(const string& CmdLine, execution_context& ExecutionContext);
bool ProcessOSCommands(const string& CmdLine, const std::function<void(bool)>& ConsoleActivatior);
std::list<std::pair<string, FarColor>> GetPrompt();
static bool IntChDir(const string& CmdLine,int ClosePanel,bool Selent=false);

Expand All @@ -103,7 +112,8 @@ class CommandLine:public SimpleScreenObject
int LastCmdPartLength;
string m_CurCmdStr;
std::stack<string> ppstack;
std::unique_ptr<execution_context> m_PluginExecutionContext;
std::weak_ptr<i_execution_context> m_ExecutionContext;
std::shared_ptr<i_execution_context> m_PluginExecutionContext;
};

#endif // CMDLINE_HPP_7E68C776_4AA9_4A24_BE9F_7F7FA6D50F30
55 changes: 29 additions & 26 deletions far/filelist.cpp
Expand Up @@ -4898,42 +4898,45 @@ bool FileList::ApplyCommand()
++UpdateDisabled;
GetSelName(nullptr,FileAttr);
Parent()->GetCmdLine()->LockUpdatePanel(true);
while (GetSelName(&strSelName,FileAttr,&strSelShortName) && !CheckForEsc())
{
string strListName, strAnotherListName;
string strShortListName, strAnotherShortListName;
string strConvertedCommand = strCommand;
int PreserveLFN=SubstFileName(nullptr,strConvertedCommand,strSelName, strSelShortName, &strListName, &strAnotherListName, &strShortListName, &strAnotherShortListName);
bool ListFileUsed=!strListName.empty()||!strAnotherListName.empty()||!strShortListName.empty()||!strAnotherShortListName.empty();

if (!strConvertedCommand.empty())
const auto ExecutionContext = Parent()->GetCmdLine()->GetExecutionContext();
while (GetSelName(&strSelName, FileAttr, &strSelShortName) && !CheckForEsc())
{
SCOPED_ACTION(PreserveLongName)(strSelShortName, PreserveLFN);
string strListName, strAnotherListName;
string strShortListName, strAnotherShortListName;
string strConvertedCommand = strCommand;
int PreserveLFN = SubstFileName(nullptr, strConvertedCommand, strSelName, strSelShortName, &strListName, &strAnotherListName, &strShortListName, &strAnotherShortListName);
bool ListFileUsed = !strListName.empty() || !strAnotherListName.empty() || !strShortListName.empty() || !strAnotherShortListName.empty();

execute_info Info;
Info.Command = strConvertedCommand;
Info.WaitMode = ListFileUsed? execute_info::wait_mode::wait_idle : execute_info::wait_mode::no_wait;
if (!strConvertedCommand.empty())
{
SCOPED_ACTION(PreserveLongName)(strSelShortName, PreserveLFN);

Parent()->GetCmdLine()->ExecString(Info);
//if (!(Global->Opt->ExcludeCmdHistory&EXCLUDECMDHISTORY_NOTAPPLYCMD))
// Global->CtrlObject->CmdHistory->AddToHistory(strConvertedCommand);
}
execute_info Info;
Info.Command = strConvertedCommand;
Info.WaitMode = ListFileUsed ? execute_info::wait_mode::wait_idle : execute_info::wait_mode::no_wait;

ClearLastGetSelection();
Parent()->GetCmdLine()->ExecString(Info);

if (!strListName.empty())
os::DeleteFile(strListName);
//if (!(Global->Opt->ExcludeCmdHistory&EXCLUDECMDHISTORY_NOTAPPLYCMD))
// Global->CtrlObject->CmdHistory->AddToHistory(strConvertedCommand);
}

if (!strAnotherListName.empty())
os::DeleteFile(strAnotherListName);
ClearLastGetSelection();

if (!strShortListName.empty())
os::DeleteFile(strShortListName);
if (!strListName.empty())
os::DeleteFile(strListName);

if (!strAnotherShortListName.empty())
os::DeleteFile(strAnotherShortListName);
}
if (!strAnotherListName.empty())
os::DeleteFile(strAnotherListName);

if (!strShortListName.empty())
os::DeleteFile(strShortListName);

if (!strAnotherShortListName.empty())
os::DeleteFile(strAnotherShortListName);
}
}
Parent()->GetCmdLine()->LockUpdatePanel(false);
Parent()->GetCmdLine()->Show();
if (Global->Opt->ShowKeyBar)
Expand Down

0 comments on commit 4ae9399

Please sign in to comment.