1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 20:45:08 +00:00

VisualBuilder: Add a simple mechanism to write a form out to disk.

This commit is contained in:
Andreas Kling 2019-05-08 04:39:42 +02:00
parent 7ce3b10568
commit 5d707745b6
5 changed files with 31 additions and 10 deletions

View file

@ -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");
}
}