blob: 1316ccd2903f9689415fe2221d92cc1482d743d7 (
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
|
#include <AK/FileSystemPath.h>
#include <AK/Optional.h>
#include <LibCore/CUserInfo.h>
#include <LibGUI/GDialog.h>
#include <LibGUI/GTableView.h>
class GDirectoryModel;
class GLabel;
class GFilePicker final : public GDialog {
C_OBJECT(GFilePicker)
public:
enum class Mode {
Open,
Save
};
static Optional<String> get_open_filepath();
static Optional<String> get_save_filepath(const String& title, const String& extension);
static bool file_exists(const StringView& path);
GFilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = String(get_current_user_home_path()), CObject* parent = nullptr);
virtual ~GFilePicker() override;
FileSystemPath selected_file() const { return m_selected_file; }
private:
void set_preview(const FileSystemPath&);
void clear_preview();
static String ok_button_name(Mode mode)
{
switch (mode) {
case Mode::Open:
return "Open";
case Mode::Save:
return "Save";
default:
return "OK";
}
}
GTableView* m_view { nullptr };
NonnullRefPtr<GDirectoryModel> m_model;
FileSystemPath m_selected_file;
GLabel* m_preview_image_label { nullptr };
GLabel* m_preview_name_label { nullptr };
GLabel* m_preview_geometry_label { nullptr };
Mode m_mode { Mode::Open };
};
|