aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2016-06-16 23:29:56 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2016-06-16 23:29:56 -0400
commit4e55b247304ebc962d59ffa61d8788df802b0d6a (patch)
treee502b3e57a216efaa7dbef95c0a5bdf9ea76231a /core
parentb2a88f20460e036012156aa2085114befadfd9af (diff)
downloadtextadept-4e55b247304ebc962d59ffa61d8788df802b0d6a.tar.gz
textadept-4e55b247304ebc962d59ffa61d8788df802b0d6a.zip
Changed arguments to `ui.goto_view()` and `view:goto_buffer()`.
They can accept either objects or relative numbers now. They do not accept absolute indices anymore.
Diffstat (limited to 'core')
-rw-r--r--core/.view.luadoc12
-rw-r--r--core/file_io.lua10
-rw-r--r--core/ui.lua35
3 files changed, 26 insertions, 31 deletions
diff --git a/core/.view.luadoc b/core/.view.luadoc
index 2ae3cb43..4f4af0d2 100644
--- a/core/.view.luadoc
+++ b/core/.view.luadoc
@@ -33,16 +33,12 @@ function split(view, vertical) end
function unsplit(view) end
---
--- Switches to buffer number *n* in the view.
--- *relative* indicates whether or not *n* is an index relative to the current
--- buffer's index in `_BUFFERS` instead of an absolute index.
+-- Switches to buffer *buffer* or the buffer *buffer* number of buffers relative
+-- to the current one.
-- Emits `BUFFER_BEFORE_SWITCH` and `BUFFER_AFTER_SWITCH` events.
-- @param view The view to switch buffers in.
--- @param n A relative or absolute buffer index in `_BUFFERS`. An absolute index
--- of `-1` goes to the last buffer.
--- @param relative Optional flag indicating whether *n* is a relative or
--- absolute index. The default value is `false`, for an absolute index.
+-- @param buffer A buffer or relative buffer number (typically 1 or -1).
-- @see _G._BUFFERS
-- @see events.BUFFER_BEFORE_SWITCH
-- @see events.BUFFER_AFTER_SWITCH
-function goto_buffer(view, n, relative) end
+function goto_buffer(view, buffer) end
diff --git a/core/file_io.lua b/core/file_io.lua
index c4aecfe3..84f0287f 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -104,7 +104,7 @@ function io.open_file(filenames)
local filename = lfs.abspath((filenames[i]:gsub('^file://', '')))
for j = 1, #_BUFFERS do
if filename == _BUFFERS[j].filename then
- view:goto_buffer(j) -- already open
+ view:goto_buffer(_BUFFERS[j]) -- already open
goto continue
end
end
@@ -234,10 +234,10 @@ end
-- @see io.save_file
-- @name save_all_files
function io.save_all_files()
- local current_buffer = _BUFFERS[buffer]
+ local current_buffer = buffer
for i = 1, #_BUFFERS do
if _BUFFERS[i].filename and _BUFFERS[i].modify then
- view:goto_buffer(i)
+ view:goto_buffer(_BUFFERS[i])
io.save_file()
end
end
@@ -272,7 +272,7 @@ end
-- @name close_all_buffers
function io.close_all_buffers()
while #_BUFFERS > 1 do
- view:goto_buffer(#_BUFFERS)
+ view:goto_buffer(_BUFFERS[#_BUFFERS])
if not io.close_buffer() then return false end
end
return io.close_buffer() -- the last one
@@ -311,7 +311,7 @@ end)
events_connect(events.FILE_OPENED, function()
local buf = _BUFFERS[1]
if #_BUFFERS == 2 and not (buf.filename or buf._type or buf.modify) then
- view:goto_buffer(1)
+ view:goto_buffer(_BUFFERS[1])
io.close_buffer()
end
end)
diff --git a/core/ui.lua b/core/ui.lua
index a529c4a4..a30b5e7a 100644
--- a/core/ui.lua
+++ b/core/ui.lua
@@ -59,10 +59,11 @@ local function _print(buffer_type, ...)
events.emit(events.FILE_OPENED)
elseif not ui.silent_print then
for i = 1, #_VIEWS do
- if _VIEWS[i].buffer._type == buffer_type then ui.goto_view(i) break end
+ local view = _VIEWS[i]
+ if view.buffer._type == buffer_type then ui.goto_view(view) break end
end
if view.buffer._type ~= buffer_type then
- view:goto_buffer(_BUFFERS[print_buffer])
+ view:goto_buffer(print_buffer)
end
end
local args, n = {...}, select('#', ...)
@@ -169,7 +170,7 @@ function ui.switch_buffer()
title = _L['Switch Buffers'], columns = columns, items = utf8_list,
width = CURSES and ui.size[1] - 2 or nil
}
- if button == 1 and i then view:goto_buffer(i) end
+ if button == 1 and i then view:goto_buffer(_BUFFERS[i]) end
end
---
@@ -201,16 +202,16 @@ function ui.goto_file(filename, split, preferred_view, sloppy)
local other_view = _VIEWS[preferred_view]
for i = 1, #_VIEWS do
if (_VIEWS[i].buffer.filename or ''):find(patt) then
- ui.goto_view(i)
+ ui.goto_view(_VIEWS[i])
return
end
- if not other_view and _VIEWS[i] ~= view then other_view = i end
+ if not other_view and _VIEWS[i] ~= view then other_view = _VIEWS[i] end
end
if other_view then ui.goto_view(other_view) end
end
for i = 1, #_BUFFERS do
if (_BUFFERS[i].filename or ''):find(patt) then
- view:goto_buffer(i)
+ view:goto_buffer(_BUFFERS[i])
return
end
end
@@ -234,15 +235,15 @@ function ui.set_theme(name, props)
_HOME..'/themes/?.lua')
if not name or not lfs.attributes(name) then return end
props = props or {}
- local current_buffer, current_view = _BUFFERS[buffer], _VIEWS[view]
+ local current_buffer, current_view = buffer, view
for i = 1, #_BUFFERS do
- view:goto_buffer(i)
+ view:goto_buffer(_BUFFERS[i])
dofile(name)
for prop, value in pairs(props) do buffer.property[prop] = value end
end
view:goto_buffer(current_buffer)
for i = 1, #_VIEWS do
- ui.goto_view(i)
+ ui.goto_view(_VIEWS[i])
dofile(name)
for prop, value in pairs(props) do buffer.property[prop] = value end
end
@@ -448,8 +449,9 @@ end)
events_connect(events.BUFFER_BEFORE_SWITCH,
function() view._prev_buffer = buffer end)
events_connect(events.BUFFER_DELETED, function()
- local i = _BUFFERS[view._prev_buffer]
- if i and _BUFFERS[buffer] ~= i then view:goto_buffer(i) end
+ if _BUFFERS[view._prev_buffer] and buffer ~= view._prev_buffer then
+ view:goto_buffer(view._prev_buffer)
+ end
end)
-- Enables and disables mouse mode in curses and focuses and resizes views based
@@ -494,7 +496,7 @@ if CURSES then
if event == buffer.MOUSE_PRESS then
local view = get_view(ui.get_split_table(), y - 1, x) -- title is at y = 1
if not view[1] and not view[2] then
- ui.goto_view(_VIEWS[view])
+ ui.goto_view(view)
resize = nil
else
resize = function(y2, x2)
@@ -558,13 +560,10 @@ local dialog
local get_split_table
---
--- Shifts to view number *n*.
--- *relative* indicates whether or not *n* is an index relative to the current
--- view's index in `_VIEWS` instead of an absolute index.
+-- Shifts to view *view* or the view *view* number of views relative to the
+-- current one.
-- Emits `VIEW_BEFORE_SWITCH` and `VIEW_AFTER_SWITCH` events.
--- @param n A relative or absolute view index in `_VIEWS`.
--- @param relative Optional flag that indicates whether *n* is a relative or
--- absolute index. The default value is `false`, for an absolute index.
+-- @param view A view or relative view number (typically 1 or -1).
-- @see _G._VIEWS
-- @see events.VIEW_BEFORE_SWITCH
-- @see events.VIEW_AFTER_SWITCH