Changes and fixes to c++ project creation
This commit is contained in:
+11
-8
@@ -246,14 +246,14 @@ local function open_filtered_table()
|
|||||||
local function prompt_filter()
|
local function prompt_filter()
|
||||||
vim.api.nvim_buf_set_lines(search.bufnr, 0, -1, false, { "" })
|
vim.api.nvim_buf_set_lines(search.bufnr, 0, -1, false, { "" })
|
||||||
vim.api.nvim_buf_set_option(search.bufnr, "modifiable", true)
|
vim.api.nvim_buf_set_option(search.bufnr, "modifiable", true)
|
||||||
if search.winid and vim.api.nvim_win_is_valid(search.winid) then
|
if vim.api.nvim_win_is_valid(search.winid) then
|
||||||
vim.api.nvim_set_current_win(search.winid)
|
vim.api.nvim_set_current_win(search.winid)
|
||||||
end
|
end
|
||||||
vim.cmd("startinsert")
|
vim.cmd("startinsert")
|
||||||
|
|
||||||
vim.keymap.set("i", "<CR>", function()
|
vim.keymap.set("i", "<CR>", function()
|
||||||
local input = vim.api.nvim_buf_get_lines(search.bufnr, 0, 1, false)[1]
|
local input = vim.api.nvim_buf_get_lines(search.bufnr, 0, 1, false)[1]
|
||||||
if input and input ~= "" then
|
if input ~= "" then
|
||||||
current_view = fuzzy_filter(entries, input)
|
current_view = fuzzy_filter(entries, input)
|
||||||
render()
|
render()
|
||||||
end
|
end
|
||||||
@@ -287,7 +287,7 @@ local function open_filtered_table()
|
|||||||
-- Deletes Folder and confirms deletion
|
-- Deletes Folder and confirms deletion
|
||||||
popup:map("n", "D", function()
|
popup:map("n", "D", function()
|
||||||
local entry = get_selected_entry()
|
local entry = get_selected_entry()
|
||||||
if entry and not entry.is_up then
|
if not entry.is_up then
|
||||||
vim.ui.input({ prompt = "(y/N) Defaults to N: " .. entry.name }, function(input)
|
vim.ui.input({ prompt = "(y/N) Defaults to N: " .. entry.name }, function(input)
|
||||||
if input == "y" or input == "Y" then
|
if input == "y" or input == "Y" then
|
||||||
vim.fn.delete(entry.full_path, "rf")
|
vim.fn.delete(entry.full_path, "rf")
|
||||||
@@ -338,7 +338,7 @@ local function open_filtered_table()
|
|||||||
-- Renames Files and Folders
|
-- Renames Files and Folders
|
||||||
popup:map("n", "R", function()
|
popup:map("n", "R", function()
|
||||||
local entry = get_selected_entry()
|
local entry = get_selected_entry()
|
||||||
if entry and not entry.is_up then
|
if not entry.is_up then
|
||||||
vim.ui.input({ prompt = "Rename:", default = entry.name }, function(input)
|
vim.ui.input({ prompt = "Rename:", default = entry.name }, function(input)
|
||||||
if input then
|
if input then
|
||||||
local new_path = cwd .. "/" .. input
|
local new_path = cwd .. "/" .. input
|
||||||
@@ -353,13 +353,13 @@ local function open_filtered_table()
|
|||||||
-- Changes working directory or edits a file
|
-- Changes working directory or edits a file
|
||||||
popup:map("n", "<CR>", function()
|
popup:map("n", "<CR>", function()
|
||||||
local entry = get_selected_entry()
|
local entry = get_selected_entry()
|
||||||
if entry and entry.type == "directory" then
|
if entry.type == "directory" then
|
||||||
cwd = entry.full_path
|
cwd = entry.full_path
|
||||||
vim.cmd("cd " .. cwd)
|
vim.cmd("cd " .. cwd)
|
||||||
refresh()
|
refresh()
|
||||||
render()
|
render()
|
||||||
end
|
end
|
||||||
if entry and entry.type == "file" then
|
if entry.type == "file" then
|
||||||
popup:unmount()
|
popup:unmount()
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.cmd("edit " .. vim.fn.fnameescape(entry.full_path))
|
vim.cmd("edit " .. vim.fn.fnameescape(entry.full_path))
|
||||||
@@ -378,8 +378,11 @@ local function open_filtered_table()
|
|||||||
|
|
||||||
popup:on(event.BufLeave, function()
|
popup:on(event.BufLeave, function()
|
||||||
vim.defer_fn(function()
|
vim.defer_fn(function()
|
||||||
if not (popup.winid and vim.api.nvim_win_is_valid(popup.winid)) and
|
local function is_valid_win(winid)
|
||||||
not (search.winid and vim.api.nvim_win_is_valid(search.winid)) then
|
return type(winid) == "number" and vim.api.nvim_win_is_valid(winid)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not is_valid_win(popup.winid) and not is_valid_win(search.winid) then
|
||||||
popup:unmount()
|
popup:unmount()
|
||||||
end
|
end
|
||||||
end, 50)
|
end, 50)
|
||||||
|
|||||||
+10
-10
@@ -21,6 +21,16 @@ function M.setup(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.get_project_root()
|
||||||
|
local dir = vim.fn.expand("%:p:h")
|
||||||
|
while dir ~= "/" do
|
||||||
|
if vim.fn.isdirectory(dir .. "/src") == 1 or vim.fn.filereadable(dir .. "/CMakeLists.txt") == 1 then
|
||||||
|
return dir
|
||||||
|
end
|
||||||
|
dir = vim.fn.fnamemodify(dir, ":h")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function M.create_new_header_file()
|
function M.create_new_header_file()
|
||||||
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
||||||
if not header_name then return print("Header file creation canceled.") end
|
if not header_name then return print("Header file creation canceled.") end
|
||||||
@@ -42,16 +52,6 @@ void example_function();
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_project_root()
|
|
||||||
local dir = vim.fn.expand("%:p:h")
|
|
||||||
while dir ~= "/" do
|
|
||||||
if vim.fn.isdirectory(dir .. "/src") == 1 or vim.fn.filereadable(dir .. "/CMakeLists.txt") == 1 then
|
|
||||||
return dir
|
|
||||||
end
|
|
||||||
dir = vim.fn.fnamemodify(dir, ":h")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.run()
|
function M.run()
|
||||||
local root = M.get_project_root()
|
local root = M.get_project_root()
|
||||||
if not root then return print("Error: Project root not found.") end
|
if not root then return print("Error: Project root not found.") end
|
||||||
|
|||||||
@@ -92,16 +92,12 @@ return M
|
|||||||
for _, path in ipairs({ "/src", "/build", "/include" }) do vim.fn.mkdir(full_project_root .. path, "p") end
|
for _, path in ipairs({ "/src", "/build", "/include" }) do vim.fn.mkdir(full_project_root .. path, "p") end
|
||||||
utils.write_file(full_project_root .. "/build/" .. project_name .. ".polydev", project_name)
|
utils.write_file(full_project_root .. "/build/" .. project_name .. ".polydev", project_name)
|
||||||
utils.write_file(full_project_root .. "/src/main.c", [[
|
utils.write_file(full_project_root .. "/src/main.c", [[
|
||||||
/* If you have vcpkg and want to use it:
|
|
||||||
vcpkg new --application
|
|
||||||
vcpkg add port <package_name>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main() {
|
int
|
||||||
printf("%s", "Hello World");
|
main() {
|
||||||
return 0;
|
printf("%s", "Hello World");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
]])
|
]])
|
||||||
utils.write_file(full_project_root .. "/CMakeLists.txt", string.format([[
|
utils.write_file(full_project_root .. "/CMakeLists.txt", string.format([[
|
||||||
@@ -161,16 +157,11 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
|||||||
end
|
end
|
||||||
utils.write_file(full_project_root .. "/build/" .. project_name .. ".polydev", project_name)
|
utils.write_file(full_project_root .. "/build/" .. project_name .. ".polydev", project_name)
|
||||||
utils.write_file(full_project_root .. "/src/main.cpp", [[
|
utils.write_file(full_project_root .. "/src/main.cpp", [[
|
||||||
/* If you have vcpkg and want to use it:
|
|
||||||
vcpkg new --application
|
|
||||||
vcpkg add port <package_name>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "Hello World" << std::endl;
|
std::cout << "Hello World" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
]])
|
]])
|
||||||
utils.write_file(full_project_root .. "/CMakeLists.txt", string.format([[
|
utils.write_file(full_project_root .. "/CMakeLists.txt", string.format([[
|
||||||
|
|||||||
Reference in New Issue
Block a user