From d46475532f95a1371dd9187382c407eec7d52a98 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 27 Aug 2021 23:55:17 +0200 Subject: [PATCH] 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. --- data/core/commandview.lua | 2 ++ data/core/docview.lua | 1 + data/core/logview.lua | 1 + data/core/rootview.lua | 5 +---- data/core/view.lua | 4 ++++ data/plugins/projectsearch.lua | 1 + 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/data/core/commandview.lua b/data/core/commandview.lua index 4d518d02..eb7febc7 100644 --- a/data/core/commandview.lua +++ b/data/core/commandview.lua @@ -15,6 +15,8 @@ end local CommandView = DocView:extend() +CommandView.context = "application" + local max_suggestions = 10 local noop = function() end diff --git a/data/core/docview.lua b/data/core/docview.lua index 89da8190..17fb534a 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -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 diff --git a/data/core/logview.lua b/data/core/logview.lua index d7142fb5..b731df3c 100644 --- a/data/core/logview.lua +++ b/data/core/logview.lua @@ -5,6 +5,7 @@ local View = require "core.view" local LogView = View:extend() +LogView.context = "session" function LogView:new() LogView.super.new(self) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 8bc402f9..f2499e68 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -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 diff --git a/data/core/view.lua b/data/core/view.lua index 2fb431d6..d1374ee4 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -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 } diff --git a/data/plugins/projectsearch.lua b/data/plugins/projectsearch.lua index 3873da3b..45967697 100644 --- a/data/plugins/projectsearch.lua +++ b/data/plugins/projectsearch.lua @@ -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)