Skip to content

Commit

Permalink
preserve aliases on console detach
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Feb 28, 2016
1 parent 0cbd875 commit f29c977
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
6 changes: 5 additions & 1 deletion far/changelog
@@ -1,4 +1,8 @@
drkns 27.02.2016 18:05:26 +0200 - build 4564
drkns 28.02.2016 20:01:24 +0200 - build 4565

1. При детаче консоли (Ctrl+Shift+Tab) скопируем алиасы из старой в новую.

drkns 27.02.2016 18:05:26 +0200 - build 4564

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

Expand Down
41 changes: 41 additions & 0 deletions far/console.cpp
Expand Up @@ -529,6 +529,47 @@ virtual bool GetAlias(LPCWSTR Source, LPWSTR TargetBuffer, size_t TargetBufferLe
return GetConsoleAlias(const_cast<LPWSTR>(Source), TargetBuffer, static_cast<DWORD>(TargetBufferLength), const_cast<LPWSTR>(ExeName))!=0;
}

virtual std::unordered_map<string, std::unordered_map<string, string>> GetAllAliases() const
{
std::unordered_map<string, std::unordered_map<string, string>> Result;
if (const auto ExeLength = GetConsoleAliasExesLength())
{
std::vector<wchar_t> ExeBuffer(ExeLength / sizeof(wchar_t) + 1);
std::vector<wchar_t> AliasesBuffer;

if (GetConsoleAliasExes(ExeBuffer.data(), ExeLength))
{
FOR(const auto& ExeToken, os::enum_strings(ExeBuffer.data()))
{
string Exe(ALL_RANGE(ExeToken));
auto& ExeMap = Result[Exe];
const auto AliasesLength = GetConsoleAliasesLength(const_cast<wchar_t*>(Exe.data()));
AliasesBuffer.resize(AliasesLength / sizeof(wchar_t) + 1);
if (GetConsoleAliases(AliasesBuffer.data(), AliasesLength, const_cast<wchar_t*>(Exe.data())))
{
FOR(const auto& AliasToken, os::enum_strings(AliasesBuffer.data()))
{
auto SeparatorPos = std::find(ALL_RANGE(AliasToken), L'=');
ExeMap.insert(std::make_pair(string(AliasToken.begin(), SeparatorPos), string(SeparatorPos + 1, AliasToken.end())));
}
}
}
}
}
return Result;
}

virtual void SetAllAliases(const std::unordered_map<string, std::unordered_map<string, string>>& Aliases) const
{
FOR(const auto& ExeItem, Aliases)
{
FOR(const auto& AliasesItem, ExeItem.second)
{
AddConsoleAlias(const_cast<wchar_t*>(AliasesItem.first.data()), const_cast<wchar_t*>(AliasesItem.second.data()), const_cast<wchar_t*>(ExeItem.first.data()));
}
}
}

virtual bool GetDisplayMode(DWORD& Mode) const override
{
return GetConsoleDisplayMode(&Mode)!=FALSE;
Expand Down
4 changes: 4 additions & 0 deletions far/console.hpp
Expand Up @@ -111,6 +111,10 @@ class console: noncopyable

virtual bool GetAlias(LPCWSTR Source, LPWSTR TargetBuffer, size_t TargetBufferLength, LPCWSTR ExeName) const = 0;

virtual std::unordered_map<string, std::unordered_map<string, string>> GetAllAliases() const = 0;

virtual void SetAllAliases(const std::unordered_map<string, std::unordered_map<string, string>>& Aliases) const = 0;

virtual bool GetDisplayMode(DWORD& Mode) const = 0;

virtual COORD GetLargestWindowSize() const = 0;
Expand Down
4 changes: 3 additions & 1 deletion far/execute.cpp
Expand Up @@ -956,6 +956,8 @@ bool Execute(execute_info& Info, bool FolderRun, bool Silent, const std::functio
(ctrl ?bCtrl:!bCtrl) &&
(shift ?bShift:!bShift))
{
auto Aliases = Console().GetAllAliases();

ConsoleIcons().restorePreviousIcons();

Console().ReadInput(ir, 256, rd);
Expand All @@ -981,7 +983,7 @@ bool Execute(execute_info& Info, bool FolderRun, bool Silent, const std::functio
InitConsole(0);

ConsoleIcons().setFarIcons();

Console().SetAllAliases(Aliases);
stop=1;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4564)m4_dnl
m4_define(BUILD,4565)m4_dnl

0 comments on commit f29c977

Please sign in to comment.