From ab1902793deda83cf54adb84f62a16153ef12572 Mon Sep 17 00:00:00 2001 From: lainsce Date: Mon, 2 Sep 2024 23:37:38 -0300 Subject: [PATCH] Refactor: Reuse `He.ViewTitle` instance to update appbar titles - Introduced a single `He.ViewTitle` instance for updating the appbar titles. - Simplified the code by removing redundant instantiations of `He.ViewTitle`. - Updated the title labels directly on the existing `He.ViewTitle` instance. --- src/MainWindow.vala | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 5bb3cac..42b92b7 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -128,23 +128,23 @@ public class Mondai.MainWindow : He.ApplicationWindow { actions.add_action_entries (ACTION_ENTRIES, this); insert_action_group ("win", actions); + var title = new He.ViewTitle (); + stack.visible_child_name = "select"; - appbar.viewtitle_widget = null; - appbar.viewtitle_widget = new He.ViewTitle () { label = _("Select Component") }; + appbar.viewtitle_widget = title; + title.label = _("Select Component"); appbar.show_back = false; appbar.scroller = s; to_describe.clicked.connect (() => { stack.visible_child_name = "describe"; - appbar.viewtitle_widget = null; - appbar.viewtitle_widget = new He.ViewTitle () { label = _("Describe Issue") }; + title.label = _("Describe Issue"); appbar.scroller = s1; appbar.show_back = true; appbar.back_button.clicked.connect (() => { stack.visible_child_name = "select"; - appbar.viewtitle_widget = null; - appbar.viewtitle_widget = new He.ViewTitle () { label = _("Select Component") }; + title.label = _("Select Component"); appbar.show_back = false; appbar.scroller = s; }); @@ -153,14 +153,12 @@ public class Mondai.MainWindow : He.ApplicationWindow { submit.clicked.connect (() => { submit_report.begin (() => { stack.visible_child_name = "submitted"; - appbar.viewtitle_widget = null; - appbar.viewtitle_widget = new He.ViewTitle () { label = _("Report submitted!") }; + title.label = _("Report submitted!"); appbar.scroller = s2; appbar.back_button.clicked.connect (() => { stack.visible_child_name = "describe"; - appbar.viewtitle_widget = null; - appbar.viewtitle_widget = new He.ViewTitle () { label = _("Select Component") }; + title.label = _("Select Component"); appbar.scroller = s1; }); });