Sfoglia il codice sorgente

CalendarSettings: Use new GML compiler

kleines Filmröllchen 2 anni fa
parent
commit
63687c46ff

+ 2 - 5
Userland/Applications/CalendarSettings/CMakeLists.txt

@@ -4,16 +4,13 @@ serenity_component(
     TARGETS CalendarSettings
 )
 
-stringify_gml(CalendarSettingsWidget.gml CalendarSettingsWidgetGML.h calendar_settings_widget_gml)
+compile_gml(CalendarSettingsWidget.gml CalendarSettingsWidgetGML.cpp)
 
 set(SOURCES
     main.cpp
+    CalendarSettingsWidgetGML.cpp
     CalendarSettingsWidget.cpp
 )
 
-set(GENERATED_SOURCES
-    CalendarSettingsWidgetGML.h
-)
-
 serenity_app(CalendarSettings ICON app-calendar)
 target_link_libraries(CalendarSettings PRIVATE LibConfig LibCore LibGfx LibGUI LibMain)

+ 6 - 5
Userland/Applications/CalendarSettings/CalendarSettingsWidget.cpp

@@ -7,12 +7,13 @@
 
 #include "CalendarSettingsWidget.h"
 #include <AK/DateConstants.h>
-#include <Applications/CalendarSettings/CalendarSettingsWidgetGML.h>
 #include <LibConfig/Client.h>
 #include <LibGUI/ComboBox.h>
 #include <LibGUI/ItemListModel.h>
 #include <LibGUI/SpinBox.h>
 
+namespace CalendarSettings {
+
 void CalendarSettingsWidget::apply_settings()
 {
     Config::write_string("Calendar"sv, "View"sv, "FirstDayOfWeek"sv, m_first_day_of_week_combobox->text());
@@ -29,17 +30,15 @@ void CalendarSettingsWidget::reset_default_values()
     m_default_view_combobox->set_text("Month");
 }
 
-ErrorOr<NonnullRefPtr<CalendarSettingsWidget>> CalendarSettingsWidget::try_create()
+ErrorOr<NonnullRefPtr<CalendarSettingsWidget>> CalendarSettingsWidget::create()
 {
-    auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) CalendarSettingsWidget()));
+    auto widget = TRY(try_create());
     TRY(widget->setup());
     return widget;
 }
 
 ErrorOr<void> CalendarSettingsWidget::setup()
 {
-    TRY(load_from_gml(calendar_settings_widget_gml));
-
     m_first_day_of_week_combobox = *find_descendant_of_type_named<GUI::ComboBox>("first_day_of_week");
     m_first_day_of_week_combobox->set_text(Config::read_string("Calendar"sv, "View"sv, "FirstDayOfWeek"sv, "Sunday"sv));
     m_first_day_of_week_combobox->set_only_allow_values_from_model(true);
@@ -71,3 +70,5 @@ ErrorOr<void> CalendarSettingsWidget::setup()
     };
     return {};
 }
+
+}

+ 4 - 4
Userland/Applications/CalendarSettings/CalendarSettingsWidget.gml

@@ -1,4 +1,4 @@
-@GUI::Frame {
+@CalendarSettings::CalendarSettingsWidget {
     fill_with_background_color: true
     layout: @GUI::VerticalBoxLayout {
         margins: [8]
@@ -15,7 +15,7 @@
 
         @GUI::Label {
             text: "Determines which day a week starts with in the calendar view."
-            word_wrap: true
+            text_wrapping: "Wrap"
             text_alignment: "CenterLeft"
         }
 
@@ -46,7 +46,7 @@
 
         @GUI::Label {
             text: "Determines the start and length of the weekend."
-            word_wrap: true
+            text_wrapping: "Wrap"
             text_alignment: "CenterLeft"
         }
 
@@ -103,7 +103,7 @@
 
         @GUI::Label {
             text: "Show the month or the year view when Calendar is started."
-            word_wrap: true
+            text_wrapping: "Wrap"
             text_alignment: "CenterLeft"
         }
 

+ 7 - 1
Userland/Applications/CalendarSettings/CalendarSettingsWidget.h

@@ -9,17 +9,21 @@
 
 #include <LibGUI/SettingsWindow.h>
 
+namespace CalendarSettings {
+
 class CalendarSettingsWidget final : public GUI::SettingsWindow::Tab {
     C_OBJECT_ABSTRACT(CalendarSettingsWidget)
 
 public:
-    static ErrorOr<NonnullRefPtr<CalendarSettingsWidget>> try_create();
+    static ErrorOr<NonnullRefPtr<CalendarSettingsWidget>> create();
 
     virtual void apply_settings() override;
     virtual void reset_default_values() override;
 
 private:
     CalendarSettingsWidget() = default;
+    static ErrorOr<NonnullRefPtr<CalendarSettingsWidget>> try_create();
+
     ErrorOr<void> setup();
     static constexpr Array<StringView, 2> const m_view_modes = { "Month"sv, "Year"sv };
 
@@ -28,3 +32,5 @@ private:
     RefPtr<GUI::SpinBox> m_weekend_length_spinbox;
     RefPtr<GUI::ComboBox> m_default_view_combobox;
 };
+
+}

+ 1 - 1
Userland/Applications/CalendarSettings/main.cpp

@@ -33,7 +33,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     auto app_icon = GUI::Icon::default_icon("app-calendar"sv);
 
     auto window = TRY(GUI::SettingsWindow::create("Calendar Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes));
-    (void)TRY(window->add_tab<CalendarSettingsWidget>("Calendar"_string, "Calendar"sv));
+    (void)TRY(window->add_tab(TRY(CalendarSettings::CalendarSettingsWidget::create()), "Calendar"_string, "Calendar"sv));
     window->set_icon(app_icon.bitmap_for_size(16));
     window->set_active_tab(selected_tab);