2019-05-26 09:09:31 -03:00
|
|
|
#include <AK/FileSystemPath.h>
|
2019-07-13 21:58:04 -03:00
|
|
|
#include <AK/Optional.h>
|
2019-07-28 15:04:57 -03:00
|
|
|
#include <LibCore/CUserInfo.h>
|
2019-05-08 17:10:00 -03:00
|
|
|
#include <LibGUI/GDialog.h>
|
2019-05-08 20:24:37 -03:00
|
|
|
#include <LibGUI/GTableView.h>
|
|
|
|
|
|
|
|
|
|
class GDirectoryModel;
|
2019-05-26 17:33:54 -03:00
|
|
|
class GLabel;
|
2019-07-29 17:50:06 -03:00
|
|
|
class GTextBox;
|
2019-03-09 17:38:13 -03:00
|
|
|
|
2019-05-08 17:10:00 -03:00
|
|
|
class GFilePicker final : public GDialog {
|
2019-07-25 14:49:28 -03:00
|
|
|
C_OBJECT(GFilePicker)
|
2019-03-09 17:38:13 -03:00
|
|
|
public:
|
2019-07-13 21:58:04 -03:00
|
|
|
enum class Mode {
|
|
|
|
|
Open,
|
|
|
|
|
Save
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-26 16:42:34 -03:00
|
|
|
static Optional<String> get_open_filepath(const String& window_title = {});
|
2019-07-29 01:45:50 -03:00
|
|
|
static Optional<String> get_save_filepath(const String& title, const String& extension);
|
2019-07-13 21:58:04 -03:00
|
|
|
static bool file_exists(const StringView& path);
|
|
|
|
|
|
2019-03-09 17:38:13 -03:00
|
|
|
virtual ~GFilePicker() override;
|
|
|
|
|
|
2019-05-26 09:09:31 -03:00
|
|
|
FileSystemPath selected_file() const { return m_selected_file; }
|
2019-05-08 23:56:52 -03:00
|
|
|
|
2019-03-16 08:57:04 -03:00
|
|
|
private:
|
2019-05-26 17:33:54 -03:00
|
|
|
void set_preview(const FileSystemPath&);
|
|
|
|
|
void clear_preview();
|
2019-07-29 17:50:06 -03:00
|
|
|
void on_file_return();
|
2019-05-26 17:33:54 -03:00
|
|
|
|
2019-10-01 02:18:20 -03:00
|
|
|
GFilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = String(get_current_user_home_path()), CObject* parent = nullptr);
|
|
|
|
|
|
2019-07-13 21:58:04 -03:00
|
|
|
static String ok_button_name(Mode mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case Mode::Open:
|
|
|
|
|
return "Open";
|
|
|
|
|
case Mode::Save:
|
|
|
|
|
return "Save";
|
|
|
|
|
default:
|
|
|
|
|
return "OK";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-21 19:31:54 -03:00
|
|
|
RefPtr<GTableView> m_view;
|
2019-06-21 13:37:47 -03:00
|
|
|
NonnullRefPtr<GDirectoryModel> m_model;
|
2019-05-26 09:09:31 -03:00
|
|
|
FileSystemPath m_selected_file;
|
2019-05-26 17:33:54 -03:00
|
|
|
|
2019-09-21 19:31:54 -03:00
|
|
|
RefPtr<GTextBox> m_filename_textbox;
|
|
|
|
|
RefPtr<GLabel> m_preview_image_label;
|
|
|
|
|
RefPtr<GLabel> m_preview_name_label;
|
|
|
|
|
RefPtr<GLabel> m_preview_geometry_label;
|
2019-07-13 21:58:04 -03:00
|
|
|
Mode m_mode { Mode::Open };
|
2019-07-25 14:49:28 -03:00
|
|
|
};
|