#include #include #include #include #include class GDirectoryModel; class GLabel; class GTextBox; class GFilePicker final : public GDialog { C_OBJECT(GFilePicker) public: enum class Mode { Open, Save }; static Optional get_open_filepath(const String& window_title = {}); static Optional get_save_filepath(const String& title, const String& extension); static bool file_exists(const StringView& path); virtual ~GFilePicker() override; FileSystemPath selected_file() const { return m_selected_file; } private: void set_preview(const FileSystemPath&); void clear_preview(); void on_file_return(); GFilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = String(get_current_user_home_path()), CObject* parent = nullptr); static String ok_button_name(Mode mode) { switch (mode) { case Mode::Open: return "Open"; case Mode::Save: return "Save"; default: return "OK"; } } RefPtr m_view; NonnullRefPtr m_model; FileSystemPath m_selected_file; RefPtr m_filename_textbox; RefPtr m_preview_image_label; RefPtr m_preview_name_label; RefPtr m_preview_geometry_label; Mode m_mode { Mode::Open }; };