diff options
author | jgmdev <jgmdev@gmail.com> | 2022-05-24 19:29:50 -0400 |
---|---|---|
committer | jgmdev <jgmdev@gmail.com> | 2022-05-24 19:29:50 -0400 |
commit | 35e947d1933613bb0b5a1488bf0fa4587f98ef7d (patch) | |
tree | 07d2515f44db03b1e865f6aef6adfd12b118890b /plugins/centerdoc.lua | |
parent | c1f3671e2a8defbc67d1e77c72d5866f2825cdb5 (diff) | |
download | lite-xl-plugins-35e947d1933613bb0b5a1488bf0fa4587f98ef7d.tar.gz lite-xl-plugins-35e947d1933613bb0b5a1488bf0fa4587f98ef7d.zip |
added config_spec and other plugin compatibility fixes.
Diffstat (limited to 'plugins/centerdoc.lua')
-rw-r--r-- | plugins/centerdoc.lua | 75 |
1 files changed, 56 insertions, 19 deletions
diff --git a/plugins/centerdoc.lua b/plugins/centerdoc.lua index a771925..fb5943c 100644 --- a/plugins/centerdoc.lua +++ b/plugins/centerdoc.lua @@ -8,7 +8,8 @@ local treeview = require "plugins.treeview" local DocView = require "core.docview" config.plugins.centerdoc = common.merge({ - enable = true + enable = true, + zen_mode = false }, config.plugins.centerdoc) local draw_line_gutter = DocView.draw_line_gutter @@ -38,33 +39,69 @@ function DocView:get_gutter_width() end end -local zen_mode = false + local previous_win_status = system.get_window_mode() local previous_treeview_status = treeview.visible local previous_statusbar_status = core.status_view.visible +local function toggle_zen_mode(enabled) + config.plugins.centerdoc.zen_mode = enabled + + if config.plugins.centerdoc.zen_mode then + previous_win_status = system.get_window_mode() + previous_treeview_status = treeview.visible + previous_statusbar_status = core.status_view.visible + + config.plugins.centerdoc.enable = true + system.set_window_mode("fullscreen") + treeview.visible = false + command.perform "status-bar:hide" + else + config.plugins.centerdoc.enable = false + system.set_window_mode(previous_win_status) + treeview.visible = previous_treeview_status + core.status_view.visible = previous_statusbar_status + end +end + +local on_startup = true + +-- The config specification used by the settings gui +config.plugins.centerdoc.config_spec = { + name = "Center Document", + { + label = "Enable", + description = "Activates document centering by default.", + path = "enable", + type = "toggle", + default = true + }, + { + label = "Zen Mode", + description = "Activates zen mode by default.", + path = "zen_mode", + type = "toggle", + default = false, + on_apply = function(enabled) + if on_startup then + core.add_thread(function() + toggle_zen_mode(enabled) + end) + on_startup = false + else + toggle_zen_mode(enabled) + end + end + } +} + + command.add(nil, { ["center-doc:toggle"] = function() config.plugins.centerdoc.enable = not config.plugins.centerdoc.enable end, ["center-doc:zen-mode-toggle"] = function() - zen_mode = not zen_mode - - if zen_mode then - previous_win_status = system.get_window_mode() - previous_treeview_status = treeview.visible - previous_statusbar_status = core.status_view.visible - - config.plugins.centerdoc.enable = true - system.set_window_mode("fullscreen") - treeview.visible = false - command.perform "status-bar:hide" - else - config.plugins.centerdoc.enable = false - system.set_window_mode(previous_win_status) - treeview.visible = previous_treeview_status - core.status_view.visible = previous_statusbar_status - end + toggle_zen_mode(not config.plugins.centerdoc.zen_mode) end, }) |