Merge branch 'master' into dev
This commit is contained in:
commit
3c290adcef
|
@ -353,7 +353,7 @@ local commands = {
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:rename"] = function()
|
["file:rename"] = function()
|
||||||
local old_filename = doc().filename
|
local old_filename = doc().filename
|
||||||
if not old_filename then
|
if not old_filename then
|
||||||
core.error("Cannot rename unsaved doc")
|
core.error("Cannot rename unsaved doc")
|
||||||
|
@ -370,6 +370,21 @@ local commands = {
|
||||||
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
|
return common.home_encode_list(common.path_suggest(common.home_expand(text)))
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
||||||
|
["file:delete"] = function()
|
||||||
|
local filename = doc().abs_filename
|
||||||
|
if not filename then
|
||||||
|
core.error("Cannot remove unsaved doc")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for i,docview in ipairs(core.get_views_referencing_doc(doc())) do
|
||||||
|
local node = core.root_view.root_node:get_node_for_view(docview)
|
||||||
|
node:close_view(core.root_view, docview)
|
||||||
|
end
|
||||||
|
os.remove(filename)
|
||||||
|
core.log("Removed \"%s\"", filename)
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -189,6 +189,16 @@ local function project_scan_thread()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function core.is_project_folder(dirname)
|
||||||
|
for _, dir in ipairs(core.project_directories) do
|
||||||
|
if dir.name == dirname then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.scan_project_folder(dirname, filename)
|
function core.scan_project_folder(dirname, filename)
|
||||||
for _, dir in ipairs(core.project_directories) do
|
for _, dir in ipairs(core.project_directories) do
|
||||||
if dir.name == dirname then
|
if dir.name == dirname then
|
||||||
|
|
|
@ -738,6 +738,12 @@ function RootView:close_all_docviews()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- Function to intercept mouse pressed events on the active view.
|
||||||
|
-- Do nothing by default.
|
||||||
|
function RootView.on_view_mouse_pressed(button, x, y, clicks)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function RootView:on_mouse_pressed(button, x, y, clicks)
|
function RootView:on_mouse_pressed(button, x, y, clicks)
|
||||||
local div = self.root_node:get_divider_overlapping_point(x, y)
|
local div = self.root_node:get_divider_overlapping_point(x, y)
|
||||||
if div then
|
if div then
|
||||||
|
@ -759,9 +765,11 @@ function RootView:on_mouse_pressed(button, x, y, clicks)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
core.set_active_view(node.active_view)
|
core.set_active_view(node.active_view)
|
||||||
|
if not self.on_view_mouse_pressed(button, x, y, clicks) then
|
||||||
node.active_view:on_mouse_pressed(button, x, y, clicks)
|
node.active_view:on_mouse_pressed(button, x, y, clicks)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function RootView:on_mouse_released(...)
|
function RootView:on_mouse_released(...)
|
||||||
|
|
|
@ -12,7 +12,7 @@ else
|
||||||
local prefix = EXEDIR:match("^(.+)[/\\]bin$")
|
local prefix = EXEDIR:match("^(.+)[/\\]bin$")
|
||||||
DATADIR = prefix and (prefix .. '/share/lite-xl') or (EXEDIR .. '/data')
|
DATADIR = prefix and (prefix .. '/share/lite-xl') or (EXEDIR .. '/data')
|
||||||
end
|
end
|
||||||
USERDIR = HOME and (HOME .. '/.config/lite-xl') or (EXEDIR .. '/user')
|
USERDIR = os.getenv("XDG_CONFIG_HOME") or (HOME and (HOME .. '/.config/lite-xl') or (EXEDIR .. '/user'))
|
||||||
|
|
||||||
package.path = DATADIR .. '/?.lua;' .. package.path
|
package.path = DATADIR .. '/?.lua;' .. package.path
|
||||||
package.path = DATADIR .. '/?/init.lua;' .. package.path
|
package.path = DATADIR .. '/?/init.lua;' .. package.path
|
||||||
|
|
|
@ -219,43 +219,20 @@ end
|
||||||
|
|
||||||
|
|
||||||
local menu = ContextMenu()
|
local menu = ContextMenu()
|
||||||
local root_view_on_mouse_pressed = RootView.on_mouse_pressed
|
local on_view_mouse_pressed = RootView.on_view_mouse_pressed
|
||||||
local root_view_on_mouse_moved = RootView.on_mouse_moved
|
local on_mouse_moved = RootView.on_mouse_moved
|
||||||
local root_view_update = RootView.update
|
local root_view_update = RootView.update
|
||||||
local root_view_draw = RootView.draw
|
local root_view_draw = RootView.draw
|
||||||
|
|
||||||
function RootView:on_mouse_moved(...)
|
function RootView:on_mouse_moved(...)
|
||||||
if menu:on_mouse_moved(...) then return end
|
if menu:on_mouse_moved(...) then return end
|
||||||
root_view_on_mouse_moved(self, ...)
|
on_mouse_moved(self, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- this function is mostly copied from lite-xl's source
|
function RootView.on_view_mouse_pressed(button, x, y, clicks)
|
||||||
function RootView:on_mouse_pressed(button, x,y, clicks)
|
-- We give the priority to the menu to process mouse pressed events.
|
||||||
local div = self.root_node:get_divider_overlapping_point(x, y)
|
local handled = menu:on_mouse_pressed(button, x, y, clicks)
|
||||||
if div then
|
return handled or on_view_mouse_pressed(button, x, y, clicks)
|
||||||
self.dragged_divider = div
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local node = self.root_node:get_child_overlapping_point(x, y)
|
|
||||||
if node.hovered_scroll_button > 0 then
|
|
||||||
node:scroll_tabs(node.hovered_scroll_button)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local idx = node:get_tab_overlapping_point(x, y)
|
|
||||||
if idx then
|
|
||||||
if button == "middle" or node.hovered_close == idx then
|
|
||||||
node:close_view(self.root_node, node.views[idx])
|
|
||||||
else
|
|
||||||
self.dragged_node = { node, idx or #node.views }
|
|
||||||
node:set_active_view(node.views[idx])
|
|
||||||
end
|
|
||||||
else
|
|
||||||
core.set_active_view(node.active_view)
|
|
||||||
-- send to context menu first
|
|
||||||
if not menu:on_mouse_pressed(button, x, y, clicks) then
|
|
||||||
node.active_view:on_mouse_pressed(button, x, y, clicks)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function RootView:update(...)
|
function RootView:update(...)
|
||||||
|
|
|
@ -222,11 +222,20 @@ function TreeView:on_mouse_pressed(button, x, y, clicks)
|
||||||
else
|
else
|
||||||
if core.project_files_limit and not hovered_item.expanded then
|
if core.project_files_limit and not hovered_item.expanded then
|
||||||
local filename, abs_filename = hovered_item.filename, hovered_item.abs_filename
|
local filename, abs_filename = hovered_item.filename, hovered_item.abs_filename
|
||||||
local index = string.find(abs_filename, filename, 1, true)
|
local index = 0
|
||||||
|
-- The loop below is used to find the first match starting from the end
|
||||||
|
-- in case there are multiple matches.
|
||||||
|
while index and index + #filename < #abs_filename do
|
||||||
|
index = string.find(abs_filename, filename, index + 1, true)
|
||||||
|
end
|
||||||
|
-- we assume here index is not nil because the abs_filename must contain the
|
||||||
|
-- relative filename
|
||||||
local dirname = string.sub(abs_filename, 1, index - 2)
|
local dirname = string.sub(abs_filename, 1, index - 2)
|
||||||
|
if core.is_project_folder(dirname) then
|
||||||
core.scan_project_folder(dirname, filename)
|
core.scan_project_folder(dirname, filename)
|
||||||
self:invalidate_cache(dirname)
|
self:invalidate_cache(dirname)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
hovered_item.expanded = not hovered_item.expanded
|
hovered_item.expanded = not hovered_item.expanded
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue