Add sub_menu_on option
This commit is contained in:
parent
5ff71f7385
commit
4e54b38991
|
@ -125,7 +125,7 @@ Multiple items can have multiple sets of options.
|
|||
| icon_size | Icon size | number |
|
||||
| auto_resize | Resize menu if items are too large | boolean |
|
||||
| parent_geometry | Set the menu parent | geometry array |
|
||||
| arrow_type | Set the arrow type when use arrow style | see "arrow_type" |
|
||||
| arrow_type | Set the arrow type when use arrow style | see "arrow_type" enum |
|
||||
| visible | Show or hide the menu | boolean |
|
||||
| direction | The direction from which the arrow will point | "left","right","top","bottom" |
|
||||
| row | Number of row (in grid layout) | number |
|
||||
|
@ -144,6 +144,7 @@ Multiple items can have multiple sets of options.
|
|||
| disable_markup | Disable pango markup in items text | boolean |
|
||||
| x | X position (absolute) | number |
|
||||
| y | Y position (absolute) | number |
|
||||
| sub_menu_on | Show submenu on selection or when clicking | see "sub_menu_on" enum |
|
||||
|
||||
###Item options
|
||||
|
||||
|
|
5
bar.lua
5
bar.lua
|
@ -93,6 +93,11 @@ local function create_item(item,data)
|
|||
m:set_widget(layout)
|
||||
|
||||
-- Content
|
||||
if item.icon then
|
||||
local icon = wibox.widget.imagebox()
|
||||
icon:set_image(item.icon)
|
||||
layout:add(icon)
|
||||
end
|
||||
local tb = wibox.widget.textbox()
|
||||
layout:add(tb)
|
||||
item.widget = bg
|
||||
|
|
42
base.lua
42
base.lua
|
@ -16,11 +16,13 @@ local module = {
|
|||
CENTERED = 2,
|
||||
},
|
||||
sub_menu_on ={
|
||||
SELECTED = 0,
|
||||
CLICKED = 1,
|
||||
NEVER = 2,
|
||||
NEVER = 0,
|
||||
BUTTON1 = 1,
|
||||
BUTTON2 = 2,
|
||||
BUTTON3 = 3,
|
||||
SELECTED = 100,
|
||||
},
|
||||
}
|
||||
}}
|
||||
|
||||
local function filter(data)
|
||||
if not data.filter == false then
|
||||
|
@ -44,6 +46,21 @@ local function filter(data)
|
|||
end
|
||||
end
|
||||
|
||||
local function execute_sub_menu(data,item)
|
||||
if (item._private_data.sub_menu_f or item._private_data.sub_menu_m) then
|
||||
local sub_menu = item._private_data.sub_menu_m or item._private_data.sub_menu_f()
|
||||
if sub_menu and sub_menu.rowcount > 0 then
|
||||
sub_menu.arrow_type = module.arrow_type.NONE
|
||||
sub_menu.parent_item = item
|
||||
sub_menu.parent_geometry = data
|
||||
sub_menu.visible = true
|
||||
item._tmp_menu = sub_menu
|
||||
data._tmp_menu = sub_menu
|
||||
end
|
||||
end
|
||||
end
|
||||
module._execute_sub_menu = execute_sub_menu
|
||||
|
||||
------------------------------------KEYBOARD HANDLING-----------------------------------
|
||||
local function activateKeyboard(data)
|
||||
if not data then return end
|
||||
|
@ -75,8 +92,12 @@ local function activateKeyboard(data)
|
|||
end
|
||||
|
||||
if (key == 'Return') and data._current_item and data._current_item.button1 then
|
||||
if data.sub_menu_on == module.sub_menu_on.BUTTON1 then
|
||||
execute_sub_menu(data,data._current_item)
|
||||
else
|
||||
data._current_item.button1()
|
||||
data.visible = false
|
||||
end
|
||||
elseif key == 'Escape' or (key == 'Tab' and data.filter_string == "") then
|
||||
data.visible = false
|
||||
capi.keygrabber.stop()
|
||||
|
@ -154,16 +175,8 @@ local function add_item(data,args)
|
|||
end
|
||||
data._current_item.selected = false
|
||||
end
|
||||
if (private_data.sub_menu_f or private_data.sub_menu_m)and data._current_item ~= item then
|
||||
local sub_menu = private_data.sub_menu_m or private_data.sub_menu_f()
|
||||
if sub_menu and sub_menu.rowcount > 0 then
|
||||
sub_menu.arrow_type = module.arrow_type.NONE
|
||||
sub_menu.parent_item = item
|
||||
sub_menu.parent_geometry = data
|
||||
sub_menu.visible = true
|
||||
item._tmp_menu = sub_menu
|
||||
data._tmp_menu = sub_menu
|
||||
end
|
||||
if data.sub_menu_on == module.sub_menu_on.SELECTED and data._current_item ~= item then
|
||||
execute_sub_menu(data,item)
|
||||
end
|
||||
data.item_style(data,item,true,false)
|
||||
data._current_item = item
|
||||
|
@ -274,6 +287,7 @@ local function new(args)
|
|||
disable_markup = args.disable_markup or false,
|
||||
x = args.x or 0,
|
||||
y = args.y or 0,
|
||||
sub_menu_on = args.sub_menu_on or module.sub_menu_on.SELECTED,
|
||||
},
|
||||
get_map = {
|
||||
is_menu = function() return true end,
|
||||
|
|
13
context.lua
13
context.lua
|
@ -173,7 +173,14 @@ local function setup_item(data,item,args)
|
|||
buttons[#buttons+1] = button({},i,args["button"..i])
|
||||
end
|
||||
end
|
||||
if not buttons[3] then --Hide on right click
|
||||
|
||||
-- Click to open sub_menu
|
||||
if not buttons[1] and data.sub_menu_on == base.sub_menu_on.BUTTON1 then
|
||||
buttons[#buttons+1] = button({},1,function() base._execute_sub_menu(data,item) end)
|
||||
end
|
||||
|
||||
--Hide on right click
|
||||
if not buttons[3] then
|
||||
buttons[#buttons+1] = button({},3,function()
|
||||
data.visible = false
|
||||
if data.parent_geometry and data.parent_geometry.is_menu then
|
||||
|
@ -181,11 +188,15 @@ local function setup_item(data,item,args)
|
|||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Scroll up
|
||||
if not buttons[4] then
|
||||
buttons[#buttons+1] = button({},4,function()
|
||||
data:scroll_up()
|
||||
end)
|
||||
end
|
||||
|
||||
-- Scroll down
|
||||
if not buttons[5] then
|
||||
buttons[#buttons+1] = button({},5,function()
|
||||
data:scroll_down()
|
||||
|
|
Loading…
Reference in New Issue