diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-10 08:35:01 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-10 08:35:01 +0100 |
commit | 2cf1dd5b6f10b898f24203c879290d665531a989 (patch) | |
tree | e06e872f557e489b2d0fe3cb0ea2302e8a72ef91 /Applications/FileManager/DirectoryView.h | |
parent | 29f2a22d34554737a67af5b2b2ab8613591383be (diff) | |
download | serenity-2cf1dd5b6f10b898f24203c879290d665531a989.zip |
Move apps into a top-level Applications/ directory.
Diffstat (limited to 'Applications/FileManager/DirectoryView.h')
-rw-r--r-- | Applications/FileManager/DirectoryView.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Applications/FileManager/DirectoryView.h b/Applications/FileManager/DirectoryView.h new file mode 100644 index 0000000000..cf6e1935ed --- /dev/null +++ b/Applications/FileManager/DirectoryView.h @@ -0,0 +1,55 @@ +#pragma once + +#include <LibGUI/GWidget.h> +#include <AK/Function.h> +#include <sys/stat.h> + +class GScrollBar; + +class DirectoryView final : public GWidget { +public: + DirectoryView(GWidget* parent); + virtual ~DirectoryView() override; + + void open(const String& path); + void reload(); + + Function<void(const String&)> on_path_change; + + int item_height() const { return 16; } + int item_count() const { return m_directories.size() + m_files.size(); } + +private: + virtual void paint_event(GPaintEvent&) override; + virtual void resize_event(GResizeEvent&) override; + virtual void mousedown_event(GMouseEvent&) override; + + Rect row_rect(int item_index) const; + + struct Entry { + String name; + size_t size { 0 }; + mode_t mode { 0 }; + + bool is_directory() const { return S_ISDIR(mode); } + }; + + const Entry& entry(size_t index) const + { + if (index < m_directories.size()) + return m_directories[index]; + return m_files[index - m_directories.size()]; + } + const GraphicsBitmap& icon_for(const Entry&) const; + bool should_show_size_for(const Entry&) const; + + Vector<Entry> m_files; + Vector<Entry> m_directories; + + String m_path; + RetainPtr<GraphicsBitmap> m_directory_icon; + RetainPtr<GraphicsBitmap> m_file_icon; + RetainPtr<GraphicsBitmap> m_symlink_icon; + + GScrollBar* m_scrollbar { nullptr }; +}; |