Skip to content

Commit

Permalink
FCTL_<G|S>ETUSERSCREEN available in -e and -v modes
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Aug 14, 2017
1 parent 7cfb35d commit 82f56bf
Show file tree
Hide file tree
Showing 15 changed files with 325 additions and 209 deletions.
4 changes: 4 additions & 0 deletions far/changelog
@@ -1,3 +1,7 @@
drkns 14.08.2017 21:38:39 +0000 - build 5006

1. Теперь FCTL_<G|S>ETUSERSCREEN можно использовать и из режимов редактора (-e) и просмотра (-v).

drkns 13.08.2017 17:07:42 +0000 - build 5005

1. Уточнение 4959.
Expand Down
177 changes: 1 addition & 176 deletions far/cmdline.cpp
Expand Up @@ -873,120 +873,6 @@ void CommandLine::SetPromptSize(int NewSize)
PromptSize = NewSize? std::clamp(NewSize, 5, 95) : DEFAULT_CMDLINE_WIDTH;
}

class execution_context: noncopyable, public i_execution_context
{
public:
void Activate() override
{
if (m_Activated)
return;

m_Activated = true;
++Global->SuppressIndicators;
++Global->SuppressClock;

Global->WindowManager->ModalDesktopWindow();
Global->WindowManager->PluginCommit();
}

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

m_Command = Command;
m_ShowCommand = true;

DoPrologue();
}

void Consolise(bool SetTextColour = true) override
{
assert(m_Activated);

if (m_Consolised)
return;
m_Consolised = true;

Global->ScrBuf->MoveCursor(0, WhereY());
SetInitialCursorType();

if (!m_Command.empty())
ConsoleTitle::SetFarTitle(m_Command);

// BUGBUG, implement better & safer way to do this
const auto LockCount = Global->ScrBuf->GetLockCount();
Global->ScrBuf->SetLockCount(0);

Global->ScrBuf->Flush();

// BUGBUG, implement better & safer way to do this
Global->ScrBuf->SetLockCount(LockCount);

if (SetTextColour)
Console().SetTextAttributes(colors::PaletteColorToFarColor(COL_COMMANDLINEUSERSCREEN));
}

void DoPrologue() override
{
Global->CtrlObject->Desktop->TakeSnapshot();
int X1, Y1, X2, Y2;
Global->CtrlObject->CmdLine()->GetPosition(X1, Y1, X2, Y2);
GotoXY(0, Y1);
m_Finalised = false;
}

void DoEpilogue() override
{
if (!m_Activated)
return;

if (m_Finalised)
return;

if (m_Consolised)
{
if (Global->Opt->ShowKeyBar)
{
Console().Write(L"\n");
}
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
// ShowCommand is false when there is no "command" - class instantiated by FCTL_GETUSERSCREEN.
if (!m_Command.empty() || !m_ShowCommand)
{
ScrollScreen(1);
}

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

m_Finalised = true;
}

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

Global->WindowManager->UnModalDesktopWindow();
Global->WindowManager->PluginCommit();
--Global->SuppressClock;
--Global->SuppressIndicators;
}

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

static bool ProcessFarCommands(const string& Command, const std::function<void(bool)>& ConsoleActivatior)
{
if (equal_icase(Command, L"far:config"_sv))
Expand Down Expand Up @@ -1041,7 +927,7 @@ void CommandLine::ExecString(execute_info& Info)
bool Silent = false;
bool IsUpdateNeeded = false;

const auto ExecutionContext = GetExecutionContext();
const auto ExecutionContext = Global->CtrlObject->Desktop->ConsoleSession().GetContext();

SCOPE_EXIT
{
Expand Down Expand Up @@ -1454,64 +1340,3 @@ void CommandLine::LockUpdatePanel(bool Mode)
{
m_Flags.Change(FCMDOBJ_LOCKUPDATEPANEL,Mode);
}

void CommandLine::EnterPluginExecutionContext()
{
if (!m_PluginExecutionContextInvocations)
{
m_PluginExecutionContext = GetExecutionContext();
m_PluginExecutionContext->Activate();
}
else
{
m_PluginExecutionContext->DoEpilogue();
}

m_PluginExecutionContext->DoPrologue();
m_PluginExecutionContext->Consolise(!m_PluginExecutionContextInvocations);

++m_PluginExecutionContextInvocations;
}

void CommandLine::LeavePluginExecutionContext()
{
if (m_PluginExecutionContextInvocations)
--m_PluginExecutionContextInvocations;

if (m_PluginExecutionContext)
{
m_PluginExecutionContext->DoEpilogue();
}
else
{
// FCTL_SETUSERSCREEN without corresponding FCTL_GETUSERSCREEN
// Old (1.x) behaviour emulation:
if (Global->Opt->ShowKeyBar)
{
Console().Write(L"\n");
}
Console().Commit();
Global->ScrBuf->FillBuf();
ScrollScreen(1);
Global->CtrlObject->Desktop->TakeSnapshot();
}

if (m_PluginExecutionContextInvocations)
return;

m_PluginExecutionContext.reset();
}

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;
}
}
17 changes: 0 additions & 17 deletions far/cmdline.hpp
Expand Up @@ -52,17 +52,6 @@ struct execute_info
bool RunAs{};
};

class i_execution_context
{
public:
virtual void Activate() = 0;
virtual void DrawCommand(const string& Command) = 0;
virtual void DoPrologue() = 0;
virtual void DoEpilogue() = 0;
virtual void Consolise(bool SetTextColour = true) = 0;
virtual ~i_execution_context() = default;
};

class CommandLine:public SimpleScreenObject
{
public:
Expand Down Expand Up @@ -93,9 +82,6 @@ class CommandLine:public SimpleScreenObject
int GetPromptSize() const {return PromptSize;}
void SetPromptSize(int NewSize);
void DrawFakeCommand(const string& FakeCommand);
void EnterPluginExecutionContext();
void LeavePluginExecutionContext();
std::shared_ptr<i_execution_context> GetExecutionContext();

private:
virtual void DisplayObject() override;
Expand All @@ -113,9 +99,6 @@ class CommandLine:public SimpleScreenObject
int LastCmdPartLength;
string m_CurCmdStr;
std::stack<string> ppstack;
std::weak_ptr<i_execution_context> m_ExecutionContext;
std::shared_ptr<i_execution_context> m_PluginExecutionContext;
unsigned m_PluginExecutionContextInvocations{};
};

#endif // CMDLINE_HPP_7E68C776_4AA9_4A24_BE9F_7F7FA6D50F30

0 comments on commit 82f56bf

Please sign in to comment.