-- TIME_STAMP 2019-01-05 13:54:21 v 0.2 shell = require "shell" local opt = {} opt.DeclareVars = EventClass:new(Common) function opt.DeclareVars:OnBeforeSave(fname) if props['FileExt']:lower() ~= 'au3' then return end local mustdeclare = tonumber(props['Opt.MustDeclareVars.au3']) or 0 if mustdeclare == 1 and shell.fileexists(fname) then return end opt.InsertMustDeclare(mustdeclare) end opt.InsertMustDeclare = function(_opt) local caret = editor.CurrentPos local firstVisible, iDiff = editor.FirstVisibleLine, 0 -- Inhalt Editor auslesen local fileread = editor:GetText() -- suchen, ob bereits Deklaration vorhanden local optstart, optend, opttxt, posval, val = fileread:find('([Oo]pt%s*%(["'.."'"..'][Mm]ust[Dd]eclare[Vv]ars["'.."'"..']%s*,%s*()(%d)%s*%))') -- print('Debug: optstart, optend, opttxt, posval, val', optstart, optend, opttxt, posval, val) -- abhängig von gesetzter Property if _opt == 1 then -- Option MIT Deklarationspflicht NUR NEUDATEI local bTimeStamp1st = (tonumber(props['Opt.MustDeclareVars.TimeStamp.First']) == 1) if bTimeStamp1st then local a, e = fileread:find(';%-%- TIME_STAMP.*\r\n') editor:InsertText(e, "Opt('MustDeclareVars', 1)\n") -- in Zeile hinter TimeStamp (und Leerzeile) einfügen else editor:InsertText(0, "Opt('MustDeclareVars', 1)\n") -- in erster Zeile einfügen end iDiff = 1 elseif _opt == 2 then -- Option MIT Deklarationspflicht ALLE DATEIEN if optstart == nil then -- keine Optionsdeklaration im Skript editor:InsertText(0, "Opt('MustDeclareVars', 1)\n") -- in erster Zeile einfügen iDiff = 1 else -- Deklaration existiert if val == 1 then -- korrekte Option gesetzt return else -- Option muss geändert werden editor:SetSelection(posval-1, posval) -- Wert der Option markieren editor:ReplaceSel(1) -- Markierung ersetzen mit "1" end end else -- Option OHNE Deklarationspflicht if optstart == nil then -- keine Optionsdeklaration im Skript return -- keine Aktion erforderlich else -- Deklaration existiert if val == 0 then -- korrekte Option gesetzt return else -- Option muss geändert werden editor:SetSelection(posval-1, posval) -- Wert der Option markieren editor:ReplaceSel(0) -- Markierung ersetzen mit "0" end end end if iDiff == 1 then caret = caret + 27 end -- Cursorposition verschiebt sich um Länge des Eintrags editor:SetSelection(caret, caret) -- Cursor an alte Position setzen editor.FirstVisibleLine = firstVisible +iDiff -- erst sichtbare Zeile an vorige Position end