Skip to content

Commit

Permalink
experimental: internal associations work in command line
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Jun 23, 2016
1 parent 3dde279 commit e049326
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 24 deletions.
4 changes: 4 additions & 0 deletions far/changelog
@@ -1,3 +1,7 @@
drkns 24.06.2016 01:15:01 +0200 - build 4723

1. Очень экспериментальная фича: встроенные ассоциации распространяются на комстроку.

drkns 23.06.2016 22:46:27 +0200 - build 4722

1. Уточнение 4710.
Expand Down
43 changes: 31 additions & 12 deletions far/execute.cpp
Expand Up @@ -48,6 +48,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "constitle.hpp"
#include "console.hpp"
#include "language.hpp"
#include "filetype.hpp"

enum class image_type
{
Expand Down Expand Up @@ -652,7 +653,7 @@ void OpenFolderInShell(const string& Folder)
Execute(Info, true, true);
}

bool Execute(execute_info& Info, bool FolderRun, bool Silent, const std::function<void()>& ConsoleActivator)
void Execute(execute_info& Info, bool FolderRun, bool Silent, const std::function<void()>& ConsoleActivator)
{
bool Result = false;
string strNewCmdStr;
Expand Down Expand Up @@ -770,17 +771,37 @@ bool Execute(execute_info& Info, bool FolderRun, bool Silent, const std::functio
Info.ExecMode = execute_info::exec_mode::external;
strNewCmdStr = Info.Command;
}
else if (GetImageType(FoundModuleName, ImageType) || GetAssociatedImageType(FoundModuleName, ImageType) || GetImageTypeFallback(ImageType))
else
{
// We can run it directly
Info.ExecMode = execute_info::exec_mode::direct;
strNewCmdStr = FoundModuleName;
strNewCmdPar = os::env::expand_strings(strNewCmdPar);
auto FoundModuleNameShort = FoundModuleName;
ConvertNameToShort(FoundModuleNameShort, FoundModuleNameShort);
const auto LastX = WhereX(), LastY = WhereY();
if (ProcessLocalFileTypes(FoundModuleName, FoundModuleNameShort, FILETYPE_EXEC, Info.WaitMode == execute_info::wait_mode::wait_finish, false, [&](execute_info& AssocInfo)
{
GotoXY(LastX, LastY);
if (!strNewCmdPar.empty())
{
AssocInfo.Command.append(L" ").append(strNewCmdPar);
}
Execute(AssocInfo, FolderRun, Silent, ConsoleActivator);
}))
{
return;
}
GotoXY(LastX, LastY);

if (ImageType == image_type::graphical)
if (GetImageType(FoundModuleName, ImageType) || GetAssociatedImageType(FoundModuleName, ImageType) || GetImageTypeFallback(ImageType))
{
Silent = true;
Info.NewWindow = true;
// We can run it directly
Info.ExecMode = execute_info::exec_mode::direct;
strNewCmdStr = FoundModuleName;
strNewCmdPar = os::env::expand_strings(strNewCmdPar);

if (ImageType == image_type::graphical)
{
Silent = true;
Info.NewWindow = true;
}
}
}
}
Expand Down Expand Up @@ -873,7 +894,7 @@ bool Execute(execute_info& Info, bool FolderRun, bool Silent, const std::functio
if (strComspec.empty())
{
Message(MSG_WARNING, 1, MSG(MError), MSG(MComspecNotFound), MSG(MOk));
return false;
return;
}
}

Expand Down Expand Up @@ -1067,8 +1088,6 @@ bool Execute(execute_info& Info, bool FolderRun, bool Silent, const std::functio
nullptr,
{ Info.ExecMode == execute_info::exec_mode::direct? strNewCmdStr : strComspec });
}

return Result;
}


