Advertisement
BugFix

Untitled

Jan 29th, 2014
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | None | 0 0
  1. ------------------------------------------------------
  2. local function ShowStatementList()
  3.     local tList = {"If-Then", "If-Then-Else", "If-Then-ElseIf", "If-Then-ElseIf-Else",
  4.                 "For-Loop", "While-Loop", "Do-Until", "With-EndWith", "Func-EndFunc"}
  5.     local sep = '•'
  6.     local list = table.concat(tList, sep)
  7.     local sep_tmp = editor.AutoCSeparator
  8.     editor.AutoCSeparator = string.byte(sep)
  9.     editor:UserListShow(99, list)
  10.     editor.AutoCSeparator = sep_tmp
  11. end
  12.  
  13. ------------------------------------------------------
  14. local function GetReplacement(_sel)
  15.     local selStart = editor.SelectionStart
  16.     local sSelection = editor:GetSelText():gsub('(\r\n)$', ''):gsub('(\r\n)', '\n\t')
  17.     local tStatements = {
  18.     ["If-Then"]             = {"If  Then\n\t"..sSelection.."\nEndIf\n", 3},
  19.     ["If-Then-Else"]        = {"If  Then\n\t"..sSelection.."\nElse\n\t\nEndIf\n", 3},
  20.     ["If-Then-ElseIf"]      = {"If  Then\n\t"..sSelection.."\nElseIf\n\t\nEndIf\n", 3},
  21.     ["If-Then-ElseIf-Else"] = {"If  Then\n\t"..sSelection.."\nElseIf\n\t\nElse\n\t\nEndIf\n", 3},
  22.     ["For-Loop"]            = {"For \n\t"..sSelection.."\nNext\n", 4},
  23.     ["While-Loop"]          = {"While 1\n\t"..sSelection.."\nWEnd\n", 6},
  24.     ["Do-Until"]            = {"Do\n\t"..sSelection.."\nUntil \n", nil},
  25.     ["With-EndWith"]        = {"With \n\t"..sSelection.."\nEndWith\n", 5},
  26.     ["Func-EndFunc"]        = {"Func \n\t"..sSelection.."\nEndFunc\n", 5}}
  27.     local iCol = nil
  28.     if tStatements[_sel][2] then
  29.         iCol = selStart + tStatements[_sel][2]
  30.     else
  31.         iCol = selStart + string.len(tStatements[_sel][1])
  32.     end
  33.     return tStatements[_sel][1], iCol
  34. end
  35. ------------------------------------------------------
  36. AddEventHandler("OnUserListSelection", function(tp, sel_value)
  37.     if tp == 99 then
  38.         local sReplacement, iCol = GetReplacement(sel_value)
  39.         if iCol then
  40.             editor:ReplaceSel(sReplacement)
  41.             editor.CurrentPos = iCol
  42.             editor:SetSel(iCol, iCol)
  43.         end
  44.     end
  45. end)
  46.  
  47. -- irgendwelche Zeilen markieren und dann ausführen, Selektion wird in Statement eingepackt
  48.  
  49. ShowStatementList()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement