Register `View` classes
This allows matching a `View` class name to the class itself.
This commit is contained in:
parent
ccba91261d
commit
b4ed485ce9
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue