Added ActivateFile method instead of a global function (#166).
This commit is contained in:
@@ -220,25 +220,6 @@ function ReLoadFile(filePath, editor, ...)
|
||||
return editor
|
||||
end
|
||||
|
||||
function ActivateFile(filename)
|
||||
local name, suffix, value = filename:match('(.+):([lLpP]?)(%d+)$')
|
||||
if name and not wx.wxFileExists(filename) then filename = name end
|
||||
|
||||
-- check if non-existing file can be loaded from the project folder;
|
||||
-- this is to handle: "project file" used on the command line
|
||||
if not wx.wxFileExists(filename) and not wx.wxIsAbsolutePath(filename) then
|
||||
filename = GetFullPathIfExists(ide:GetProject(), filename) or filename
|
||||
end
|
||||
|
||||
local opened = LoadFile(filename, nil, true)
|
||||
if opened and value then
|
||||
if suffix:upper() == 'P' then opened:GotoPosDelayed(tonumber(value))
|
||||
else opened:GotoPosDelayed(opened:PositionFromLine(value-1))
|
||||
end
|
||||
end
|
||||
return opened
|
||||
end
|
||||
|
||||
local function getExtsString(ed)
|
||||
local exts = ed and ed.spec and ed.spec.exts or {}
|
||||
local knownexts = #exts > 0 and "*."..table.concat(exts, ";*.") or nil
|
||||
|
||||
@@ -861,3 +861,22 @@ function ide:IsProjectSubDirectory(dir)
|
||||
path:Normalize()
|
||||
return path:SameAs(wx.wxFileName(projdir))
|
||||
end
|
||||
|
||||
function ide:ActivateFile(filename)
|
||||
local name, suffix, value = filename:match('(.+):([lLpP]?)(%d+)$')
|
||||
if name and not wx.wxFileExists(filename) then filename = name end
|
||||
|
||||
-- check if non-existing file can be loaded from the project folder;
|
||||
-- this is to handle: "project file" used on the command line
|
||||
if not wx.wxFileExists(filename) and not wx.wxIsAbsolutePath(filename) then
|
||||
filename = GetFullPathIfExists(ide:GetProject(), filename) or filename
|
||||
end
|
||||
|
||||
local opened = LoadFile(filename, nil, true)
|
||||
if opened and value then
|
||||
if suffix:upper() == 'P' then opened:GotoPosDelayed(tonumber(value))
|
||||
else opened:GotoPosDelayed(opened:PositionFromLine(value-1))
|
||||
end
|
||||
end
|
||||
return opened
|
||||
end
|
||||
|
||||
@@ -48,7 +48,7 @@ if success then -- ok, server was started, we are solo
|
||||
RequestAttention()
|
||||
if wx.wxDirExists(filename) then
|
||||
ProjectUpdateProjectDir(filename)
|
||||
elseif not ActivateFile(filename) then
|
||||
elseif not ide:ActivateFile(filename) then
|
||||
DisplayOutputLn(TR("Can't open file '%s': %s"):format(filename, wx.wxSysErrorMsg()))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -659,7 +659,7 @@ do
|
||||
if filename ~= "--" then
|
||||
if wx.wxDirExists(filename) then
|
||||
ProjectUpdateProjectDir(filename)
|
||||
elseif not ActivateFile(filename) then
|
||||
elseif not ide:ActivateFile(filename) then
|
||||
DisplayOutputLn(("Can't open file '%s': %s"):format(filename, wx.wxSysErrorMsg()))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,10 +6,10 @@ ok(pcall(function() LoadFile('some-nonexisting-name') end), "Load non-existing f
|
||||
ClosePage()
|
||||
|
||||
local fullpath = MergeFullPath(wx.wxFileName.GetCwd(), 't/test.lua')
|
||||
ok(ActivateFile('t/test.lua:10'), "Load file:line.")
|
||||
ok(not ActivateFile('t/foo.bar:10'), "Doesn't load non-existent file:line.")
|
||||
ok(ActivateFile(fullpath..':10'), "Load fullpath/file:line.")
|
||||
ok(not ActivateFile(fullpath..'/foo.bar:10'), "Doesn't load non-existent fullpath/file:line.")
|
||||
ok(ide:ActivateFile('t/test.lua:10'), "Load file:line.")
|
||||
ok(not ide:ActivateFile('t/foo.bar:10'), "Doesn't load non-existent file:line.")
|
||||
ok(ide:ActivateFile(fullpath..':10'), "Load fullpath/file:line.")
|
||||
ok(not ide:ActivateFile(fullpath..'/foo.bar:10'), "Doesn't load non-existent fullpath/file:line.")
|
||||
ClosePage() -- close activated file
|
||||
|
||||
local sep = GetPathSeparator()
|
||||
|
||||
@@ -7,7 +7,7 @@ debugger:Listen()
|
||||
local debugfile = MergeFullPath(wx.wxStandardPaths.Get():GetTempDir(), "debug.lua")
|
||||
FileWrite(debugfile, "local a = 1+2\na = 2+3\na = 3+4\na = 4+5\na = 5+6")
|
||||
ok(wx.wxFileExists(debugfile), "File created before starting debugging.")
|
||||
local editor = ActivateFile(debugfile)
|
||||
local editor = ide:ActivateFile(debugfile)
|
||||
editor:BreakpointToggle(4)
|
||||
|
||||
ide:GetMenuBar():Check(ID_CLEAROUTPUT, false)
|
||||
|
||||
Reference in New Issue
Block a user