From d775a65feba6f0a76159eb817081c94eebf8a10b Mon Sep 17 00:00:00 2001 From: chatlanin Date: Sat, 18 Mar 2023 14:37:32 +0300 Subject: [PATCH] add delete file and dirs --- src/rrr/content/content.cpp | 29 +++++++++++++++++-- src/rrr/content/content.hpp | 1 + .../gui/browser/navigation/navigation.cpp | 9 ++++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/rrr/content/content.cpp b/src/rrr/content/content.cpp index 6d43d29..cdafeea 100644 --- a/src/rrr/content/content.cpp +++ b/src/rrr/content/content.cpp @@ -1,5 +1,6 @@ #include "content.hpp" +#include #include #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); } } diff --git a/src/rrr/content/content.hpp b/src/rrr/content/content.hpp index f86a934..5967bd5 100644 --- a/src/rrr/content/content.hpp +++ b/src/rrr/content/content.hpp @@ -33,6 +33,7 @@ namespace rrr void navigation_right(); void navigation_left(); void create_file(std::string); + void delete_file(file); private: content_type::navigation nav; diff --git a/src/rrr/layers/gui/browser/navigation/navigation.cpp b/src/rrr/layers/gui/browser/navigation/navigation.cpp index b38a4ba..c11dcbb 100644 --- a/src/rrr/layers/gui/browser/navigation/navigation.cpp +++ b/src/rrr/layers/gui/browser/navigation/navigation.cpp @@ -131,15 +131,18 @@ namespace rrr::layers::gui freeze = false; break; case types::event_type::DELETE_CURRENT_FILE: - freeze = false; - hack::log()("DELETE FILE"); + { + freeze = false; + cnt->delete_file(current_file); + cursor_position = cnt->get_cursor_position(TYPE_WIN::NAVIGATION); + } break; case types::event_type::CREATE_FILE: { freeze = false; auto filename = std::any_cast(value); cnt->create_file(filename); - data = cnt->get(TYPE_WIN::NAVIGATION); + cursor_position = cnt->get_cursor_position(TYPE_WIN::NAVIGATION); } break; default: