Merge branch 'master' into PR_commandview_options2
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
local style = require "core.style"
|
||||
local common = require "core.common"
|
||||
|
||||
style.background = { common.color "#2e2e32" } -- Docview
|
||||
style.background2 = { common.color "#252529" } -- Treeview
|
||||
style.background3 = { common.color "#252529" } -- Command view
|
||||
style.text = { common.color "#97979c" }
|
||||
style.caret = { common.color "#93DDFA" }
|
||||
style.accent = { common.color "#e1e1e6" }
|
||||
-- style.dim - text color for nonactive tabs, tabs divider, prefix in log and
|
||||
-- search result, hotkeys for context menu and command view
|
||||
style.dim = { common.color "#525257" }
|
||||
style.divider = { common.color "#202024" } -- Line between nodes
|
||||
style.selection = { common.color "#48484f" }
|
||||
style.line_number = { common.color "#525259" }
|
||||
style.line_number2 = { common.color "#83838f" } -- With cursor
|
||||
style.line_highlight = { common.color "#343438" }
|
||||
style.scrollbar = { common.color "#414146" }
|
||||
style.scrollbar2 = { common.color "#4b4b52" } -- Hovered
|
||||
style.scrollbar_track = { common.color "#252529" }
|
||||
style.nagbar = { common.color "#FF0000" }
|
||||
style.nagbar_text = { common.color "#FFFFFF" }
|
||||
style.nagbar_dim = { common.color "rgba(0, 0, 0, 0.45)" }
|
||||
style.drag_overlay = { common.color "rgba(255,255,255,0.1)" }
|
||||
style.drag_overlay_tab = { common.color "#93DDFA" }
|
||||
style.good = { common.color "#72b886" }
|
||||
style.warn = { common.color "#FFA94D" }
|
||||
style.error = { common.color "#FF3333" }
|
||||
style.modified = { common.color "#1c7c9c" }
|
||||
|
||||
style.syntax["normal"] = { common.color "#e1e1e6" }
|
||||
style.syntax["symbol"] = { common.color "#e1e1e6" }
|
||||
style.syntax["comment"] = { common.color "#676b6f" }
|
||||
style.syntax["keyword"] = { common.color "#E58AC9" } -- local function end if case
|
||||
style.syntax["keyword2"] = { common.color "#F77483" } -- self int float
|
||||
style.syntax["number"] = { common.color "#FFA94D" }
|
||||
style.syntax["literal"] = { common.color "#FFA94D" } -- true false nil
|
||||
style.syntax["string"] = { common.color "#f7c95c" }
|
||||
style.syntax["operator"] = { common.color "#93DDFA" } -- = + - / < >
|
||||
style.syntax["function"] = { common.color "#93DDFA" }
|
||||
|
||||
style.log["INFO"] = { icon = "i", color = style.text }
|
||||
style.log["WARN"] = { icon = "!", color = style.warn }
|
||||
style.log["ERROR"] = { icon = "!", color = style.error }
|
||||
|
||||
return style
|
||||
+30
-2
@@ -140,9 +140,25 @@ function common.fuzzy_match_with_recents(haystack, recents, needle)
|
||||
end
|
||||
|
||||
|
||||
function common.path_suggest(text)
|
||||
function common.path_suggest(text, root)
|
||||
if root and root:sub(-1) ~= PATHSEP then
|
||||
root = root .. PATHSEP
|
||||
end
|
||||
local path, name = text:match("^(.-)([^/\\]*)$")
|
||||
local files = system.list_dir(path == "" and "." or path) or {}
|
||||
-- ignore root if path is absolute
|
||||
local is_absolute = common.is_absolute_path(text)
|
||||
if not is_absolute then
|
||||
if path == "" then
|
||||
path = root or "."
|
||||
else
|
||||
path = (root or "") .. path
|
||||
end
|
||||
end
|
||||
|
||||
local files = system.list_dir(path) or {}
|
||||
if path:sub(-1) ~= PATHSEP then
|
||||
path = path .. PATHSEP
|
||||
end
|
||||
local res = {}
|
||||
for _, file in ipairs(files) do
|
||||
file = path .. file
|
||||
@@ -151,6 +167,13 @@ function common.path_suggest(text)
|
||||
if info.type == "dir" then
|
||||
file = file .. PATHSEP
|
||||
end
|
||||
if root then
|
||||
-- remove root part from file path
|
||||
local s, e = file:find(root, nil, true)
|
||||
if s == 1 then
|
||||
file = file:sub(e + 1)
|
||||
end
|
||||
end
|
||||
if file:lower():find(text:lower(), nil, true) == 1 then
|
||||
table.insert(res, file)
|
||||
end
|
||||
@@ -385,6 +408,11 @@ function common.normalize_path(filename)
|
||||
end
|
||||
|
||||
|
||||
function common.is_absolute_path(path)
|
||||
return path:sub(1, 1) == PATHSEP or path:match("^(%a):\\")
|
||||
end
|
||||
|
||||
|
||||
function common.path_belongs_to(filename, path)
|
||||
return string.find(filename, path .. PATHSEP, 1, true) == 1
|
||||
end
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@ require "core.strict"
|
||||
require "core.regex"
|
||||
local common = require "core.common"
|
||||
local config = require "core.config"
|
||||
local style = require "core.style"
|
||||
local style = require "colors.default"
|
||||
local command
|
||||
local keymap
|
||||
local dirwatch
|
||||
@@ -605,7 +605,7 @@ end
|
||||
-- This function should get only filenames normalized using
|
||||
-- common.normalize_path function.
|
||||
function core.project_absolute_path(filename)
|
||||
if filename:match('^%a:\\') or filename:find('/', 1, true) == 1 then
|
||||
if common.is_absolute_path(filename) then
|
||||
return common.normalize_path(filename)
|
||||
elseif not core.project_dir then
|
||||
local cwd = system.absolute_path(".")
|
||||
|
||||
+1
-42
@@ -28,44 +28,7 @@ style.icon_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 16 * SCALE,
|
||||
style.icon_big_font = style.icon_font:copy(23 * SCALE)
|
||||
style.code_font = renderer.font.load(DATADIR .. "/fonts/JetBrainsMono-Regular.ttf", 15 * SCALE)
|
||||
|
||||
style.background = { common.color "#2e2e32" } -- Docview
|
||||
style.background2 = { common.color "#252529" } -- Treeview
|
||||
style.background3 = { common.color "#252529" } -- Command view
|
||||
style.text = { common.color "#97979c" }
|
||||
style.caret = { common.color "#93DDFA" }
|
||||
style.accent = { common.color "#e1e1e6" }
|
||||
-- style.dim - text color for nonactive tabs, tabs divider, prefix in log and
|
||||
-- search result, hotkeys for context menu and command view
|
||||
style.dim = { common.color "#525257" }
|
||||
style.divider = { common.color "#202024" } -- Line between nodes
|
||||
style.selection = { common.color "#48484f" }
|
||||
style.line_number = { common.color "#525259" }
|
||||
style.line_number2 = { common.color "#83838f" } -- With cursor
|
||||
style.line_highlight = { common.color "#343438" }
|
||||
style.scrollbar = { common.color "#414146" }
|
||||
style.scrollbar2 = { common.color "#4b4b52" } -- Hovered
|
||||
style.scrollbar_track = { common.color "#252529" }
|
||||
style.nagbar = { common.color "#FF0000" }
|
||||
style.nagbar_text = { common.color "#FFFFFF" }
|
||||
style.nagbar_dim = { common.color "rgba(0, 0, 0, 0.45)" }
|
||||
style.drag_overlay = { common.color "rgba(255,255,255,0.1)" }
|
||||
style.drag_overlay_tab = { common.color "#93DDFA" }
|
||||
style.good = { common.color "#72b886" }
|
||||
style.warn = { common.color "#FFA94D" }
|
||||
style.error = { common.color "#FF3333" }
|
||||
style.modified = { common.color "#1c7c9c" }
|
||||
|
||||
style.syntax = {}
|
||||
style.syntax["normal"] = { common.color "#e1e1e6" }
|
||||
style.syntax["symbol"] = { common.color "#e1e1e6" }
|
||||
style.syntax["comment"] = { common.color "#676b6f" }
|
||||
style.syntax["keyword"] = { common.color "#E58AC9" } -- local function end if case
|
||||
style.syntax["keyword2"] = { common.color "#F77483" } -- self int float
|
||||
style.syntax["number"] = { common.color "#FFA94D" }
|
||||
style.syntax["literal"] = { common.color "#FFA94D" } -- true false nil
|
||||
style.syntax["string"] = { common.color "#f7c95c" }
|
||||
style.syntax["operator"] = { common.color "#93DDFA" } -- = + - / < >
|
||||
style.syntax["function"] = { common.color "#93DDFA" }
|
||||
|
||||
-- This can be used to override fonts per syntax group.
|
||||
-- The syntax highlighter will take existing values from this table and
|
||||
@@ -74,10 +37,6 @@ style.syntax["function"] = { common.color "#93DDFA" }
|
||||
style.syntax_fonts = {}
|
||||
-- style.syntax_fonts["comment"] = renderer.font.load(path_to_font, size_of_font, rendering_options)
|
||||
|
||||
style.log = {
|
||||
INFO = { icon = "i", color = style.text },
|
||||
WARN = { icon = "!", color = style.warn },
|
||||
ERROR = { icon = "!", color = style.error }
|
||||
}
|
||||
style.log = {}
|
||||
|
||||
return style
|
||||
|
||||
@@ -176,5 +176,5 @@ function DocView:draw_line_text(idx, x, y)
|
||||
end
|
||||
end
|
||||
|
||||
draw_line_text(self, idx, x, y)
|
||||
return draw_line_text(self, idx, x, y)
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- mod-version:3
|
||||
-- mod-version:3 --priority:10
|
||||
local core = require "core"
|
||||
local common = require "core.common"
|
||||
local DocView = require "core.docview"
|
||||
|
||||
+113
-44
@@ -389,6 +389,7 @@ function TreeView:draw()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function TreeView:get_parent(item)
|
||||
local parent_path = common.dirname(item.abs_filename)
|
||||
if not parent_path then return end
|
||||
@@ -399,6 +400,40 @@ function TreeView:get_parent(item)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function TreeView:get_item(item, where)
|
||||
local last_item, last_x, last_y, last_w, last_h
|
||||
local stop = false
|
||||
|
||||
for it, x, y, w, h in self:each_item() do
|
||||
if not item and where >= 0 then
|
||||
return it, x, y, w, h
|
||||
end
|
||||
if item == it then
|
||||
if where < 0 and last_item then
|
||||
break
|
||||
elseif where == 0 or (where < 0 and not last_item) then
|
||||
return it, x, y, w, h
|
||||
end
|
||||
stop = true
|
||||
elseif stop then
|
||||
item = it
|
||||
return it, x, y, w, h
|
||||
end
|
||||
last_item, last_x, last_y, last_w, last_h = it, x, y, w, h
|
||||
end
|
||||
return last_item, last_x, last_y, last_w, last_h
|
||||
end
|
||||
|
||||
function TreeView:get_next(item)
|
||||
return self:get_item(item, 1)
|
||||
end
|
||||
|
||||
function TreeView:get_previous(item)
|
||||
return self:get_item(item, -1)
|
||||
end
|
||||
|
||||
|
||||
function TreeView:toggle_expand(toggle)
|
||||
local item = self.selected_item
|
||||
|
||||
@@ -483,6 +518,15 @@ function core.on_quit_project()
|
||||
end
|
||||
|
||||
local function is_project_folder(path)
|
||||
for _,dir in pairs(core.project_directories) do
|
||||
if dir.name == path then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function is_primary_project_folder(path)
|
||||
return core.project_dir == path
|
||||
end
|
||||
|
||||
@@ -512,6 +556,17 @@ menu:register(
|
||||
}
|
||||
)
|
||||
|
||||
menu:register(
|
||||
function()
|
||||
return view.hovered_item
|
||||
and not is_primary_project_folder(view.hovered_item.abs_filename)
|
||||
and is_project_folder(view.hovered_item.abs_filename)
|
||||
end,
|
||||
{
|
||||
{ text = "Remove directory", command = "treeview:remove-project-directory" },
|
||||
}
|
||||
)
|
||||
|
||||
local previous_view = nil
|
||||
|
||||
-- Register the TreeView commands and keymap
|
||||
@@ -548,38 +603,13 @@ command.add(nil, {
|
||||
|
||||
command.add(TreeView, {
|
||||
["treeview:next"] = function()
|
||||
local item = view.selected_item
|
||||
local item_y
|
||||
local stop = false
|
||||
for it, _, y in view:each_item() do
|
||||
if item == it then
|
||||
stop = true
|
||||
elseif stop then
|
||||
item = it
|
||||
item_y = y
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local item, _, item_y = view:get_next(view.selected_item)
|
||||
view:set_selection(item, item_y)
|
||||
end,
|
||||
|
||||
["treeview:previous"] = function()
|
||||
local last_item
|
||||
local last_item_y
|
||||
for it, _, y in view:each_item() do
|
||||
if it == view.selected_item then
|
||||
if not last_item then
|
||||
last_item = it
|
||||
last_item_y = y
|
||||
end
|
||||
break
|
||||
end
|
||||
last_item = it
|
||||
last_item_y = y
|
||||
end
|
||||
|
||||
view:set_selection(last_item, last_item_y)
|
||||
local item, _, item_y = view:get_previous(view.selected_item)
|
||||
view:set_selection(item, item_y)
|
||||
end,
|
||||
|
||||
["treeview:open"] = function()
|
||||
@@ -627,7 +657,17 @@ command.add(TreeView, {
|
||||
end,
|
||||
|
||||
["treeview:expand"] = function()
|
||||
view:toggle_expand(true)
|
||||
local item = view.selected_item
|
||||
if not item or item.type ~= "dir" then return end
|
||||
|
||||
if item.expanded then
|
||||
local next_item, _, next_y = view:get_next(item)
|
||||
if next_item.depth > item.depth then
|
||||
view:set_selection(next_item, next_y)
|
||||
end
|
||||
else
|
||||
view:toggle_expand(true)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -646,8 +686,13 @@ command.add(
|
||||
)
|
||||
end, {
|
||||
["treeview:delete"] = function()
|
||||
local filename = treeitem().abs_filename
|
||||
local relfilename = treeitem().filename
|
||||
local item = treeitem()
|
||||
local filename = item.abs_filename
|
||||
local relfilename = item.filename
|
||||
if item.dir_name ~= core.project_dir then
|
||||
-- add secondary project dirs names to the file path to show
|
||||
relfilename = common.basename(item.dir_name) .. PATHSEP .. relfilename
|
||||
end
|
||||
local file_info = system.get_file_info(filename)
|
||||
local file_type = file_info.type == "dir" and "Directory" or "File"
|
||||
-- Ask before deleting
|
||||
@@ -687,13 +732,16 @@ command.add(
|
||||
|
||||
command.add(function() return treeitem() ~= nil end, {
|
||||
["treeview:rename"] = function()
|
||||
local old_filename = treeitem().filename
|
||||
local old_abs_filename = treeitem().abs_filename
|
||||
local item = treeitem()
|
||||
local old_filename = item.filename
|
||||
local old_abs_filename = item.abs_filename
|
||||
core.command_view:enter("Rename", {
|
||||
text = old_filename,
|
||||
submit = function(filename)
|
||||
filename = core.normalize_to_project_dir(filename)
|
||||
local abs_filename = core.project_absolute_path(filename)
|
||||
local abs_filename = filename
|
||||
if not common.is_absolute_path(filename) then
|
||||
abs_filename = item.dir_name .. PATHSEP .. filename
|
||||
end
|
||||
local res, err = os.rename(old_abs_filename, abs_filename)
|
||||
if res then -- successfully renamed
|
||||
for _, doc in ipairs(core.docs) do
|
||||
@@ -708,42 +756,51 @@ command.add(function() return treeitem() ~= nil end, {
|
||||
core.error("Error while renaming \"%s\" to \"%s\": %s", old_abs_filename, abs_filename, err)
|
||||
end
|
||||
end,
|
||||
suggest = common.path_suggest
|
||||
suggest = function(text)
|
||||
return common.path_suggest(text, item.dir_name)
|
||||
end
|
||||
})
|
||||
end,
|
||||
|
||||
["treeview:new-file"] = function()
|
||||
local text
|
||||
if not is_project_folder(treeitem().abs_filename) then
|
||||
text = treeitem().filename .. "/"
|
||||
local item = treeitem()
|
||||
if not is_project_folder(item.abs_filename) then
|
||||
text = treeitem().filename .. PATHSEP
|
||||
end
|
||||
core.command_view:enter("Filename", {
|
||||
text = text,
|
||||
submit = function(filename)
|
||||
local doc_filename = core.project_dir .. PATHSEP .. filename
|
||||
local doc_filename = item.dir_name .. PATHSEP .. filename
|
||||
core.log(doc_filename)
|
||||
local file = io.open(doc_filename, "a+")
|
||||
file:write("")
|
||||
file:close()
|
||||
core.root_view:open_doc(core.open_doc(doc_filename))
|
||||
core.log("Created %s", doc_filename)
|
||||
end,
|
||||
suggest = common.path_suggest
|
||||
suggest = function(text)
|
||||
return common.path_suggest(text, item.dir_name)
|
||||
end
|
||||
})
|
||||
end,
|
||||
|
||||
["treeview:new-folder"] = function()
|
||||
local text
|
||||
if not is_project_folder(treeitem().abs_filename) then
|
||||
text = treeitem().filename .. "/"
|
||||
local item = treeitem()
|
||||
if not is_project_folder(item.abs_filename) then
|
||||
text = treeitem().filename .. PATHSEP
|
||||
end
|
||||
core.command_view:enter("Folder Name", {
|
||||
text = text,
|
||||
submit = function(filename)
|
||||
local dir_path = core.project_dir .. PATHSEP .. filename
|
||||
local dir_path = item.dir_name .. PATHSEP .. filename
|
||||
common.mkdirp(dir_path)
|
||||
core.log("Created %s", dir_path)
|
||||
end,
|
||||
suggest = common.path_suggest
|
||||
suggest = function(text)
|
||||
return common.path_suggest(text, item.dir_name)
|
||||
end
|
||||
})
|
||||
end,
|
||||
|
||||
@@ -760,6 +817,18 @@ command.add(function() return treeitem() ~= nil end, {
|
||||
end
|
||||
})
|
||||
|
||||
command.add(function()
|
||||
local item = treeitem()
|
||||
return item
|
||||
and not is_primary_project_folder(item.abs_filename)
|
||||
and is_project_folder(item.abs_filename)
|
||||
end, {
|
||||
["treeview:remove-project-directory"] = function()
|
||||
core.remove_project_directory(treeitem().dir_name)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
keymap.add {
|
||||
["ctrl+\\"] = "treeview:toggle",
|
||||
["up"] = "treeview:previous",
|
||||
|
||||
Reference in New Issue
Block a user