Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-802: Macro API to report VMenu alignment state. Part 2: Plumbing and Lua API. #902

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion enc/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
t-rex 2012-11-05 01:19:38+02:00 - build
MZK 2025-01-25 20:59:20-05:00

1. gh-802: Описание Menu.HorizontalAlignment.

t-rex 2012-11-05 01:19:38+02:00

1. Переделка всех tools на работу с enc_rus3.work

Expand Down
6 changes: 4 additions & 2 deletions enc/enc_lua/macroapi_manual.en.tsi
Original file line number Diff line number Diff line change
Expand Up @@ -2239,8 +2239,9 @@ mtime=3607109038
#_
#_**Properties:**
#_
#_ Id: string (GUID)
#_ Value: string
#_ HorizontalAlignment: number
#_ Id: string (GUID)
#_ Value: string
#_
#_**Functions:**
#_
Expand All @@ -2255,6 +2256,7 @@ mtime=3607109038
#_{filterstr}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.FilterStr
#_{filter}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.Filter
#_{getvalue}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.GetValue
#_{horizontalalignment}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.HorizontalAlignment
#_{id}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.Info.Id
#_{itemstatus}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.ItemStatus
#_{select}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.Select
Expand Down
6 changes: 4 additions & 2 deletions enc/enc_lua/macroapi_manual.pl.tsi
Original file line number Diff line number Diff line change
Expand Up @@ -2238,8 +2238,9 @@ mtime=3607109038
#_
#_**Właściwości:**
#_
#_ Id: łańcuch (GUID)
#_ Value: łańcuch
#_ HorizontalAlignment: liczba
#_ Id: łańcuch (GUID)
#_ Value: łańcuch
#_
#_**Funkcje:**
#_
Expand All @@ -2254,6 +2255,7 @@ mtime=3607109038
#_{filterstr}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.FilterStr
#_{filter}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.Filter
#_{getvalue}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.GetValue
#_{horizontalalignment}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.HorizontalAlignment
#_{id}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.Info.Id
#_{itemstatus}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.ItemStatus
#_{select}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.Select
Expand Down
6 changes: 4 additions & 2 deletions enc/enc_lua/macroapi_manual.ru.tsi
Original file line number Diff line number Diff line change
Expand Up @@ -2234,8 +2234,9 @@ mtime=3607109106
#_
#_**Свойства:**
#_
#_ Id: string (GUID)
#_ Value: string
#_ HorizontalAlignment: number
#_ Id: string (GUID)
#_ Value: string
#_
#_**Функции:**
#_
Expand All @@ -2250,6 +2251,7 @@ mtime=3607109106
#_{filterstr}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.FilterStr
#_{filter}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.Filter
#_{getvalue}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.GetValue
#_{horizontalalignment}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.HorizontalAlignment
#_{id}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.Info.Id
#_{itemstatus}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.ItemStatus
#_{select}: http://api.farmanager.com/ru/macro/macrocmd/prop_func/menus.html#Menu.Select
Expand Down
5 changes: 5 additions & 0 deletions enc/enc_rus/meta/defs/macroopcode.html
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,11 @@ <h1>MACROOPCODE</h1>
<td>0x80844</td>
<td>Menu.Info.Id</td>
</tr>
<tr>
<td>MCODE_V_MENU_HORIZONTALALIGNMENT</td>
<td>0x80845</td>
<td>Menu.HorizontalAlignment</td>
</tr>
</table>

</body>
Expand Down
18 changes: 17 additions & 1 deletion enc/enc_rus/meta/macro/macrocmd/prop_func/menus.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ <h1>Свойства и функции для работы с меню и спи
меню пользователя (<code>UserMenu</code>), меню выбора диска (<code>Disks</code>).</p>

<p>Под списками понимается: список автодополнения (<code>AutoCompletion</code>),
и различные открытые списки в диалогах (<code>Dialog</code>) - List box / Combo box / History.</p>
различные открытые списки в диалогах (<code>Dialog</code>) - List box / Combo box / History,
а также список всех найденных строк (<code>FindAll</code>) в редакторе (<code>Editor</code>).</p>

<p>Далее в тексте "меню" и "списки" не разделяются, и упоминаются под общим названием "меню".</p>

Expand All @@ -42,6 +43,21 @@ <h2>Свойства</h2>
<td>String</td>
<td>строковое представление идентификатора текущего меню</td>
</tr>
<tr>
<td><a name="Menu.HorizontalAlignment">Menu.HorizontalAlignment</a></td>
<td>Number</td>
<td><p>горизонтальное выравнивание пунктов меню:</p>
<table class="cont2 params lite tiny">
<col class="value">
<col>
<tr><th><var>Значение</var></th><th>Описание</th></tr>
<tr><td>0</td><td>пункты меню не выравнены</td></tr>
<tr><td>1</td><td>все пункты меню выравнены налево</td></tr>
<tr><td>2</td><td>все пункты меню выравнены направо</td></tr>
<tr><td>4</td><td>все пункты меню выравнены по аннотациям, т.е., по найденному образцу в списке всех найденных строк (<code>FindAll</code>) в редакторе (<code>Editor</code>)</td></tr>
<tr><td>-1</td><td>оператор вызван не для меню</td></tr>
</table>
</tr>

<tr><th colspan="3">Меню выбора диска</th></tr>
<tr><th>Оператор</th><th>Тип</th><th>Описание</th></tr>
Expand Down
5 changes: 5 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
--------------------------------------------------------------------------------
MZK 2025-01-25 20:59:20-05:00 - build 6422

1. gh-802: Macro API to report VMenu alignment state. Part 2: Plumbing and Lua API.

--------------------------------------------------------------------------------
drkns 2025-01-22 18:11:36+00:00 - build 6421

Expand Down
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
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6421
6422
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
4 changes: 2 additions & 2 deletions plugins/luamacro/_globalinfo.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function export.GetGlobalInfo()
return {
Version = { 3, 0, 0, 864 },
MinFarVersion = { 3, 0, 0, 6380 },
Version = { 3, 0, 0, 865 },
MinFarVersion = { 3, 0, 0, 6422 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Description = "Far macros in Lua",
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,
HorizontalAlignment = function() return MacroCallFar(0x80845) end,
Id = function() return MacroCallFar(0x80844) end,
Value = function() return MacroCallFar(0x80843) end,
})
--------------------------------------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions plugins/luamacro/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
MZK 2025-01-25 20:59:20-05:00 - build 865

1. gh-802: Macro API to report VMenu alignment state: Menu.HorizontalAlignment.

shmuel 2025-01-23 00:39:05+02:00 - build 864

1. LuaFAR: a temporary workaround in processing timer events.
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/luafar/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include <farversion.hpp>

#define PLUGIN_BUILD 864
#define PLUGIN_BUILD 865
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
Loading