Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#include <AK/FileSystemPath.h>
30#include <AK/Function.h>
31#include <LibGUI/Application.h>
32#include <LibGUI/TextEditor.h>
33#include <LibGUI/Widget.h>
34#include <LibGUI/Window.h>
35
36class TextEditorWidget final : public GUI::Widget {
37 C_OBJECT(TextEditorWidget)
38public:
39 virtual ~TextEditorWidget() override;
40 void open_sesame(const String& path);
41 bool request_close();
42
43 GUI::TextEditor& editor() { return *m_editor; }
44
45private:
46 TextEditorWidget();
47 void set_path(const FileSystemPath& file);
48 void update_title();
49
50 virtual void drop_event(GUI::DropEvent&) override;
51
52 RefPtr<GUI::TextEditor> m_editor;
53 String m_path;
54 String m_name;
55 String m_extension;
56 RefPtr<GUI::Action> m_new_action;
57 RefPtr<GUI::Action> m_open_action;
58 RefPtr<GUI::Action> m_save_action;
59 RefPtr<GUI::Action> m_save_as_action;
60 RefPtr<GUI::Action> m_find_replace_action;
61 RefPtr<GUI::Action> m_line_wrapping_setting_action;
62 RefPtr<GUI::Action> m_find_next_action;
63 RefPtr<GUI::Action> m_find_previous_action;
64 RefPtr<GUI::Action> m_replace_next_action;
65 RefPtr<GUI::Action> m_replace_previous_action;
66 RefPtr<GUI::Action> m_replace_all_action;
67
68 RefPtr<GUI::StatusBar> m_statusbar;
69
70 RefPtr<GUI::TextBox> m_find_textbox;
71 RefPtr<GUI::TextBox> m_replace_textbox;
72 GUI::Button* m_find_previous_button { nullptr };
73 GUI::Button* m_find_next_button { nullptr };
74 GUI::Button* m_replace_previous_button { nullptr };
75 GUI::Button* m_replace_next_button { nullptr };
76 GUI::Button* m_replace_all_button { nullptr };
77 RefPtr<GUI::Widget> m_find_replace_widget;
78 RefPtr<GUI::Widget> m_find_widget;
79 RefPtr<GUI::Widget> m_replace_widget;
80
81 bool m_document_dirty { false };
82 bool m_document_opening { false };
83};