From 1b425b5d105249d7ddeb750f050a0ef987c678cf Mon Sep 17 00:00:00 2001 From: IgorTimofeev Date: Fri, 3 Jun 2022 01:30:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D0=B0=D0=BD=D1=83?= =?UTF-8?q?=D0=BB=20=D0=B5=D0=B1=D0=B0=D0=BB=D1=83=20=D1=8D=D1=82=D1=83=20?= =?UTF-8?q?=D1=81=20=D1=8F=D1=80=D0=BB=D1=8B=D0=BA=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Libraries/System.lua | 94 ++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 39 deletions(-) diff --git a/Libraries/System.lua b/Libraries/System.lua index aa3f5af5..b4002518 100755 --- a/Libraries/System.lua +++ b/Libraries/System.lua @@ -472,12 +472,14 @@ function system.updateIconProperties() computer.pushSignal("system", "updateFileList") end -local function iconFieldGetSelectedIcons(iconField) - local selectedIcons = {} +local function gridIconFieldGetSelectedIcons(iconField) + local selectedIcons, icon = {} for i = 2, #iconField.children do - if iconField.children[i].selected then - table.insert(selectedIcons, iconField.children[i]) + icon = iconField.children[i] + + if icon.selected then + table.insert(selectedIcons, icon) end end @@ -770,31 +772,32 @@ local function iconOnRightClick(selectedIcons, icon, e1, e2, e3, e4) if not icon.isShortcut or #selectedIcons > 1 then local subMenu = contextMenu:addSubMenuItem(localization.createShortcut) - subMenu:addItem(localization.inCurrentDirectory).onTouch = function() - for i = 1, #selectedIcons do - if not selectedIcons[i].isShortcut then - system.createShortcut( - filesystem.path(selectedIcons[i].path) .. filesystem.hideExtension(selectedIcons[i].name), - selectedIcons[i].path - ) + local function addShortcutItem(name, pathGetter) + subMenu:addItem(name).onTouch = function() + local selectedIcon + + for i = 1, #selectedIcons do + selectedIcon = selectedIcons[i] + + if not selectedIcon.isShortcut then + system.createShortcut( + pathGetter(selectedIcon) .. filesystem.hideExtension(selectedIcon.name), + selectedIcon.path + ) + end end + + computer.pushSignal("system", "updateFileList") end - - computer.pushSignal("system", "updateFileList") end - subMenu:addItem(localization.onDesktop).onTouch = function() - for i = 1, #selectedIcons do - if not selectedIcons[i].isShortcut then - system.createShortcut( - paths.user.desktop .. filesystem.hideExtension(selectedIcons[i].name), - selectedIcons[i].path - ) - end - end - - computer.pushSignal("system", "updateFileList") - end + addShortcutItem(localization.inCurrentDirectory, function(selectedIcon) + return filesystem.path(selectedIcon.path) + end) + + addShortcutItem(localization.onDesktop, function(selectedIcon) + return paths.user.desktop + end) end local subMenu = contextMenu:addSubMenuItem(localization.archive .. (#selectedIcons > 1 and " (" .. #selectedIcons .. ")" or "")) @@ -899,15 +902,14 @@ local function iconFieldIconEventHandler(workspace, icon, e1, e2, e3, e4, e5, .. if e5 == 0 then iconDeselectAndSelect(icon) else - local selectedIcons = iconField:getSelectedIcons() - - -- Right click on multiple selected icons - if not icon.selected then + -- Если иконка выбрана - похуй, все ок + if icon.selected then + iconOnRightClick(iconField:getSelectedIcons(), icon, e1, e2, e3, e4, e5, ...) + -- Если не - тогда сначала выбираем ее, а потом обрабатываем + else iconDeselectAndSelect(icon) - selectedIcons = {icon} + iconOnRightClick({icon}, icon, e1, e2, e3, e4, e5, ...) end - - iconOnRightClick(selectedIcons, icon, e1, e2, e3, e4, e5, ...) end elseif e1 == "double_touch" and icon:isPointInside(e3, e4) and e5 == 0 then @@ -1128,11 +1130,11 @@ local function iconFieldUpdateFileList(iconField) anyIconFieldUpdateFileList(iconField, function(list) local function addGridIcon(x, y, path) local icon = system.icon( - x, - y, - iconField.path .. path, - iconField.colors - ) + x, + y, + iconField.path .. path, + iconField.colors + ) anyIconFieldAddIcon(iconField, icon) icon.eventHandler = iconFieldIconEventHandler @@ -1701,13 +1703,27 @@ function system.gridIconField(x, y, width, height, xOffset, yOffset, path, defau iconField.saveIconConfig = iconFieldSaveIconConfig iconField.deleteIconConfig = iconFieldDeleteIconConfig iconField.updateFileList = iconFieldUpdateFileList - iconField.getSelectedIcons = iconFieldGetSelectedIcons + iconField.getSelectedIcons = gridIconFieldGetSelectedIcons anyIconFieldAddInfo(iconField, path) return iconField end +local function listIconFieldGetSelectedIcons(iconField) + local selectedIcons, icon = {} + + for i = 1, #iconField.children do + icon = iconField.children[i] + + if icon.selected and icon.path then + table.insert(selectedIcons, icon) + end + end + + return selectedIcons +end + function system.listIconField(x, y, width, height, path, ...) local iconField = GUI.table(x, y, width, height, 1, ...) @@ -1734,7 +1750,7 @@ function system.listIconField(x, y, width, height, path, ...) iconField:addColumn(localization.type, GUI.SIZE_POLICY_ABSOLUTE, 10) iconField.updateFileList = listIconFieldUpdateFileList - iconField.getSelectedIcons = iconFieldGetSelectedIcons + iconField.getSelectedIcons = listIconFieldGetSelectedIcons anyIconFieldAddInfo(iconField, path)