yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::editor::FileBrowser Class Reference

File system browser for the sidebar. More...

#include <file_browser.h>

Collaboration diagram for yaze::editor::FileBrowser:

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
 

Detailed Description

File system browser for the sidebar.

Features:

  • Respects .gitignore patterns
  • Hides dotfiles by default (configurable)
  • Tree view rendering
  • Works with native filesystem and WASM virtual FS
  • File type detection for icons

Usage:

FileBrowser browser;
browser.SetRootPath("/path/to/asm");
browser.SetFileClickedCallback([](const std::string& path) {
// Open file in editor
});
browser.Draw();
File system browser for the sidebar.
void SetFileClickedCallback(FileClickedCallback callback)
void SetRootPath(const std::string &path)
Set the root path for the file browser.
void Draw()
Draw the file tree in ImGui.

Definition at line 92 of file file_browser.h.

Member Typedef Documentation

◆ FileClickedCallback

using yaze::editor::FileBrowser::FileClickedCallback = std::function<void(const std::string& path)>

Definition at line 141 of file file_browser.h.

◆ DirectoryClickedCallback

using yaze::editor::FileBrowser::DirectoryClickedCallback = std::function<void(const std::string& path)>

Definition at line 142 of file file_browser.h.

Constructor & Destructor Documentation

◆ FileBrowser()

yaze::editor::FileBrowser::FileBrowser ( )
default

Member Function Documentation

◆ SetRootPath()

void yaze::editor::FileBrowser::SetRootPath ( const std::string & path)

Set the root path for the file browser.

Parameters
pathPath 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_.

Here is the call graph for this function:

◆ GetRootPath()

const std::string & yaze::editor::FileBrowser::GetRootPath ( ) const
inline

Get the current root path.

Definition at line 105 of file file_browser.h.

References root_path_.

◆ HasRootPath()

bool yaze::editor::FileBrowser::HasRootPath ( ) const
inline

Check if a root path is set.

Definition at line 110 of file file_browser.h.

References root_path_.

◆ Refresh()

◆ Draw()

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.

Here is the call graph for this function:

◆ DrawCompact()

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().

◆ SetShowHiddenFiles()

void yaze::editor::FileBrowser::SetShowHiddenFiles ( bool show)
inline

Definition at line 128 of file file_browser.h.

References show_hidden_files_.

◆ GetShowHiddenFiles()

bool yaze::editor::FileBrowser::GetShowHiddenFiles ( ) const
inline

Definition at line 129 of file file_browser.h.

References show_hidden_files_.

◆ SetRespectGitignore()

void yaze::editor::FileBrowser::SetRespectGitignore ( bool respect)
inline

Definition at line 131 of file file_browser.h.

References respect_gitignore_.

◆ GetRespectGitignore()

bool yaze::editor::FileBrowser::GetRespectGitignore ( ) const
inline

Definition at line 132 of file file_browser.h.

References respect_gitignore_.

◆ SetFileFilter()

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.

◆ ClearFileFilter()

void yaze::editor::FileBrowser::ClearFileFilter ( )

Definition at line 327 of file file_browser.cc.

◆ SetFileClickedCallback()

void yaze::editor::FileBrowser::SetFileClickedCallback ( FileClickedCallback callback)
inline

Definition at line 144 of file file_browser.h.

References on_file_clicked_.

◆ SetDirectoryClickedCallback()

void yaze::editor::FileBrowser::SetDirectoryClickedCallback ( DirectoryClickedCallback callback)
inline

Definition at line 148 of file file_browser.h.

References on_directory_clicked_.

◆ GetFileCount()

size_t yaze::editor::FileBrowser::GetFileCount ( ) const
inline

Definition at line 153 of file file_browser.h.

References file_count_.

◆ GetDirectoryCount()

size_t yaze::editor::FileBrowser::GetDirectoryCount ( ) const
inline

Definition at line 154 of file file_browser.h.

References directory_count_.

◆ ScanDirectory()

◆ ShouldShow()

bool yaze::editor::FileBrowser::ShouldShow ( const std::filesystem::path & path,
bool is_directory ) const
private

Definition at line 278 of file file_browser.cc.

Referenced by ScanDirectory().

◆ MatchesFilter()

bool yaze::editor::FileBrowser::MatchesFilter ( const std::string & filename) const
private

Definition at line 294 of file file_browser.cc.

◆ DetectFileType()

FileEntry::FileType yaze::editor::FileBrowser::DetectFileType ( const std::string & filename) const
private

Definition at line 332 of file file_browser.cc.

Referenced by ScanDirectory().

◆ GetFileIcon()

const char * yaze::editor::FileBrowser::GetFileIcon ( FileEntry::FileType type) const
private

◆ DrawEntry()

void yaze::editor::FileBrowser::DrawEntry ( FileEntry & entry,
int depth = 0 )
private

Member Data Documentation

◆ root_path_

std::string yaze::editor::FileBrowser::root_path_
private

Definition at line 166 of file file_browser.h.

Referenced by GetRootPath(), HasRootPath(), Refresh(), ScanDirectory(), and SetRootPath().

◆ root_entry_

FileEntry yaze::editor::FileBrowser::root_entry_
private

Definition at line 167 of file file_browser.h.

Referenced by Refresh(), and SetRootPath().

◆ needs_refresh_

bool yaze::editor::FileBrowser::needs_refresh_ = true
private

Definition at line 168 of file file_browser.h.

Referenced by Refresh(), and SetRootPath().

◆ show_hidden_files_

bool yaze::editor::FileBrowser::show_hidden_files_ = false
private

Definition at line 171 of file file_browser.h.

Referenced by GetShowHiddenFiles(), and SetShowHiddenFiles().

◆ respect_gitignore_

bool yaze::editor::FileBrowser::respect_gitignore_ = true
private

◆ file_filter_

std::set<std::string> yaze::editor::FileBrowser::file_filter_
private

Definition at line 173 of file file_browser.h.

◆ gitignore_parser_

GitignoreParser yaze::editor::FileBrowser::gitignore_parser_
private

Definition at line 176 of file file_browser.h.

Referenced by ScanDirectory(), and SetRootPath().

◆ file_count_

size_t yaze::editor::FileBrowser::file_count_ = 0
private

Definition at line 179 of file file_browser.h.

Referenced by GetFileCount(), Refresh(), and ScanDirectory().

◆ directory_count_

size_t yaze::editor::FileBrowser::directory_count_ = 0
private

Definition at line 180 of file file_browser.h.

Referenced by GetDirectoryCount(), Refresh(), and ScanDirectory().

◆ on_file_clicked_

FileClickedCallback yaze::editor::FileBrowser::on_file_clicked_
private

Definition at line 183 of file file_browser.h.

Referenced by SetFileClickedCallback().

◆ on_directory_clicked_

DirectoryClickedCallback yaze::editor::FileBrowser::on_directory_clicked_
private

Definition at line 184 of file file_browser.h.

Referenced by SetDirectoryClickedCallback().

◆ selected_path_

std::string yaze::editor::FileBrowser::selected_path_
private

Definition at line 187 of file file_browser.h.

◆ kMaxDepth

constexpr int yaze::editor::FileBrowser::kMaxDepth = 10
staticconstexprprivate

Definition at line 190 of file file_browser.h.

Referenced by ScanDirectory().

◆ kMaxEntries

constexpr size_t yaze::editor::FileBrowser::kMaxEntries = 1000
staticconstexprprivate

Definition at line 191 of file file_browser.h.

Referenced by ScanDirectory().


The documentation for this class was generated from the following files: