2019-05-26 13:09:31 +01:00
|
|
|
#include <AK/FileSystemPath.h>
|
2019-07-13 19:58:04 -05:00
|
|
|
#include <AK/Optional.h>
|
2019-05-08 22:10:00 +02:00
|
|
|
#include <LibGUI/GDialog.h>
|
2019-05-09 01:24:37 +02:00
|
|
|
#include <LibGUI/GTableView.h>
|
|
|
|
|
|
|
|
class GDirectoryModel;
|
2019-05-26 22:33:54 +02:00
|
|
|
class GLabel;
|
2019-03-09 21:38:13 +01:00
|
|
|
|
2019-05-08 22:10:00 +02:00
|
|
|
class GFilePicker final : public GDialog {
|
2019-03-09 21:38:13 +01:00
|
|
|
public:
|
2019-07-13 19:58:04 -05:00
|
|
|
enum class Mode {
|
|
|
|
Open,
|
|
|
|
Save
|
|
|
|
};
|
|
|
|
|
|
|
|
static Optional<String> get_open_filepath();
|
|
|
|
static Optional<String> get_save_filepath();
|
|
|
|
static bool file_exists(const StringView& path);
|
|
|
|
|
|
|
|
GFilePicker(Mode type = Mode::Open, const StringView& path = "/", CObject* parent = nullptr);
|
2019-03-09 21:38:13 +01:00
|
|
|
virtual ~GFilePicker() override;
|
|
|
|
|
2019-05-26 13:09:31 +01:00
|
|
|
FileSystemPath selected_file() const { return m_selected_file; }
|
2019-05-09 04:56:52 +02:00
|
|
|
|
2019-03-09 21:38:13 +01:00
|
|
|
virtual const char* class_name() const override { return "GFilePicker"; }
|
2019-03-16 12:57:04 +01:00
|
|
|
|
|
|
|
private:
|
2019-05-26 22:33:54 +02:00
|
|
|
void set_preview(const FileSystemPath&);
|
|
|
|
void clear_preview();
|
|
|
|
|
2019-07-13 19:58:04 -05:00
|
|
|
static String ok_button_name(Mode mode)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case Mode::Open:
|
|
|
|
return "Open";
|
|
|
|
case Mode::Save:
|
|
|
|
return "Save";
|
|
|
|
default:
|
|
|
|
return "OK";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 01:24:37 +02:00
|
|
|
GTableView* m_view { nullptr };
|
2019-06-21 18:37:47 +02:00
|
|
|
NonnullRefPtr<GDirectoryModel> m_model;
|
2019-05-26 13:09:31 +01:00
|
|
|
FileSystemPath m_selected_file;
|
2019-05-26 22:33:54 +02:00
|
|
|
|
|
|
|
GLabel* m_preview_image_label { nullptr };
|
|
|
|
GLabel* m_preview_name_label { nullptr };
|
|
|
|
GLabel* m_preview_geometry_label { nullptr };
|
2019-07-13 19:58:04 -05:00
|
|
|
Mode m_mode { Mode::Open };
|
|
|
|
};
|