File system browser for the sidebar. More...
#include <file_browser.h>

Public Types | |
| using | FileClickedCallback = std::function<void(const std::string& path)> |
| using | DirectoryClickedCallback = std::function<void(const std::string& path)> |
Public Member Functions | |
| FileBrowser ()=default | |
| void | SetRootPath (const std::string &path) |
| Set the root path for the file browser. | |
| const std::string & | GetRootPath () const |
| Get the current root path. | |
| bool | HasRootPath () const |
| Check if a root path is set. | |
| void | Refresh () |
| Refresh the file tree from disk. | |
| void | Draw () |
| Draw the file tree in ImGui. | |
| void | DrawCompact () |
| Draw a compact version for narrow sidebars. | |
| void | SetShowHiddenFiles (bool show) |
| bool | GetShowHiddenFiles () const |
| void | SetRespectGitignore (bool respect) |
| bool | GetRespectGitignore () const |
| void | SetFileFilter (const std::vector< std::string > &extensions) |
| Add file extensions to filter (empty = show all) | |
| void | ClearFileFilter () |
| void | SetFileClickedCallback (FileClickedCallback callback) |
| void | SetDirectoryClickedCallback (DirectoryClickedCallback callback) |
| size_t | GetFileCount () const |
| size_t | GetDirectoryCount () const |
Private Member Functions | |
| void | ScanDirectory (const std::filesystem::path &path, FileEntry &parent, int depth=0) |
| bool | ShouldShow (const std::filesystem::path &path, bool is_directory) const |
| bool | MatchesFilter (const std::string &filename) const |
| FileEntry::FileType | DetectFileType (const std::string &filename) const |
| const char * | GetFileIcon (FileEntry::FileType type) const |
| void | DrawEntry (FileEntry &entry, int depth=0) |
Private Attributes | |
| std::string | root_path_ |
| FileEntry | root_entry_ |
| bool | needs_refresh_ = true |
| bool | show_hidden_files_ = false |
| bool | respect_gitignore_ = true |
| std::set< std::string > | file_filter_ |
| GitignoreParser | gitignore_parser_ |
| size_t | file_count_ = 0 |
| size_t | directory_count_ = 0 |
| FileClickedCallback | on_file_clicked_ |
| DirectoryClickedCallback | on_directory_clicked_ |
| std::string | selected_path_ |
Static Private Attributes | |
| static constexpr int | kMaxDepth = 10 |
| static constexpr size_t | kMaxEntries = 1000 |
File system browser for the sidebar.
Features:
Usage:
Definition at line 92 of file file_browser.h.
| using yaze::editor::FileBrowser::FileClickedCallback = std::function<void(const std::string& path)> |
Definition at line 141 of file file_browser.h.
| using yaze::editor::FileBrowser::DirectoryClickedCallback = std::function<void(const std::string& path)> |
Definition at line 142 of file file_browser.h.
|
default |
| void yaze::editor::FileBrowser::SetRootPath | ( | const std::string & | path | ) |
Set the root path for the file browser.
| path | Path to display (absolute or relative) |
Definition at line 145 of file file_browser.cc.
References yaze::editor::GitignoreParser::AddPattern(), yaze::editor::GitignoreParser::Clear(), gitignore_parser_, yaze::editor::GitignoreParser::LoadFromFile(), needs_refresh_, respect_gitignore_, root_entry_, and root_path_.

|
inline |
|
inline |
| void yaze::editor::FileBrowser::Refresh | ( | ) |
Refresh the file tree from disk.
Definition at line 192 of file file_browser.cc.
References directory_count_, file_count_, yaze::editor::FileEntry::file_type, yaze::editor::FileEntry::full_path, yaze::editor::FileEntry::is_directory, yaze::editor::FileEntry::is_expanded, yaze::editor::FileEntry::kDirectory, yaze::editor::FileEntry::name, needs_refresh_, root_entry_, root_path_, and ScanDirectory().

| void yaze::editor::FileBrowser::Draw | ( | ) |
Draw the file tree in ImGui.
Definition at line 414 of file file_browser.cc.
References yaze::gui::GetTextDisabledVec4(), yaze::gui::GetTextSecondaryVec4(), ICON_MD_FOLDER_OPEN, and ICON_MD_REFRESH.

