Rename to...Refresh file button.When a file is renamed, the editor doesn't seem to update the underlying filename for the opened file.
For example, the following script error is thrown:
Console output:
Erroring opening file: expression2/new-filename.txt
There is a typo in there (Erroring). I have also noticed that there is no stack trace, and no line break at the end of the error message.
How did you get that error message? I tested it just now, and got no error. I renamed the file while having that file opened in a tab, and I was able to use that tab just fine. When I saved that tab I had opened, however, it saved it as the old file path (which is fine and could be considered intended behavior, since this is how most editors handle this, like for example sublime text 3).
I have prepared a small snippet of code which will go through all opened tabs and check if any of them have the renamed file opened. If so, it'll update their internal path. But like I said, this is not necessary and it might even be more confusing than just leaving it as it is.
If you tell me how to reproduce the error, I can just fix that instead.
Here's the entire updated rename to function with the small change, in case I update my local copy of gmod and overwrite this change (I don't feel this change is worth creating a whole branch for)
self:AddRightClick(self.filemenu, nil, "Rename to..", function()
local fname = string.StripExtension(fileName(self.File:GetFileName()))
Derma_StringRequestNoBlur("Rename File \"" .. fname .. "\"", "Rename file " .. fname, fname,
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)
local oldpath = self.File:GetFileName()
local newpath = string.GetPathFromFilename(oldpath) .. strTextOut .. ".txt"
local contents = file.Read(oldpath)
file.Delete(oldpath)
file.Write(newpath, contents)
-- Update all references to this file path in currently opened tabs
local editor = wire_expression2_editor
if editor then
for i=1, editor:GetNumTabs() do
local chosenfile = editor:GetEditor(i).chosenfile
if chosenfile and chosenfile == oldpath then
editor:GetEditor(i).chosenfile = newpath
end
end
end
self:UpdateFolders()
end)
end)
@AbigailBuccaneer thoughts?
A git branch is very light-weight. Don't be afraid to create one, even if it's just for showing things.
It's easier to see a diff of what you actually changed that way
This might have been fixed by #1524.
This might have been fixed by #1524.
I just went to test it (Wiremod's version: 'Git 722b3c1'), and that would be a no.
This is still a bug.