ladybird/Libraries/LibGUI/GFilePicker.h
rhin123 c869d62e16 GFilePicker: Edit file name on opening window
Overlooked that you can't have two GWidgets
selected at the same time, whoops!
2019-07-30 09:19:14 +02:00

54 lines
1.5 KiB
C++

#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 GTextBox;
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();
void on_file_return();
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;
GTextBox* m_filename_textbox { nullptr };
GLabel* m_preview_image_label { nullptr };
GLabel* m_preview_name_label { nullptr };
GLabel* m_preview_geometry_label { nullptr };
Mode m_mode { Mode::Open };
};