ladybird/Libraries/LibGUI/GFilePicker.h
Sergey Bugaev fdeb91e000 LibGUI+FileManager: Merge GDirectoryModel into GFileSystemModel
We used to have two different models for displaying file system contents:
the FileManager-grade table-like directory model, which exposed rich data
(such as file icons with integrated image previews) about contents of a
single directory, and the tree-like GFileSystemModel, which only exposed
a tree of file names with very basic info about them.

This commit unifies the two. The new GFileSystemModel can be used both as a
tree-like and as a table-like model, or in fact in both ways simultaneously.
It exposes rich data about a file system subtree rooted at the given root.

The users of the two previous models are all ported to use this new model.
2020-01-10 17:45:59 +01:00

55 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 GFileSystemModel;
class GLabel;
class GTextBox;
class GFilePicker final : public GDialog {
C_OBJECT(GFilePicker)
public:
enum class Mode {
Open,
Save
};
static Optional<String> get_open_filepath(const String& window_title = {});
static Optional<String> 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<GTableView> m_view;
NonnullRefPtr<GFileSystemModel> m_model;
FileSystemPath m_selected_file;
RefPtr<GTextBox> m_filename_textbox;
RefPtr<GLabel> m_preview_image_label;
RefPtr<GLabel> m_preview_name_label;
RefPtr<GLabel> m_preview_geometry_label;
Mode m_mode { Mode::Open };
};