2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
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>
|
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-02-02 15:07:41 +01:00
|
|
|
class FilePicker final : public Dialog {
|
|
|
|
C_OBJECT(FilePicker)
|
2019-03-09 21:38:13 +01:00
|
|
|
public:
|
2019-07-13 19:58:04 -05:00
|
|
|
enum class Mode {
|
|
|
|
Open,
|
|
|
|
Save
|
|
|
|
};
|
|
|
|
|
2019-10-26 21:42:34 +02:00
|
|
|
static Optional<String> get_open_filepath(const String& window_title = {});
|
2019-07-28 23:45:50 -05:00
|
|
|
static Optional<String> get_save_filepath(const String& title, const String& extension);
|
2019-07-13 19:58:04 -05:00
|
|
|
static bool file_exists(const StringView& path);
|
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
virtual ~FilePicker() override;
|
2019-03-09 21:38:13 +01:00
|
|
|
|
2020-05-26 14:52:44 +03:00
|
|
|
LexicalPath selected_file() const { return m_selected_file; }
|
2019-05-09 04:56:52 +02:00
|
|
|
|
2019-03-16 12:57:04 +01:00
|
|
|
private:
|
2020-05-26 14:52:44 +03:00
|
|
|
void set_preview(const LexicalPath&);
|
2019-05-26 22:33:54 +02:00
|
|
|
void clear_preview();
|
2019-07-29 15:50:06 -05:00
|
|
|
void on_file_return();
|
2019-05-26 22:33:54 +02:00
|
|
|
|
2020-04-19 19:57:05 +02:00
|
|
|
FilePicker(Mode type = Mode::Open, const StringView& file_name = "Untitled", const StringView& path = Core::StandardPaths::home_directory(), Window* parent_window = nullptr);
|
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:
|
|
|
|
return "Open";
|
|
|
|
case Mode::Save:
|
|
|
|
return "Save";
|
|
|
|
default:
|
|
|
|
return "OK";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 20:50:21 +01:00
|
|
|
RefPtr<MultiView> m_view;
|
2020-02-02 15:07:41 +01:00
|
|
|
NonnullRefPtr<FileSystemModel> m_model;
|
2020-05-26 14:52:44 +03:00
|
|
|
LexicalPath m_selected_file;
|
2019-05-26 22:33:54 +02:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
RefPtr<TextBox> m_filename_textbox;
|
|
|
|
RefPtr<Label> m_preview_image_label;
|
|
|
|
RefPtr<Label> m_preview_name_label;
|
|
|
|
RefPtr<Label> m_preview_geometry_label;
|
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
|
|
|
|
|
|
|
}
|