From 851ebfe28a7c2c157cdf17d4623cb954dc3802ea Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Wed, 28 Sep 2011 17:04:18 -0400 Subject: Added gui.goto_file() for the 'find' and 'run' modules. --- core/.gui.luadoc | 12 ++++++++++++ core/gui.lua | 15 +++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'core') diff --git a/core/.gui.luadoc b/core/.gui.luadoc index 2ff13019..deb39d58 100644 --- a/core/.gui.luadoc +++ b/core/.gui.luadoc @@ -25,6 +25,18 @@ module('gui') -- false. function goto_view(n, relative) end +--- +-- Goes to the buffer with the given filename. +-- If the desired buffer is open in a view, goes to that view. Otherwise, opens +-- the buffer in either the `preferred_view` if given, the first view that is +-- not the current one, a split view if `split` is `true`, or the current view. +-- @param filename The filename of the buffer to go to. +-- @param split If there is only one view, split it and open the buffer in the +-- other view. +-- @param preferred_view When multiple views exist and the desired buffer is not +-- open in any of them, open it in this one. +function goto_file(filename, split, preferred_view) end + --- -- Gets the current split view structure. -- @return table of split views. Each split view entry is a table with 4 diff --git a/core/gui.lua b/core/gui.lua index 6c6e60ef..0beb1a11 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -63,6 +63,21 @@ function gui.switch_buffer() if i then view:goto_buffer(i + 1) end end +-- LuaDoc is in core/.gui.luadoc. +function gui.goto_file(filename, split, preferred_view) + if #_VIEWS == 1 and view.buffer.filename ~= filename and split then + view:split() + else + local other_view = _VIEWS[preferred_view] + for i, v in ipairs(_VIEWS) do + if v.buffer.filename == filename then gui.goto_view(i) return end + if not other_view and v ~= view then other_view = i end + end + if other_view then gui.goto_view(other_view) end + end + io.open_file(filename) +end + local connect = events.connect -- Sets default properties for a Scintilla window. -- cgit v1.2.3