diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index d7d0f1a3..7ac36976 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -147,6 +147,8 @@ command.add(nil, { end, ["core:change-project-folder"] = function() + local dirname = common.dirname(core.project_dir) + core.command_view:set_text(common.home_encode(dirname) .. PATHSEP) core.command_view:enter("Change Project Folder", function(text, item) text = system.absolute_path(common.home_expand(item and item.text or text)) if text == core.project_dir then return end 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/init.lua b/data/core/init.lua index c71322d1..702e31fd 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -494,6 +494,7 @@ function core.init() core.redraw = true core.visited_files = {} core.restart_request = false + core.quit_request = false core.replacements = whitespace_replacements() core.root_view = RootView() @@ -632,7 +633,7 @@ local function quit_with_function(quit_fn, force) end function core.quit(force) - quit_with_function(os.exit, force) + quit_with_function(function() core.quit_request = true end, force) end @@ -687,17 +688,19 @@ function core.load_plugins() for filename, plugin_dir in pairs(files) do local basename = filename:match("(.-)%.lua$") or filename - local version_match = check_plugin_version(plugin_dir .. '/' .. filename) - if not version_match then - core.log_quiet("Version mismatch for plugin %q from %s", basename, plugin_dir) - local list = refused_list[plugin_dir:find(USERDIR) == 1 and 'userdir' or 'datadir'].plugins - table.insert(list, filename) - end - if version_match and config.plugins[basename] ~= false then - local ok = core.try(require, "plugins." .. basename) - if ok then core.log_quiet("Loaded plugin %q from %s", basename, plugin_dir) end - if not ok then - no_errors = false + local is_lua_file, version_match = check_plugin_version(plugin_dir .. '/' .. filename) + if is_lua_file then + if not version_match then + core.log_quiet("Version mismatch for plugin %q from %s", basename, plugin_dir) + local list = refused_list[plugin_dir:find(USERDIR) == 1 and 'userdir' or 'datadir'].plugins + table.insert(list, filename) + end + if version_match and config.plugins[basename] ~= false then + local ok = core.try(require, "plugins." .. basename) + if ok then core.log_quiet("Loaded plugin %q from %s", basename, plugin_dir) end + if not ok then + no_errors = false + end end end end @@ -743,8 +746,12 @@ end function core.set_active_view(view) assert(view, "Tried to set active view to nil") - if core.active_view and core.active_view.force_focus then return end if view ~= core.active_view then + if core.active_view and core.active_view.force_focus then + core.next_active_view = view + return + end + core.next_active_view = nil if view.doc and view.doc.filename then core.set_visited(view.doc.filename) end @@ -1047,7 +1054,7 @@ function core.run() core.frame_start = system.get_time() local did_redraw = core.step() local need_more_work = run_threads() - if core.restart_request then break end + if core.restart_request or core.quit_request then break end if not did_redraw and not need_more_work then idle_iterations = idle_iterations + 1 -- do not wait of events at idle_iterations = 1 to give a chance at core.step to run diff --git a/data/core/logview.lua b/data/core/logview.lua index 8222dd3b..1ea0e43e 100644 --- a/data/core/logview.lua +++ b/data/core/logview.lua @@ -34,6 +34,7 @@ end local LogView = View:extend() +LogView.context = "session" function LogView:new() LogView.super.new(self) diff --git a/data/core/nagview.lua b/data/core/nagview.lua index 6d6f89f4..3d448cd4 100644 --- a/data/core/nagview.lua +++ b/data/core/nagview.lua @@ -193,7 +193,8 @@ function NagView:next() self:change_hovered(common.find_index(self.options, "default_yes")) end self.force_focus = self.message ~= nil - core.set_active_view(self.message ~= nil and self or core.last_active_view) + core.set_active_view(self.message ~= nil and self or + core.next_active_view or core.last_active_view) end function NagView:show(title, message, options, on_select) diff --git a/data/core/object.lua b/data/core/object.lua index af41b7e9..0941ce5d 100644 --- a/data/core/object.lua +++ b/data/core/object.lua @@ -20,17 +20,6 @@ function Object:extend() end -function Object:implement(...) - for _, cls in pairs({...}) do - for k, v in pairs(cls) do - if self[k] == nil and type(v) == "function" then - self[k] = v - end - end - end -end - - function Object:is(T) local mt = getmetatable(self) while mt do diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 02d836ba..9d017268 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -5,7 +5,6 @@ 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" @@ -605,19 +604,32 @@ end function Node:close_all_docviews(keep_active) + local node_active_view = self.active_view + local lost_active_view = false if self.type == "leaf" then local i = 1 while i <= #self.views do local view = self.views[i] - if view:is(DocView) 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 + end else i = i + 1 end end + self.tab_offset = 1 if #self.views == 0 and self.is_primary_node then + -- if we are not the primary view and we had the active view it doesn't + -- matter to reattribute the active view because, within the close_all_docviews + -- top call, the primary node will take the active view anyway. + -- Set the empty view and takes the active view. self:add_view(EmptyView()) + elseif #self.views > 0 and lost_active_view then + -- In practice we never get there but if a view remain we need + -- to reset the Node's active view. + self:set_active_view(self.views[1]) end else self.a:close_all_docviews(keep_active) 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) diff --git a/meson.build b/meson.build index 38a47d1e..0c5bc865 100644 --- a/meson.build +++ b/meson.build @@ -1,12 +1,10 @@ project('lite-xl', ['c', 'cpp'], - version : '2.0.0', + version : '2.0.1', license : 'MIT', meson_version : '>= 0.54', default_options : ['c_std=gnu11', 'cpp_std=c++03'] ) -# TODO: the project version could be automatically generated from git with: -# version : run_command('bash', 'scripts/version.sh').stdout(), #=============================================================================== # Configuration