Skip to content

Commit

Permalink
gh-802: Macro API to report VMenu alignment state. Part 2: Plumbing.
Browse files Browse the repository at this point in the history
  • Loading branch information
MKadaner committed Jan 24, 2025
1 parent adb7a17 commit 2b4e66f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 8 deletions.
1 change: 1 addition & 0 deletions far/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,7 @@ long long Dialog::VMProcess(int OpCode,void *vParam,long long iParam)
case MCODE_V_MENU_VALUE:
case MCODE_F_MENU_FILTER:
case MCODE_F_MENU_FILTERSTR:
case MCODE_V_MENU_HORIZONTALALIGNMENT:
{
const auto str = static_cast<const wchar_t*>(vParam);

Expand Down
1 change: 1 addition & 0 deletions far/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ static_assert(MCODE_V_HELPTOPIC == 0x80841); // Help.Topic
static_assert(MCODE_V_HELPSELTOPIC == 0x80842); // Help.SelTopic
static_assert(MCODE_V_MENU_VALUE == 0x80843); // Menu.Value
static_assert(MCODE_V_MENUINFOID == 0x80844); // Menu.Info.Id
static_assert(MCODE_V_MENU_HORIZONTALALIGNMENT == 0x80845); // Menu.HorizontalAlignment

// для диалога назначения клавиши
struct DlgParam
Expand Down
17 changes: 17 additions & 0 deletions far/macroapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,23 @@ void KeyMacro::CallFar(intptr_t CheckCode, FarMacroCall* Data)

return api.PassValue(tmpVar);
}

case MCODE_V_MENU_HORIZONTALALIGNMENT:
{
long long Result = -1;

const auto CurArea = GetArea();

if (IsMenuArea(CurArea) || CurArea == MACROAREA_DIALOG)
{
if (CurrentWindow)
{
Result = CurrentWindow->VMProcess(CheckCode);
}
}

return api.PassValue(Result);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions far/macroopcode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ enum MACRO_OP_CODE

MCODE_V_MENU_VALUE, // Menu.Value
MCODE_V_MENUINFOID, // Menu.Info.Id
MCODE_V_MENU_HORIZONTALALIGNMENT, // Menu.HorizontalAlignment
};

#endif // MACROOPCODE_HPP_57E7AB95_BB74_4575_9054_B2137FAD4CED
28 changes: 22 additions & 6 deletions far/vmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ enum class item_hscroll_policy
// Everything is relative to menu_layout::TextArea::first (Left edge).
class vmenu_horizontal_tracker
{
enum class alignment { Left, Right, Annotation };

struct bulk_update_scope_guard
{
NONCOPYABLE(bulk_update_scope_guard);
Expand All @@ -206,6 +204,8 @@ class vmenu_horizontal_tracker
};

public:
enum class alignment { Left, Right, Annotation };

void clear() { *this = {}; }

void add_item(int const ItemHPos, int const ItemLength, int const ItemAnnotationPos)
Expand Down Expand Up @@ -253,8 +253,9 @@ class vmenu_horizontal_tracker
add_item(NewItemHPos, ItemLength, ItemAnnotationPos);
}

int left_boundary() const noexcept { return m_LBoundary; }
int right_boundary() const noexcept { return m_RBoundary; }
int get_left_boundary() const noexcept { return m_LBoundary; }
int get_right_boundary() const noexcept { return m_RBoundary; }
std::optional<alignment> get_alignment() const noexcept { return m_StrayItems ? std::nullopt : std::optional{ m_Alignment }; }

auto get_debug_string() const
{
Expand Down Expand Up @@ -1515,7 +1516,22 @@ long long VMenu::VMProcess(int OpCode, void* vParam, long long iParam)
strId = uuid::str(MenuId);
return std::bit_cast<intptr_t>(UNSAFE_CSTR(strId));
}

case MCODE_V_MENU_HORIZONTALALIGNMENT:
{
if (const auto alignment{ m_HorizontalTracker->get_alignment() })
{
switch (*alignment)
{
case vmenu_horizontal_tracker::alignment::Left:
return 1;
case vmenu_horizontal_tracker::alignment::Right:
return 2;
case vmenu_horizontal_tracker::alignment::Annotation:
return 4;
}
}
return 0;
}
}

return 0;
Expand Down Expand Up @@ -2353,7 +2369,7 @@ bool VMenu::ShiftAllItemsHPos(const int Shift)
const auto TextAreaWidth{ CalculateTextAreaWidth() };
if (TextAreaWidth <= 0) return false;

const auto AdjustedShift{ adjust_hpos_shift(Shift, m_HorizontalTracker->left_boundary(), m_HorizontalTracker->right_boundary(), TextAreaWidth)};
const auto AdjustedShift{ adjust_hpos_shift(Shift, m_HorizontalTracker->get_left_boundary(), m_HorizontalTracker->get_right_boundary(), TextAreaWidth)};
if (!AdjustedShift) return false;

const auto Policy{ CheckFlags(VMENU_ENABLEALIGNANNOTATIONS) ? item_hscroll_policy::unbound : item_hscroll_policy::bound_stick_to_left };
Expand Down
5 changes: 3 additions & 2 deletions plugins/luamacro/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ Menu = {
}

SetProperties(Menu, {
Id = function() return MacroCallFar(0x80844) end,
Value = function() return MacroCallFar(0x80843) end,
Id = function() return MacroCallFar(0x80844) end,
Value = function() return MacroCallFar(0x80843) end,
HorizontalAlignment = function() return MacroCallFar(0x80845) end,
})
--------------------------------------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions plugins/luamacro/macrotest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ function MT.test_Menu()
assert_str(Menu.Value)
assert_eq(Menu.Id, far.Guids.PluginsMenuId)
assert_eq(Menu.Id, "937F0B1C-7690-4F85-8469-AA935517F202")
assert_num(Menu.HorizontalAlignment)
Keys("Esc")

assert_func(Menu.Filter)
Expand Down

0 comments on commit 2b4e66f

Please sign in to comment.