Register `View` classes

This allows matching a `View` class name to the class itself.
This commit is contained in:
Guldoman 2021-08-29 04:46:10 +02:00
parent ccba91261d
commit b4ed485ce9
No known key found for this signature in database
GPG Key ID: C08A498EC7F1AFDD
2 changed files with 20 additions and 0 deletions

View File

@ -36,6 +36,16 @@ local function save_session()
end
local registered_views = { }
function core.register_view(name, class)
registered_views[name] = class
end
function core.get_registered_view(name)
return registered_views[name]
end
local function update_recents_project(action, dir_path_abs)
local dirname = common.normalize_path(dir_path_abs)
if not dirname then return end

View File

@ -7,6 +7,16 @@ local Object = require "core.object"
local View = Object:extend()
-- Override how objects are created. This allows for automatic Views registration
function View:extend(register_name)
local new_class = View.super.extend(self)
if register_name then
new_class.registered_name = register_name
core.register_view(register_name, new_class)
end
return new_class
end
-- 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.