add delete file and dirs

This commit is contained in:
chatlanin
2023-03-18 14:37:32 +03:00
parent 8c61772c66
commit d775a65feb
3 changed files with 33 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
#include "content.hpp"
#include <filesystem>
#include <oneapi/tbb/parallel_for.h>
#include "logger/logger.hpp"
@@ -96,17 +97,26 @@ namespace rrr
{
cursor_position += step;
check_cursor_position();
prev.fill(nav.store[PWD].at(cursor_position).path);
// в зависимости от того пустаая ли директория
// например после удаления последнего файла
if (std::filesystem::is_empty(PWD))
prev.data.clear();
else
prev.fill(nav.store[PWD].at(cursor_position).path);
}
void content::check_cursor_position()
{
if (cursor_position == (int)nav.store[PWD].size()) cursor_position = (int)nav.store[PWD].size() - 1;
if (cursor_position < 0) cursor_position = 0;
else if (cursor_position < 0) cursor_position = 0;
else if (cursor_position > (int)nav.store[PWD].size()) cursor_position = 0;
}
void content::navigation_right()
{
if (std::filesystem::is_empty(PWD)) return;
// ставим новый pwd и заполняем навигацию и историю
PWD = PWD / nav.store[PWD].at(cursor_position).path.filename();
@@ -143,7 +153,11 @@ namespace rrr
{
// буфер заполняется только когда отсюда уходишь
// типа я тут был
buffer::state[PWD] = nav.store[PWD].at(cursor_position);
if (std::filesystem::is_empty(PWD))
buffer::state[PWD] = nav.store[PWD.parent_path()].at(cursor_position);
else
buffer::state[PWD] = nav.store[PWD].at(cursor_position);
auto from = PWD;
// ставим новый pwd и заполняем навигацию и историю
@@ -180,5 +194,14 @@ namespace rrr
hack::utils::unix_cmd(cmd);
nav.fill(PWD);
check_cursor_position();
}
void content::delete_file(file f)
{
std::string cmd = "delete " + f.path.string();
hack::utils::unix_cmd(cmd);
nav.fill(PWD);
increment_position(-1);
}
}