mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
HackStudio: Add GML Preview action tab
This allows us to show a GML Preview in realtime via HackStudio::GMLPreviewWidget! :^)
This commit is contained in:
parent
0295cf96a8
commit
6aa2b7d4cc
5 changed files with 79 additions and 0 deletions
|
@ -34,6 +34,7 @@ set(SOURCES
|
|||
Git/GitFilesView.cpp
|
||||
Git/GitRepo.cpp
|
||||
Git/GitWidget.cpp
|
||||
GMLPreviewWidget.cpp
|
||||
HackStudioWidget.cpp
|
||||
Language.cpp
|
||||
LanguageClient.cpp
|
||||
|
|
40
Userland/DevTools/HackStudio/GMLPreviewWidget.cpp
Normal file
40
Userland/DevTools/HackStudio/GMLPreviewWidget.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Conor Byrne <cbyrneee@protonmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "GMLPreviewWidget.h"
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Label.h>
|
||||
|
||||
namespace HackStudio {
|
||||
|
||||
GMLPreviewWidget::GMLPreviewWidget(String const& gml_content)
|
||||
{
|
||||
set_layout<GUI::VerticalBoxLayout>();
|
||||
load_gml(gml_content);
|
||||
}
|
||||
|
||||
void GMLPreviewWidget::load_gml(String const& gml)
|
||||
{
|
||||
remove_all_children();
|
||||
|
||||
if (gml.is_empty()) {
|
||||
auto& label = add<GUI::Label>();
|
||||
label.set_text("Open a .gml file to show the preview");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
load_from_gml(gml, [](const String& name) -> RefPtr<Core::Object> {
|
||||
return GUI::Label::construct(String::formatted("{} is not registered as a GML element!", name));
|
||||
});
|
||||
|
||||
if (children().is_empty()) {
|
||||
auto& label = add<GUI::Label>();
|
||||
label.set_text("Failed to load GML!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
23
Userland/DevTools/HackStudio/GMLPreviewWidget.h
Normal file
23
Userland/DevTools/HackStudio/GMLPreviewWidget.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Conor Byrne <cbyrneee@protonmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
|
||||
namespace HackStudio {
|
||||
|
||||
class GMLPreviewWidget final : public GUI::Widget {
|
||||
C_OBJECT(GMLPreviewWidget)
|
||||
public:
|
||||
void load_gml(String const&);
|
||||
|
||||
private:
|
||||
explicit GMLPreviewWidget(String const&);
|
||||
};
|
||||
|
||||
}
|
|
@ -288,6 +288,9 @@ bool HackStudioWidget::open_file(const String& full_filename)
|
|||
current_editor().set_focus(true);
|
||||
|
||||
current_editor().on_cursor_change = [this] { update_statusbar(); };
|
||||
current_editor().on_change = [this] { update_gml_preview(); };
|
||||
update_gml_preview();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -504,6 +507,7 @@ void HackStudioWidget::add_new_editor(GUI::Widget& parent)
|
|||
wrapper->editor().set_focus(true);
|
||||
wrapper->set_project_root(LexicalPath(m_project->root_path()));
|
||||
wrapper->editor().on_cursor_change = [this] { update_statusbar(); };
|
||||
wrapper->editor().on_change = [this] { update_gml_preview(); };
|
||||
}
|
||||
|
||||
NonnullRefPtr<GUI::Action> HackStudioWidget::create_switch_to_next_editor_action()
|
||||
|
@ -908,6 +912,7 @@ void HackStudioWidget::create_action_tab(GUI::Widget& parent)
|
|||
m_diff_viewer->set_content(original_content, diff);
|
||||
set_edit_mode(EditMode::Diff);
|
||||
});
|
||||
m_gml_preview_widget = m_action_tab_widget->add_tab<GMLPreviewWidget>("GML Preview", "");
|
||||
|
||||
ToDoEntries::the().on_update = [this]() {
|
||||
m_todo_entries_widget->refresh();
|
||||
|
@ -1150,4 +1155,10 @@ bool HackStudioWidget::any_document_is_dirty() const
|
|||
return false;
|
||||
}
|
||||
|
||||
void HackStudioWidget::update_gml_preview()
|
||||
{
|
||||
auto gml_content = current_editor_wrapper().filename().ends_with(".gml") ? current_editor_wrapper().editor().text() : "";
|
||||
m_gml_preview_widget->load_gml(gml_content);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "Debugger/DisassemblyWidget.h"
|
||||
#include "EditorWrapper.h"
|
||||
#include "FindInFilesWidget.h"
|
||||
#include "GMLPreviewWidget.h"
|
||||
#include "Git/DiffViewer.h"
|
||||
#include "Git/GitWidget.h"
|
||||
#include "Locator.h"
|
||||
|
@ -119,6 +120,8 @@ private:
|
|||
void hide_action_tabs();
|
||||
bool any_document_is_dirty() const;
|
||||
|
||||
void update_gml_preview();
|
||||
|
||||
NonnullRefPtrVector<EditorWrapper> m_all_editor_wrappers;
|
||||
RefPtr<EditorWrapper> m_current_editor_wrapper;
|
||||
|
||||
|
@ -135,6 +138,7 @@ private:
|
|||
RefPtr<GUI::Splitter> m_editors_splitter;
|
||||
RefPtr<DiffViewer> m_diff_viewer;
|
||||
RefPtr<GitWidget> m_git_widget;
|
||||
RefPtr<GMLPreviewWidget> m_gml_preview_widget;
|
||||
RefPtr<ClassViewWidget> m_class_view;
|
||||
RefPtr<GUI::Menu> m_project_tree_view_context_menu;
|
||||
RefPtr<GUI::Statusbar> m_statusbar;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue