From 0d0cb4a7b49ce17f7486466d265987e79bdb881e Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Fri, 6 Jan 2017 19:04:52 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=A1=20=D0=BF=D0=BE=D0=BB=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=D1=8E=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B4=20=D0=9E=D0=9E?= =?UTF-8?q?=D0=9F-=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D1=83=20"GUI"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 18436 -> 18436 bytes Applications.txt | 46 +- Applications/.DS_Store | Bin 71684 -> 71684 bytes Applications/3DPrint/3DPrint.lua | 1 + Applications/AppMarket/AppMarket.lua | 25 +- Applications/Control/Control.lua | 1 + Applications/Motd/.DS_Store | Bin 6148 -> 0 bytes Applications/Motd/English.txt | 28 -- Applications/Motd/Russian.txt | 11 - Applications/OCGL/Icon.pic | Bin 0 -> 177 bytes Applications/Photoshop/Photoshop.lua | 41 +- Applications/RayWalk/RayWalk.lua | 20 +- Applications/init.lua | 13 +- Applications/{Motd/motd.lua => motd} | 3 +- Installer/Installer.lua | 4 +- lib/ECSAPI.lua | 27 +- lib/GUI.lua | 36 +- lib/MineOSCore.lua | 611 +++++++++++++++------------ lib/advancedLua.lua | 2 +- lib/rayEngine.lua | 21 +- lib/syntax.lua | 4 +- lib/windows.lua | 12 + 22 files changed, 474 insertions(+), 432 deletions(-) mode change 100644 => 100755 Applications/3DPrint/3DPrint.lua mode change 100644 => 100755 Applications/Control/Control.lua delete mode 100644 Applications/Motd/.DS_Store delete mode 100644 Applications/Motd/English.txt delete mode 100644 Applications/Motd/Russian.txt create mode 100644 Applications/OCGL/Icon.pic mode change 100644 => 100755 Applications/init.lua rename Applications/{Motd/motd.lua => motd} (99%) mode change 100644 => 100755 diff --git a/.DS_Store b/.DS_Store index 82710ffd8a079e7668c136aa73343bf97e43dc6e..d19e94d54c02884dd053bec16e4ee539e233fcfc 100644 GIT binary patch delta 167 zcmZpfz}PZ@af2rN=p((3MR&ell86KC!3fFPwqD^<6&T6U<6_y;NadY$RWnE zS&io~E2HCNe>I8COhOZwpv=`Gmb@qisHjVB_EutHVVto!Ky3#TW9FfwcoP}{-8$N delta 95 zcmV-l0HFVbumps#1h6>~1vM-nGcc1N@kq0V5grDUAA(P_^B2k?la5MHvkW>oCzGqt z{{=9$;2sAM;EFdyAIFsLCN3+ezH%^{- BBe?(o diff --git a/Applications/3DPrint/3DPrint.lua b/Applications/3DPrint/3DPrint.lua old mode 100644 new mode 100755 index ee13ad07..760bff5a --- a/Applications/3DPrint/3DPrint.lua +++ b/Applications/3DPrint/3DPrint.lua @@ -23,6 +23,7 @@ if component.isAvailable("printer3d") then printer = component.printer3d else ecs.error("Этой программе требуется 3D-принтер для работы.") + return end ------------------------------------------------------------------------------------------------------------------------ diff --git a/Applications/AppMarket/AppMarket.lua b/Applications/AppMarket/AppMarket.lua index f79f334f..caca0896 100755 --- a/Applications/AppMarket/AppMarket.lua +++ b/Applications/AppMarket/AppMarket.lua @@ -2,20 +2,17 @@ -- package.loaded.GUI = nil -- _G.GUI = nil -local libraries = { - advancedLua = "advancedLua", - buffer = "doubleBuffering", - MineOSCore = "MineOSCore", - image = "image", - GUI = "GUI", - fs = "filesystem", - component = "component", - unicode = "unicode", - files = "files", - ecs = "ECSAPI", -} - -for library in pairs(libraries) do if not _G[library] then _G[library] = require(libraries[library]) end end; libraries = nil +local advancedLua = require("advancedLua") +local buffer = require("doubleBuffering") +local MineOSCore = require("MineOSCore") +local image = require("image") +local GUI = require("GUI") +local fs = require("filesystem") +local component = require("component") +local unicode = require("unicode") +local files = require("files") +local event = require("event") +local ecs = require("ECSAPI") ------------------------------------------------------------------------------------------------------------------ diff --git a/Applications/Control/Control.lua b/Applications/Control/Control.lua old mode 100644 new mode 100755 index 2d8b1043..95a9f337 --- a/Applications/Control/Control.lua +++ b/Applications/Control/Control.lua @@ -8,6 +8,7 @@ local event = require("event") local context = require("context") local screen = c.screen local gpu = c.gpu +local image = require("image") ------------------------------------------------------------------------------------------------------------------------------- diff --git a/Applications/Motd/.DS_Store b/Applications/Motd/.DS_Store deleted file mode 100644 index 3fdd17580564102fbafafcfea4e8c4caa89ab494..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%Sr=55Ufu25ZOzP9{1=;@DG--5pqpFKocVx*cdPy@VFo72lzL!x~C1Uu2&K1 z4m~xGu9=;J%uEB2$zgp3i~)@3ilUVs)9&7(fd^+qu{joKu){O%XLZj+f3Zuy{S23= zu)q!d^!>ZLRlQqrl+wr>@#1J^o5(T66CO}wgFPO}Z}5UA%a)2F6bJ=Eflwe6_)!7g*=nOaVU(dj zC=d#q6wvdbpevS+Z9+RbSXc@`)MvCA>zYd_r*JGC+k_mUNum-HRXoLzL}!2DaiwFM zFwr5Ne2B07k-Uhl&iM-qhm;AU3Z$?sC46$*p`|4aeNszo*7 zru=UGwmrRT3;HcxP2*av&{*$00@%=V 0.05) is called. -Screens will consume more power the more lit characters they display. -Most blocks act as 'cables' - use switches and power distributers to create separate networks. -Welcome to the dark side - here, have some cookies. -Screens can display Unicode - paste the special chars or use unicode.char. -Run `help` or `man programname` for ingame help on programs shipped with OpenOS - start with `man man`. -For more help, there's a wiki at http://ocdoc.cil.li/ - or find the IRC loot disk and join #oc. -Computers have a very basic, built-in speaker - control it using computer.beep(). -Many component methods have a short documentation - use `=component.componentName.methodName` in the Lua interpreter to see it. -You can get a list of all attached components using the `components` program. -If you encounter out of memory errors, throw more RAM at your computer. -Have you tried turning it off and on again? -To disable this greeting, install OpenOS to a writeable medium and delete `/etc/motd`. -Did you know OpenComputers has a forum? No? Well, it's at http://oc.cil.li/. -Please report bugs on the Github issue tracker, thank you! -Beware of cycles when building networks, or you may get duplicate messages! diff --git a/Applications/Motd/Russian.txt b/Applications/Motd/Russian.txt deleted file mode 100644 index c3c8bb21..00000000 --- a/Applications/Motd/Russian.txt +++ /dev/null @@ -1,11 +0,0 @@ -Вы можете изменить размер текста на экране, изменяя его разрешение - введите resolution 40 16 в коммандную строку -Стрельба стрелами на сенсорный экран активирует ивент touch -Вы можете изменить цвет вашего компьютера, монитора или кабеля с помощью обычных красителей -Используйте Анализатор, чтобы получить больше информации о блоках - например, чтобы понять, какого хуя компьютер вылетел с ошибкой -Чтобы вставить содержимое буфера обмена, нажмите среднюю кнопку мыши или специальную конфигурируемую клавишу, по умолчанию insert -Большинство программ можно завершить, нажав Ctrl+Alt+C -Экраны могут отображать Юникод - вставляйте нужные символы в код или используйте unicode.char() -Официальная вики мода находится по адресу http://ocdoc.cil.li/ -У компьютеров есть простенький динамик, контролируйте его через computer.beep() -Чтобы избавиться от этих подсказок, удалите файл /etc/motd -Избегайте циклов, создавая сети, иначе ваши сообщения могут дублироваться! diff --git a/Applications/OCGL/Icon.pic b/Applications/OCGL/Icon.pic new file mode 100644 index 0000000000000000000000000000000000000000..e0a17753dfd3fea839526578e1cdbbab7024d565 GIT binary patch literal 177 zcmYL?F%E-333SAP0CxZ=geIY3X{U()7!)kHkSsacFMdaxoad)V$}PLygv8dXs3Cw( literal 0 HcmV?d00001 diff --git a/Applications/Photoshop/Photoshop.lua b/Applications/Photoshop/Photoshop.lua index 89fbeae3..feec8033 100755 --- a/Applications/Photoshop/Photoshop.lua +++ b/Applications/Photoshop/Photoshop.lua @@ -55,21 +55,18 @@ copyright = nil ------------------------------------------------ Библиотеки -------------------------------------------------------------- -local libraries = { - ecs = "ECSAPI", - MineOSCore = "MineOSCore", - fs = "filesystem", - unicode = "unicode", - image = "image", - component = "component", - keyboard = "keyboard", - buffer = "doubleBuffering", - colorlib = "colorlib", - palette = "palette", - event = "event", - files = "files", -} -for library in pairs(libraries) do if not _G[library] then _G[library] = require(libraries[library]) end end; libraries = nil +local ecs = require("ECSAPI") +local MineOSCore = require("MineOSCore") +local fs = require("filesystem") +local unicode = require("unicode") +local image = require("image") +local component = require("component") +local keyboard = require("keyboard") +local buffer = require("doubleBuffering") +local colorlib = require("colorlib") +local palette = require("palette") +local event = require("event") +local files = require("files") ------------------------------------------------ Переменные -------------------------------------------------------------- @@ -186,10 +183,10 @@ local function drawTransparentZone(x, y) local stro4ka1 = "" local stro4ka2 = "" if masterPixels.width % 2 == 0 then - stro4ka1 = string.rep("▒ ", masterPixels.width / 2) + stro4ka1 = string.rep("▒ ", math.floor(masterPixels.width / 2)) stro4ka2 = stro4ka1 else - stro4ka1 = string.rep("▒ ", masterPixels.width / 2) + stro4ka1 = string.rep("▒ ", math.floor(masterPixels.width / 2)) stro4ka2 = stro4ka1 .. "▒" end @@ -250,7 +247,15 @@ end --Отрисовка верхнего меню local function drawTopMenu() - obj.menu = GUI.menu(1, 1, buffer.screen.width, colors.topMenu, colors.topMenuText, 0x3366CC, 0xFFFFFF, 0, {"PS", ecs.colors.blue}, {localization.file}, {localization.image}, {localization.edit}, {localization.view}, {localization.hotkeys}, {localization.about}):draw() + obj.menu = GUI.menu(1, 1, buffer.screen.width, colors.topMenu, colors.topMenuText, 0x3366CC, 0xFFFFFF, 0) + obj.menu:addItem("PS", ecs.colors.blue) + obj.menu:addItem(localization.file) + obj.menu:addItem(localization.image) + obj.menu:addItem(localization.edit) + obj.menu:addItem(localization.view) + obj.menu:addItem(localization.hotkeys) + obj.menu:addItem(localization.about) + obj.menu:draw() end --Функция, создающая пустой массив изображения на основе указанных ранее длины и ширины diff --git a/Applications/RayWalk/RayWalk.lua b/Applications/RayWalk/RayWalk.lua index d4229de0..013f6a0c 100755 --- a/Applications/RayWalk/RayWalk.lua +++ b/Applications/RayWalk/RayWalk.lua @@ -1,18 +1,14 @@ package.loaded.rayEngine, package.loaded.GUI, package.loaded.windows, _G.rayEngine, _G.GUI, _G.windows = nil, nil, nil, nil, nil, nil, nil, nil -local libraries = { - component = "component", - buffer = "doubleBuffering", - GUI = "GUI", - windows = "windows", - rayEngine = "rayEngine", - MineOSCore = "MineOSCore", - unicode = "unicode", - event = "event", -} - -for library in pairs(libraries) do if not _G[library] then _G[library] = require(libraries[library]) end end; libraries = nil +local component = require("component") +local buffer = require("doubleBuffering") +local GUI = require("GUI") +local windows = require("windows") +local rayEngine = require("rayEngine") +local MineOSCore = require("MineOSCore") +local unicode = require("unicode") +local event = require("event") ---------------------------------------------------------------------------------------------------------------------------------- diff --git a/Applications/init.lua b/Applications/init.lua old mode 100644 new mode 100755 index f23882e8..58585320 --- a/Applications/init.lua +++ b/Applications/init.lua @@ -1,4 +1,4 @@ -local background, foreground, logoColor = 0xCCCCCC, 0x666666, 0x262626 +local background, foreground, logoColor = 0xDDDDDD, 0x999999, 0x444444 do _G._OSVERSION = "OpenOS 1.6" @@ -59,11 +59,11 @@ do end end - local y = math.floor(h / 2) + local y = math.floor(h / 2 - 1) local function status(text) - centerText(y - 2, "MineOS", logoColor) - centerText(y, text, foreground) + centerText(y, "MineOS", logoColor) + centerText(y + 1, text, foreground) end status("Booting " .. _OSVERSION .. "...") @@ -173,8 +173,9 @@ end -- MineOS Init data do -- Загружаем необходимые библиотеки, дабы избежать потерь памяти - _G.shell = require("shell"); shell.setWorkingDirectory("") - _G.ecs = require("ECSAPI") + local shell = require("shell"); shell.setWorkingDirectory("") + local ecs = require("ECSAPI") + local component = require("component") -- Загружаем параметры ОС ecs.loadOSSettings() diff --git a/Applications/Motd/motd.lua b/Applications/motd old mode 100644 new mode 100755 similarity index 99% rename from Applications/Motd/motd.lua rename to Applications/motd index d684e710..2468c827 --- a/Applications/Motd/motd.lua +++ b/Applications/motd @@ -9,12 +9,11 @@ if not component.isAvailable("gpu") then return end +local gpu = component.gpu local xSize, ySize = gpu.getResolution() local oldBackground = gpu.getBackground() local oldForeground = gpu.getForeground() -local gpu = component.gpu - local lines = { "OpenOS (customized by ECS), " .. math.floor(computer.totalMemory() / 1024) .. "KB RAM"} local maxWidth = unicode.len(lines[1]) local f = io.open("/usr/misc/greetings/" .. _G.OSSettings.language .. ".txt") diff --git a/Installer/Installer.lua b/Installer/Installer.lua index 303cbb2d..f4c773cc 100644 --- a/Installer/Installer.lua +++ b/Installer/Installer.lua @@ -196,7 +196,7 @@ do language = data[1], dockShortcuts = { {path = "/MineOS/Applications/AppMarket.app"}, - {path = "/MineOS/Applications/Finder.app"}, + {path = "/MineOS/Applications/RayWalk.app"}, {path = "/MineOS/Applications/Photoshop.app"}, {path = "/MineOS/Applications/VK.app"}, } @@ -348,7 +348,7 @@ end -- Создаем базовые обои рабочего стола if downloadWallpapers then ecs.createShortCut(desktopPath .. "Pictures.lnk", picturesPath) - ecs.createShortCut("/MineOS/System/OS/Wallpaper.lnk", picturesPath .. "Sunbeams.pic") + ecs.createShortCut("/MineOS/System/OS/Wallpaper.lnk", picturesPath .. "Ciri.pic") end -- Создаем файл автозагрузки diff --git a/lib/ECSAPI.lua b/lib/ECSAPI.lua index 4c7ed4ea..e0ea92f1 100755 --- a/lib/ECSAPI.lua +++ b/lib/ECSAPI.lua @@ -1,20 +1,18 @@ --- Адаптивная загрузка необходимых библиотек и компонентов -local libraries = { - component = "component", - term = "term", - unicode = "unicode", - event = "event", - fs = "filesystem", - shell = "shell", - keyboard = "keyboard", - computer = "computer", - serialization = "serialization", -} -for library in pairs(libraries) do if not _G[library] then _G[library] = require(libraries[library]) end end; libraries = nil -_G.gpu = component.gpu +local advancedLua = require("advancedLua") +local component = require("component") +local term = require("term") +local unicode = require("unicode") +local event = require("event") +local fs = require("filesystem") +local shell = require("shell") +local keyboard = require("keyboard") +local computer = require("computer") +local serialization = require("serialization") + +local gpu = component.gpu local ecs = {} ---------------------------------------------------------------------------------------------------- @@ -1553,7 +1551,6 @@ end --Описание ниже, ебана. Ниже - это значит в самой жопе кода! function ecs.universalWindow(x, y, width, background, closeWindowAfter, ...) - require("advancedLua") local objects = {...} local countOfObjects = #objects diff --git a/lib/GUI.lua b/lib/GUI.lua index d02a1a04..bf61ef24 100755 --- a/lib/GUI.lua +++ b/lib/GUI.lua @@ -71,7 +71,7 @@ GUI.objectTypes = enum( "tabBar", "tabBarTab", "menu", - "menuElement", + "menuItem", "window", "inputTextBox", "textBox", @@ -653,8 +653,8 @@ local function showDropDownMenu(object) drawDropDownMenuElement(object, itemIndex, true) buffer.draw() os.sleep(0.2) - if object.items[itemIndex].onItemSelected then object.items[itemIndex].onItemSelected() end quit() + if object.items[itemIndex].onTouch then object.items[itemIndex].onTouch() end return object.items[itemIndex].text, itemIndex end break @@ -761,19 +761,31 @@ end ----------------------------------------- Menu ----------------------------------------- +local function menuAddItem(menu, text, textColor) + local x = 2; for i = 2, #menu.children do x = x + unicode.len(menu.children[i].text) + 2; end + local item = menu:addAdaptiveButton(x, 1, 1, 0, nil, textColor or menu.colors.default.text, menu.colors.pressed.background, menu.colors.pressed.text, text) + item.type = GUI.objectTypes.menuItem + return item +end + function GUI.menu(x, y, width, backgroundColor, textColor, backgroundPressedColor, textPressedColor, backgroundTransparency, ...) - local elements = {...} - local menuObject = GUI.container(x, y, width, 1) - menuObject:addPanel(1, 1, menuObject.width, 1, backgroundColor, backgroundTransparency).disableClicking = true + local menu = GUI.container(x, y, width, 1) + menu:addPanel(1, 1, menu.width, 1, backgroundColor, backgroundTransparency) + menu.colors = { + default = { + background = backgroundColor, + text = textColor, + }, + pressed = { + background = backgroundPressedColor, + text = textPressedColor, + }, + transparency = backgroundTransparency + } - local x = 2 - for elementIndex = 1, #elements do - local button = menuObject:addAdaptiveButton(x, 1, 1, 0, nil, elements[elementIndex][2] or textColor, elements[elementIndex][3] or backgroundPressedColor, elements[elementIndex][4] or textPressedColor, elements[elementIndex][1]) - button.type = GUI.objectTypes.menuElement - x = x + button.width - end + menu.addItem = menuAddItem - return menuObject + return menu end ----------------------------------------- ProgressBar Object ----------------------------------------- diff --git a/lib/MineOSCore.lua b/lib/MineOSCore.lua index 14722937..1791c6e9 100755 --- a/lib/MineOSCore.lua +++ b/lib/MineOSCore.lua @@ -1,32 +1,31 @@ ----------------------------------------------- Библиотеки ------------------------------------------------------------------------ +---------------------------------------------- Libraries ------------------------------------------------------------------------ -local libraries = { - component = "component", - advancedLua = "advancedLua", - image = "image", - buffer = "doubleBuffering", - GUI = "GUI", - ecs = "ECSAPI", - zip = "archive", - syntax = "syntax", - computer = "computer", - fs = "filesystem", -} +local component = require("component") +local computer = require("computer") +local advancedLua = require("advancedLua") +local image = require("image") +local buffer = require("doubleBuffering") +local GUI = require("GUI") +local ecs = require("ECSAPI") +local zip = require("archive") +local syntax = require("syntax") +local fs = require("filesystem") +local unicode = require("unicode") -for library in pairs(libraries) do if not _G[library] then _G[library] = require(libraries[library]) end end; libraries = nil - ------------------------------------------------------------------------------------------------------------------------------------ +---------------------------------------------- Core constants ------------------------------------------------------------------------ local MineOSCore = {} MineOSCore.showApplicationIcons = true MineOSCore.iconWidth = 12 MineOSCore.iconHeight = 6 +MineOSCore.iconClickDelay = 0.2 MineOSCore.paths = {} MineOSCore.paths.OS = "/MineOS/" MineOSCore.paths.system = MineOSCore.paths.OS .. "System/" +MineOSCore.paths.wallpaper = "OS/Wallpaper.lnk" MineOSCore.paths.localizationFile = MineOSCore.paths.system .. "OS/Languages/" .. _G.OSSettings.language .. ".lang" MineOSCore.paths.icons = MineOSCore.paths.system .. "OS/Icons/" MineOSCore.paths.applications = MineOSCore.paths.OS .. "Applications/" @@ -34,16 +33,17 @@ MineOSCore.paths.pictures = MineOSCore.paths.OS .. "Pictures/" MineOSCore.paths.desktop = MineOSCore.paths.OS .. "Desktop/" MineOSCore.paths.applicationList = MineOSCore.paths.system .. "OS/Applications.txt" MineOSCore.paths.trash = MineOSCore.paths.OS .. "Trash/" +MineOSCore.paths.OSSettings = MineOSCore.paths.system .. "OS/OSSettings.cfg" -MineOSCore.sortingMethods = { - type = 0, - name = 1, - date = 2, -} +MineOSCore.sortingMethods = enum( + "type", + "name", + "date" +) MineOSCore.localization = {} ------------------------------------------------------------------------------------------------------------------------------------ +---------------------------------------------- Current sсript processing methods ------------------------------------------------------------------------ function MineOSCore.getCurrentScriptDirectory() return fs.path(getCurrentScript()) @@ -66,16 +66,31 @@ function MineOSCore.getCurrentApplicationLocalization() return MineOSCore.getLocalization(MineOSCore.getCurrentApplicationResourcesDirectory() .. "Localization/") end ------------------------------------------------------------------------------------------------------------------------------------ +function MineOSCore.getMethodExecutionTime(method) + local oldOSClock = os.clock() + method() + return os.clock() - oldOSClock +end + +function MineOSCore.getAverageMethodExecutionTime(method, countOfTries) + local averageTime = 0 + for i = 1, countOfTries do + averageTime = (averageTime + MineOSCore.getMethodExecutionTime(method)) / 2 + os.sleep(0.1) + end + return averageTime +end + +---------------------------------------------- Filesystem-related methods ------------------------------------------------------------------------ local function getFilenameAndFormat(path) local fileName, format = string.match(path, "^(.+)(%..+)$") - return fileName or path, format and string.gsub(format, "/", "") or nil + return (fileName or path), (format and string.gsub(format, "%/+$", "") or nil) end local function getFilePathAndName(path) local filePath, fileName = string.math(path, "^(.+%/)(.+)$") - return filePath or "/", fileName or path + return (filePath or "/"), (fileName or path) end function MineOSCore.getFileFormat(path) @@ -88,22 +103,87 @@ function MineOSCore.hideFileFormat(path) return fileName end -function MineOSCore.getFileName(path) - local filePath, fileName = getFilePathAndName(path) - return fileName -end - -function MineOSCore.getFilePath(path) - local filePath, fileName = getFilePathAndName(path) - return filePath -end - function MineOSCore.isFileHidden(path) if string.match(path, "^%..+$") then return true end return false end ------------------------------------------------------------------------------------------------------------------------------------ +function MineOSCore.getFileList(path) + if not fs.exists(path) then error("Failed to get file list: directory \"" .. tostring(path) .. "\" doesn't exists") end + if not fs.isDirectory(path) then error("Failed to get file list: path \"" .. tostring(path) .. "\" is not a directory") end + + local fileList = {} + for file in fs.list(path) do table.insert(fileList, file) end + return fileList +end + +function MineOSCore.sortFileList(path, fileList, sortingMethod, showHiddenFiles) + local sortedFileList = {} + + if sortingMethod == MineOSCore.sortingMethods.type then + local typeList = {} + for i = 1, #fileList do + local fileFormat = MineOSCore.getFileFormat(fileList[i]) or "Script" + if fs.isDirectory(path .. fileList[i]) and fileFormat ~= ".app" then fileFormat = "Folder" end + typeList[fileFormat] = typeList[fileFormat] or {} + table.insert(typeList[fileFormat], fileList[i]) + end + + if typeList.Folder then + for i = 1, #typeList.Folder do + table.insert(sortedFileList, typeList.Folder[i]) + end + typeList["Folder"] = nil + end + + for fileFormat in pairs(typeList) do + for i = 1, #typeList[fileFormat] do + table.insert(sortedFileList, typeList[fileFormat][i]) + end + end + elseif MineOSCore.sortingMethods.name then + sortedFileList = fileList + elseif MineOSCore.sortingMethods.date then + for i = 1, #fileList do + fileList[i] = {fileList[i], fs.lastModified(path .. fileList[i])} + end + table.sort(fileList, function(a,b) return a[2] > b[2] end) + for i = 1, #fileList do + table.insert(sortedFileList, fileList[i][1]) + end + else + error("Unknown sorting method: " .. tostring(sortingMethod)) + end + + local i = 1 + while i <= #sortedFileList do + if not showHiddenFiles and MineOSCore.isFileHidden(sortedFileList[i]) then + table.remove(sortedFileList, i) + else + i = i + 1 + end + end + + return sortedFileList +end + +function MineOSCore.limitFileName(text, limit) + if unicode.len(text) > limit then + local partSize = math.ceil(limit / 2) + text = unicode.sub(text, 1, partSize) .. "…" .. unicode.sub(text, -partSize + 1, -1) + end + return text +end + +---------------------------------------------- MineOS Icons related methods ------------------------------------------------------------------------ + +function MineOSCore.saveOSSettings() + table.toFile(MineOSCore.paths.OSSettings, _G.OSSettings, true) +end + +function MineOSCore.loadOSSettings() + _G.OSSettings = table.fromFile(MineOSCore.paths.OSSettings) +end function MineOSCore.loadIcon(name, path) if not MineOSCore.icons[name] then MineOSCore.icons[name] = image.load(path) end @@ -131,60 +211,199 @@ function MineOSCore.init() MineOSCore.loadStandartIcons() end ------------------------------------------------------------------------------------------------------------------------------------ - ---Отрисовка одной иконки -function MineOSCore.drawIcon(x, y, path, showFileFormat, nameColor, name) - local fileFormat = MineOSCore.getFileFormat(path) - local icon - - if fs.isDirectory(path) then - if fileFormat == ".app" then +function MineOSCore.analyseIconFormat(iconObject) + if iconObject.isDirectory then + if iconObject.format == ".app" then if MineOSCore.showApplicationIcons then - icon = "cyka" - MineOSCore.icons[icon] = image.load(path .. "/Resources/Icon.pic") + iconObject.iconImage.image = image.load(iconObject.path .. "/Resources/Icon.pic") else - icon = "application" + iconObject.iconImage.image = MineOSCore.icons.application + end + + iconObject.launch = function() + ecs.applicationHelp(iconObject.path) + MineOSCore.safeLaunch(iconObject.path .. "/" .. MineOSCore.hideFileFormat(fs.name(iconObject.path)) .. ".lua") end else - icon = "folder" + iconObject.iconImage.image = MineOSCore.icons.folder + iconObject.launch = function() + MineOSCore.safeLaunch("/MineOS/Applications/Finder.app/Finder.lua", "open", iconObject.path) + end end else - if fileFormat == ".lnk" then - MineOSCore.drawIcon(x, y, ecs.readShortcut(path), showFileFormat, nameColor, fs.name(path)) - buffer.set(x + MineOSCore.iconWidth - 3, y + MineOSCore.iconHeight - 3, 0xFFFFFF, 0x000000, "<") - return 0 - elseif fileFormat == ".cfg" or fileFormat == ".config" then - icon = "config" - elseif fileFormat == ".txt" or fileFormat == ".rtf" then - icon = "text" - elseif fileFormat == ".lua" then - icon = "lua" - elseif fileFormat == ".pic" or fileFormat == ".png" then - icon = "image" - elseif fileFormat == ".paste" then - icon = "pastebin" - elseif fileFormat == ".pkg" then - icon = "archive" - elseif fileFormat == ".3dm" then - icon = "model3D" - elseif not fs.exists(path) then - icon = "fileNotExists" + if iconObject.format == ".lnk" then + iconObject.shortcutPath = ecs.readShortcut(iconObject.path) + iconObject.shortcutFormat = MineOSCore.getFileFormat(iconObject.shortcutPath) + iconObject.shortcutIsDirectory = fs.isDirectory(iconObject.shortcutPath) + iconObject.isShortcut = true + + local shortcutIconObject = MineOSCore.analyseIconFormat({ + path = iconObject.shortcutPath, + format = iconObject.shortcutFormat, + isDirectory = iconObject.shortcutIsDirectory, + iconImage = iconObject.iconImage + }) + + iconObject.iconImage.image = shortcutIconObject.iconImage.image + iconObject.launch = shortcutIconObject.launch + + shortcutIconObject = nil + elseif iconObject.format == ".cfg" or iconObject.format == ".config" then + iconObject.iconImage.image = MineOSCore.icons.config + iconObject.launch = function() + ecs.prepareToExit() + MineOSCore.safeLaunch("/bin/edit.lua", iconObject.path) + end + elseif iconObject.format == ".txt" or iconObject.format == ".rtf" then + iconObject.iconImage.image = MineOSCore.icons.text + iconObject.launch = function() + ecs.prepareToExit() + MineOSCore.safeLaunch("/bin/edit.lua", iconObject.path) + end + elseif iconObject.format == ".lua" then + iconObject.iconImage.image = MineOSCore.icons.lua + iconObject.launch = function() + ecs.prepareToExit() + MineOSCore.safeLaunch(iconObject.path) + end + elseif iconObject.format == ".pic" or iconObject.format == ".png" then + iconObject.iconImage.image = MineOSCore.icons.image + iconObject.launch = function() + MineOSCore.safeLaunch("/MineOS/Applications/Viewer.app/Viewer.lua", "open", iconObject.path) + end + elseif iconObject.format == ".pkg" or iconObject.format == ".zip" then + iconObject.iconImage.image = MineOSCore.icons.archive + iconObject.launch = function() + zip.unarchive(iconObject.path, (fs.path(iconObject.path) or "")) + end + elseif iconObject.format == ".3dm" then + iconObject.iconImage.image = MineOSCore.icons.model3D + iconObject.launch = function() + MineOSCore.safeLaunch("/MineOS/Applications/3DPrint.app/3DPrint.lua", "open", iconObject.path) + end + elseif not fs.exists(iconObject.path) then + iconObject.iconImage.image = MineOSCore.icons.fileNotExists + iconObject.launch = function() + GUI.error("Application is corrupted") + end else - icon = "script" + iconObject.iconImage.image = MineOSCore.icons.script + iconObject.launch = function() + ecs.prepareToExit() + MineOSCore.safeLaunch("/bin/edit.lua", iconObject.path) + end end end - --Рисуем иконку - buffer.image(x + 2, y, MineOSCore.icons[icon]) + return iconObject +end - --Делаем текст для иконки - local text = name or fs.name(path) - if not showFileFormat and fileFormat then text = unicode.sub(text, 1, -(unicode.len(fileFormat) + 1)) end - text = ecs.stringLimit("end", text, MineOSCore.iconWidth) - x = x + math.floor(MineOSCore.iconWidth / 2 - unicode.len(text) / 2) - --Рисуем текст под иконкой - buffer.text(x, y + MineOSCore.iconHeight - 1, nameColor or 0xffffff, text) +function MineOSCore.getParametersForDrawingIcons(fieldWidth, fieldHeight, xSpaceBetweenIcons, ySpaceBetweenIcons) + local xCountOfIcons, yCountOfIcons = math.floor(fieldWidth / (MineOSCore.iconWidth + xSpaceBetweenIcons)), math.floor(fieldHeight / (MineOSCore.iconHeight + ySpaceBetweenIcons)) + local totalCountOfIcons = xCountOfIcons * yCountOfIcons + return xCountOfIcons, yCountOfIcons, totalCountOfIcons +end + +function MineOSCore.createIconObject(x, y, path, textColor, showFileFormat) + local iconObject = GUI.container(x, y, MineOSCore.iconWidth, MineOSCore.iconHeight) + + iconObject.path = path + iconObject.size = fs.size(iconObject.path) + iconObject.isDirectory = fs.isDirectory(iconObject.path) + iconObject.format = MineOSCore.getFileFormat(iconObject.path) + iconObject.showFormat = showFileFormat + iconObject.isShortcut = false + iconObject.isSelected = false + + iconObject.iconImage = iconObject:addImage(3, 1, {width = 8, height = 4}) + iconObject.textLabel = iconObject:addLabel(1, MineOSCore.iconHeight, MineOSCore.iconWidth, 1, textColor, fs.name(iconObject.path)):setAlignment(GUI.alignment.horizontal.center, GUI.alignment.vertical.top) + + local oldDraw = iconObject.draw + iconObject.draw = function(iconObject) + if iconObject.isSelected then buffer.square(iconObject.x, iconObject.y, iconObject.width, iconObject.height, 0xFFFFFF, 0x000000, " ", 50) end + if iconObject.showFormat then + iconObject.textLabel.text = MineOSCore.limitFileName(fs.name(iconObject.path), iconObject.textLabel.width) + else + iconObject.textLabel.text = MineOSCore.limitFileName(MineOSCore.hideFileFormat(fs.name(iconObject.path)), iconObject.textLabel.width) + end + oldDraw(iconObject) + if iconObject.isShortcut then buffer.set(iconObject.iconImage.x + iconObject.iconImage.width - 1, iconObject.iconImage.y + iconObject.iconImage.height - 1, 0xFFFFFF, 0x000000, "<") end + end + + -- Поддержка изменяемых извне функций правого и левого кликов + iconObject.onLeftClick = MineOSCore.iconLeftClick + iconObject.onRightClick = MineOSCore.iconRightClick + + -- Обработка клика непосредственно на иконку + iconObject.iconImage.onTouch = function(eventData) + iconObject.isSelected = true + local firstParent = iconObject:getFirstParent() + firstParent:draw() + buffer.draw() + + if eventData[5] == 0 then + os.sleep(MineOSCore.iconClickDelay) + iconObject.onLeftClick(iconObject, eventData) + else + iconObject.onRightClick(iconObject, eventData) + end + + iconObject.isSelected = false + firstParent:draw() + buffer.draw() + end + + -- Онализ формата и прочего говна иконки для последующего получения изображения иконки и функции-лаунчера + MineOSCore.analyseIconFormat(iconObject) + + return iconObject +end + +local function updateIconFieldFileList(iconField) + iconField.fileList = MineOSCore.getFileList(iconField.workpath) + iconField.fileList = MineOSCore.sortFileList(iconField.workpath, iconField.fileList, iconField.sortingMethod, iconField.showHiddenFiles) + iconField.children = {} + + local xPos, yPos, counter = 1, 1, 1 + for i = iconField.fromFile, iconField.fromFile + iconField.iconCount.total - 1 do + if not iconField.fileList[i] then break end + + iconField:addChild( + MineOSCore.createIconObject( + xPos, yPos, iconField.workpath .. iconField.fileList[i], iconField.colors.iconText, iconField.showFileFormat + ), + GUI.objectTypes.container + ) + + xPos, counter = xPos + MineOSCore.iconWidth + iconField.spaceBetweenIcons.x, counter + 1 + if counter > iconField.iconCount.width then + xPos, counter = 1, 1 + yPos = yPos + MineOSCore.iconHeight + iconField.spaceBetweenIcons.y + end + end + + return iconField +end + +function MineOSCore.createIconField(x, y, width, height, xCountOfIcons, yCountOfIcons, totalCountOfIcons, xSpaceBetweenIcons, ySpaceBetweenIcons, iconTextColor, showFileFormat, showHiddenFiles, sortingMethod, workpathworkpath) + local iconField = GUI.container(x, y, width, height) + + iconField.colors = {iconText = iconTextColor} + + iconField.iconCount = {} + iconField.spaceBetweenIcons = {x = xSpaceBetweenIcons, y = ySpaceBetweenIcons} + iconField.iconCount.width, iconField.iconCount.height, iconField.iconCount.total = xCountOfIcons, yCountOfIcons, totalCountOfIcons + + iconField.workpath = workpath + iconField.showFileFormat = showFileFormat + iconField.showHiddenFiles = showHiddenFiles + iconField.sortingMethod = sortingMethod + iconField.fileList = {} + iconField.fromFile = fromFile + + iconField.updateFileList = updateIconFieldFileList + + return iconField end ----------------------------------------------------------------------------------------------------------------------------------- @@ -369,10 +588,6 @@ function MineOSCore.safeLaunch(path, ...) -- end -- end - -- ecs.error("EXISTS: " .. tostring(applicationExists)) - -- ecs.error("PATH: " .. errorPath .. ", ERRORLINE: " .. errorLine) - -- ecs.error("REASON: " .. finalReason) - drawErrorWindow(errorPath, programVersion, errorLine, finalReason, applicationExists) else GUI.error("Unknown error in lib/MineOSCore.lua due program execution: possible reason is \"" .. tostring(finalReason) .. "\"") @@ -385,120 +600,25 @@ end ----------------------------------------------------------------------------------------------------------------------------------- --- Запуск приложения -function MineOSCore.launchIcon(path, translate) - --Получаем файл формат заранее - local fileFormat = ecs.getFileFormat(path) - local isDirectory = fs.isDirectory(path) - --Если это приложение - if fileFormat == ".app" then - ecs.applicationHelp(path) - MineOSCore.safeLaunch(path .. "/" .. ecs.hideFileFormat(fs.name(path)) .. ".lua") - --Если это папка - elseif (fileFormat == "" or fileFormat == nil) and isDirectory then - MineOSCore.safeLaunch("/MineOS/Applications/Finder.app/Finder.lua", "open", path) - --Если это обычный луа файл - т.е. скрипт - elseif fileFormat == ".lua" or fileFormat == nil then - buffer.clear(0x262626) - ecs.prepareToExit() - MineOSCore.safeLaunch(path) - - --Если это фоточка - elseif fileFormat == ".pic" then - MineOSCore.safeLaunch("MineOS/Applications/Viewer.app/Viewer.lua", "open", path) - - --Если это 3D-модель - elseif fileFormat == ".3dm" then - MineOSCore.safeLaunch("MineOS/Applications/3DPrint.app/3DPrint.lua", "open", path) - - --Если это текст или конфиг или языковой - elseif fileFormat == ".txt" or fileFormat == ".cfg" or fileFormat == ".lang" then - ecs.prepareToExit() - MineOSCore.safeLaunch("bin/edit.lua", path) - - --Если это ярлык - elseif fileFormat == ".lnk" then - local shortcutLink = ecs.readShortcut(path) - if fs.exists(shortcutLink) then - MineOSCore.launchIcon(shortcutLink) +function MineOSCore.iconLeftClick(iconObject, eventData) + if iconObject.isDirectory then + if iconObject.format == ".app" then + iconObject.launch() + computer.pushSignal("MineOSCore", "updateFileList") else - GUI.error(MineOSCore.localization.shortcutIsCorrupted) - end - - --Если это архив - elseif fileFormat == ".zip" then - zip.unarchive(path, (fs.path(path) or "")) - end -end - ------------------------------------------------------------------------------------------------------------------------------------ - -function MineOSCore.getParametersForDrawingIcons(fieldWidth, fieldHeight, xSpaceBetweenIcons, ySpaceBetweenIcons) - local xCountOfIcons, yCountOfIcons = math.floor(fieldWidth / (MineOSCore.iconWidth + xSpaceBetweenIcons)), math.floor(fieldHeight / (MineOSCore.iconHeight + ySpaceBetweenIcons)) - local totalCountOfIcons = xCountOfIcons * yCountOfIcons - return xCountOfIcons, yCountOfIcons, totalCountOfIcons -end - -function MineOSCore.drawIconField(x, y, xCountOfIcons, yCountOfIcons, fromIcon, totalCountOfIcons, xSpaceBetweenIcons, ySpaceBetweenIcons, path, fileList, showFileFormat, iconTextColor) - local iconObjects = {} - - local xPos, yPos, iconCounter = x, y, 1 - for i = fromIcon, (fromIcon + totalCountOfIcons - 1) do - if not fileList[i] then break end - - local iconObject = GUI.object(xPos, yPos, MineOSCore.iconWidth, MineOSCore.iconHeight) - iconObject.path = path .. fileList[i] - table.insert(iconObjects, iconObject) - MineOSCore.drawIcon(xPos, yPos, iconObject.path, showFileFormat, iconTextColor) - - xPos = xPos + MineOSCore.iconWidth + xSpaceBetweenIcons - iconCounter = iconCounter + 1 - if iconCounter > xCountOfIcons then - xPos = x - yPos = yPos + MineOSCore.iconHeight + ySpaceBetweenIcons - iconCounter = 1 - end - end - - return iconObjects -end - ------------------------------------------------------------------------------------------------------------------------------------ - -local function executeMethod(methodArray) - methodArray.method(table.unpack(methodArray.arguments)) -end - -function MineOSCore.iconSelect(icon, selectionColor, selectionTransparency, iconTextColor) - local oldPixelsOfIcon = buffer.copy(icon.x, icon.y, MineOSCore.iconWidth, MineOSCore.iconHeight) - buffer.square(icon.x, icon.y, MineOSCore.iconWidth, MineOSCore.iconHeight, selectionColor, 0xFFFFFF, " ", selectionTransparency) - MineOSCore.drawIcon(icon.x, icon.y, icon.path, false, iconTextColor) - buffer.draw() - return oldPixelsOfIcon -end - -function MineOSCore.iconLeftClick(icon, oldPixelsOfIcon, fileFormat, drawAllMethod, fullRefreshMethod, changeCurrentPathMethod) - if fs.isDirectory(icon.path) then - if fileFormat == ".app" then - MineOSCore.launchIcon(icon.path) - executeMethod(fullRefreshMethod) - else - executeMethod(changeCurrentPathMethod) - executeMethod(drawAllMethod) + computer.pushSignal("MineOSCore", "changeWorkpath", iconObject.path) end else - MineOSCore.launchIcon(icon.path) - buffer.start() - executeMethod(fullRefreshMethod) - -- GUI.error("Скрипт выполнен успешно") + iconObject.launch() + computer.pushSignal("MineOSCore", "updateFileListAndBufferTrueRedraw") end end -function MineOSCore.iconRightClick(icon, oldPixelsOfIcon, eventData, fileFormat, somethingCanBeAddedToDock, drawAllMethod, fullRefreshMethod, changeCurrentPathMethod) +function MineOSCore.iconRightClick(icon, eventData) local action -- Разные контекстные меню - if fs.isDirectory(icon.path) then - if fileFormat == ".app" then + if icon.isDirectory then + if icon.format == ".app" then action = GUI.contextMenu(eventData[3], eventData[4], {MineOSCore.localization.contextMenuShowPackageContent}, "-", @@ -506,7 +626,7 @@ function MineOSCore.iconRightClick(icon, oldPixelsOfIcon, eventData, fileFormat, {MineOSCore.localization.contextMenuCopy}, "-", {MineOSCore.localization.contextMenuRename}, - {MineOSCore.localization.contextMenuCreateShortcut, fileFormat == ".lnk"}, + {MineOSCore.localization.contextMenuCreateShortcut, icon.format == ".lnk"}, -- "-", -- {MineOSCore.localization.contextMenuUploadToPastebin, true}, "-", @@ -518,7 +638,7 @@ function MineOSCore.iconRightClick(icon, oldPixelsOfIcon, eventData, fileFormat, {MineOSCore.localization.contextMenuCut}, {MineOSCore.localization.contextMenuCopy}, {MineOSCore.localization.contextMenuRename}, - {MineOSCore.localization.contextMenuCreateShortcut, fileFormat == ".lnk"}, + {MineOSCore.localization.contextMenuCreateShortcut, icon.format == ".lnk"}, "-", {MineOSCore.localization.contextMenuArchive}, "-", @@ -526,7 +646,7 @@ function MineOSCore.iconRightClick(icon, oldPixelsOfIcon, eventData, fileFormat, ):show() end else - if fileFormat == ".pic" then + if icon.format == ".pic" then action = GUI.contextMenu(eventData[3], eventData[4], -- {MineOSCore.localization.contextMenuEdit}, {MineOSCore.localization.contextMenuEditInPhotoshop}, @@ -535,23 +655,23 @@ function MineOSCore.iconRightClick(icon, oldPixelsOfIcon, eventData, fileFormat, {MineOSCore.localization.contextMenuCut}, {MineOSCore.localization.contextMenuCopy}, {MineOSCore.localization.contextMenuRename}, - {MineOSCore.localization.contextMenuCreateShortcut, fileFormat == ".lnk"}, + {MineOSCore.localization.contextMenuCreateShortcut, icon.format == ".lnk"}, -- "-", -- {MineOSCore.localization.contextMenuUploadToPastebin, true}, "-", {MineOSCore.localization.contextMenuAddToDock}, {MineOSCore.localization.contextMenuDelete, false} ):show() - elseif fileFormat == ".lua" then + elseif icon.format == ".lua" then action = GUI.contextMenu(eventData[3], eventData[4], {MineOSCore.localization.contextMenuEdit}, - {MineOSCore.localization.contextMenuFlashEEPROM, (not component.isAvailable("eeprom") or fs.size(icon.path) > 4096)}, + {MineOSCore.localization.contextMenuFlashEEPROM, (not component.isAvailable("eeprom") or icon.size > 4096)}, {MineOSCore.localization.contextMenuCreateApplication}, "-", {MineOSCore.localization.contextMenuCut}, {MineOSCore.localization.contextMenuCopy}, {MineOSCore.localization.contextMenuRename}, - {MineOSCore.localization.contextMenuCreateShortcut, fileFormat == ".lnk"}, + {MineOSCore.localization.contextMenuCreateShortcut, icon.format == ".lnk"}, -- "-", -- {MineOSCore.localization.contextMenuUploadToPastebin, true}, "-", @@ -566,7 +686,7 @@ function MineOSCore.iconRightClick(icon, oldPixelsOfIcon, eventData, fileFormat, {MineOSCore.localization.contextMenuCut}, {MineOSCore.localization.contextMenuCopy}, {MineOSCore.localization.contextMenuRename}, - {MineOSCore.localization.contextMenuCreateShortcut, fileFormat == ".lnk"}, + {MineOSCore.localization.contextMenuCreateShortcut, icon.format == ".lnk"}, -- "-", -- {MineOSCore.localization.contextMenuUploadToPastebin, true}, "-", @@ -578,102 +698,54 @@ function MineOSCore.iconRightClick(icon, oldPixelsOfIcon, eventData, fileFormat, if action == MineOSCore.localization.contextMenuEdit then ecs.prepareToExit() - MineOSCore.safeLaunch("bin/edit.lua", icon.path) - executeMethod(fullRefreshMethod) + MineOSCore.safeLaunch("/bin/edit.lua", icon.path) + computer.pushSignal("MineOSCore", "updateFileListAndBufferTrueRedraw") elseif action == MineOSCore.localization.contextMenuEditInPhotoshop then MineOSCore.safeLaunch("MineOS/Applications/Photoshop.app/Photoshop.lua", "open", icon.path) - executeMethod(fullRefreshMethod) - -- buffer.paste(1, 1, oldPixelsOfFullScreen) - -- drawAll(true) + computer.pushSignal("MineOSCore", "updateFileList") elseif action == MineOSCore.localization.contextMenuAddToFavourites then - -- addToFavourites(fs.name(path), path) computer.pushSignal("finderFavouriteAdded", icon.path) - executeMethod(drawAllMethod) elseif action == MineOSCore.localization.contextMenuShowPackageContent then - executeMethod(changeCurrentPathMethod) - executeMethod(drawAllMethod) - -- changePath(path) - -- drawAll() + computer.pushSignal("MineOSCore", "updateFileList") elseif action == MineOSCore.localization.contextMenuCopy then _G.clipboard = icon.path - executeMethod(drawAllMethod) elseif action == MineOSCore.localization.contextMenuCut then _G.clipboard = icon.path _G.clipboardCut = true - executeMethod(drawAllMethod) + computer.pushSignal("MineOSCore", "updateFileList") elseif action == MineOSCore.localization.contextMenuDelete then fs.remove(icon.path) - executeMethod(drawAllMethod) - -- getFileList(workPathHistory[currentWorkPathHistoryElement]) - -- drawAll() + computer.pushSignal("MineOSCore", "updateFileList") elseif action == MineOSCore.localization.contextMenuRename then ecs.rename(icon.path) - executeMethod(drawAllMethod) - -- getFileList(workPathHistory[currentWorkPathHistoryElement]) - -- drawAll() + computer.pushSignal("MineOSCore", "updateFileList") elseif action == MineOSCore.localization.contextMenuCreateShortcut then ecs.createShortCut(fs.path(icon.path) .. "/" .. ecs.hideFileFormat(fs.name(icon.path)) .. ".lnk", icon.path) - executeMethod(drawAllMethod) - -- getFileList(workPathHistory[currentWorkPathHistoryElement]) - -- drawAll() + computer.pushSignal("MineOSCore", "updateFileList") elseif action == MineOSCore.localization.contextMenuArchive then -- ecs.info("auto", "auto", "", "Архивация файлов...") archive.pack(ecs.hideFileFormat(fs.name(icon.path))..".pkg", icon.path) - executeMethod(drawAllMethod) - -- getFileList(workPathHistory[currentWorkPathHistoryElement]) - -- drawAll() - elseif action == MineOSCore.localization.contextMenuUploadToPastebin then - MineOSCore.safeLaunch("MineOS/Applications/Pastebin.app/Pastebin.lua", "upload", icon.path) - executeMethod(fullRefreshMethod) - -- shell.execute("MineOS/Applications/Pastebin.app/Pastebin.lua upload " .. path) - -- getFileList(workPathHistory[currentWorkPathHistoryElement]) - -- drawAll(true) + computer.pushSignal("MineOSCore", "updateFileList") elseif action == MineOSCore.localization.contextMenuSetAsWallpaper then - --ecs.error(path) - local wallpaperPath = "MineOS/System/OS/Wallpaper.lnk" - fs.remove(wallpaperPath) - ecs.createShortCut(wallpaperPath, icon.path) - computer.pushSignal("OSWallpaperChanged") - executeMethod(drawAllMethod) - return true - -- buffer.paste(1, 1, oldPixelsOfFullScreen) - -- buffer.draw() + fs.remove(MineOSCore.paths.wallpaper) + ecs.createShortCut(MineOSCore.paths.wallpaper, icon.path) + computer.pushSignal("MineOSCore", "updateWallpaper") elseif action == MineOSCore.localization.contextMenuFlashEEPROM then local file = io.open(icon.path, "r") component.eeprom.set(file:read("*a")) file:close() computer.beep(1500, 0.2) - executeMethod(drawAllMethod) elseif action == MineOSCore.localization.contextMenuCreateApplication then ecs.newApplicationFromLuaFile(icon.path, fs.path(icon.path) or "") - executeMethod(drawAll) - -- getFileList(workPathHistory[currentWorkPathHistoryElement]) - -- drawAll() + computer.pushSignal("MineOSCore", "updateFileList") elseif action == MineOSCore.localization.contextMenuAddToDock then table.insert(_G.OSSettings.dockShortcuts, {path = icon.path}) - ecs.saveOSSettings() - executeMethod(fullRefreshMethod) - else - buffer.paste(icon.x, icon.y, oldPixelsOfIcon) - buffer.draw() + MineOSCore.saveOSSettings() + computer.pushSignal("MineOSCore", "updateFileList") end end -function MineOSCore.iconClick(icon, eventData, selectionColor, selectionTransparency, iconTextColor, clickSleepDelay, somethingCanBeAddedToDock, drawAllMethod, fullRefreshMethod, changeCurrentPathMethod) - local fileFormat = ecs.getFileFormat(icon.path) - local oldPixelsOfIcon = MineOSCore.iconSelect(icon, selectionColor, selectionTransparency, iconTextColor) - local dataToReturn - - if eventData[5] == 0 then - os.sleep(clickSleepDelay) - dataToReturn = MineOSCore.iconLeftClick(icon, oldPixelsOfIcon, fileFormat, drawAllMethod, fullRefreshMethod, changeCurrentPathMethod) - else - dataToReturn = MineOSCore.iconRightClick(icon, oldPixelsOfIcon, eventData, fileFormat, somethingCanBeAddedToDock, drawAllMethod, fullRefreshMethod, changeCurrentPathMethod) - end - return dataToReturn -end - -function MineOSCore.emptyZoneClick(eventData, workPath, drawAllMethod, fullRefreshMethod) +function MineOSCore.emptyZoneClick(eventData, workspace, workpath) local action = GUI.contextMenu(eventData[3], eventData[4], {MineOSCore.localization.contextMenuNewFile}, {MineOSCore.localization.contextMenuNewFolder}, @@ -681,23 +753,24 @@ function MineOSCore.emptyZoneClick(eventData, workPath, drawAllMethod, fullRefre "-", {MineOSCore.localization.contextMenuPaste, (_G.clipboard == nil)} ):show() + if action == MineOSCore.localization.contextMenuNewFile then - ecs.newFile(workPath) - executeMethod(fullRefreshMethod) + ecs.newFile(workpath) + computer.pushSignal("MineOSCore", "updateFileListAndBufferTrueRedraw") elseif action == MineOSCore.localization.contextMenuNewFolder then - ecs.newFolder(workPath) - executeMethod(drawAllMethod) + ecs.newFolder(workpath) + computer.pushSignal("MineOSCore", "updateFileList") elseif action == MineOSCore.localization.contextMenuPaste then - ecs.copy(_G.clipboard, workPath) + ecs.copy(_G.clipboard, workpath) if _G.clipboardCut then fs.remove(_G.clipboard) _G.clipboardCut = nil _G.clipboard = nil end - executeMethod(drawAllMethod) + computer.pushSignal("MineOSCore", "updateFileList") elseif action == MineOSCore.localization.contextMenuNewApplication then - ecs.newApplication(workPath) - executeMethod(drawAllMethod) + ecs.newApplication(workpath) + computer.pushSignal("MineOSCore", "updateFileList") end end diff --git a/lib/advancedLua.lua b/lib/advancedLua.lua index 01b35287..5d75dc76 100755 --- a/lib/advancedLua.lua +++ b/lib/advancedLua.lua @@ -21,7 +21,7 @@ function _G.getCurrentScript() while true do info = debug.getinfo(runLevel) if info then - if info.what == "main" and fs.exists(info.short_src) then return info.short_src end + if info.what == "main" and filesystem.exists(info.short_src) then return info.short_src end else error("Failed to get running script: current runLevel is " .. runLevel) end diff --git a/lib/rayEngine.lua b/lib/rayEngine.lua index 8362e6f4..a6dfe7e0 100755 --- a/lib/rayEngine.lua +++ b/lib/rayEngine.lua @@ -1,15 +1,13 @@ -local libraries = { - computer = "computer", - advancedLua = "advancedLua", - colorlib = "colorlib", - image = "image", - buffer = "doubleBuffering", - GUI = "GUI", - files = "files", - event = "event", -} -for library in pairs(libraries) do if not _G[library] then _G[library] = require(libraries[library]) end end; libraries = nil +local component = require("component") +local computer = require("computer") +local advancedLua = require("advancedLua") +local colorlib = require("colorlib") +local image = require("image") +local buffer = require("doubleBuffering") +local GUI = require("GUI") +local files = require("files") +local event = require("event") ---------------------------------------------------- Константы ------------------------------------------------------------------ @@ -551,7 +549,6 @@ end ---------------------------------------------------------------------------------------------------------------------------------- function rayEngine.changeResolution(width, height) - buffer.clear(0x000000); buffer.draw() component.gpu.setResolution(width, height) buffer.start() rayEngine.calculateAllParameters() diff --git a/lib/syntax.lua b/lib/syntax.lua index c8c9b9ac..e1034234 100755 --- a/lib/syntax.lua +++ b/lib/syntax.lua @@ -1,5 +1,5 @@ -if not _G.buffer then _G.buffer = require("doubleBuffering") end -if not _G.unicode then _G.unicode = require("unicode") end +local buffer = require("doubleBuffering") +local unicode = require("unicode") local syntax = {} diff --git a/lib/windows.lua b/lib/windows.lua index 95bdfd8b..f4c4bbc8 100755 --- a/lib/windows.lua +++ b/lib/windows.lua @@ -94,6 +94,16 @@ local function comboBoxHandler(window, object, objectIndex, eventData) executeObjectMethod(object.onItemSelected, eventData) end +local function menuItemHandler(window, object, objectIndex, eventData) + object.pressed = true + window:draw() + buffer.draw() + executeObjectMethod(object.onTouch, eventData) + object.pressed = false + window:draw() + buffer.draw() +end + function windows.handleEventData(window, eventData) if eventData[1] == "touch" then local object, objectIndex = window:getClickedObject(eventData[3], eventData[4]) @@ -111,6 +121,8 @@ function windows.handleEventData(window, eventData) switchHandler(window, object, objectIndex, eventData) elseif object.type == GUI.objectTypes.comboBox then comboBoxHandler(window, object, objectIndex, eventData) + elseif object.type == GUI.objectTypes.menuItem then + menuItemHandler(window, object, objectIndex, eventData) elseif object.onTouch then executeObjectMethod(object.onTouch, eventData) end