mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 11:35:07 +00:00
VisualBuilder: Add a simple mechanism to write a form out to disk.
This commit is contained in:
parent
7ce3b10568
commit
5d707745b6
5 changed files with 31 additions and 10 deletions
|
@ -1,8 +1,11 @@
|
||||||
#include "VBForm.h"
|
#include "VBForm.h"
|
||||||
#include "VBWidget.h"
|
#include "VBWidget.h"
|
||||||
|
#include "VBProperty.h"
|
||||||
#include <LibGUI/GPainter.h>
|
#include <LibGUI/GPainter.h>
|
||||||
#include <LibGUI/GMenu.h>
|
#include <LibGUI/GMenu.h>
|
||||||
#include <LibGUI/GAction.h>
|
#include <LibGUI/GAction.h>
|
||||||
|
#include <LibGUI/GMessageBox.h>
|
||||||
|
#include <LibCore/CFile.h>
|
||||||
|
|
||||||
static VBForm* s_current;
|
static VBForm* s_current;
|
||||||
VBForm* VBForm::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()
|
void VBForm::dump()
|
||||||
{
|
{
|
||||||
dbgprintf("[Form]\n");
|
dbgprintf("[Form]\n");
|
||||||
|
@ -308,7 +332,9 @@ void VBForm::dump()
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto& widget : m_widgets) {
|
for (auto& widget : m_widgets) {
|
||||||
dbgprintf("[Widget %d]\n", i++);
|
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");
|
dbgprintf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ public:
|
||||||
|
|
||||||
Function<void(VBWidget*)> on_widget_selected;
|
Function<void(VBWidget*)> on_widget_selected;
|
||||||
|
|
||||||
|
void write_to_file(const String& path);
|
||||||
void dump();
|
void dump();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -195,10 +195,3 @@ void VBWidget::capture_transform_origin_rect()
|
||||||
{
|
{
|
||||||
m_transform_origin_rect = 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; }
|
Rect transform_origin_rect() const { return m_transform_origin_rect; }
|
||||||
void capture_transform_origin_rect();
|
void capture_transform_origin_rect();
|
||||||
|
|
||||||
void dump();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VBWidget(VBWidgetType, VBForm&);
|
VBWidget(VBWidgetType, VBForm&);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,9 @@ int main(int argc, char** argv)
|
||||||
file_menu->add_action(GAction::create("Dump Form", [&] (auto&) {
|
file_menu->add_action(GAction::create("Dump Form", [&] (auto&) {
|
||||||
form1->dump();
|
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));
|
menubar->add_menu(move(file_menu));
|
||||||
|
|
||||||
auto edit_menu = make<GMenu>("Edit");
|
auto edit_menu = make<GMenu>("Edit");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue