bookmark updated
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
@@ -333,8 +334,9 @@ private:
|
||||
// ── overlays ───────────────────────────────────────────────────────────
|
||||
bool confirm_overlay(const std::string &prompt);
|
||||
std::string overlay_picker(const std::string &title,
|
||||
const std::vector<std::string> &items,
|
||||
bool allow_cancel = true);
|
||||
std::vector<std::string> items,
|
||||
bool allow_cancel = true,
|
||||
const std::function<void(const std::string &)> &on_delete = nullptr);
|
||||
|
||||
// ── input ──────────────────────────────────────────────────────────────
|
||||
bool handle_key(int key); // returns false to quit
|
||||
@@ -1102,8 +1104,9 @@ bool FileManager::confirm_overlay(const std::string &prompt) {
|
||||
}
|
||||
|
||||
std::string FileManager::overlay_picker(const std::string &title,
|
||||
const std::vector<std::string> &items,
|
||||
bool allow_cancel) {
|
||||
std::vector<std::string> items,
|
||||
bool allow_cancel,
|
||||
const std::function<void(const std::string &)> &on_delete) {
|
||||
if (items.empty()) return "";
|
||||
|
||||
int nitems = static_cast<int>(items.size());
|
||||
@@ -1205,6 +1208,14 @@ std::string FileManager::overlay_picker(const std::string &title,
|
||||
case 'q': case 'Q': case 'h':
|
||||
if (allow_cancel) { need_full_redraw_ = true; return ""; }
|
||||
break;
|
||||
case KEY_DC:
|
||||
if (on_delete && !items.empty()) {
|
||||
on_delete(items[psel]);
|
||||
items.erase(items.begin() + psel);
|
||||
nitems = static_cast<int>(items.size());
|
||||
if (nitems == 0) { need_full_redraw_ = true; return ""; }
|
||||
}
|
||||
break;
|
||||
case 27: need_full_redraw_ = true; return "";
|
||||
default: break;
|
||||
}
|
||||
@@ -1621,8 +1632,8 @@ void FileManager::do_help() {
|
||||
{" + chmod +x (make executable)", false, false},
|
||||
{" - chmod -x (remove executable)", false, false},
|
||||
{"", true, false},
|
||||
{" b bookmark current dir", false, false},
|
||||
{" B open bookmark picker", false, false},
|
||||
{" b open bookmark picker", false, false},
|
||||
{" B bookmark current dir", false, false},
|
||||
{" c copy path to clipboard", false, false},
|
||||
{" ~ go to home directory", false, false},
|
||||
{" ` jump to previous directory", false, false},
|
||||
@@ -2023,7 +2034,18 @@ void FileManager::do_bookmark_jump() {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string chosen = overlay_picker(" BOOKMARKS", bookmarks);
|
||||
auto remove_bookmark = [&](const std::string &path) {
|
||||
std::vector<std::string> kept;
|
||||
std::ifstream fin(bookmark_file_);
|
||||
std::string l;
|
||||
while (std::getline(fin, l))
|
||||
if (l != path) kept.push_back(l);
|
||||
fin.close();
|
||||
std::ofstream fout(bookmark_file_, std::ios::trunc);
|
||||
for (const auto &k : kept) fout << k << '\n';
|
||||
flash_msg("bookmark removed: " + path);
|
||||
};
|
||||
std::string chosen = overlay_picker(" BOOKMARKS", bookmarks, true, remove_bookmark);
|
||||
if (chosen.empty()) { need_full_redraw_ = true; return; }
|
||||
|
||||
if (fs::is_directory(chosen)) {
|
||||
@@ -2443,8 +2465,8 @@ bool FileManager::handle_key(int key) {
|
||||
do_open(); break;
|
||||
case 'h': case KEY_LEFT:
|
||||
do_go_back(); break;
|
||||
case 'b': do_bookmark_add(); break;
|
||||
case 'B': do_bookmark_jump(); break;
|
||||
case 'b': do_bookmark_jump(); break;
|
||||
case 'B': do_bookmark_add(); break;
|
||||
case '?': do_help(); break;
|
||||
case 'R': load_entries(); flash_msg("refreshed"); break;
|
||||
case '/': do_search(); break;
|
||||
|
||||
Reference in New Issue
Block a user