blob: 60bc82ebf0d0062be0fe9fd21e27f79891d870ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#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;
Function<void(String)> on_status_message;
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;
void set_status_message(String&&);
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 };
};
|