Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------
- local function ShowStatementList()
- local tList = {"If-Then", "If-Then-Else", "If-Then-ElseIf", "If-Then-ElseIf-Else",
- "For-Loop", "While-Loop", "Do-Until", "With-EndWith", "Func-EndFunc"}
- local sep = '•'
- local list = table.concat(tList, sep)
- local sep_tmp = editor.AutoCSeparator
- editor.AutoCSeparator = string.byte(sep)
- editor:UserListShow(99, list)
- editor.AutoCSeparator = sep_tmp
- end
- ------------------------------------------------------
- local function GetReplacement(_sel)
- local selStart = editor.SelectionStart
- local sSelection = editor:GetSelText():gsub('(\r\n)$', ''):gsub('(\r\n)', '\n\t')
- local tStatements = {
- ["If-Then"] = {"If Then\n\t"..sSelection.."\nEndIf\n", 3},
- ["If-Then-Else"] = {"If Then\n\t"..sSelection.."\nElse\n\t\nEndIf\n", 3},
- ["If-Then-ElseIf"] = {"If Then\n\t"..sSelection.."\nElseIf\n\t\nEndIf\n", 3},
- ["If-Then-ElseIf-Else"] = {"If Then\n\t"..sSelection.."\nElseIf\n\t\nElse\n\t\nEndIf\n", 3},
- ["For-Loop"] = {"For \n\t"..sSelection.."\nNext\n", 4},
- ["While-Loop"] = {"While 1\n\t"..sSelection.."\nWEnd\n", 6},
- ["Do-Until"] = {"Do\n\t"..sSelection.."\nUntil \n", nil},
- ["With-EndWith"] = {"With \n\t"..sSelection.."\nEndWith\n", 5},
- ["Func-EndFunc"] = {"Func \n\t"..sSelection.."\nEndFunc\n", 5}}
- local iCol = nil
- if tStatements[_sel][2] then
- iCol = selStart + tStatements[_sel][2]
- else
- iCol = selStart + string.len(tStatements[_sel][1])
- end
- return tStatements[_sel][1], iCol
- end
- ------------------------------------------------------
- AddEventHandler("OnUserListSelection", function(tp, sel_value)
- if tp == 99 then
- local sReplacement, iCol = GetReplacement(sel_value)
- if iCol then
- editor:ReplaceSel(sReplacement)
- editor.CurrentPos = iCol
- editor:SetSel(iCol, iCol)
- end
- end
- end)
- -- irgendwelche Zeilen markieren und dann ausführen, Selektion wird in Statement eingepackt
- ShowStatementList()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement