2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-05-28 15:40:53 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-05-26 08:52:44 -03:00
|
|
|
#include <AK/LexicalPath.h>
|
2019-07-13 21:58:04 -03:00
|
|
|
#include <AK/Optional.h>
|
2020-04-19 14:57:05 -03:00
|
|
|
#include <LibCore/StandardPaths.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Dialog.h>
|
2020-07-22 10:29:51 -03:00
|
|
|
#include <LibGUI/ImageWidget.h>
|
2020-07-11 09:47:26 -03:00
|
|
|
#include <LibGUI/Model.h>
|
2019-05-08 20:24:37 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
namespace GUI {
|
2019-03-09 17:38:13 -03:00
|
|
|
|
2020-08-13 15:06:14 -03:00
|
|
|
class FilePicker final
|
|
|
|
|
: public Dialog
|
|
|
|
|
, private ModelClient {
|
|
|
|
|
C_OBJECT(FilePicker);
|
|
|
|
|
|
2019-03-09 17:38:13 -03:00
|
|
|
public:
|
2019-07-13 21:58:04 -03:00
|
|
|
enum class Mode {
|
|
|
|
|
Open,
|
2020-07-12 02:13:12 -03:00
|
|
|
OpenMultiple,
|
2021-04-11 20:34:10 -03:00
|
|
|
OpenFolder,
|
2019-07-13 21:58:04 -03:00
|
|
|
Save
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
static Optional<String> get_open_filepath(Window* parent_window, String const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), bool folder = false, ScreenPosition screen_position = Dialog::ScreenPosition::CenterWithinParent);
|
|
|
|
|
static Optional<String> get_save_filepath(Window* parent_window, String const& title, String const& extension, StringView path = Core::StandardPaths::home_directory(), ScreenPosition screen_position = Dialog::ScreenPosition::CenterWithinParent);
|
2019-07-13 21:58:04 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
virtual ~FilePicker() override;
|
2019-03-09 17:38:13 -03:00
|
|
|
|
2021-05-20 15:40:32 -03:00
|
|
|
String const& 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-07-29 17:50:06 -03:00
|
|
|
void on_file_return();
|
2019-05-26 17:33:54 -03:00
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
void set_path(String const&);
|
2020-07-19 16:42:00 -03:00
|
|
|
|
2020-08-13 15:06:14 -03:00
|
|
|
// ^GUI::ModelClient
|
|
|
|
|
virtual void model_did_update(unsigned) override;
|
2020-07-11 09:47:26 -03:00
|
|
|
|
2022-07-11 14:32:29 -03:00
|
|
|
FilePicker(Window* parent_window, Mode type = Mode::Open, StringView filename = "Untitled"sv, StringView path = Core::StandardPaths::home_directory(), ScreenPosition screen_position = Dialog::ScreenPosition::CenterWithinParent);
|
2019-10-01 02:18:20 -03:00
|
|
|
|
2019-07-13 21:58:04 -03:00
|
|
|
static String ok_button_name(Mode mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case Mode::Open:
|
2020-07-12 02:13:12 -03:00
|
|
|
case Mode::OpenMultiple:
|
2021-04-11 20:34:10 -03:00
|
|
|
case Mode::OpenFolder:
|
2019-07-13 21:58:04 -03:00
|
|
|
return "Open";
|
|
|
|
|
case Mode::Save:
|
|
|
|
|
return "Save";
|
|
|
|
|
default:
|
|
|
|
|
return "OK";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 13:18:57 -03:00
|
|
|
struct CommonLocationButton {
|
|
|
|
|
String path;
|
2021-10-21 14:33:08 -03:00
|
|
|
size_t tray_item_index { 0 };
|
2021-04-26 13:18:57 -03:00
|
|
|
};
|
|
|
|
|
|
2020-02-24 16:50:21 -03:00
|
|
|
RefPtr<MultiView> m_view;
|
2020-02-02 11:07:41 -03:00
|
|
|
NonnullRefPtr<FileSystemModel> m_model;
|
2021-05-20 15:40:32 -03:00
|
|
|
String m_selected_file;
|
2019-05-26 17:33:54 -03:00
|
|
|
|
2021-07-27 08:52:28 -03:00
|
|
|
RefPtr<GUI::Label> m_error_label;
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
RefPtr<TextBox> m_filename_textbox;
|
2020-07-11 09:47:26 -03:00
|
|
|
RefPtr<TextBox> m_location_textbox;
|
2021-04-26 13:18:57 -03:00
|
|
|
Vector<CommonLocationButton> m_common_location_buttons;
|
2021-03-29 14:26:28 -03:00
|
|
|
RefPtr<Menu> m_context_menu;
|
2019-07-13 21:58:04 -03:00
|
|
|
Mode m_mode { Mode::Open };
|
2019-07-25 14:49:28 -03:00
|
|
|
};
|
2020-02-02 11:07:41 -03:00
|
|
|
|
|
|
|
|
}
|