GFilePicker.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. GFilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = String(get_current_user_home_path()), CObject* parent = nullptr);
  20. virtual ~GFilePicker() override;
  21. FileSystemPath selected_file() const { return m_selected_file; }
  22. private:
  23. void set_preview(const FileSystemPath&);
  24. void clear_preview();
  25. void on_file_return();
  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. ObjectPtr<GTableView> m_view;
  38. NonnullRefPtr<GDirectoryModel> m_model;
  39. FileSystemPath m_selected_file;
  40. ObjectPtr<GTextBox> m_filename_textbox;
  41. ObjectPtr<GLabel> m_preview_image_label;
  42. ObjectPtr<GLabel> m_preview_name_label;
  43. ObjectPtr<GLabel> m_preview_geometry_label;
  44. Mode m_mode { Mode::Open };
  45. };