diff options
author | jgmdev <jgmdev@gmail.com> | 2022-11-27 12:24:37 -0400 |
---|---|---|
committer | jgmdev <jgmdev@gmail.com> | 2022-11-27 12:34:46 -0400 |
commit | 082a647832f6e5b144711b6fe69b4a3f32ea57dc (patch) | |
tree | e230095a8f41c0c9023ab1672a69b3bb1a43d075 /plugins/settings.lua | |
parent | e263d07cba069726fe3ee903b982b5434d1350c2 (diff) | |
download | lite-xl-plugins-082a647832f6e5b144711b6fe69b4a3f32ea57dc.tar.gz lite-xl-plugins-082a647832f6e5b144711b6fe69b4a3f32ea57dc.zip |
settings: merge a plugin settings when enabled at runtime
Diffstat (limited to 'plugins/settings.lua')
-rw-r--r-- | plugins/settings.lua | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/plugins/settings.lua b/plugins/settings.lua index 48b77b1..17ce998 100644 --- a/plugins/settings.lua +++ b/plugins/settings.lua @@ -32,6 +32,7 @@ local Fonts = require "widget.fonts" local FilePicker = require "widget.filepicker" local MessageBox = require "widget.messagebox" +---@class plugins.settings local settings = {} settings.core = {} @@ -965,6 +966,28 @@ local function merge_font_settings(option, path, saved_value) end end +---Load the user_settings.lua stored options for a plugin into global config. +---@param plugin_name string +---@param options settings.option[] +local function merge_plugin_settings(plugin_name, options) + for _, option in pairs(options) do + if type(option.path) == "string" then + local path = "plugins." .. plugin_name .. "." .. option.path + local saved_value = get_config_value(settings.config, path) + if type(saved_value) ~= "nil" then + if option.type == settings.type.FONT or option.type == "font" then + merge_font_settings(option, path, saved_value) + else + set_config_value(config, path, saved_value) + end + if option.on_apply then + option.on_apply(saved_value) + end + end + end + end +end + ---Merge previously saved settings without destroying the config table. local function merge_settings() if type(settings.config) ~= "table" then return end @@ -994,22 +1017,7 @@ local function merge_settings() for _, section in ipairs(settings.plugin_sections) do local plugins = settings.plugins[section] for plugin_name, options in pairs(plugins) do - for _, option in pairs(options) do - if type(option.path) == "string" then - local path = "plugins." .. plugin_name .. "." .. option.path - local saved_value = get_config_value(settings.config, path) - if type(saved_value) ~= "nil" then - if option.type == settings.type.FONT or option.type == "font" then - merge_font_settings(option, path, saved_value) - else - set_config_value(config, path, saved_value) - end - if option.on_apply then - option.on_apply(saved_value) - end - end - end - end + merge_plugin_settings(plugin_name, options) end end @@ -1449,6 +1457,8 @@ function Settings:enable_plugin(plugin) pane = pane.container end + merge_plugin_settings(plugin, options) + for _, opt in ipairs(options) do ---@type settings.option local option = opt |