Introduce View objects context property

Used to determine if an instance of the given class should
be closed or not when a project session is terminated.
This commit is contained in:
Francesco Abbate 2021-08-27 23:55:17 +02:00
parent 9592ce85f5
commit d46475532f
6 changed files with 10 additions and 4 deletions

View File

@ -15,6 +15,8 @@ end
local CommandView = DocView:extend()
CommandView.context = "application"
local max_suggestions = 10
local noop = function() end

View File

@ -9,6 +9,7 @@ local View = require "core.view"
local DocView = View:extend()
DocView.context = "session"
local function move_to_line_offset(dv, line, col, offset)
local xo = dv.last_x_offset

View File

@ -5,6 +5,7 @@ local View = require "core.view"
local LogView = View:extend()
LogView.context = "session"
function LogView:new()
LogView.super.new(self)

View File

@ -5,10 +5,8 @@ local style = require "core.style"
local keymap = require "core.keymap"
local Object = require "core.object"
local View = require "core.view"
local CommandView = require "core.commandview"
local NagView = require "core.nagview"
local DocView = require "core.docview"
local LogView = require "core.logview"
local EmptyView = View:extend()
@ -602,8 +600,7 @@ function Node:close_all_docviews(keep_active)
local i = 1
while i <= #self.views do
local view = self.views[i]
if (view:is(DocView) or view:is(LogView)) and not view:is(CommandView) and
(not keep_active or view ~= self.active_view) then
if view.context == "session" and (not keep_active or view ~= self.active_view) then
table.remove(self.views, i)
if view == node_active_view then
lost_active_view = true

View File

@ -7,6 +7,10 @@ local Object = require "core.object"
local View = Object:extend()
-- context can be "application" or "session". The instance of objects
-- with context "session" will be closed when a project session is
-- terminated. The context "application" is for functional UI elements.
View.context = "application"
function View:new()
self.position = { x = 0, y = 0 }

View File

@ -9,6 +9,7 @@ local View = require "core.view"
local ResultsView = View:extend()
ResultsView.context = "session"
function ResultsView:new(text, fn)
ResultsView.super.new(self)