Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Sep 26, 2024
1 parent b2191c0 commit 49841b2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 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-26 21:57:37+03:00 - build 6376

1. Refactoring.

--------------------------------------------------------------------------------
shmuel 2024-09-25 23:38:23+03:00 - build 6375

Expand Down
42 changes: 13 additions & 29 deletions far/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,10 @@ static_assert(MCODE_V_MENUINFOID == 0x80844); // Menu.Info.Id
struct DlgParam
{
unsigned long long Flags;
const FARMACROAREA Area;
DWORD Key;
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 @@ -606,28 +599,25 @@ bool KeyMacro::ProcessEvent(const FAR_INPUT_RECORD *Rec)
if (ctrldot||ctrlshiftdot) // признак конца записи?
{
m_InternalInput=1;
DWORD MacroKey;
// выставляем флаги по умолчанию.
unsigned long long Flags = 0;
int AssignRet=AssignMacroKey(MacroKey,Flags);
DlgParam Param {0,0,false};
int AssignRet = AssignMacroKey(&Param);

if (AssignRet == AMK_NOTCHANGED && !m_RecCode.empty())
if (AssignRet && !Param.Changed && !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))
if (ctrlshiftdot && !GetMacroSettings(Param.Key, Param.Flags))
{
AssignRet = AMK_CANCELED;
AssignRet = false;
}
}
m_InternalInput=0;
if (AssignRet != AMK_CANCELED)
if (AssignRet)
{
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);
const auto strKey = KeyToText(Param.Key);
Param.Flags |= m_Recording == MACROSTATE_RECORDING_COMMON? MFLAGS_NONE : MFLAGS_NOSENDKEYSTOPLUGINS;
LM_ProcessRecordedMacro(m_StartArea, strKey, m_RecCode, Param.Flags, m_RecDescription);
if (Global->Opt->AutoSaveSetup)
SaveMacros();
}
Expand Down Expand Up @@ -1433,7 +1423,7 @@ intptr_t KeyMacro::AssignMacroDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,v

// если УЖЕ есть такой макрос...
GetMacroData Data;
if (LM_GetMacro(&Data,KMParam->Area,strKeyText,true) && Data.IsKeyboardMacro)
if (LM_GetMacro(&Data,m_StartArea,strKeyText,true) && Data.IsKeyboardMacro)
{
// общие макросы учитываем только при удалении.
if (m_RecCode.empty() || Data.Area!=MACROAREA_COMMON)
Expand Down Expand Up @@ -1511,7 +1501,7 @@ intptr_t KeyMacro::AssignMacroDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,v
return Dlg->DefProc(Msg,Param1,Param2);
}

int KeyMacro::AssignMacroKey(DWORD &MacroKey, unsigned long long& Flags)
bool KeyMacro::AssignMacroKey(DlgParam *Param)
{
/*
1 2 3
Expand All @@ -1538,18 +1528,12 @@ int KeyMacro::AssignMacroKey(DWORD &MacroKey, unsigned long long& Flags)
{DI_COMBOBOX, {{5, 3}, {28, 3}}, DIF_FOCUS | DIF_DEFAULTBUTTON, },
});

DlgParam Param{ Flags, m_StartArea, 0 };
Global->IsProcessAssignMacroKey++;
const auto Dlg = Dialog::create(MacroAssignDlg, std::bind_front(&KeyMacro::AssignMacroDlgProc, this), &Param);
const auto Dlg = Dialog::create(MacroAssignDlg, std::bind_front(&KeyMacro::AssignMacroDlgProc, this), Param);
Dlg->SetPosition({ -1, -1, 34, 6 });
Dlg->SetHelp(L"KeyMacro"sv);
Dlg->Process();
Global->IsProcessAssignMacroKey--;

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

MacroKey = Param.Key;
Flags = Param.Flags;
return Param.Changed ? AMK_CHANGED : AMK_NOTCHANGED;
return (Dlg->GetExitCode() >= 0);
}
3 changes: 2 additions & 1 deletion far/macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct MacroPanelSelect
};

class Dialog;
struct DlgParam;

class KeyMacro: noncopyable
{
Expand Down Expand Up @@ -117,7 +118,7 @@ class KeyMacro: noncopyable
private:
static int GetExecutingState();
intptr_t AssignMacroDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* Param2);
int AssignMacroKey(DWORD& MacroKey, unsigned long long& Flags);
bool AssignMacroKey(DlgParam *Param);
bool GetMacroSettings(int Key, unsigned long long &Flags, string_view Src = {}, string_view Descr = {});
intptr_t ParamMacroDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* Param2);
void RestoreMacroChar() const;
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6375
6376

0 comments on commit 49841b2

Please sign in to comment.