TreeView Changes (#898)

* Change to 1 click as per RFC on discord, with 100% in favour.

* Added in the ability to specify  as a view name, so it doesn't modify the title, and also fixed a bug where if you clicked *over* the amount of times your config says, it wouldn't regsiter.

* Changed plugin to use keymap.
This commit is contained in:
Adam 2022-04-26 18:29:05 -04:00 committed by GitHub
parent a7ea84ae8f
commit 4934e741b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 48 deletions

View File

@ -1170,12 +1170,13 @@ end
local function get_title_filename(view) local function get_title_filename(view)
local doc_filename = view.get_filename and view:get_filename() or view:get_name() local doc_filename = view.get_filename and view:get_filename() or view:get_name()
return (doc_filename ~= "---") and doc_filename or "" if doc_filename ~= "---" then return doc_filename end
return ""
end end
function core.compose_window_title(title) function core.compose_window_title(title)
return title == "" and "Lite XL" or title .. " - Lite XL" return (title == "" or title == nil) and "Lite XL" or title .. " - Lite XL"
end end
@ -1214,7 +1215,7 @@ function core.step()
-- update window title -- update window title
local current_title = get_title_filename(core.active_view) local current_title = get_title_filename(core.active_view)
if current_title ~= core.window_title then if current_title ~= nil and current_title ~= core.window_title then
system.set_window_title(core.compose_window_title(current_title)) system.set_window_title(core.compose_window_title(current_title))
core.window_title = current_title core.window_title = current_title
end end

View File

@ -11,8 +11,6 @@ local RootView = require "core.rootview"
local CommandView = require "core.commandview" local CommandView = require "core.commandview"
config.plugins.treeview = common.merge({ config.plugins.treeview = common.merge({
-- Amount of clicks to open a file
clicks_to_open = 2,
-- Default treeview width -- Default treeview width
size = 200 * SCALE size = 200 * SCALE
}, config.plugins.treeview) }, config.plugins.treeview)
@ -111,7 +109,7 @@ end
function TreeView:get_name() function TreeView:get_name()
return "Project" return nil
end end
@ -237,46 +235,6 @@ function TreeView:on_mouse_moved(px, py, ...)
end end
local function create_directory_in(item)
local path = item.abs_filename
core.command_view:enter("Create directory in " .. path, function(text)
local dirname = path .. PATHSEP .. text
local success, err = system.mkdir(dirname)
if not success then
core.error("cannot create directory %q: %s", dirname, err)
end
item.expanded = true
end)
end
function TreeView:on_mouse_pressed(button, x, y, clicks)
if not self.visible then return end
local caught = TreeView.super.on_mouse_pressed(self, button, x, y, clicks)
if caught or button ~= "left" then
return true
end
if self.hovered_item then
self:set_selection(self.hovered_item)
if keymap.modkeys["ctrl"] and button == "left" then
create_directory_in(self.selected_item)
elseif self.selected_item.type == "dir"
or (self.selected_item.type == "file"
and clicks == config.plugins.treeview.clicks_to_open
)
then
command.perform "treeview:open"
end
else
return false
end
return true
end
function TreeView:update() function TreeView:update()
-- update width -- update width
local dest = self.visible and self.target_size or 0 local dest = self.visible and self.target_size or 0
@ -644,6 +602,17 @@ command.add(TreeView, {
view.selected_item = nil view.selected_item = nil
end, end,
["treeview:select"] = function()
view:set_selection(view.hovered_item)
end,
["treeview:select-and-open"] = function()
if view.hovered_item then
view:set_selection(view.hovered_item)
command.perform "treeview:open"
end
end,
["treeview:collapse"] = function() ["treeview:collapse"] = function()
if view.selected_item then if view.selected_item then
if view.selected_item.type == "dir" and view.selected_item.expanded then if view.selected_item.type == "dir" and view.selected_item.expanded then
@ -775,7 +744,7 @@ command.add(function() return treeitem() ~= nil end, {
elseif PLATFORM == "Linux" or string.find(PLATFORM, "BSD") then elseif PLATFORM == "Linux" or string.find(PLATFORM, "BSD") then
system.exec(string.format("xdg-open %q", hovered_item.abs_filename)) system.exec(string.format("xdg-open %q", hovered_item.abs_filename))
end end
end, end
}) })
keymap.add { keymap.add {
@ -787,7 +756,10 @@ keymap.add {
["return"] = "treeview:open", ["return"] = "treeview:open",
["escape"] = "treeview:deselect", ["escape"] = "treeview:deselect",
["delete"] = "treeview:delete", ["delete"] = "treeview:delete",
["ctrl+return"] = "treeview:new-folder" ["ctrl+return"] = "treeview:new-folder",
["lclick"] = "treeview:select-and-open",
["mclick"] = "treeview:select",
["ctrl+lclick"] = "treeview:new-folder"
} }
-- Return the treeview with toolbar and contextmenu to allow -- Return the treeview with toolbar and contextmenu to allow