if not Sci then Sci = {}; end -- создание объекта Scintilla -- hWnd: дескриптор окна, где будем размещать Sci Sci.Create = function(hWnd) local tSize = Window.GetSize(hWnd); DLL.CallFunction("kernel32.dll", "LoadLibraryA", "\"".._SourceFolder.."\\SciLexer.dll\"", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL); return WinApi.CreateWindowEx("0", "Scintilla", "SciLexer", 1378942976, 0, 0, tSize.Width, tSize.Height, hWnd, 0, 0, 0); end -- отправка сообщения -- hWnd: дескриптор Sci -- Msg: сообщение -- wParam, lParam: параметры Sci.SendMessage = function (hWnd, Msg, wParam, lParam) lParam = lParam or 0 if type(lParam) == 'string' then lParam = "\""..lParam.."\""; end if type(wParam) == 'string' then wParam = "\""..wParam.."\""; end return DLL.CallFunction("user32.dll", "SendMessageA", hWnd..","..Msg..","..wParam..","..lParam, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL); end -- установка стиля -- hWnd: дескриптор Sci -- nStyle: номер стиля -- nForeColor: цвет текста -- nBackColor: цвет фона -- nSize: размер шрифта -- strFont: тип начертания -- bBold, bItalic, bUnderline: стиль начертания (жирный, курсив, подчеркнутый) Sci.SetStyle = function (hWnd, nStyle, nForeColor, nBackColor, nSize, strFont, bBold, bItalic, bUnderline) nSize = nSize or 0; strFont = strFont or ""; bBold = bBold or false; bItalic = bItalic or false; bUnderline = bUnderline or false; if bBold == true then bBold = 1; else bBold = 0; end if bItalic == true then bItalic = 1; else bItalic = 0; end if bUnderline == true then bUnderline = 1; else bUnderline = 0; end Sci.SendMessage(hWnd, SCI_STYLESETFORE, nStyle, nForeColor); Sci.SendMessage(hWnd, SCI_STYLESETBACK, nStyle, nBackColor); if nSize >= 1 then Sci.SendMessage(hWnd, SCI_STYLESETSIZE, nStyle, nSize); end if strFont ~= "" then Sci.SendMessage(hWnd, SCI_STYLESETFONT, nStyle, strFont, 'str'); end Sci.SendMessage(hWnd, SCI_STYLESETBOLD, nStyle, bBold); Sci.SendMessage(hWnd, SCI_STYLESETBOLD, nStyle, bItalic); Sci.SendMessage(hWnd, SCI_STYLESETBOLD, nStyle, bUnderline); end -- установка свойства -- hWnd: дескриптор Sci -- vProperty: свойство -- vValue: значение Sci.SetProperty = function (hWnd, vProperty, vValue) return Sci.SendMessage(hWnd, SCI_SETPROPERTY, vProperty, vValue); end -- первоначальные настройки редактора -- вообще настроек редактора куча и, -- если желаете просвятиться по этому поводу, то читайте официальные доки Sci.Init = function(hWnd) local nBits = tonumber(Sci.SendMessage(hWnd, SCI_GETSTYLEBITSNEEDED, 0)); Sci.SendMessage(hWnd, SCI_SETSTYLEBITS, nBits, 0); Sci.SendMessage(hWnd, SCI_SETTABWIDTH, 4); Sci.SendMessage(hWnd, SCI_SETINDENTATIONGUIDES, 4, 1); Sci.SendMessage(hWnd, SCI_SETMARGINTYPEN, MARGIN_SCRIPT_NUMBER, SC_MARGIN_NUMBER); Sci.SendMessage(hWnd, SCI_SETMARGINWIDTHN, MARGIN_SCRIPT_NUMBER, tonumber(Sci.SendMessage(hWnd, SCI_TEXTWIDTH, STYLE_LINENUMBER, "_999"))); Sci.SendMessage(hWnd, SCI_SETMARGINWIDTHN, MARGIN_SCRIPT_ICON, 16); Sci.SendMessage(hWnd, SCI_AUTOCSETSEPARATOR, String.Asc("\r"), 0); Sci.SendMessage(hWnd, SCI_AUTOCSETIGNORECASE, 1); end -- Получение текста --[[ Использование local sText = Sci.GetText(hSci); Dialog.Message("Notice", sText); ]] Sci.GetText = function (hWnd) local Ret = ""; local nLen = Sci.SendMessage(hWnd, SCI_GETTEXT, 0, 0); local hBuf = Memory.Allocate(nLen + 1); Sci.SendMessage(hWnd, SCI_GETTEXT, (nLen + 1), hBuf); Ret = Memory.GetString(hBuf, -1, "Ascii"); Memory.Free(hBuf); return Ret; end -- Вставка текста -- hWnd: дескриптор Sci -- nPos: позиция (число) -- sText: текст (строка) --[[ Использование Sci.InserText(hSci, 10, "Ololo"); ]] Sci.InserText = function (hWnd, nPos, sText) Sci.SendMessage(hWnd, SCI_INSERTTEXT, nPos, sText); end -- Очистка объекта -- hWnd: дескриптор Sci --[[ Использование Sci.Clear(hSci); ]] Sci.Clear = function (hWnd) Sci.SendMessage(hWnd, SCI_CLEARALL, 0, 0); end -- здесь определяем подстветку синтаксиса Sci.SetLexer = function(hWnd) -- будем раскрашивать смесь языка LUA с AMS Sci.SendMessage(hWnd, SCI_SETLEXER, SCLEX_LUA); local strWord1 = 'and break do else elseif end false for function if in local nil not or repeat return then true until while this'; local strWord2 = '_VERSION assert collectgarbage dofile error gcinfo loadfile loadstring print rawget rawset require tonumber tostring type unpack'; strWord2 = strWord2 ..' _G getfenv getmetatable ipairs loadlib next pairs pcall rawequal setfenv setmetatable xpcall table math coroutine debug load module select'; local strWord3 = 'string string.byte string.char string.dump string.find string.len string.lower string.rep string.sub string.upper string.format string.gfind string.gsub'; strWord3 = strWord3 .. ' table.concat table.foreach table.foreachi table.getn table.sort table.insert table.remove table.setn math.abs math.acos math.asin math.atan math.atan2'; strWord3 = strWord3 .. ' math.ceil math.cos math.deg math.exp math.floor math.frexp math.ldexp math.log math.log10 math.max math.min math.mod math.pi math.pow math.rad math.random'; strWord3 = strWord3 .. ' math.randomseed math.sin math.sqrt math.tan :byte :char :find :len :lower :rep :sub :upper :format :gfind :gmatch :gsub string.gmatch string.match string.reverse'; strWord3 = strWord3 .. ' table.maxn math.cosh math.fmod math.modf math.sinh math.tanh math.huge'; local strWord4 = 'coroutine.create coroutine.resume coroutine.status coroutine.wrap coroutine.yield io os io.close io.flush io.input io.lines io.open io.output io.read io.tmpfile'; strWord4 = strWord4 .. ' io.type io.write :close :flush :lines :read :seek :setvbuf :write io.stdin io.stdout io.stderr os.clock os.date os.difftime os.execute os.exit os.getenv'; strWord4 = strWord4 .. ' os.remove os.rename os.setlocale os.time os.tmpname coroutine.running package.cpath package.loaded package.loadlib package.path package.preload package.seeall'; strWord4 = strWord4 .. ' io.popen lines debug.debug debug.getfenv debug.gethook debug.getinfo debug.getlocal debug.getmetatable debug.getregistry debug.getupvalue debug.setfenv'; strWord4 = strWord4 .. ' debug.sethook debug.setlocal debug.setmetatable debug.setupvalue debug.traceback'; -- допишите остальные функи AMS local strWord5 = 'Dialog.Message Math.Atan'; -- кастомный набор слов Sci.SendMessage(hWnd, SCI_SETKEYWORDS, 1, strWord1); Sci.SendMessage(hWnd, SCI_SETKEYWORDS, 2, strWord2); Sci.SendMessage(hWnd, SCI_SETKEYWORDS, 3, strWord3); Sci.SendMessage(hWnd, SCI_SETKEYWORDS, 4, strWord4); Sci.SendMessage(hWnd, SCI_SETKEYWORDS, 5, strWord5); Sci.SetStyle(hWnd, STYLE_DEFAULT, Math.HexColorToNumber("000000"), Math.HexColorToNumber("FFFFFF"), 9, "Courier New"); Sci.SendMessage(hWnd, SCI_STYLECLEARALL, 0, 0); Sci.SetStyle(hWnd, STYLE_DEFAULT, Math.HexColorToNumber("000000"), Math.HexColorToNumber("FFFFFF")); Sci.SetStyle(hWnd, SCE_LUA_COMMENT, Math.HexColorToNumber("008000"), Math.HexColorToNumber("FFFFFF"), nil, nil, false, true); Sci.SetStyle(hWnd, SCE_LUA_COMMENTLINE, Math.HexColorToNumber("008000"), Math.HexColorToNumber("FFFFFF"), nil, nil, false, true); Sci.SetStyle(hWnd, SCE_LUA_COMMENTDOC, Math.HexColorToNumber("008000"), Math.HexColorToNumber("FFFFFF"), nil, nil, false, true); Sci.SetStyle(hWnd, SCE_LUA_NUMBER, Math.HexColorToNumber("FF99CC"), Math.HexColorToNumber("FFFFFF")); Sci.SetStyle(hWnd, SCE_LUA_OPERATOR, Math.HexColorToNumber("FF0000"), Math.HexColorToNumber("FFFFFF")); Sci.SetStyle(hWnd, SCE_LUA_STRING, Math.HexColorToNumber("800080"), Math.HexColorToNumber("FFFFFF")); Sci.SetStyle(hWnd, SCE_LUA_WORD, Math.HexColorToNumber("800080"), Math.HexColorToNumber("FFFFFF")); Sci.SetStyle(hWnd, SCE_LUA_CHARACTER, Math.HexColorToNumber("800080"), Math.HexColorToNumber("FFFFFF")); Sci.SetStyle(hWnd, SCE_LUA_LITERALSTRING, Math.HexColorToNumber("800080"), Math.HexColorToNumber("FFFFFF")); -- strWord1 Sci.SetStyle(hWnd, SCE_LUA_WORD2, Math.HexColorToNumber("0000FF"), Math.HexColorToNumber("FFFFFF"), nil, nil); -- strWord2 Sci.SetStyle(hWnd, SCE_LUA_WORD3, Math.HexColorToNumber("000080"), Math.HexColorToNumber("FFFFFF")); -- strWord3 Sci.SetStyle(hWnd, SCE_LUA_WORD4, Math.HexColorToNumber("0000FF"), Math.HexColorToNumber("FFFF99")); -- strWord4 Sci.SetStyle(hWnd, SCE_LUA_WORD5, Math.HexColorToNumber("0000FF"), Math.HexColorToNumber("FFFF99")); -- strWord5 Sci.SetStyle(hWnd, SCE_LUA_WORD6, Math.HexColorToNumber("0000FF"), Math.HexColorToNumber("FFFF99"), nil, nil, nil, false, true); end -- загружаем константы local strConsts = TextFile.ReadToString(_SourceFolder.."\\AutoPlay\\Scripts\\Sci.h.lua"); assert(loadstring(strConsts))(); local hWnd = Input.GetProperties("Input1").WindowHandle; local hSci = Sci.Create(hWnd); Sci.Init(hSci); Sci.SetLexer(hSci); local strText = [[local function BakupFile(filename) local sbck = tonumber(props['backup.files']) if sbck == nil or sbck == 0 then return false end local sfilename = filename filename = GetPath().."\\"..string.gsub(filename,'.*\\','') local nbck = 1 while (sbck > nbck ) do local fn1 = sbck-nbck local fn2 = sbck-nbck+1 os.remove (filename.."."..fn2..".bak") if fn1 == 1 then os.rename (filename..".bak", filename.."."..fn2..".bak") else os.rename (filename.."."..fn1..".bak", filename.."."..fn2..".bak") end nbck = nbck + 1 end os.remove (filename..".bak") if not shell.fileexists(sfilename) then io.output(sfilename) io.close() end os.rename (sfilename, filename..".bak") if not shell.fileexists(filename..".bak") then _ALERT("=>\tERROR CREATE BACKUP FILE: "..filename..".bak".."\t"..sbck) end return false end]] Sci.SendMessage(hSci, SCI_ADDTEXT, #strText, strText);