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()
|
||||
vim.api.nvim_buf_set_lines(search.bufnr, 0, -1, false, { "" })
|
||||
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)
|
||||
end
|
||||
vim.cmd("startinsert")
|
||||
|
||||
vim.keymap.set("i", "<CR>", function()
|
||||
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)
|
||||
render()
|
||||
end
|
||||
@@ -287,7 +287,7 @@ local function open_filtered_table()
|
||||
-- Deletes Folder and confirms deletion
|
||||
popup:map("n", "D", function()
|
||||
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)
|
||||
if input == "y" or input == "Y" then
|
||||
vim.fn.delete(entry.full_path, "rf")
|
||||
@@ -338,7 +338,7 @@ local function open_filtered_table()
|
||||
-- Renames Files and Folders
|
||||
popup:map("n", "R", function()
|
||||
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)
|
||||
if input then
|
||||
local new_path = cwd .. "/" .. input
|
||||
@@ -353,13 +353,13 @@ local function open_filtered_table()
|
||||
-- Changes working directory or edits a file
|
||||
popup:map("n", "<CR>", function()
|
||||
local entry = get_selected_entry()
|
||||
if entry and entry.type == "directory" then
|
||||
if entry.type == "directory" then
|
||||
cwd = entry.full_path
|
||||
vim.cmd("cd " .. cwd)
|
||||
refresh()
|
||||
render()
|
||||
end
|
||||
if entry and entry.type == "file" then
|
||||
if entry.type == "file" then
|
||||
popup:unmount()
|
||||
vim.schedule(function()
|
||||
vim.cmd("edit " .. vim.fn.fnameescape(entry.full_path))
|
||||
@@ -378,8 +378,11 @@ local function open_filtered_table()
|
||||
|
||||
popup:on(event.BufLeave, function()
|
||||
vim.defer_fn(function()
|
||||
if not (popup.winid and vim.api.nvim_win_is_valid(popup.winid)) and
|
||||
not (search.winid and vim.api.nvim_win_is_valid(search.winid)) then
|
||||
local function is_valid_win(winid)
|
||||
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()
|
||||
end
|
||||
end, 50)
|
||||
|
||||
+10
-10
@@ -21,6 +21,16 @@ function M.setup(opts)
|
||||
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()
|
||||
vim.ui.input({ prompt = "Enter header file name: " }, function(header_name)
|
||||
if not header_name then return print("Header file creation canceled.") end
|
||||
@@ -42,16 +52,6 @@ void example_function();
|
||||
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()
|
||||
local root = M.get_project_root()
|
||||
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
|
||||
utils.write_file(full_project_root .. "/build/" .. project_name .. ".polydev", project_name)
|
||||
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>
|
||||
|
||||
int main() {
|
||||
printf("%s", "Hello World");
|
||||
return 0;
|
||||
int
|
||||
main() {
|
||||
printf("%s", "Hello World");
|
||||
return 0;
|
||||
}
|
||||
]])
|
||||
utils.write_file(full_project_root .. "/CMakeLists.txt", string.format([[
|
||||
@@ -161,16 +157,11 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
end
|
||||
utils.write_file(full_project_root .. "/build/" .. project_name .. ".polydev", project_name)
|
||||
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>
|
||||
|
||||
int main() {
|
||||
std::cout << "Hello World" << std::endl;
|
||||
return 0;
|
||||
std::cout << "Hello World" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
]])
|
||||
utils.write_file(full_project_root .. "/CMakeLists.txt", string.format([[
|
||||
|
||||
Reference in New Issue
Block a user