diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2023-12-02 11:28:22 -0500 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2023-12-02 11:28:22 -0500 |
commit | 9b36bc80bb856ce60595f8911acabaf03428ab8f (patch) | |
tree | 4e91de294ebcc4d9a5491295a89b917a17b728b1 | |
parent | aa0c6115638195b39eeca614cd28f7831c22dd0a (diff) | |
download | lite-xl-plugin-manager-9b36bc80bb856ce60595f8911acabaf03428ab8f.tar.gz lite-xl-plugin-manager-9b36bc80bb856ce60595f8911acabaf03428ab8f.zip |
Reworded things, incorporated Guldo's changes.
-rw-r--r-- | plugins/plugin_manager/init.lua | 7 | ||||
-rw-r--r-- | plugins/welcome.lua | 76 |
2 files changed, 55 insertions, 28 deletions
diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua index 3f27f96..76f799a 100644 --- a/plugins/plugin_manager/init.lua +++ b/plugins/plugin_manager/init.lua @@ -131,7 +131,7 @@ local function run(cmd, progress) progress_line, v[3] = extract_progress(v[3]) if err then v[2]:reject(json.decode(err).error) - else + else v[2]:reject(err) end end @@ -366,9 +366,4 @@ if pcall(require, "plugins.terminal") then }) end -keymap.add({ - ['ctrl+shift+1'] = 'plugin-manager:show', - ['ctrl+shift+2'] = 'plugin-manager:open-session' -}) - return PluginManager diff --git a/plugins/welcome.lua b/plugins/welcome.lua index f0d0401..afd28ed 100644 --- a/plugins/welcome.lua +++ b/plugins/welcome.lua @@ -12,7 +12,13 @@ local Node = require "core.node" local PluginManager = require "plugins.plugin_manager" local PluginView = require "plugins.plugin_manager.plugin_view" + local welcomed = system.get_file_info(USERDIR .. PATHSEP .. "welcomed") ~= nil +if welcomed then return end + +local status, tv = pcall(require "plugins.treeview") +if not status then command.perform("treeview:toggle") end + local loading = nil local hovered_button = nil @@ -20,21 +26,23 @@ local function draw_button(view, x, y, w, button) local highlight = hovered_button == button if highlight then core.request_cursor("hand") end local button_height = style.font:get_height() + style.padding.y * 2 - renderer.draw_rect(x + w, y, button_height, button_height, highlight and style.dim or style.background2) - renderer.draw_text(style.icon_font, "+", x + w + style.padding.x, y + style.padding.y + 2, style.accent) - common.draw_text(style.font, highlight and style.accent or style.text, button.label, "left", x + style.padding.x, y, w, button_height) - return x, y, w, button_height + local tw = common.draw_text(style.font, highlight and style.accent or style.text, button.label, "left", x, y, w, button_height) + if tw < x + w then + renderer.draw_rect(x + w, y - 3, button_height, button_height, highlight and style.dim or style.background2) + renderer.draw_text(style.icon_font, "+", x + w + style.padding.x, y + style.padding.y, style.accent) + end + return x, y, w + button_height, button_height end local buttons = { { label = "Install Addons Package", command = "welcome:install-addons", tooltip = { - "Will install the basic addons package for lite-xl.", + "Installs syntax highlightings, themes, and plugins that make Lite XL easier to use.", "", - "Includes all syntax higlightings, various themes, as well as a few extra plugins to help lite-xl a bit more easy to interact with.", - "Recommened for newcomers to lite-xl. After install, your editor will silently restart, and you'll be fully ready to start with lite-xl." + "Recommended for newcomers to Lite XL.", + "Requires a network connection." } }, - { label = "Open Plugin Manager", command = "welcome:open-plugin-manager", tooltip = { "Will open the plugin manager, and allow you to select which plugins you'd like to install before beginning with lite-xl." } }, - { label = "Dismiss Welcome Options", command = "welcome:dismiss", tooltip = { "Dismisses this screen, never to be seen again." } } + { label = "Open Plugin Manager", command = "welcome:open-plugin-manager", tooltip = { "Manually select plugins you'd like to install before beginning with Lite XL.", "", "Requires a network connection." } }, + { label = "Dismiss Welcome Options", command = "welcome:dismiss", tooltip = { "Dismisses this screen permanently." } } } local old_get_name = EmptyView.get_name @@ -42,21 +50,46 @@ function EmptyView:get_name() if welcomed then return old_get_name(self) end ret local old_draw = EmptyView.draw function EmptyView:draw() + if welcomed then return old_draw(self) end + self:draw_background(style.background) if loading then local y = self.position.y + self.size.y / 2 self:draw_background(style.background) PluginView.draw_loading_screen(self, loading.label, loading.percent) - -- common.draw_text(style.big_font, style.dim, "Installing addons package. Please wait...", "center", self.position.x, y, self.size.x, style.font:get_height()) return end - old_draw(self) - if welcomed then return end - local x, y, w, h = self.position.x + self.size.x / 2 + + + local title = "Lite XL" + local version = "version " .. VERSION + local title_width = style.big_font:get_width(title) + local version_width = style.font:get_width(version) local button_width = math.min(self.size.x / 2 - 80, 300) - x = self.position.x + self.size.x / 2 - 50 + + local th = style.big_font:get_height() + local dh = 2 * th + style.padding.y * #buttons + local w = math.max(title_width, version_width) + button_width + style.padding.x * 2 + math.ceil(1*SCALE) + local h = (style.font:get_height() + style.padding.y) * #buttons + style.padding.y + style.font:get_height() + local x = self.position.x + math.max(style.padding.x, (self.size.x - w) / 2) + local y = self.position.y + (self.size.y - h) / 2 + + + local x1, y1 = x, y + ((dh - th) / #buttons) + local xv + if version_width > title_width then + version = VERSION + version_width = style.font:get_width(version) + xv = x1 - (version_width - title_width) + end + x = renderer.draw_text(style.big_font, title, x1, y1, style.dim) + renderer.draw_text(style.font, version, xv, y1 + th, style.dim) + x = x + style.padding.x + renderer.draw_rect(x, y, math.ceil(1 * SCALE), dh, style.dim) + + x = x + style.padding.x + local button_height = style.padding.y * 2 + style.font:get_height() - local y = self.position.y + self.size.y / 2 - ((button_height + style.padding.y) * #buttons) / 2 - style.padding.y renderer.draw_rect(x, y, button_width, #buttons * (button_height + style.padding.y), style.background) for i,v in ipairs(buttons) do v.x, v.y, v.w, v.h = draw_button(self, x + style.padding.x, y, button_width, v) @@ -65,11 +98,11 @@ function EmptyView:draw() if hovered_button then for i, v in ipairs(hovered_button.tooltip) do - common.draw_text(style.font, style.dim, v, "center", self.position.x, y, self.size.x, style.font:get_height()) + common.draw_text(style.font, style.text, v, "center", self.position.x, y + style.padding.y, self.size.x, style.font:get_height()) y = y + style.font:get_height() end else - common.draw_text(style.font, style.dim, "Hover over one of the options below to get started.", "center", self.position.x, y, self.size.x, style.font:get_height()) + common.draw_text(style.font, style.text, "Hover over one of the options above to get started.", "center", self.position.x, y + style.padding.y, self.size.x, style.font:get_height()) end end @@ -82,7 +115,7 @@ function EmptyView:on_mouse_moved(x, y) end end -function EmptyView:on_mouse_released(button, x, y) +function EmptyView:on_mouse_pressed(button, x, y) if hovered_button and not welcomed then command.perform(hovered_button.command) end end @@ -90,6 +123,7 @@ end local function terminate_welcome() io.open(USERDIR .. PATHSEP .. "welcomed", "wb"):close() + command.perform("treeview:toggle") welcomed = true end @@ -98,8 +132,8 @@ command.add(EmptyView, { core.log("Installing addons...") loading = { percent = 0, label = "Initializing..." } core.redraw = true - PluginManager:install({ id = "meta_addons" }, { progress = function(progress) - loading = progress + PluginManager:install({ id = "meta_addons" }, { progress = function(progress) + loading = progress core.redraw = true end, restart = false }):done(function() loading = false @@ -114,11 +148,9 @@ command.add(EmptyView, { end, ["welcome:open-plugin-manager"] = function() command.perform("plugin-manager:show") - terminate_welcome() end, ["welcome:dismiss"] = function() terminate_welcome() end }) -return { } |