diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/plugin_manager/init.lua | 17 | ||||
-rw-r--r-- | plugins/plugin_manager/plugin_view.lua | 21 | ||||
-rw-r--r-- | plugins/welcome.lua | 156 |
3 files changed, 181 insertions, 13 deletions
diff --git a/plugins/plugin_manager/init.lua b/plugins/plugin_manager/init.lua index e30d7f6..76f799a 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 @@ -195,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 @@ -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 @@ -225,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 @@ -249,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 @@ -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, { diff --git a/plugins/plugin_manager/plugin_view.lua b/plugins/plugin_manager/plugin_view.lua index 9e9d67c..f8f503b 100644 --- a/plugins/plugin_manager/plugin_view.lua +++ b/plugins/plugin_manager/plugin_view.lua @@ -145,20 +145,25 @@ 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 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 +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 and self.progress.label, self.progress and self.progress.percent) end diff --git a/plugins/welcome.lua b/plugins/welcome.lua new file mode 100644 index 0000000..5516568 --- /dev/null +++ b/plugins/welcome.lua @@ -0,0 +1,156 @@ +-- mod-version:3 --lite-xl 2.1 + +local core = require "core" +local style = require "core.style" +local command = require "core.command" +local keymap = require "core.keymap" +local View = require "core.view" +local common = require "core.common" +local EmptyView = require "core.emptyview" +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 +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 + 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 = { + "Installs syntax highlightings, themes, and plugins that make Lite XL easier to use.", + "", + "Recommended for newcomers to Lite XL.", + "Requires a network connection." + } }, + { 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 +function EmptyView:get_name() if welcomed then return old_get_name(self) end return "Welcome!" end + +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) + return + end + + + 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) + + 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 = x1 + 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() + 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) + y = y + v.h + style.padding.y * 2 + end + + if hovered_button then + for i, v in ipairs(hovered_button.tooltip) do + 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.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 + +function EmptyView:on_mouse_moved(x, y) + hovered_button = nil + for i,v in ipairs(buttons) do + if v.x and x >= v.x and x < v.x + v.w and y >= v.y and y < v.y + v.h then + hovered_button = v + end + end +end + +function EmptyView:on_mouse_pressed(button, x, y) + if hovered_button and not welcomed then command.perform(hovered_button.command) end +end + + + +local function terminate_welcome() + io.open(USERDIR .. PATHSEP .. "welcomed", "wb"):close() + command.perform("treeview:toggle") + welcomed = true +end + +command.add(EmptyView, { + ["welcome:install-addons"] = function() + core.log("Installing addons...") + loading = { percent = 0, label = "Initializing..." } + core.redraw = true + 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 = false + core.redraw = true + core.error(err or "Error installing addons.") + end) + end, + ["welcome:open-plugin-manager"] = function() + command.perform("plugin-manager:show") + end, + ["welcome:dismiss"] = function() + terminate_welcome() + end +}) + |