From 24c1f05d660b6f5db7710bc2f19924f51bdbd96a Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 4 Jan 2012 23:55:07 -0200 Subject: [PATCH] close menus when resizing windows --- modules/core_lib/ext/table.lua | 20 +++++++++++++++++++- modules/core_widgets/uipopupmenu.lua | 17 +++++++++++++++++ tools/katepart-syntax/lua.xml | 7 ++++--- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/modules/core_lib/ext/table.lua b/modules/core_lib/ext/table.lua index 5a8e8e68..c7f3c190 100644 --- a/modules/core_lib/ext/table.lua +++ b/modules/core_lib/ext/table.lua @@ -19,7 +19,7 @@ function table.copy(t) return res end -function table.selective_copy(t, keys) +function table.selectivecopy(t, keys) local res = { } for i,v in ipairs(keys) do res[v] = t[v] @@ -32,3 +32,21 @@ function table.merge(t, src) t[k] = v end end + +function table.find(t, value) + for k,v in pairs(t) do + if v == value then return k end + end +end + +function table.removevalue(t, value) + local queue = {} + for k,v in pairs(t) do + if v == value then + table.insert(queue, k) + end + end + for i,v in pairs(queue) do + table.remove(t, i) + end +end diff --git a/modules/core_widgets/uipopupmenu.lua b/modules/core_widgets/uipopupmenu.lua index f3543ad2..ecf5c319 100644 --- a/modules/core_widgets/uipopupmenu.lua +++ b/modules/core_widgets/uipopupmenu.lua @@ -1,5 +1,7 @@ UIPopupMenu = extends(UIWidget) +local displayedMenuList = {} + function UIPopupMenu.create() local menu = UIPopupMenu.internalCreate() local layout = UIVerticalLayout.create(menu) @@ -8,6 +10,11 @@ function UIPopupMenu.create() return menu end +function UIPopupMenu:destroy() + table.removevalue(displayedMenuList, self) + UIWidget.destroy(self) +end + function UIPopupMenu:display(pos) -- don't display if not options was added if self:getChildCount() == 0 then @@ -19,6 +26,7 @@ function UIPopupMenu:display(pos) self:bindRectToParent() self:grabMouse() self:grabKeyboard() + table.insert(displayedMenuList, self) end function UIPopupMenu:addOption(optionName, optionCallback) @@ -53,3 +61,12 @@ function UIPopupMenu:onKeyPress(keyCode, keyText, keyboardModifiers) end return false end + +local function onRootGeometryUpdate() + -- close all menus when the window is resized + for i,menu in ipairs(displayedMenuList) do + menu:destroy() + end +end + +connect(rootWidget, { onGeometryUpdate = onRootGeometryUpdate} ) diff --git a/tools/katepart-syntax/lua.xml b/tools/katepart-syntax/lua.xml index 9a12ec14..5fc330e8 100644 --- a/tools/katepart-syntax/lua.xml +++ b/tools/katepart-syntax/lua.xml @@ -117,10 +117,11 @@ openfile closefile date clock - string.trim string.starts + string.trim string.starts string.split - table.dump table.copy - table.selective_copy table.merge + table.dump table.copy + table.selectivecopy table.merge + table.find table.removevalue toboolean