Skip to content

Commit 67e842b

Browse files
committed
Add plugin_view workspace state management support
1 parent aaf09e9 commit 67e842b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

plugins/plugin_manager/plugin_view.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,36 @@ function PluginView:new()
4444
plugin_view = self
4545
end
4646

47+
function PluginView:get_state()
48+
return {
49+
sort = self.sort,
50+
selected_plugin_idx = self.selected_plugin_idx,
51+
scroll = {
52+
x = self.scroll.x,
53+
y = self.scroll.y,
54+
to = { x = self.scroll.to.x, y = self.scroll.to.y }
55+
},
56+
}
57+
end
58+
59+
function PluginView.from_state(state)
60+
local pv = PluginView()
61+
pv.sort = state.sort
62+
pv.scroll = state.scroll
63+
core.add_thread(function()
64+
while not pv.initialized do
65+
coroutine.yield(0.3)
66+
end
67+
local offset = state.selected_plugin_idx
68+
if offset > 0 then
69+
pv.selected_plugin = pv:get_sorted_plugins()[offset]
70+
pv.selected_plugin_idx = offset
71+
core.redraw = true
72+
end
73+
end)
74+
return pv
75+
end
76+
4777
local function get_plugin_text(plugin)
4878
return (plugin.name or plugin.id), (plugin.status == "core" and VERSION or plugin.version), plugin.type, plugin.status, join(", ", plugin.tags), plugin.author or "unknown", plugin.description-- (plugin.description or ""):gsub("%[[^]+%]%([^)]+%)", "")
4979
end

0 commit comments

Comments
 (0)