mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03:00
VisualBuilder: Add a simple mechanism to write a form out to disk.
This commit is contained in:
parent
7ce3b10568
commit
5d707745b6
Notes:
sideshowbarker
2024-07-19 14:11:55 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5d707745b67
@ -1,8 +1,11 @@
|
||||
#include "VBForm.h"
|
||||
#include "VBWidget.h"
|
||||
#include "VBProperty.h"
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GMessageBox.h>
|
||||
#include <LibCore/CFile.h>
|
||||
|
||||
static VBForm* s_current;
|
||||
VBForm* VBForm::current()
|
||||
@ -300,6 +303,27 @@ void VBForm::mousemove_event(GMouseEvent& event)
|
||||
}
|
||||
}
|
||||
|
||||
void VBForm::write_to_file(const String& path)
|
||||
{
|
||||
CFile file(path);
|
||||
if (!file.open(CIODevice::WriteOnly)) {
|
||||
GMessageBox box(String::format("Could not open '%s' for writing", path.characters()), "Error", window());
|
||||
box.exec();
|
||||
return;
|
||||
}
|
||||
file.printf("[Form]\n");
|
||||
file.printf("Name=%s\n", m_name.characters());
|
||||
file.printf("\n");
|
||||
int i = 0;
|
||||
for (auto& widget : m_widgets) {
|
||||
file.printf("[Widget %d]\n", i++);
|
||||
widget->for_each_property([&] (auto& property) {
|
||||
file.printf("%s=%s\n", property.name().characters(), property.value().to_string().characters());
|
||||
});
|
||||
file.printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void VBForm::dump()
|
||||
{
|
||||
dbgprintf("[Form]\n");
|
||||
@ -308,7 +332,9 @@ void VBForm::dump()
|
||||
int i = 0;
|
||||
for (auto& widget : m_widgets) {
|
||||
dbgprintf("[Widget %d]\n", i++);
|
||||
widget->dump();
|
||||
widget->for_each_property([] (auto& property) {
|
||||
dbgprintf("%s=%s\n", property.name().characters(), property.value().to_string().characters());
|
||||
});
|
||||
dbgprintf("\n");
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public:
|
||||
|
||||
Function<void(VBWidget*)> on_widget_selected;
|
||||
|
||||
void write_to_file(const String& path);
|
||||
void dump();
|
||||
|
||||
protected:
|
||||
|
@ -195,10 +195,3 @@ void VBWidget::capture_transform_origin_rect()
|
||||
{
|
||||
m_transform_origin_rect = rect();
|
||||
}
|
||||
|
||||
void VBWidget::dump()
|
||||
{
|
||||
for (auto& property : m_properties) {
|
||||
dbgprintf("%s=%s\n", property->name().characters(), property->value().to_string().characters());
|
||||
}
|
||||
}
|
||||
|
@ -59,8 +59,6 @@ public:
|
||||
Rect transform_origin_rect() const { return m_transform_origin_rect; }
|
||||
void capture_transform_origin_rect();
|
||||
|
||||
void dump();
|
||||
|
||||
private:
|
||||
VBWidget(VBWidgetType, VBForm&);
|
||||
|
||||
|
@ -40,6 +40,9 @@ int main(int argc, char** argv)
|
||||
file_menu->add_action(GAction::create("Dump Form", [&] (auto&) {
|
||||
form1->dump();
|
||||
}));
|
||||
file_menu->add_action(GAction::create("Save Form...", { Mod_Ctrl, Key_S }, [form1] (auto&) {
|
||||
form1->write_to_file("/tmp/form.frm");
|
||||
}));
|
||||
menubar->add_menu(move(file_menu));
|
||||
|
||||
auto edit_menu = make<GMenu>("Edit");
|
||||
|
Loading…
Reference in New Issue
Block a user