Skip to content

Commit

Permalink
Merge pull request #1844 from Linus045/master
Browse files Browse the repository at this point in the history
Added ability to rename folders
  • Loading branch information
thegrb93 authored Mar 4, 2019
2 parents c32c86f + 956836b commit b9bbbbf
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lua/wire/client/wire_expression2_browser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,31 @@ function PANEL:Init()
self:UpdateFolders()
end)
end)
self:AddRightClick(self.foldermenu, nil, "Rename to..", function()
--get full path and remove the current folder name
local fullpath = string.Split(self.File:GetFolder(),"/")
local oldFolderName = table.remove(fullpath)

Derma_StringRequestNoBlur("Rename folder \"" .. self.File:GetFolder() .. "\"", "Rename Folder", oldFolderName,
function(strTextOut)
-- Renaming starts in the garrysmod folder now, in comparison to other commands that start in the data folder.
strTextOut = string.gsub(strTextOut, ".", invalid_filename_chars)

--we are editing the root folder ("expression2" folder node)
if #fullpath == 0 or #strTextOut == 0 then
return
end

local newFolderPath = table.concat(fullpath,"/") .. "/" .. strTextOut
if file.Exists(newFolderPath, "DATA") then
WireLib.AddNotify("Folder already exists (" .. strTextOut .. ")", NOTIFY_ERROR, 7, NOTIFYSOUND_ERROR1)
elseif not file.Rename(self.File:GetFolder(), newFolderPath) then
WireLib.AddNotify("Rename was not successful", NOTIFY_ERROR, 7, NOTIFYSOUND_ERROR1)
end
self:UpdateFolders()
end)
end)

self:AddRightClick(self.panelmenu, nil, "New File..", function()
Derma_StringRequestNoBlur("New File in \"" .. self.File:GetFolder() .. "\"", "Create new file", "",
function(strTextOut)
Expand Down

0 comments on commit b9bbbbf

Please sign in to comment.