mirror of
https://github.com/m1ngsama/TUT.git
synced 2026-02-08 00:54:05 +00:00
Major architectural refactoring from ncurses to FTXUI framework with professional engineering structure. Project Structure: - src/core/: Browser engine, URL parser, HTTP client - src/ui/: FTXUI components (main window, address bar, content view, panels) - src/renderer/: HTML renderer, text formatter, style parser - src/utils/: Logger, config manager, theme manager - tests/unit/: Unit tests for core components - tests/integration/: Integration tests - assets/: Default configs, themes, keybindings New Features: - btop-style four-panel layout with rounded borders - TOML-based configuration system - Multiple color themes (default, nord, gruvbox, solarized) - Comprehensive logging system - Modular architecture with clear separation of concerns Build System: - Updated CMakeLists.txt for modular build - Prefer system packages (Homebrew) over FetchContent - Google Test integration for testing - Version info generation via cmake/version.hpp.in Configuration: - Default config.toml with browser settings - Four built-in themes - Default keybindings configuration - Config stored in ~/.config/tut/ Removed: - Legacy v1 source files (ncurses-based) - Old render/ directory - Duplicate and obsolete test files - Old documentation files Binary: ~827KB (well under 5MB goal) Dependencies: FTXUI, cpp-httplib, toml11, gumbo-parser, OpenSSL
93 lines
2.7 KiB
C++
93 lines
2.7 KiB
C++
/**
|
|
* @file bookmark_panel.cpp
|
|
* @brief 书签面板组件实现
|
|
*/
|
|
|
|
#include "ui/bookmark_panel.hpp"
|
|
#include <algorithm>
|
|
|
|
namespace tut {
|
|
|
|
class BookmarkPanel::Impl {
|
|
public:
|
|
std::vector<BookmarkItem> bookmarks_;
|
|
int selected_index_{0};
|
|
bool visible_{false};
|
|
std::function<void(const BookmarkItem&)> on_select_;
|
|
};
|
|
|
|
BookmarkPanel::BookmarkPanel() : impl_(std::make_unique<Impl>()) {}
|
|
|
|
BookmarkPanel::~BookmarkPanel() = default;
|
|
|
|
void BookmarkPanel::setBookmarks(const std::vector<BookmarkItem>& bookmarks) {
|
|
impl_->bookmarks_ = bookmarks;
|
|
impl_->selected_index_ = bookmarks.empty() ? -1 : 0;
|
|
}
|
|
|
|
std::vector<BookmarkItem> BookmarkPanel::getBookmarks() const {
|
|
return impl_->bookmarks_;
|
|
}
|
|
|
|
void BookmarkPanel::addBookmark(const BookmarkItem& bookmark) {
|
|
impl_->bookmarks_.push_back(bookmark);
|
|
}
|
|
|
|
void BookmarkPanel::removeBookmark(const std::string& id) {
|
|
impl_->bookmarks_.erase(
|
|
std::remove_if(impl_->bookmarks_.begin(), impl_->bookmarks_.end(),
|
|
[&id](const BookmarkItem& item) { return item.id == id; }),
|
|
impl_->bookmarks_.end());
|
|
}
|
|
|
|
void BookmarkPanel::selectNext() {
|
|
if (impl_->bookmarks_.empty()) return;
|
|
impl_->selected_index_ =
|
|
(impl_->selected_index_ + 1) % static_cast<int>(impl_->bookmarks_.size());
|
|
}
|
|
|
|
void BookmarkPanel::selectPrevious() {
|
|
if (impl_->bookmarks_.empty()) return;
|
|
impl_->selected_index_--;
|
|
if (impl_->selected_index_ < 0) {
|
|
impl_->selected_index_ = static_cast<int>(impl_->bookmarks_.size()) - 1;
|
|
}
|
|
}
|
|
|
|
int BookmarkPanel::getSelectedIndex() const {
|
|
return impl_->selected_index_;
|
|
}
|
|
|
|
void BookmarkPanel::onSelect(std::function<void(const BookmarkItem&)> callback) {
|
|
impl_->on_select_ = std::move(callback);
|
|
}
|
|
|
|
std::vector<BookmarkItem> BookmarkPanel::search(const std::string& query) const {
|
|
std::vector<BookmarkItem> results;
|
|
std::string lower_query = query;
|
|
std::transform(lower_query.begin(), lower_query.end(), lower_query.begin(), ::tolower);
|
|
|
|
for (const auto& bookmark : impl_->bookmarks_) {
|
|
std::string lower_title = bookmark.title;
|
|
std::transform(lower_title.begin(), lower_title.end(), lower_title.begin(), ::tolower);
|
|
|
|
std::string lower_url = bookmark.url;
|
|
std::transform(lower_url.begin(), lower_url.end(), lower_url.begin(), ::tolower);
|
|
|
|
if (lower_title.find(lower_query) != std::string::npos ||
|
|
lower_url.find(lower_query) != std::string::npos) {
|
|
results.push_back(bookmark);
|
|
}
|
|
}
|
|
return results;
|
|
}
|
|
|
|
void BookmarkPanel::setVisible(bool visible) {
|
|
impl_->visible_ = visible;
|
|
}
|
|
|
|
bool BookmarkPanel::isVisible() const {
|
|
return impl_->visible_;
|
|
}
|
|
|
|
} // namespace tut
|