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