GFilePicker.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <AK/FileSystemPath.h>
  2. #include <AK/Optional.h>
  3. #include <LibCore/CUserInfo.h>
  4. #include <LibGUI/GDialog.h>
  5. #include <LibGUI/GTableView.h>
  6. class GDirectoryModel;
  7. class GLabel;
  8. class GTextBox;
  9. class GFilePicker final : public GDialog {
  10. C_OBJECT(GFilePicker)
  11. public:
  12. enum class Mode {
  13. Open,
  14. Save
  15. };
  16. static Optional<String> get_open_filepath();
  17. static Optional<String> get_save_filepath(const String& title, const String& extension);
  18. static bool file_exists(const StringView& path);
  19. virtual ~GFilePicker() override;
  20. FileSystemPath selected_file() const { return m_selected_file; }
  21. private:
  22. void set_preview(const FileSystemPath&);
  23. void clear_preview();
  24. void on_file_return();
  25. GFilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = String(get_current_user_home_path()), CObject* parent = nullptr);
  26. static String ok_button_name(Mode mode)
  27. {
  28. switch (mode) {
  29. case Mode::Open:
  30. return "Open";
  31. case Mode::Save:
  32. return "Save";
  33. default:
  34. return "OK";
  35. }
  36. }
  37. RefPtr<GTableView> m_view;
  38. NonnullRefPtr<GDirectoryModel> m_model;
  39. FileSystemPath m_selected_file;
  40. RefPtr<GTextBox> m_filename_textbox;
  41. RefPtr<GLabel> m_preview_image_label;
  42. RefPtr<GLabel> m_preview_name_label;
  43. RefPtr<GLabel> m_preview_geometry_label;
  44. Mode m_mode { Mode::Open };
  45. };