From f91c4d2671012a52ac0ed988426fe8bbdb1216c9 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 30 Nov 2023 14:19:32 -0500 Subject: Split off loading screen functionality. --- plugins/plugin_manager/plugin_view.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'plugins/plugin_manager') diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua index 9e9d67c..b864675 100644 --- a/plugins/plugin_manager/plugin_view.lua +++ b/plugins/plugin_manager/plugin_view.lua @@ -145,20 +145,23 @@ local function draw_loading_bar(x, y, width, height, percent) renderer.draw_rect(x, y, width * percent, height, style.caret) end +function PluginView:draw_loading_screen(label, percent) + 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 + if self.progress then + common.draw_text(style.font, style.dim, label, "center", self.position.x, self.position.y + offset_y + lh, self.size.x, lh) + draw_loading_bar(self.position.x + (self.size.x / 2) - (width / 2), self.position.y + self.size.y / 2 + (lh * 2), width, lh, percent) + end +end + function PluginView:draw() self:draw_background(style.background) local th = style.font:get_height() local lh = th + style.padding.y 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 - if self.progress then - common.draw_text(style.font, style.dim, self.progress.label, "center", self.position.x, self.position.y + offset_y + lh, self.size.x, lh) - draw_loading_bar(self.position.x + (self.size.x / 2) - (width / 2), self.position.y + self.size.y / 2 + (lh * 2), width, lh, self.progress.percent) - end - return + return self:draw_loading_screen(self.progress.label, self.progress.percent) end -- cgit v1.2.3 From 7cfcdcea4b4a4984cd6625a60e9fc2a44d0ec9c9 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 30 Nov 2023 14:47:42 -0500 Subject: Added in loading screen for welcome dialog. --- plugins/plugin_manager/init.lua | 16 ++++++++++++++-- plugins/plugin_manager/plugin_view.lua | 6 ++++-- plugins/welcome.lua | 10 +++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) (limited to 'plugins/plugin_manager') diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua index e30d7f6..2fde4e3 100644 --- a/plugins/plugin_manager/init.lua +++ b/plugins/plugin_manager/init.lua @@ -5,6 +5,7 @@ local common = require "core.common" local config = require "core.config" local command = require "core.command" local json = require "libraries.json" +local keymap = require "core.keymap" local PluginManager = { @@ -128,7 +129,11 @@ local function run(cmd, progress) local err = v[1]:read_stderr(2048) core.error("error running " .. join(" ", cmd) .. ": " .. (err or "?")) progress_line, v[3] = extract_progress(v[3]) - v[2]:reject(v[3]) + if err then + v[2]:reject(json.decode(err).error) + else + v[2]:reject(err) + end end break end @@ -208,6 +213,8 @@ local function run_stateful_plugin_command(plugin_manager, cmd, args, options) else plugin_manager:refresh(options):forward(promise) end + end):fail(function(arg) + promise:reject(arg) end) return promise end @@ -347,7 +354,7 @@ command.add(nil, { if pcall(require, "plugins.terminal") then local terminal = require "plugins.terminal" command.add(nil, { - ["plugin-manager:session"] = function() + ["plugin-manager:open-session"] = function() local arguments = { "-" } for i,v in ipairs(default_arguments) do table.insert(arguments, v) end local tv = terminal.class(common.merge(config.plugins.terminal, { @@ -359,4 +366,9 @@ 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/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua index b864675..f8f503b 100644 --- a/plugins/plugin_manager/plugin_view.lua +++ b/plugins/plugin_manager/plugin_view.lua @@ -149,7 +149,9 @@ function PluginView:draw_loading_screen(label, percent) 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 - if self.progress then + if label or percent then + local th = style.font:get_height() + local lh = th + style.padding.y common.draw_text(style.font, style.dim, label, "center", self.position.x, self.position.y + offset_y + lh, self.size.x, lh) draw_loading_bar(self.position.x + (self.size.x / 2) - (width / 2), self.position.y + self.size.y / 2 + (lh * 2), width, lh, percent) end @@ -161,7 +163,7 @@ function PluginView:draw() local lh = th + style.padding.y if not self.initialized or not self.widths then - return self:draw_loading_screen(self.progress.label, self.progress.percent) + return self:draw_loading_screen(self.progress and self.progress.label, self.progress and self.progress.percent) end diff --git a/plugins/welcome.lua b/plugins/welcome.lua index a90ea82..f0d0401 100644 --- a/plugins/welcome.lua +++ b/plugins/welcome.lua @@ -98,14 +98,18 @@ 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 end, restart = false }):done(function() + PluginManager:install({ id = "meta_addons" }, { progress = function(progress) + loading = progress + core.redraw = true + end, restart = false }):done(function() loading = false core.log("Addons installed!") terminate_welcome() command.perform("core:restart") end):fail(function(err) - loading = true - core.error(err) + loading = false + core.redraw = true + core.error(err or "Error installing addons.") end) end, ["welcome:open-plugin-manager"] = function() -- cgit v1.2.3 From aa0c6115638195b39eeca614cd28f7831c22dd0a Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Thu, 30 Nov 2023 14:49:12 -0500 Subject: Added in extra error handling. --- plugins/plugin_manager/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/plugin_manager') diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua index 2fde4e3..3f27f96 100644 --- a/plugins/plugin_manager/init.lua +++ b/plugins/plugin_manager/init.lua @@ -200,7 +200,7 @@ function PluginManager:get_addons(options) else self:refresh(options):done(function() prom:resolve(self.addons) - end) + end):fail(function(arg) promise:reject(arg) end) end return prom end @@ -232,7 +232,7 @@ function PluginManager:unstub(addon, options) local unstubbed_addon = json.decode(result).addons[1] for k,v in pairs(unstubbed_addon) do addon[k] = v end promise:resolve(addon) - end) + end):fail(function(arg) promise:reject(arg) end) end return promise end @@ -256,7 +256,7 @@ function PluginManager:get_addon(name_and_version, options) end end if not match then promise:reject() end - end) + end):fail(function(arg) promise:reject(arg) end) return promise end -- cgit v1.2.3 From 9b36bc80bb856ce60595f8911acabaf03428ab8f Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sat, 2 Dec 2023 11:28:22 -0500 Subject: Reworded things, incorporated Guldo's changes. --- plugins/plugin_manager/init.lua | 7 +--- plugins/welcome.lua | 76 +++++++++++++++++++++++++++++------------ 2 files changed, 55 insertions(+), 28 deletions(-) (limited to 'plugins/plugin_manager') 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 { } -- cgit v1.2.3