diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2023-02-04 15:36:01 -0500 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2023-02-04 15:36:01 -0500 |
commit | 5c61eb11703b92270592507b6fd3ae27ae6f76a5 (patch) | |
tree | 9c38068495c894795854fdc845fd64d68dcf86cc /plugins | |
parent | 52fbb4b6985e9dee33387c67727437910d0b8d0b (diff) | |
download | lite-xl-plugin-manager-5c61eb11703b92270592507b6fd3ae27ae6f76a5.tar.gz lite-xl-plugin-manager-5c61eb11703b92270592507b6fd3ae27ae6f76a5.zip |
Added in refresh and upgrade commands.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/plugin_manager/init.lua | 20 | ||||
-rw-r--r-- | plugins/plugin_manager/plugin_view.lua | 74 |
2 files changed, 64 insertions, 30 deletions
diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua index eea9efb..9dee036 100644 --- a/plugins/plugin_manager/init.lua +++ b/plugins/plugin_manager/init.lua @@ -21,7 +21,7 @@ config.plugins.plugin_manager = common.merge({ cachdir = USERDIR .. PATHSEP .. "lpm", -- Path to the folder that holds user-specified plugins. userdir = USERDIR, - -- Path to ssl certificate directory. + -- Path to ssl certificate directory or bunde. Nil will auto-detect. ssl_certs = nil, -- Whether or not to force install things. force = false, @@ -165,6 +165,17 @@ function PluginManager:refresh(progress) end +function PluginManager:upgrade(progress) + local prom = Promise.new() + run({ "update" }, progress):done(function() + run({ "upgrade" }, progress):done(function() + prom:resolve() + end) + end) + return prom +end + + function PluginManager:get_addons() local prom = Promise.new() if self.addons then @@ -227,7 +238,7 @@ command.add(nil, { function(name) PluginManager:get_addon(name):done(function(addon) core.log("Attempting to install plugin " .. name .. "...") - PluginManager:install(addon):done(function() + PluginManager:install(addon, PluginManager.view.progress_callback):done(function() core.log("Successfully installed plugin " .. addon.id .. ".") end) end):fail(function() @@ -252,7 +263,7 @@ command.add(nil, { function(name) PluginManager:get_addon(name):done(function(addon) core.log("Attempting to uninstall plugin " .. addon.id .. "...") - PluginManager:install(addon):done(function() + PluginManager:uninstall(addon, PluginManager.view.progress_callback):done(function() core.log("Successfully uninstalled plugin " .. addon.id .. ".") end) end):fail(function() @@ -299,7 +310,8 @@ command.add(nil, { end ) end, - ["plugin-manager:refresh"] = function() PluginManager:refresh():done(function() core.log("Successfully refreshed plugin listing.") end) end, + ["plugin-manager:refresh"] = function() PluginManager:refresh(PluginManager.view.progress_callback):done(function() core.log("Successfully refreshed plugin listing.") end) end, + ["plugin-manager:upgrade"] = function() PluginManager:upgrade(PluginManager.view.progress_callback):done(function() core.log("Successfully upgraded installed plugins.") end) end, ["plugin-manager:show"] = function() local node = core.root_view:get_active_node_default() node:add_view(PluginManager.view(PluginManager)) diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua index 98dcc7b..1f16b3c 100644 --- a/plugins/plugin_manager/plugin_view.lua +++ b/plugins/plugin_manager/plugin_view.lua @@ -23,12 +23,6 @@ end local plugin_view = nil PluginView.menu = ContextMenu() -PluginView.menu:register(nil, { - { text = "Install", command = "plugin-manager:install-hovered" }, - { text = "Uninstall", command = "plugin-manager:uninstall-hovered" }, - { text = "View Source", command = "plugin-manager:view-source-hovered" } -}) - function PluginView:new() PluginView.super.new(self) self.scrollable = true @@ -46,10 +40,7 @@ function PluginView:new() self.progress = progress core.redraw = true end - self.plugin_manager:refresh(self.progress_callback):done(function() - self.initialized = true - self:refresh() - end) + self:refresh() plugin_view = self end @@ -104,22 +95,27 @@ end function PluginView:refresh() - self.widths = {} - for i,v in ipairs(self.plugin_table_columns) do - table.insert(self.widths, style.font:get_width(v)) - end - for i, plugin in ipairs(self:get_plugins()) do - local t = { get_plugin_text(plugin) } - for j = 1, #self.widths do - self.widths[j] = math.max(style.font:get_width(t[j] or ""), self.widths[j]) + self.loading = true + return self.plugin_manager:refresh(self.progress_callback):done(function() + self.loading = false + self.initialized = true + self.widths = {} + for i,v in ipairs(self.plugin_table_columns) do + table.insert(self.widths, style.font:get_width(v)) end - end - local max = 0 - if self.widths then - for i, v in ipairs(self.widths) do max = max + v end - end - self.max_width = max + style.padding.x * #self.widths - core.redraw = true + for i, plugin in ipairs(self:get_plugins()) do + local t = { get_plugin_text(plugin) } + for j = 1, #self.widths do + self.widths[j] = math.max(style.font:get_width(t[j] or ""), self.widths[j]) + end + end + local max = 0 + if self.widths then + for i, v in ipairs(self.widths) do max = max + v end + end + self.max_width = max + style.padding.x * #self.widths + core.redraw = true + end) end @@ -154,7 +150,7 @@ function PluginView:draw() local th = style.font:get_height() local lh = th + style.padding.y - if not self.initialized then + if not self.initialized or not self.widths then common.draw_text(style.big_font, style.dim, "Loading...", "center", self.position.x, self.position.y, self.size.x, self.size.y) local width = self.size.x / 2 local offset_y = self.size.y / 2 @@ -231,6 +227,15 @@ function PluginView:reinstall(plugin) end) end + +function PluginView:upgrade() + self.loading = true + return self.plugin_manager:upgrade(self.progress_callback):done(function() + self.loading = false + self.selected_plugin, plugin_view.selected_plugin_idx = nil, nil + end) +end + command.add(PluginView, { ["plugin-manager:select"] = function(x, y) plugin_view.selected_plugin, plugin_view.selected_plugin_idx = plugin_view.hovered_plugin, plugin_view.hovered_plugin_idx @@ -282,6 +287,12 @@ command.add(PluginView, { end, ["plugin-manager:scroll-page-bottom"] = function() plugin_view.scroll.to.y = plugin_view:get_scrollable_size() + end, + ["plugin-manager:refresh-all"] = function() -- Separate command from `refresh`, because we want to only have the keycombo be valid on the plugin view screen. + plugin_view:refresh():done(function() core.log("Successfully refreshed plugin listing.") end) + end, + ["plugin-manager:upgrade-all"] = function() + plugin_view:upgrade():done(function() core.log("Successfully upgraded installed plugins.") end) end }) command.add(function() @@ -332,9 +343,20 @@ keymap.add { ["end"] = "plugin-manager:scroll-page-bottom", ["lclick"] = "plugin-manager:select", ["ctrl+f"] = "plugin-manager:find", + ["ctrl+r"] = "plugin-manager:refresh-all", + ["ctrl+u"] = "plugin-manager:upgrade-all", ["2lclick"] = { "plugin-manager:install-selected", "plugin-manager:uninstall-selected" }, ["return"] = { "plugin-manager:install-selected", "plugin-manager:uninstall-selected" } } +PluginView.menu:register(nil, { + { text = "Install", command = "plugin-manager:install-hovered" }, + { text = "Uninstall", command = "plugin-manager:uninstall-hovered" }, + { text = "View Source", command = "plugin-manager:view-source-hovered" }, + ContextMenu.DIVIDER, + { text = "Refresh Listing", command = "plugin-manager:refresh-all" }, + { text = "Upgrade All", command = "plugin-manager:upgrade-all" }, +}) + return PluginView |