From c67b0cd28291247869aaf5cba34700833a706c46 Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Mon, 21 Jan 2019 09:35:05 +0300 Subject: [PATCH] Added creating an archive on desktop/in current directory feature --- Libraries/Filesystem.lua | 4 ++-- Libraries/GUI.lua | 2 +- Libraries/System.lua | 24 +++++++++++++++++------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Libraries/Filesystem.lua b/Libraries/Filesystem.lua index 879dde17..3a784e16 100644 --- a/Libraries/Filesystem.lua +++ b/Libraries/Filesystem.lua @@ -21,8 +21,8 @@ function filesystem.path(path) return path:match("^(.+%/).") or "" end -function filesystem.name(path, removeSlashes) - return path:match(removeSlashes and "%/?([^%/]+)%/?$" or "%/?([^%/]+%/?)$") +function filesystem.name(path) + return path:match("%/?([^%/]+%/?)$") end function filesystem.extension(path, lower) diff --git a/Libraries/GUI.lua b/Libraries/GUI.lua index 280d2334..60514a8b 100755 --- a/Libraries/GUI.lua +++ b/Libraries/GUI.lua @@ -2482,7 +2482,7 @@ local function filesystemTreeUpdateFileListRecursively(tree, path, offset) if tree.showMode == GUI.IO_MODE_BOTH or tree.showMode == GUI.IO_MODE_DIRECTORY then for i = 1, #expandables do - tree:addItem(filesystem.name(expandables[i], true), path .. expandables[i], offset, true) + tree:addItem(filesystem.name(expandables[i]):sub(1, -2), path .. expandables[i], offset, true) if tree.expandedItems[path .. expandables[i]] then filesystemTreeUpdateFileListRecursively(tree, path .. expandables[i], offset + 2) diff --git a/Libraries/System.lua b/Libraries/System.lua index 27e313b3..95b61065 100755 --- a/Libraries/System.lua +++ b/Libraries/System.lua @@ -483,7 +483,7 @@ function system.icon(x, y, path, textColor, selectionColor) icon.path = path icon.extension = filesystem.extension(icon.path) icon.isDirectory = filesystem.isDirectory(icon.path) - icon.name = filesystem.name(path, true) + icon.name = icon.isDirectory and filesystem.name(path):sub(1, -2) or filesystem.name(path) icon.nameWithoutExtension = filesystem.hideExtension(icon.name) icon.isShortcut = false icon.selected = false @@ -757,12 +757,12 @@ local function iconOnRightClick(icon, e1, e2, e3, e4) local container = addBackgroundContainerWithInput("", system.localization.newFolderFromChosen .. " (" .. #selectedIcons .. ")", system.localization.folderName) container.input.onInputFinished = function() - local path = filesystem.path(selectedIcons[1].path) .. container.input.text + local path = filesystem.path(selectedIcons[1].path) .. container.input.text .. "/" if checkFileToExists(container, path) then filesystem.makeDirectory(path) for i = 1, #selectedIcons do - filesystem.rename(selectedIcons[i].path, path .. "/" .. selectedIcons[i].name) + filesystem.rename(selectedIcons[i].path, path .. selectedIcons[i].name) end iconFieldSaveIconPosition(icon.parent.parent, container.input.text, e3, e4) @@ -776,20 +776,30 @@ local function iconOnRightClick(icon, e1, e2, e3, e4) contextMenu:addSeparator() end - contextMenu:addItem(system.localization.archive .. (#selectedIcons > 1 and " (" .. #selectedIcons .. ")" or "")).onTouch = function() + local subMenu = contextMenu:addSubMenu(system.localization.archive .. (#selectedIcons > 1 and " (" .. #selectedIcons .. ")" or "")) + + local function archive(where) local itemsToArchive = {} for i = 1, #selectedIcons do table.insert(itemsToArchive, selectedIcons[i].path) end - local success, reason = require("Compressor").pack(filesystem.path(icon.path) .. "/Archive.pkg", itemsToArchive) + local success, reason = require("Compressor").pack(where .. "/Archive.pkg", itemsToArchive) if not success then GUI.alert(reason) end - + computer.pushSignal("system", "updateFileList") end + subMenu:addItem(system.localization.inCurrentDirectory).onTouch = function() + archive(filesystem.path(icon.path)) + end + + subMenu:addItem(system.localization.onDesktop).onTouch = function() + archive(paths.user.desktop) + end + local function cutOrCopy(cut) for i = 1, #icon.parent.children do icon.parent.children[i].cut = nil @@ -817,7 +827,7 @@ local function iconOnRightClick(icon, e1, e2, e3, e4) for i = 1, #selectedIcons do if not selectedIcons[i].isShortcut then system.createShortcut( - filesystem.path(selectedIcons[i].path) .. "/" .. selectedIcons[i].nameWithoutExtension .. ".lnk", + filesystem.path(selectedIcons[i].path) .. selectedIcons[i].nameWithoutExtension .. ".lnk", selectedIcons[i].path ) end