aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorJipok <braaga@inbox.ru>2021-12-18 22:42:49 +0500
committerjgmdev <jgmdev@gmail.com>2022-05-22 13:16:10 -0400
commit1831d2dd523ba38416fefe1e04e9046762f652f2 (patch)
treee00214d2ed39e54f419c197de263db2e2a6ac5af /plugins
parent7578b80d602ba2e70efaaad08425aa06637cf16e (diff)
downloadlite-xl-plugins-1831d2dd523ba38416fefe1e04e9046762f652f2.tar.gz
lite-xl-plugins-1831d2dd523ba38416fefe1e04e9046762f652f2.zip
nonicons.lua: Use features from v2.1
Diffstat (limited to 'plugins')
-rw-r--r--plugins/nonicons.lua116
1 files changed, 60 insertions, 56 deletions
diff --git a/plugins/nonicons.lua b/plugins/nonicons.lua
index 1f87ae3..baded52 100644
--- a/plugins/nonicons.lua
+++ b/plugins/nonicons.lua
@@ -1,11 +1,23 @@
-- mod-version:3 --lite-xl 2.1
+-- Author: Jipok
+-- Doesn't work well with scaling mode == "ui"
+
local core = require "core"
local common = require "core.common"
+local config = require "core.config"
local style = require "core.style"
local TreeView = require "plugins.treeview"
+local Node = require "core.node"
+-- Config
+config.plugins.nonicons = common.merge({
+ use_default_dir_icons = false,
+ use_default_chevrons = false,
+ draw_tab_icons = true
+}, config.plugins.nonicons)
local icon_font = renderer.font.load(USERDIR.."/fonts/nonicons.ttf", 15 * SCALE)
+local chevron_width = icon_font:get_width("")
local extension_icons = {
[".lua"] = { "#51a0cf", "" },
[".md"] = { "#519aba", "" }, -- Markdown
@@ -39,7 +51,7 @@ local extension_icons = {
[".swift"] = { "#e37933", "" },
[".ts"] = { "#519aba", "" }, -- TypeScript
[".elm"] = { "#519aba", "" },
- [".diff"] = { "#41535b", "" }, [".patch"] = { "#41535b", "" },
+ [".diff"] = { "#41535b", "" },
[".ex"] = { "#a074c4", "" }, [".exs"] = { "#a074c4", "" }, -- Elixir
-- Following without special icon:
[".awk"] = { "#4d5a5e", "" },
@@ -48,6 +60,7 @@ local extension_icons = {
}
local known_names_icons = {
["changelog"] = { "#657175", "" }, ["changelog.txt"] = { "#4d5a5e", "" },
+ ["changelog.md"] = { "#519aba", "" },
["makefile"] = { "#6d8086", "" },
["dockerfile"] = { "#296478", "" },
["docker-compose.yml"] = { "#4289a1", "" },
@@ -66,67 +79,58 @@ for k, v in pairs(known_names_icons) do
v[1] = { common.color(v[1]) }
end
--- Replace original draw
-function TreeView:draw()
- if not self.visible then return end
- self:draw_background(style.background2)
-
- local icon_width = icon_font:get_width("")
- local spacing = icon_font:get_width("") / 2
-
- local doc = core.active_view.doc
- local active_filename = doc and system.absolute_path(doc.filename or "")
-
- for item, x,y,w,h in self:each_item() do
- local color = style.text
-
- -- highlight active_view doc
- if item.abs_filename == active_filename then
- color = style.accent
+-- Override function to define dir and file custom icons if setting is disabled
+if not config.plugins.nonicons.use_default_dir_icons then
+ function TreeView:get_item_icon(item, active, hovered)
+ local icon = "" -- unicode 61766
+ if item.type == "dir" then
+ icon = item.expanded and "" or "" -- unicode 61771 and 61772
end
+ return icon, icon_font, style.text
+ end
+end
- -- hovered item background
- if item == self.hovered_item then
- renderer.draw_rect(x, y, w, h, style.line_highlight)
- color = style.accent
- end
+-- Override function to change default icons for special extensions and names
+local TreeView_get_item_icon = TreeView.get_item_icon
+function TreeView:get_item_icon(item, active, hovered)
+ local icon, font, color = TreeView_get_item_icon(self, item, active, hovered)
+ local custom_icon = known_names_icons[item.name:lower()]
+ if custom_icon == nil then
+ custom_icon = extension_icons[item.name:match("^.+(%..+)$")]
+ end
+ if custom_icon ~= nil then
+ color = custom_icon[1]
+ icon = custom_icon[2]
+ font = icon_font
+ end
+ if active or hovered then
+ color = style.accent
+ end
+ return icon, font, color
+end
- -- icons
- x = x + item.depth * style.padding.x + style.padding.x
+-- Override function to draw chevrons if setting is disabled
+if not config.plugins.nonicons.use_default_chevrons then
+ function TreeView:draw_item_chevron(item, active, hovered, x, y, w, h)
if item.type == "dir" then
- local icon1 = item.expanded and "" or "" -- unicode 61726 and 61728
- local icon2 = item.expanded and "" or "" -- unicode 61771 and 61772
- x = x - spacing
- common.draw_text(icon_font, color, icon1, nil, x, y, 0, h)
- x = x + style.padding.x + spacing
- common.draw_text(icon_font, color, icon2, nil, x, y, 0, h)
- x = x + icon_width
- else
- x = x + style.padding.x
- -- default icon
- local icon = "" -- unicode 61766
- local icon_color = color
- -- icon depending on the file extension or full name
- local custom_icon = known_names_icons[item.name:lower()]
- if custom_icon == nil then
- custom_icon = extension_icons[item.name:match("^.+(%..+)$")]
- end
- if custom_icon ~= nil then
- icon_color = custom_icon[1]
- icon = custom_icon[2]
- end
- common.draw_text(icon_font, icon_color, icon, nil, x, y, 0, h)
- x = x + icon_width
+ local chevron_icon = item.expanded and "" or ""
+ local chevron_color = hovered and style.accent or style.text
+ common.draw_text(icon_font, chevron_color, chevron_icon, nil, x, y, 0, h)
end
-
- -- text
- x = x + spacing
- x = common.draw_text(style.font, color, item.name, nil, x, y, 0, h)
+ return chevron_width + style.padding.x/4
end
+end
- self:draw_scrollbar()
- if self.hovered_item and self.tooltip.alpha > 0 then
- core.root_view:defer_draw(self.draw_tooltip, self)
+-- Override function to draw icons in tabs titles if setting is enabled
+if config.plugins.nonicons.draw_tab_icons then
+ local Node_draw_tab_title = Node.draw_tab_title
+ function Node:draw_tab_title(view, font, is_active, is_hovered, x, y, w, h)
+ local padx = chevron_width + style.padding.x/2
+ local tx = x + padx -- Space for icon
+ w = w - padx
+ Node_draw_tab_title(self, view, font, is_active, is_hovered, tx, y, w, h)
+ if (view == nil) or (view.doc == nil) then return end
+ local item = { type = "file", name = view.doc:get_name() }
+ TreeView:draw_item_icon(item, false, is_hovered, x, y, w, h)
end
end
-