Expand Down
2 changes: 1 addition & 1 deletion far/execute.hpp
Expand Up @@ -39,7 +39,7 @@ bool GetShellType(const string&Ext, string &strType, ASSOCIATIONTYPE aType=AT_FI

void OpenFolderInShell(const string& Folder);

bool Execute(struct execute_info& Info, bool FolderRun, bool Silent, const std::function<void()>& ConsoleActivator = nullptr);
void Execute(struct execute_info& Info, bool FolderRun, bool Silent, const std::function<void()>& ConsoleActivator = nullptr);

bool IsExecutable(const string& Filename);

Expand Down
24 changes: 15 additions & 9 deletions far/filetype.cpp
Expand Up @@ -89,15 +89,10 @@ size_t GetDescriptionWidth()
- Убрал непонятный мне запрет на использование маски файлов типа "*.*"
(был когда-то, вроде, такой баг-репорт)
*/
bool ProcessLocalFileTypes(const string& Name, const string& ShortName, FILETYPE_MODE Mode, bool AlwaysWaitFinish)
bool ProcessLocalFileTypes(const string& Name, const string& ShortName, FILETYPE_MODE Mode, bool AlwaysWaitFinish, bool AddToHistory, const std::function<void(execute_info&)>& Launcher)
{
string strCommand, strDescription, strMask;
{
const auto TypesMenu = VMenu2::create(MSG(MSelectAssocTitle), nullptr, 0, ScrY - 4);
TypesMenu->SetHelp(L"FileAssoc");
TypesMenu->SetMenuFlags(VMENU_WRAPMODE);
TypesMenu->SetId(SelectAssocMenuId);

int ActualCmdCount=0; // отображаемых ассоциаций в меню
filemasks FMask; // для работы с масками файлов

Expand All @@ -106,6 +101,8 @@ bool ProcessLocalFileTypes(const string& Name, const string& ShortName, FILETYPE
unsigned __int64 id;
string FileName = PointToName(Name);

std::vector<MenuItemEx> MenuItems;

while (ConfigProvider().AssocConfig()->EnumMasksForType(Mode,Index++,&id,strMask))
{
strCommand.clear();
Expand Down Expand Up @@ -144,7 +141,7 @@ bool ProcessLocalFileTypes(const string& Name, const string& ShortName, FILETYPE
MenuItemEx TypesMenuItem(strDescription);
TypesMenuItem.SetSelect(Index==1);
TypesMenuItem.UserData = strCommand;
TypesMenu->AddItem(TypesMenuItem);
MenuItems.push_back(std::move(TypesMenuItem));
}

if (!CommandCount)
Expand All @@ -155,6 +152,15 @@ bool ProcessLocalFileTypes(const string& Name, const string& ShortName, FILETYPE

int ExitCode=0;

const auto TypesMenu = VMenu2::create(MSG(MSelectAssocTitle), nullptr, 0, ScrY - 4);
TypesMenu->SetHelp(L"FileAssoc");
TypesMenu->SetMenuFlags(VMENU_WRAPMODE);
TypesMenu->SetId(SelectAssocMenuId);
for (auto& Item : MenuItems)
{
TypesMenu->AddItem(std::move(Item));
}

if (ActualCmdCount>1)
{
ExitCode=TypesMenu->Run();
Expand Down Expand Up @@ -187,9 +193,9 @@ bool ProcessLocalFileTypes(const string& Name, const string& ShortName, FILETYPE
Info.Command = strCommand;
Info.WaitMode = AlwaysWaitFinish? execute_info::wait_mode::wait_finish : ListFileUsed? execute_info::wait_mode::wait_idle : execute_info::wait_mode::no_wait;

Global->CtrlObject->CmdLine()->ExecString(Info);
Launcher? Launcher(Info) : Global->CtrlObject->CmdLine()->ExecString(Info);

if (!(Global->Opt->ExcludeCmdHistory&EXCLUDECMDHISTORY_NOTFARASS) && !AlwaysWaitFinish) //AN
if (AddToHistory && !(Global->Opt->ExcludeCmdHistory&EXCLUDECMDHISTORY_NOTFARASS) && !AlwaysWaitFinish) //AN
{
const auto curDir = Global->CtrlObject->CmdLine()->GetCurDir();
Global->CtrlObject->CmdHistory->AddToHistory(strCommand, HR_DEFAULT, nullptr, nullptr, curDir.data());
Expand Down
2 changes: 1 addition & 1 deletion far/filetype.hpp
Expand Up @@ -53,7 +53,7 @@ enum FILETYPE_MODE
*/
bool GetFiletypeOpenMode(int keyPressed, FILETYPE_MODE& mode, bool& shouldForceInternal);

bool ProcessLocalFileTypes(const string& Name, const string& ShortName, FILETYPE_MODE Mode, bool AlwaysWaitFinish);
bool ProcessLocalFileTypes(const string& Name, const string& ShortName, FILETYPE_MODE Mode, bool AlwaysWaitFinish, bool AddToHistory = true, const std::function<void(struct execute_info&)>& Launcher = nullptr);
void ProcessExternal(const string& Command, const string& Name, const string& ShortName, bool AlwaysWaitFinish);
void EditFileTypes();

Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4722)m4_dnl
m4_define(BUILD,4723)m4_dnl

0 comments on commit e049326

Please sign in to comment.