Philippe Lhoste a écrit :
Very nice, useful as I have a number of small routines which I don't want to put in the tool menu.
Here is my take on ordering the list:

A little improvement:

-- User Defined Lists
local udl_Separator = "~"
local udl_SuperAbbr = 10
local udl_ListTools = 15

-- April White's tool menu generator

local tools =
{
        ["Normalize line"] = { 1, Normalize },
        ["Sort all lines"] = { 2, SortLines },
        ["Add XML Tag"] = { 3, AddXMLTag },
        ["Super Abbreviations"] = { 4, SuperAbbr },
}

local function udl_Initialize()
        local tl = {}
        for title, tool in pairs(tools) do
                tl[tool[1]] = title
        end
        toolList = table.concat(tl, udl_Separator)
--      editor.AutoCMaxHeight = 10
end

function LuaTools()
        editor:GrabFocus()
        editorACS = editor.AutoCSeparator
        editor.AutoCSeparator = string.byte(udl_Separator)
        editor:UserListShow(udl_ListTools, toolList)
        editor.AutoCSeparator = editorACS
end

function OnClear()
        udl_Initialize()
        return false
end

function OnUserListSelection(lt, choice)
        if lt == udl_ListTools then
                local tool = tools[choice]
                tool[2]()
                return true
        elseif lt == udl_SuperAbbr then
                editor:InsertText(-1, abbrList[txt]["template"])
                -- Should locate posChar, remove it and put the caret there
                return true
        else
                return false
        end
end

I almost forgot that in Lua, you can put functions in lists, and call them!

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --

_______________________________________________
Scite-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scite-interest

Reply via email to