Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Sep 25, 2024
1 parent fefba90 commit b2191c0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
shmuel 2024-09-25 23:38:23+03:00 - build 6375

1. Refactoring.

--------------------------------------------------------------------------------
drkns 2024-09-23 16:09:43+01:00 - build 6374

Expand Down
2 changes: 1 addition & 1 deletion far/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2480,7 +2480,7 @@ void Options::Save(bool Manual)
filters::Save(Manual);
SavePanelModes(Manual);
SaveSortLayers(Manual);
Global->CtrlObject->Macro.SaveMacros(Manual);
Global->CtrlObject->Macro.SaveMacros();
}

enum
Expand Down
44 changes: 23 additions & 21 deletions far/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,17 @@ static_assert(MCODE_V_MENUINFOID == 0x80844); // Menu.Info.Id
struct DlgParam
{
unsigned long long Flags;
FARMACROAREA Area;
const FARMACROAREA Area;
DWORD Key;
int Recurse;
bool Changed;
};

enum ASSIGN_MACRO_KEY_STATUS {
AMK_CANCELED, // operation was canceled
AMK_NOTCHANGED, // Macro Settings dialog was not called
AMK_CHANGED, // Macro Settings dialog was called
};

static const wchar_t* GetMacroLanguage(FARKEYMACROFLAGS Flags)
{
switch(Flags & KMFLAGS_LANGMASK)
Expand Down Expand Up @@ -443,7 +448,7 @@ bool KeyMacro::LoadMacros(bool FromFar, bool InitedRAM, const FarMacroLoad *Data
return CallMacroPlugin(&info);
}

bool KeyMacro::SaveMacros(bool /*always*/)
bool KeyMacro::SaveMacros()
{
OpenMacroPluginInfo info{ MCT_WRITEMACROS };
return CallMacroPlugin(&info);
Expand Down Expand Up @@ -606,33 +611,29 @@ bool KeyMacro::ProcessEvent(const FAR_INPUT_RECORD *Rec)
unsigned long long Flags = 0;
int AssignRet=AssignMacroKey(MacroKey,Flags);

if (AssignRet && AssignRet!=2 && !m_RecCode.empty())
if (AssignRet == AMK_NOTCHANGED && !m_RecCode.empty())
{
m_RecCode = concat(L"Keys(\""sv, m_RecCode, L"\")"sv);
// добавим проверку на удаление
// если удаляем или был вызван диалог изменения, то не нужно выдавать диалог настройки.
//if (MacroKey != (DWORD)-1 && (Key==KEY_CTRLSHIFTDOT || Recording==2) && RecBufferSize)
if (ctrlshiftdot && !GetMacroSettings(MacroKey,Flags))
{
AssignRet=0;
AssignRet = AMK_CANCELED;
}
}
m_InternalInput=0;
if (AssignRet)
if (AssignRet != AMK_CANCELED)
{
const auto strKey = KeyToText(MacroKey);
Flags |= m_Recording == MACROSTATE_RECORDING_COMMON? MFLAGS_NONE : MFLAGS_NOSENDKEYSTOPLUGINS;
LM_ProcessRecordedMacro(m_StartArea, strKey, m_RecCode, Flags, m_RecDescription);
if (Global->Opt->AutoSaveSetup)
SaveMacros();
}

m_Recording=MACROSTATE_NOMACRO;
m_RecCode.clear();
m_RecDescription.clear();
Global->ScrBuf->RestoreMacroChar();

if (Global->Opt->AutoSaveSetup)
SaveMacros(false); // записать только изменения!

return true;
}
else
Expand Down Expand Up @@ -1213,8 +1214,7 @@ bool KeyMacro::GetMacroSettings(int Key, unsigned long long& Flags, string_view
MacroSettingsDlg[MS_EDIT_SEQUENCE].strData = Src.empty()? m_RecCode : Src;
MacroSettingsDlg[MS_EDIT_DESCR].strData = Descr.empty()? m_RecDescription : Descr;

DlgParam Param{ 0, MACROAREA_OTHER, 0 };
const auto Dlg = Dialog::create(MacroSettingsDlg, std::bind_front(&KeyMacro::ParamMacroDlgProc, this), &Param);
const auto Dlg = Dialog::create(MacroSettingsDlg, std::bind_front(&KeyMacro::ParamMacroDlgProc, this), nullptr);
Dlg->SetPosition({ -1, -1, 73, 21 });
Dlg->SetHelp(L"KeyMacroSetting"sv);
Dlg->Process();
Expand Down Expand Up @@ -1319,8 +1319,9 @@ DWORD KeyMacro::GetMacroParseError(point& ErrPos, string& ErrSrc)
// обработчик диалогового окна назначения клавиши
intptr_t KeyMacro::AssignMacroDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* Param2)
{
static unsigned LastKey = 0;
static DlgParam *KMParam=nullptr;
static int Recurse;
static unsigned LastKey;
static DlgParam *KMParam;
const INPUT_RECORD* record=nullptr;
unsigned key = 0;
bool KeyIsValid = false;
Expand All @@ -1340,6 +1341,7 @@ intptr_t KeyMacro::AssignMacroDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,v
{
KMParam = static_cast<DlgParam*>(Param2);
LastKey=0;
Recurse=0;
// <Клавиши, которые нельзя ввести в диалоге назначения>
static const DWORD PreDefKeyMain[]=
{
Expand Down Expand Up @@ -1384,7 +1386,7 @@ intptr_t KeyMacro::AssignMacroDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,v
LastKey=0;
key = KeyNameToKey(static_cast<FarDialogItem*>(Param2)->Data);

if (key && !KMParam->Recurse)
if (key && !Recurse)
KeyIsValid = true;
}
else if (Msg == DN_CONTROLINPUT && record->EventType==KEY_EVENT && (((key&KEY_END_SKEY) < KEY_END_FKEY) ||
Expand Down Expand Up @@ -1497,9 +1499,9 @@ intptr_t KeyMacro::AssignMacroDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,v
}
}

KMParam->Recurse++;
Recurse++;
Dlg->SendMessage(DM_SETTEXTPTR,2, UNSAFE_CSTR(strKeyText));
KMParam->Recurse--;
Recurse--;
//if(key == KEY_F1 && LastKey == KEY_F1)
//LastKey=-1;
//else
Expand Down Expand Up @@ -1545,9 +1547,9 @@ int KeyMacro::AssignMacroKey(DWORD &MacroKey, unsigned long long& Flags)
Global->IsProcessAssignMacroKey--;

if (Dlg->GetExitCode() < 0)
return 0;
return AMK_CANCELED;

MacroKey = Param.Key;
Flags = Param.Flags;
return Param.Changed ? 2 : 1;
return Param.Changed ? AMK_CHANGED : AMK_NOTCHANGED;
}
2 changes: 1 addition & 1 deletion far/macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class KeyMacro: noncopyable
static bool IsHistoryDisabled(int TypeHistory);
static bool MacroExists(int Key, FARMACROAREA Area, bool UseCommon);
static void RunStartMacro();
static bool SaveMacros(bool always);
static bool SaveMacros();
static void SetMacroConst(int ConstIndex, long long Value);
static long long GetMacroConst(int ConstIndex);
static bool PostNewMacro(const wchar_t* Sequence, FARKEYMACROFLAGS InputFlags, DWORD AKey = 0);
Expand Down
2 changes: 1 addition & 1 deletion far/plugapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2333,7 +2333,7 @@ intptr_t WINAPI apiMacroControl(const UUID* PluginId, FAR_MACRO_CONTROL_COMMANDS

// Param1=0, Param2 - 0
case MCTL_SAVEALL:
return !Macro.IsRecording() && Macro.SaveMacros(true);
return !Macro.IsRecording() && Macro.SaveMacros();

// Param1=FARMACROSENDSTRINGCOMMAND, Param2 - MacroSendMacroText*
case MCTL_SENDSTRING:
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6374
6375

0 comments on commit b2191c0

Please sign in to comment.