-- TIME_STAMP 2017-01-17 12:34:43 v 0.2 ---------------------------------------------------------------------------------------------------- TipTools = {} fCallTipShow = false EvtUserlistTip = EventClass:new(Common) EvtKeyWhileTipShow = EventClass:new(Common) -- alternative key-code definition for closing Tip -- needs to be declared too, for resetting the variable "fCallTipShow" -- default key processing is avoiding tEscEquivalent = {[13]=true, [27]=true, [32]=true, [37]=true, [38]=true, [39]=true, [40]=true} -- Enter, Esc, Space, Arrows: left, up, right, down ---------------------------------------------------------------------------------------------------- -- Event Select Userlist (Search Variable by Tip) function EvtUserlistTip:OnUserListSelection(_id, _str) if _id ~= 99 then return false end local iFirst = _str:find('[\.\.\.]') +3 local iLast = _str:find('[\.\.\.]', iFirst +1) -1 local var = _str:sub(iFirst,iLast) editor:ReplaceSel(var) return false end -- Event Key while CallTip is shown function EvtKeyWhileTipShow:OnKey(_keycode, _shift, _ctrl, _alt) if fCallTipShow then if tEscEquivalent[_keycode] then -- one of the alternative key code fCallTipShow = false scite.SendEditor(SCI_CANCEL) -- send return true -- avoids default processing end end end ---------------------------------------------------------------------------------------------------- do ---------------------------------------------------------------------------------------------------- local VariableGetTip = function(_param) if props['FileExt']:upper() ~= 'AU3' then return end local GetVarFromCursor = function() local caret = editor.CurrentPos if editor.StyleAt[caret] ~= 9 then if editor.StyleAt[caret-1] ~= 9 then return '', caret end end local iStart, iEnd, iPos, iEnd2, fBrace, sDebugAU3 = caret, caret, nil, nil, false, '' local iLine = editor:LineFromPosition(iStart) local iZero = editor:PositionFromLine(iLine) local iCol = iStart - iZero local sLine = editor:GetLine(iLine) local sRight = Trim(sLine, iCol) iStart = iCol while sLine:sub(iStart,iStart):find('[$a-zA-Z0-9_]') do iStart = iStart -1 end iEnd = iStart +1 iStart = iStart +1 while sLine:sub(iEnd,iEnd):find('[$a-zA-Z0-9_]') do sDebugAU3 = sDebugAU3..sLine:sub(iEnd,iEnd) iEnd = iEnd +1 end return sDebugAU3, caret end -- GetVarFromCursor() local GetFuncFromCursor = function() local iCaret = editor.CurrentPos local sFunc local sLine = editor:GetLine(editor:LineFromPosition(iCaret)) local tLineFunc = {} for s, func, _, e in sLine:gmatch('()([%w_]+)()%s*%b()()') do table.insert(tLineFunc, {['s']=s,['e']=e,['func']=func}) end if #tLineFunc == 0 then return '' end local iCol = editor.Column[iCaret] +1 for i=1, #tLineFunc do if iCol >= tLineFunc[i]['s'] and iCol <= tLineFunc[i]['e'] then return tLineFunc[i]['func'], iCaret end end return '' end -- GetFuncFromCursor() local Output = function(sText1, sText2) if tonumber(props['Variable.Tipp.CallTip.*.au3']) == 1 then if sText2 ~= nil then sText1 = sText1..'\n'..sText2:gsub('\\n', '\n') end fCallTipShow = true editor:CallTipShow(editor.CurrentPos, sText1) else print('!> '..sText1) if sText2 ~= nil then print('>> '..sText2:gsub('\\n', '\n>> ')) end end end -- Output local GetAllTip = function(_param) local tTip = {} local s = editor:GetText() -- in vorhergehender Zeile deklariert for p, tip in s:gmatch('()\n[\t%s]*;%-1%s*([^\r\n]+)') do local _, _, var = editor:GetLine(editor:LineFromPosition(p) -1):find('(%$[%w_]+)') table.insert(tTip, {var,tip,p,'global'}) end -- mit "at"-Tag gesetzter Tipp for p, var, tip in s:gmatch('()\n[\t%s]*;@%s-(%$[%w_]+)%s([^\r\n]+)') do table.insert(tTip, {var,tip,p,'global'}) end -- in Region gesetzte Tipps local tReg = {} for p in s:gmatch("()#[Rr]egion %- [Vv]ariablen%-[Tt]ipp") do table.insert(tReg, p) end if table.getn(tReg) > 0 then for i=1,table.getn(tReg) do local line = editor:LineFromPosition(tReg[i]) while not editor:GetLine(line):find('#[Ee]nd[Rr]egion') do line = line +1 local _, _, var, tip = editor:GetLine(line):find(';%s-(%$[%w_]+)%s([^\r\n]+)') if var then table.insert(tTip, {var,tip,tReg[i],'global'}) end end end end if _param == 'v' then -- Funktionstipps, nur bei Aufruf mit Parameter 'v' for p, tip in s:gmatch('()\n[\t%s]*;%-f%s*([^\r\n]+)') do local _, _, sFunc = editor:GetLine(editor:LineFromPosition(p) -1):find('([%w_]+)%s*%b()') table.insert(tTip, {sFunc,tip,p,sFunc}) end end return tTip end -- GetAllTip local GetFuncs = function() -- Ermitteln aller Funktionsdeklarationen (Startpos, Endpos, Funktionsname) local tFuncs = {} for iStart, sFunc in editor:GetText():gmatch('()[Ff][Uu][Nn][Cc]%s+([%w_]+)%s*%b()') do local iLine, iEnd = editor:LineFromPosition(iStart) while true do iLine = iLine +1 iEnd = editor:GetLine(iLine):find('[Ee][Nn][Dd][Ff][Uu][Nn][Cc]') if iEnd ~= nil then break end end table.insert(tFuncs, {iStart, editor:PositionFromLine(iLine), sFunc}) end return tFuncs end -- GetFuncs if _param == 'v' then local varCurr, varPos = GetVarFromCursor() local fIsFuncTip = false if varCurr == '' then varCurr, varPos = GetFuncFromCursor() if varCurr ~= '' then fIsFuncTip = true end end local tFuncs, tTip, fMatch, fMatchFunc, fInFunc, sFunc, sTip = GetFuncs(), GetAllTip(_param), false, false, false local GetTip = function(_var, _scope) _scope = _scope or 'global' for i=1,table.getn(tTip) do if tTip[i][1]:lower() == _var:lower() and tTip[i][4] == _scope then return tTip[i][2] end end return nil end -- GetTip if table.getn(tTip) > 0 and table.getn(tFuncs) > 0 then -- den Tipps die Funktionen zuordnen for i=1,table.getn(tTip) do for j=1,table.getn(tFuncs) do if tTip[i][3] >= tFuncs[j][1] and tTip[i][3] <= tFuncs[j][2] then tTip[i][4] = tFuncs[j][3] break end end end end local IsVarInFunc = function(_var, _pos) if table.getn(tFuncs) == 0 then return false, nil end for i=1,table.getn(tFuncs) do if _pos >= tFuncs[i][1] and _pos <= tFuncs[i][2] then return true, tFuncs[i][3] -- Return: True/False, Funktionsname end end return false, nil end -- IsVarInFunc if table.getn(tTip) == 0 then Output('Keine Tipps hinterlegt!') else if varCurr == '' then Output('Cursor steht nicht auf einer Variablen\noder einem Funktionsaufruf!') else if not fIsFuncTip then fInFunc, sFunc = IsVarInFunc(varCurr, varPos) end if fInFunc then sTip = GetTip(varCurr, sFunc) if sTip ~= nil then Output(varCurr..' [ Local: Func '..sFunc..'() ]', sTip) else sTip = GetTip(varCurr, 'global') if sTip ~= nil then Output(varCurr..' [ Global ]', sTip) else Output(varCurr, 'Es ist kein Tipp hinterlegt!') end end elseif fIsFuncTip then sTip = GetTip(varCurr, varCurr) if sTip ~= nil then Output(varCurr..'( )', sTip) else Output(varCurr..'( )', 'Es ist kein Tipp hinterlegt!') end else sTip = GetTip(varCurr, 'global') if sTip ~= nil then Output(varCurr..' [ Global ]', sTip) else Output(varCurr, 'Es ist kein Tipp hinterlegt!') end end end end elseif _param == 's' then local tTip = GetAllTip(_param) -- {variable, tipp, position, scope} local sWord = AutoItTools:GetWord() local tFound, sFound, sep, iS, sTipN = {}, '', ';' if sWord:gsub('[%s]+', '') == '' or table.getn(tTip) == 0 then return end local fList = false if props['Userlist.VarGetTip'] == '1' then fList = true end local OutputGrouped = function(_fList) local iMax, sOut, sLineEnd = 0, '', '\n' if _fList then sLineEnd = sep end for i=1,table.getn(tFound) do if tFound[i][2]:len() > iMax then iMax = tFound[i][2]:len() end end for i=1,table.getn(tFound) do sOut = sOut..tFound[i][1]..'...'..tFound[i][2]..('.'):rep(iMax-tFound[i][2]:len()+3)..tFound[i][3]..sLineEnd end return sOut end local SelectCurrentWord = function() local iCaret = editor.CurrentPos local iLine = editor:LineFromPosition(iCaret) local iLine1stPos = editor:PositionFromLine(iLine) local iDiffPos = iCaret - iLine1stPos +1 local sLine = editor:GetLine(iLine) local sWord = props["CurrentWord"] if sWord == '' then return end local s, p = sLine:find(sWord) local tMatch = {} while s ~= nil do table.insert(tMatch, {s,p}) s, p = sLine:find(sWord, s+1) end if table.getn(tMatch) > 0 then for i=1, table.getn(tMatch) do if iDiffPos >= tMatch[i][1] and iDiffPos <= tMatch[i][2] then editor:SetSel(iLine1stPos-1 +tMatch[i][1], iLine1stPos +tMatch[i][2]) break end end end end for i=1,table.getn(tTip) do iS = tTip[i][2]:lower():find(sWord:lower()) if iS then sTipN = tTip[i][2]:gsub('\\n', ' \[LINEBREAK\] ') table.insert(tFound, {tTip[i][4], tTip[i][1], sTipN}) end end if table.getn(tFound) > 0 then sFound = OutputGrouped(fList) else sFound = 'Kein Tipp mit diesem Begriff vorhanden.' end SelectCurrentWord() if not fList then print(sFound) editor:ReplaceSel('') return end editor.AutoCSeparator = string.byte(sep) editor:UserListShow(99, sFound) editor.AutoCSeparator = string.byte(' ') end end --> VariableGetTip ---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- local VarGetTip = function() VariableGetTip('v') end local VarByTip = function() VariableGetTip('s') end ---------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------- -- SYNTAX TipTools.VarGetTip = VarGetTip -- Modul.VarGetTip() or Modul:VarGetTip() TipTools.VarByTip = VarByTip -- Modul.VarByTip() or Modul:VarByTip() ---------------------------------------------------------------------------------------------------- end