| void yaze::editor::FileBrowser::DrawCompact | ( | ) |
Draw a compact version for narrow sidebars.
Definition at line 459 of file file_browser.cc.
Referenced by yaze::editor::ActivityBar::DrawSidePanel().
|
inline |
Definition at line 128 of file file_browser.h.
References show_hidden_files_.
|
inline |
Definition at line 129 of file file_browser.h.
References show_hidden_files_.
|
inline |
Definition at line 131 of file file_browser.h.
References respect_gitignore_.
|
inline |
Definition at line 132 of file file_browser.h.
References respect_gitignore_.
| void yaze::editor::FileBrowser::SetFileFilter | ( | const std::vector< std::string > & | extensions | ) |
Add file extensions to filter (empty = show all)
Definition at line 312 of file file_browser.cc.
| void yaze::editor::FileBrowser::ClearFileFilter | ( | ) |
Definition at line 327 of file file_browser.cc.
|
inline |
Definition at line 144 of file file_browser.h.
References on_file_clicked_.
|
inline |
Definition at line 148 of file file_browser.h.
References on_directory_clicked_.
|
inline |
Definition at line 153 of file file_browser.h.
References file_count_.
|
inline |
Definition at line 154 of file file_browser.h.
References directory_count_.
|
private |
Definition at line 211 of file file_browser.cc.
References DetectFileType(), directory_count_, file_count_, yaze::editor::FileEntry::file_type, yaze::editor::FileEntry::full_path, gitignore_parser_, yaze::editor::FileEntry::is_directory, yaze::editor::GitignoreParser::IsIgnored(), yaze::editor::FileEntry::kDirectory, kMaxDepth, kMaxEntries, yaze::editor::FileEntry::name, respect_gitignore_, root_path_, ScanDirectory(), and ShouldShow().
Referenced by Refresh(), and ScanDirectory().

|
private |
Definition at line 278 of file file_browser.cc.
Referenced by ScanDirectory().
|
private |
Definition at line 294 of file file_browser.cc.
|
private |
Definition at line 332 of file file_browser.cc.
Referenced by ScanDirectory().
|
private |
Definition at line 389 of file file_browser.cc.
References ICON_MD_CODE, ICON_MD_DATA_OBJECT, ICON_MD_DESCRIPTION, ICON_MD_DEVELOPER_BOARD, ICON_MD_FOLDER, ICON_MD_HEXAGON, ICON_MD_IMAGE, ICON_MD_INSERT_DRIVE_FILE, ICON_MD_MEMORY, and ICON_MD_SETTINGS.
|
private |
Definition at line 475 of file file_browser.cc.
References yaze::editor::FileEntry::children, yaze::editor::FileEntry::file_type, yaze::editor::FileEntry::full_path, yaze::editor::FileEntry::is_directory, and yaze::editor::FileEntry::name.
|
private |
Definition at line 166 of file file_browser.h.
Referenced by GetRootPath(), HasRootPath(), Refresh(), ScanDirectory(), and SetRootPath().
|
private |
Definition at line 167 of file file_browser.h.
Referenced by Refresh(), and SetRootPath().
|
private |
Definition at line 168 of file file_browser.h.
Referenced by Refresh(), and SetRootPath().
|
private |
Definition at line 171 of file file_browser.h.
Referenced by GetShowHiddenFiles(), and SetShowHiddenFiles().
|
private |
Definition at line 172 of file file_browser.h.
Referenced by GetRespectGitignore(), ScanDirectory(), SetRespectGitignore(), and SetRootPath().
|
private |
Definition at line 173 of file file_browser.h.
|
private |
Definition at line 176 of file file_browser.h.
Referenced by ScanDirectory(), and SetRootPath().
|
private |
Definition at line 179 of file file_browser.h.
Referenced by GetFileCount(), Refresh(), and ScanDirectory().
|
private |
Definition at line 180 of file file_browser.h.
Referenced by GetDirectoryCount(), Refresh(), and ScanDirectory().
|
private |
Definition at line 183 of file file_browser.h.
Referenced by SetFileClickedCallback().
|
private |
Definition at line 184 of file file_browser.h.
Referenced by SetDirectoryClickedCallback().
|
private |
Definition at line 187 of file file_browser.h.
|
staticconstexprprivate |
Definition at line 190 of file file_browser.h.
Referenced by ScanDirectory().
|
staticconstexprprivate |
Definition at line 191 of file file_browser.h.
Referenced by ScanDirectory().