Skip to content

Commit

Permalink
M#3227 & refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed May 2, 2016
1 parent 24157d8 commit aa81ff1
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 85 deletions.
10 changes: 9 additions & 1 deletion far/changelog
@@ -1,4 +1,12 @@
drkns 30.04.2016 20:54:00 +0200 - build 4655
drkns 02.05.2016 12:23:29 +0200 - build 4656

1. 0003227: Не работает открытие папки в проводнике через Shift+Enter

2. FCTL_GETUSERSCREEN / FCTL_SETUSERSCREEN должны работать более адекватно.

3. Рефакторинг.

drkns 30.04.2016 20:54:00 +0200 - build 4655

1. 0003225: Зависание при нажатии на "крестик" консоли из модального редактора

Expand Down
23 changes: 21 additions & 2 deletions far/cmdline.cpp
Expand Up @@ -96,6 +96,8 @@ CommandLine::CommandLine(window_ptr Owner):
SetDelRemovesBlocks(Global->Opt->CmdLine.DelRemovesBlocks);
}

CommandLine::~CommandLine() = default;

void CommandLine::SetPersistentBlocks(bool Mode)
{
CmdStr.SetPersistentBlocks(Mode);
Expand Down Expand Up @@ -880,9 +882,10 @@ void CommandLine::SetPromptSize(int NewSize)
class execution_context: noncopyable
{
public:
execution_context(const string& Command):
execution_context(const string& Command, bool ShowCommand = true):
m_CurrentWindow(Global->WindowManager->GetCurrentWindow()),
m_Command(Command),
m_ShowCommand(ShowCommand),
m_Activated(),
m_Consolised()
{
Expand All @@ -898,7 +901,10 @@ class execution_context: noncopyable

Global->WindowManager->ActivateWindow(Global->CtrlObject->Desktop);
Global->WindowManager->ShowBackground();
Global->CtrlObject->CmdLine()->DrawFakeCommand(m_Command);
if (m_ShowCommand)
{
Global->CtrlObject->CmdLine()->DrawFakeCommand(m_Command);
}
ScrollScreen(1);
Global->CtrlObject->Desktop->TakeSnapshot();
int X1, Y1, X2, Y2;
Expand Down Expand Up @@ -963,6 +969,7 @@ class execution_context: noncopyable
private:
const window_ptr m_CurrentWindow;
const string m_Command;
const bool m_ShowCommand;
bool m_Activated;
bool m_Consolised;
};
Expand Down Expand Up @@ -1400,3 +1407,15 @@ void CommandLine::LockUpdatePanel(bool Mode)
{
m_Flags.Change(FCMDOBJ_LOCKUPDATEPANEL,Mode);
}

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

void CommandLine::LeavePluginExecutionContext()
{
m_PluginExecutionContext.reset();
}
9 changes: 7 additions & 2 deletions far/cmdline.hpp
Expand Up @@ -50,11 +50,13 @@ struct execute_info
bool RunAs;
};

class execution_context;

class CommandLine:public SimpleScreenObject
{
public:
CommandLine(window_ptr Owner);
virtual ~CommandLine() {};
virtual ~CommandLine();

virtual int ProcessKey(const Manager::Key& Key) override;
virtual int ProcessMouse(const MOUSE_EVENT_RECORD *MouseEvent) override;
Expand All @@ -80,11 +82,13 @@ class CommandLine:public SimpleScreenObject
int GetPromptSize() const {return PromptSize;}
void SetPromptSize(int NewSize);
void DrawFakeCommand(const string& FakeCommand);
void EnterPluginExecutionContext();
void LeavePluginExecutionContext();

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

Expand All @@ -97,6 +101,7 @@ class CommandLine:public SimpleScreenObject
int LastCmdPartLength;
string m_CurCmdStr;
std::stack<string> ppstack;
std::unique_ptr<execution_context> m_PluginExecutionContext;
};

#endif // CMDLINE_HPP_7E68C776_4AA9_4A24_BE9F_7F7FA6D50F30
2 changes: 1 addition & 1 deletion far/config.cpp
Expand Up @@ -1492,7 +1492,7 @@ void Options::InitConfigData()

string strDefaultLanguage = GetFarIniString(L"General", L"DefaultLanguage", L"English");

#define OPT_DEF(option, def) &option, std::remove_reference_t<decltype(option)>::type(def)
#define OPT_DEF(option, def) &option, std::remove_reference_t<decltype(option)>::underlying_type(def)

static FARConfigItem RoamingData[] =
{
Expand Down
2 changes: 1 addition & 1 deletion far/config.hpp
Expand Up @@ -141,7 +141,7 @@ template<class base_type, class derived>
class OptionImpl: public Option
{
public:
typedef base_type type;
typedef base_type underlying_type;

OptionImpl(): Option(base_type()) {}
OptionImpl(const base_type& Value): Option(Value) {}
Expand Down
2 changes: 1 addition & 1 deletion far/dizlist.cpp
Expand Up @@ -235,7 +235,7 @@ const wchar_t* DizList::Get(const string& Name, const string& ShortName, const _
}

template<class T>
auto Find_t(T& Map, const string& Name, const string& ShortName, uintptr_t Codepage)
static auto Find_t(T& Map, const string& Name, const string& ShortName, uintptr_t Codepage)
{
auto Iterator = Map.find(Name);
if (Iterator == Map.end())
Expand Down
7 changes: 6 additions & 1 deletion far/execute.cpp
Expand Up @@ -679,7 +679,7 @@ bool Execute(execute_info& Info, bool FolderRun, bool Silent, const std::functio
Info.ExecMode = Info.external;
}

const bool IsDirectory = os::fs::is_directory(strNewCmdStr);
bool IsDirectory = false;

if(Info.RunAs)
{
Expand All @@ -695,8 +695,13 @@ bool Execute(execute_info& Info, bool FolderRun, bool Silent, const std::functio
{
Silent = true;

auto Unquoted = strNewCmdStr;
Unquote(Unquoted);
IsDirectory = os::fs::is_directory(Unquoted);

if (strNewCmdPar.empty() && IsDirectory)
{
strNewCmdStr = Unquoted;
ConvertNameToFull(strNewCmdStr, strNewCmdStr);
Info.ExecMode = Info.direct;
FolderRun=true;
Expand Down
40 changes: 24 additions & 16 deletions far/farwinapi.cpp
Expand Up @@ -1266,23 +1266,21 @@ bool CreateDirectory(const string& PathName,LPSECURITY_ATTRIBUTES lpSecurityAttr

bool CreateDirectoryEx(const string& TemplateDirectory, const string& NewDirectory, LPSECURITY_ATTRIBUTES SecurityAttributes)
{
NTPath NtTemplateDirectory(TemplateDirectory);
NTPath NtNewDirectory(NewDirectory);
BOOL Result = FALSE;
for(size_t i = 0; i < 2 && !Result; ++i)

auto Create = [&](const string& Template)
{
Result = NtTemplateDirectory.empty()? ::CreateDirectory(NtNewDirectory.data(), SecurityAttributes) : ::CreateDirectoryEx(NtTemplateDirectory.data(), NtNewDirectory.data(), SecurityAttributes);
if(!Result && ElevationRequired(ELEVATION_MODIFY_REQUEST))
{
Result = Global->Elevation->fCreateDirectoryEx(NtTemplateDirectory, NtNewDirectory, SecurityAttributes);
}
if(!Result)
auto Result = Template.empty()? ::CreateDirectory(NtNewDirectory.data(), SecurityAttributes) != FALSE : ::CreateDirectoryEx(Template.data(), NtNewDirectory.data(), SecurityAttributes) != FALSE;
if (!Result && ElevationRequired(ELEVATION_MODIFY_REQUEST))
{
// CreateDirectoryEx may fail on some FS, try to create anyway.
NtTemplateDirectory.clear();
Result = Global->Elevation->fCreateDirectoryEx(Template, NtNewDirectory, SecurityAttributes);
}
}
return Result != FALSE;
return Result;
};

return Create(NTPath(TemplateDirectory)) ||
// CreateDirectoryEx may fail on some FS, try to create anyway.
Create({});
}

DWORD GetFileAttributes(const string& FileName)
Expand All @@ -1305,7 +1303,6 @@ bool SetFileAttributes(const string& FileName, DWORD dwFileAttributes)
Result = Global->Elevation->fSetFileAttributes(NtName, dwFileAttributes);
}
return Result;

}

bool CreateSymbolicLinkInternal(const string& Object, const string& Target, DWORD dwFlags)
Expand Down Expand Up @@ -1803,6 +1800,18 @@ string GetPrivateProfileString(const string& AppName, const string& KeyName, con
return string(Buffer.get(), size);
}

bool IsWow64Process()
{
#ifdef _WIN64
return false;
#else
auto GetValue = [] { BOOL Value = FALSE; return Imports().IsWow64Process(GetCurrentProcess(), &Value) && Value; };
static const auto Wow64Process = GetValue();
return Wow64Process;
#endif
}


DWORD GetAppPathsRedirectionFlag()
{
const auto GetFlag = []
Expand All @@ -1813,8 +1822,7 @@ DWORD GetAppPathsRedirectionFlag()
#ifdef _WIN64
return KEY_WOW64_32KEY;
#else
BOOL Wow64Process = FALSE;
if (Imports().IsWow64Process(GetCurrentProcess(), &Wow64Process) && Wow64Process)
if (IsWow64Process())
{
return KEY_WOW64_64KEY;
}
Expand Down
2 changes: 1 addition & 1 deletion far/farwinapi.hpp
Expand Up @@ -202,6 +202,7 @@ namespace os
bool SetFileSecurity(const string& Object, SECURITY_INFORMATION RequestedInformation, const FAR_SECURITY_DESCRIPTOR& SecurityDescriptor);
bool DetachVirtualDisk(const string& Object, VIRTUAL_STORAGE_TYPE& VirtualStorageType);
string GetPrivateProfileString(const string& AppName, const string& KeyName, const string& Default, const string& FileName);
bool IsWow64Process();
DWORD GetAppPathsRedirectionFlag();

bool CreateSymbolicLinkInternal(const string& Object, const string& Target, DWORD dwFlags);
Expand All @@ -210,7 +211,6 @@ namespace os
bool SetFileTimeEx(HANDLE Object, const FILETIME* CreationTime, const FILETIME* LastAccessTime, const FILETIME* LastWriteTime, const FILETIME* ChangeTime);
bool DetachVirtualDiskInternal(const string& Object, VIRTUAL_STORAGE_TYPE& VirtualStorageType);


namespace fs
{
class enum_file: noncopyable, public enumerator<enum_file, FAR_FIND_DATA>
Expand Down
8 changes: 3 additions & 5 deletions far/grabber.hpp
Expand Up @@ -63,15 +63,13 @@ class Grabber: public SimpleModal
void CopyGrabbedArea(bool Append, bool VerticalBlock);
void Reset();

struct GrabberArea
struct
{
COORD Begin;
COORD End;
COORD Current;
};

GrabberArea PrevArea;
GrabberArea GArea;
}
PrevArea, GArea;
bool ResetArea;
bool m_VerticalBlock;
static monitored<bool> m_StreamSelection;
Expand Down
13 changes: 9 additions & 4 deletions far/mix.cpp
Expand Up @@ -40,6 +40,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "cmdline.hpp"
#include "dlgedit.hpp"
#include "imports.hpp"


/*
Expand Down Expand Up @@ -205,15 +206,19 @@ SetAutocomplete::~SetAutocomplete()
void ReloadEnvironment()
{
// these are handled incorrectly by CreateEnvironmentBlock
const wchar_t* PreservedNames[] =
std::vector<const wchar_t*> PreservedNames =
{
#ifndef _WIN64 // TODO: Use IsWow64Process() too?
L"PROCESSOR_ARCHITECTURE", // incorrect under WOW64
#endif
L"USERDOMAIN", // absent
L"USERNAME", //absent
};

#ifndef _WIN64
if (os::IsWow64Process())
{
PreservedNames.emplace_back(L"PROCESSOR_ARCHITECTURE"); // Incorrect under WOW64
}
#endif

std::vector<std::pair<const wchar_t*, string>> PreservedVariables;
PreservedVariables.reserve(std::size(PreservedNames));

Expand Down
30 changes: 4 additions & 26 deletions far/plugapi.cpp
Expand Up @@ -1402,37 +1402,15 @@ intptr_t WINAPI apiPanelControl(HANDLE hPlugin,FILE_CONTROL_COMMANDS Command,int
return Processed;
}

// BUGBUG consider replacing with execution_context
case FCTL_SETUSERSCREEN:
case FCTL_GETUSERSCREEN:
{
if (!FPanels || !FPanels->LeftPanel() || !FPanels->RightPanel())
return FALSE;

Global->KeepUserScreen++;
FPanels->LeftPanel()->ProcessingPluginCommand++;
FPanels->RightPanel()->ProcessingPluginCommand++;
Console().Write(L"\n");
Global->ScrBuf->FillBuf();
Global->CtrlObject->Desktop->TakeSnapshot();
Global->KeepUserScreen--;
FPanels->LeftPanel()->ProcessingPluginCommand--;
FPanels->RightPanel()->ProcessingPluginCommand--;

// BUGBUG
Global->WindowManager->ResizeAllWindows();

Global->CtrlObject->CmdLine()->EnterPluginExecutionContext();
return TRUE;
}

case FCTL_GETUSERSCREEN:
case FCTL_SETUSERSCREEN:
{
Global->WindowManager->ShowBackground();
int Lock=Global->ScrBuf->GetLockCount();
Global->ScrBuf->SetLockCount(0);
MoveCursor(0,ScrY-1);
SetInitialCursorType();
Global->ScrBuf->Flush();
Global->ScrBuf->SetLockCount(Lock);
Global->CtrlObject->CmdLine()->LeavePluginExecutionContext();
return TRUE;
}

Expand Down
8 changes: 4 additions & 4 deletions far/scrbuf.hpp
Expand Up @@ -51,16 +51,16 @@ enum class flush_type
inline auto operator|(flush_type a, flush_type b)
{
return static_cast<flush_type>(
static_cast<std::underlying_type<flush_type>::type>(a) |
static_cast<std::underlying_type<flush_type>::type>(b)
static_cast<std::underlying_type_t<flush_type>>(a) |
static_cast<std::underlying_type_t<flush_type>>(b)
);
}

inline auto operator&(flush_type a, flush_type b)
{
return
static_cast<std::underlying_type<flush_type>::type>(a) &
static_cast<std::underlying_type<flush_type>::type>(b);
static_cast<std::underlying_type_t<flush_type>>(a) &
static_cast<std::underlying_type_t<flush_type>>(b);
}


Expand Down

0 comments on commit aa81ff1

Please sign in to comment.