Skip to content

Commit

Permalink
Don't append txt if the user already did (#1606)
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrb93 authored Jan 29, 2024
1 parent 080364f commit 750c21f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
10 changes: 0 additions & 10 deletions lua/starfall/editor/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ if CLIENT then
SF.Editor.colors.medlight = Color(127, 178, 240)
SF.Editor.colors.light = Color(173, 213, 247)

local invalid_filename_chars = {
["*"] = "",
["?"] = "",
[">"] = "",
["<"] = "",
["|"] = "",
["\\"] = "",
['"'] = "",
}

function SF.Editor.init()
if SF.Editor.initialized or SF.Editor.editor then return end

Expand Down
8 changes: 5 additions & 3 deletions lua/starfall/editor/sfderma.lua
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,11 @@ function PANEL:DoRightClick(node)
local oldFile = node:GetFileName()
local saveFile
if string.sub(text, 1, 1)=="/" then
saveFile = "starfall/"..SF.NormalizePath(text)..".txt"
saveFile = "starfall/"..SF.NormalizePath(text)
else
saveFile = string.GetPathFromFilename(node:GetFileName())..SF.NormalizePath(text)..".txt"
saveFile = string.GetPathFromFilename(node:GetFileName())..SF.NormalizePath(text)
end
if not string.match(saveFile, "%.txt$") then saveFile = saveFile .. ".txt" end
SF.Editor.renameFile(oldFile,saveFile)
self:ReloadTree()
end)
Expand All @@ -416,7 +417,8 @@ function PANEL:DoRightClick(node)
function (text)
if text == "" then return end
text = string.GetFileFromFilename(string.gsub(text, ".", invalid_filename_chars))
local saveFile = node:GetFolder().."/"..text..".txt"
local saveFile = node:GetFolder().."/"..text
if not string.match(saveFile, "%.txt$") then saveFile = saveFile .. ".txt" end
SF.FileWrite(saveFile, SF.DefaultCode())
SF.AddNotify(LocalPlayer(), "New file: " .. saveFile, "GENERIC", 7, "DRIP3")
self:ReloadTree()
Expand Down
3 changes: 2 additions & 1 deletion lua/starfall/editor/sfframe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,8 @@ function Editor:SaveFile(Line, close, SaveAs, Func)

Derma_StringRequestNoBlur("Save to New File", "", (str ~= nil and str .. "/" or "") .. self.savefilefn,
function(strTextOut)
strTextOut = self.Location .. "/" .. string.gsub(strTextOut, ".", invalid_filename_chars) .. ".txt"
strTextOut = self.Location .. "/" .. string.gsub(strTextOut, ".", invalid_filename_chars)
if not string.match(strTextOut, "%.txt$") then strTextOut = strTextOut .. ".txt" end
local function save()
if Func then
Func(strTextOut)
Expand Down

0 comments on commit 750c21f

Please sign in to comment.