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.
|
|
|
|
*/
|
|
|
|
|
2019-10-27 12:55:10 +01:00
|
|
|
#include "EditorWrapper.h"
|
|
|
|
#include "Editor.h"
|
2020-08-10 22:28:38 +02:00
|
|
|
#include "HackStudio.h"
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/Action.h>
|
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
#include <LibGUI/InputBox.h>
|
|
|
|
#include <LibGUI/Label.h>
|
2020-02-15 00:24:14 +01:00
|
|
|
#include <LibGfx/Font.h>
|
2019-10-27 12:55:10 +01:00
|
|
|
|
2020-08-17 15:22:30 +02:00
|
|
|
namespace HackStudio {
|
|
|
|
|
2020-09-27 00:11:15 +03:00
|
|
|
EditorWrapper::EditorWrapper()
|
2019-10-27 12:55:10 +01:00
|
|
|
{
|
2020-03-04 09:43:54 +01:00
|
|
|
set_layout<GUI::VerticalBoxLayout>();
|
2019-10-27 12:55:10 +01:00
|
|
|
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& label_wrapper = add<GUI::Widget>();
|
|
|
|
label_wrapper.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
|
|
|
label_wrapper.set_preferred_size(0, 14);
|
|
|
|
label_wrapper.set_fill_with_background_color(true);
|
|
|
|
label_wrapper.set_layout<GUI::HorizontalBoxLayout>();
|
|
|
|
label_wrapper.layout()->set_margins({ 2, 0, 2, 0 });
|
2019-10-27 12:55:10 +01:00
|
|
|
|
2020-03-04 19:07:55 +01:00
|
|
|
m_filename_label = label_wrapper.add<GUI::Label>("(Untitled)");
|
2020-02-06 11:56:38 +01:00
|
|
|
m_filename_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
2020-02-02 15:07:41 +01:00
|
|
|
m_filename_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
2019-10-27 13:06:03 +01:00
|
|
|
m_filename_label->set_preferred_size(0, 14);
|
2019-10-27 12:55:10 +01:00
|
|
|
|
2020-03-04 19:07:55 +01:00
|
|
|
m_cursor_label = label_wrapper.add<GUI::Label>("(Cursor)");
|
2020-02-06 11:56:38 +01:00
|
|
|
m_cursor_label->set_text_alignment(Gfx::TextAlignment::CenterRight);
|
2020-02-02 15:07:41 +01:00
|
|
|
m_cursor_label->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
2019-10-27 13:06:03 +01:00
|
|
|
m_cursor_label->set_preferred_size(0, 14);
|
2019-10-27 12:55:10 +01:00
|
|
|
|
2020-02-23 10:57:42 +01:00
|
|
|
m_editor = add<Editor>();
|
2019-10-27 12:55:10 +01:00
|
|
|
m_editor->set_ruler_visible(true);
|
|
|
|
m_editor->set_line_wrapping_enabled(true);
|
|
|
|
m_editor->set_automatic_indentation_enabled(true);
|
|
|
|
|
|
|
|
m_editor->on_cursor_change = [this] {
|
2020-10-08 13:41:36 +02:00
|
|
|
m_cursor_label->set_text(String::formatted("Line: {}, Column: {}", m_editor->cursor().line() + 1, m_editor->cursor().column()));
|
2019-10-27 12:55:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
m_editor->on_focus = [this] {
|
2020-09-19 17:25:05 +03:00
|
|
|
set_current_editor_wrapper(this);
|
2019-10-27 12:55:10 +01:00
|
|
|
};
|
2020-03-12 00:18:13 +02:00
|
|
|
|
2020-08-10 22:28:38 +02:00
|
|
|
m_editor->on_open = [](String path) {
|
2020-09-19 17:25:05 +03:00
|
|
|
open_file(path);
|
2020-03-12 00:18:13 +02:00
|
|
|
};
|
2019-10-27 12:55:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorWrapper::~EditorWrapper()
|
|
|
|
{
|
|
|
|
}
|
2019-10-27 20:43:34 +01:00
|
|
|
|
|
|
|
void EditorWrapper::set_editor_has_focus(Badge<Editor>, bool focus)
|
|
|
|
{
|
2020-02-06 11:56:38 +01:00
|
|
|
m_filename_label->set_font(focus ? Gfx::Font::default_bold_font() : Gfx::Font::default_font());
|
2019-10-27 20:43:34 +01:00
|
|
|
}
|
2020-08-17 15:22:30 +02:00
|
|
|
|
|
|
|
}
|