diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 423db1be9..47153d697 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -95,11 +95,8 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { return_button.clicked.connect (view_return); homepage.package_selected.connect (package_selected); - homepage.subview_entered.connect (view_opened); installed_view.package_selected.connect (package_selected); - installed_view.subview_entered.connect (view_opened); search_view.package_selected.connect (package_selected); - search_view.subview_entered.connect (view_opened); search_view.home_return_clicked.connect (() => { stack.visible_child = homepage; }); @@ -444,35 +441,35 @@ public class AppCenter.MainWindow : Hdy.ApplicationWindow { selected_package = package; } - private void view_opened (string? return_name, bool allow_search, string? custom_header = null, string? custom_search_placeholder = null) { + public void set_return_name (string? return_name) { if (return_name != null) { if (return_button_history.peek_head () != return_name) { return_button_history.offer_head (return_name); } return_button.label = return_name; - return_button.no_show_all = false; - return_button.visible = true; - } else { - return_button.no_show_all = true; - return_button.visible = false; } + return_button.no_show_all = return_name == null; + return_button.visible = return_name != null; + } + + public void configure_search (bool sensitive, string? placeholder_text = _("Search Apps")) { + search_entry.sensitive = sensitive; + search_entry.placeholder_text = placeholder_text; + + if (sensitive) { + search_entry.grab_focus_without_selecting (); + } + } + + public void set_custom_header (string? custom_header) { if (custom_header != null) { homepage_header.label = custom_header; custom_title_stack.visible_child = homepage_header; } else { custom_title_stack.visible_child = view_mode_revealer; } - - if (custom_search_placeholder != null) { - search_entry.placeholder_text = custom_search_placeholder; - } else { - search_entry.placeholder_text = _("Search Apps"); - } - - search_entry.sensitive = allow_search; - search_entry.grab_focus_without_selecting (); } private void view_return () { diff --git a/src/Views/AbstractView.vala b/src/Views/AbstractView.vala index 15dbba571..d1e2e9544 100644 --- a/src/Views/AbstractView.vala +++ b/src/Views/AbstractView.vala @@ -18,7 +18,6 @@ */ public abstract class AppCenter.AbstractView : Gtk.Stack { - public signal void subview_entered (string? return_name, bool allow_search, string? custom_header = null, string? custom_search_placeholder = null); public signal void package_selected (AppCenterCore.Package package); protected AppCenterCore.Package? previous_package = null; @@ -28,6 +27,14 @@ public abstract class AppCenter.AbstractView : Gtk.Stack { get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW); expand = true; + notify["visible-child"].connect (() => { + if (visible_child is Views.AppInfoView) { + var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window (); + main_window.set_custom_header (""); + main_window.configure_search (false); + } + }); + notify["transition-running"].connect (() => { // Transition finished if (!transition_running) { @@ -71,7 +78,9 @@ public abstract class AppCenter.AbstractView : Gtk.Stack { show_package (_package, remember_history); if (remember_history) { previous_package = package; - subview_entered (package.get_name (), false, "", null); + + var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window (); + main_window.set_return_name (package.get_name ()); } transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT; }); diff --git a/src/Views/Homepage.vala b/src/Views/Homepage.vala index 7754e2c6d..9b32f1911 100644 --- a/src/Views/Homepage.vala +++ b/src/Views/Homepage.vala @@ -28,7 +28,11 @@ public class AppCenter.Homepage : AbstractView { public signal void page_loaded (); - public bool viewing_package { get; private set; default = false; } + public bool viewing_package { + get { + return visible_child is Views.AppInfoView; + } + } public AppStream.Category? currently_viewed_category { get { @@ -189,6 +193,8 @@ public class AppCenter.Homepage : AbstractView { destroy.connect (() => { banner_timeout_stop (); }); + + notify["visible-child"].connect (update_navigation); } private async void load_banners_and_carousels () { @@ -265,36 +271,50 @@ public class AppCenter.Homepage : AbstractView { bool remember_history = true ) { base.show_package (package, remember_history); - viewing_package = true; if (remember_history) { current_category = null; - subview_entered (_("Home"), false, ""); + + var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window (); + main_window.set_return_name (_("Home")); } } public override void return_clicked () { + var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window (); + if (previous_package != null) { show_package (previous_package); if (current_category != null) { - subview_entered (current_category.name, false, ""); + main_window.set_return_name (current_category.name); } else { - subview_entered (_("Home"), false, ""); + main_window.set_return_name (_("Home")); } } else if (viewing_package && current_category != null) { visible_child = get_child_by_name (current_category.name); - viewing_package = false; - subview_entered (_("Home"), true, current_category.name, _("Search %s").printf (current_category.name)); + + main_window.set_return_name (_("Home")); } else { set_visible_child (scrolled_window); - viewing_package = false; + } + } + + private void update_navigation () { + var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window (); + + if (visible_child is CategoryView) { + current_category = ((CategoryView) visible_child).category; + main_window.set_custom_header (current_category.name); + main_window.set_return_name (_("Home")); + main_window.configure_search (true, _("Search %s").printf (current_category.name)); + } else if (visible_child == scrolled_window) { current_category = null; - subview_entered (null, true); + main_window.set_return_name (null); + main_window.set_custom_header (null); + main_window.configure_search (true); } } public void show_app_list_for_category (AppStream.Category category) { - subview_entered (_("Home"), true, category.name, _("Search %s").printf (category.name)); - current_category = category; var child = get_child_by_name (category.name); if (child != null) { visible_child = child; @@ -307,9 +327,10 @@ public class AppCenter.Homepage : AbstractView { visible_child = category_view; category_view.show_app.connect ((package) => { - viewing_package = true; base.show_package (package); - subview_entered (category.name, false, ""); + + var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window (); + main_window.set_return_name (category.name); }); } diff --git a/src/Views/InstalledView.vala b/src/Views/InstalledView.vala index 5168d3b42..93461275a 100644 --- a/src/Views/InstalledView.vala +++ b/src/Views/InstalledView.vala @@ -29,7 +29,8 @@ public class AppCenter.Views.InstalledView : AbstractView { app_list_view = new AppListUpdateView (); app_list_view.show_app.connect ((package) => { - subview_entered (C_("view", "Installed"), false, ""); + var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window (); + main_window.set_return_name (C_("view", "Installed")); show_package (package); }); @@ -52,12 +53,15 @@ public class AppCenter.Views.InstalledView : AbstractView { } public override void return_clicked () { + var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window (); if (previous_package != null) { show_package (previous_package); - subview_entered (C_("view", "Installed"), false, null); + main_window.set_return_name (C_("view", "Installed")); } else { set_visible_child (app_list_view); - subview_entered (null, false); + main_window.set_return_name (null); + main_window.set_custom_header (null); + main_window.configure_search (false); } } diff --git a/src/Views/SearchView.vala b/src/Views/SearchView.vala index 5604a4ce3..82af9a2bf 100644 --- a/src/Views/SearchView.vala +++ b/src/Views/SearchView.vala @@ -36,8 +36,9 @@ public class AppCenter.Views.SearchView : AbstractView { app_list_view = new AppListView (); add (app_list_view); app_list_view.show_app.connect ((package) => { + var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window (); /// TRANSLATORS: the name of the Search view - subview_entered (C_("view", "Search"), false); + main_window.set_return_name (C_("view", "Search")); viewing_package = true; show_package (package); }); @@ -51,11 +52,17 @@ public class AppCenter.Views.SearchView : AbstractView { set_visible_child (app_list_view); viewing_package = false; + var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window (); if (current_category != null) { - subview_entered (current_category.name, true, current_category.name); + main_window.set_custom_header (current_category.name); + main_window.set_return_name (current_category.name); } else { - subview_entered (_("Home"), true); + main_window.set_custom_header (null); + main_window.set_return_name (_("Home")); } + + main_window.configure_search (true); + } } else if (current_category != null) { category_return_clicked (current_category); @@ -82,11 +89,16 @@ public class AppCenter.Views.SearchView : AbstractView { app_list_view.add_packages (found_apps); } + var main_window = (AppCenter.MainWindow) ((Gtk.Application) GLib.Application.get_default ()).get_active_window (); if (current_category != null) { - subview_entered (current_category.name, true, current_category.name); + main_window.set_custom_header (current_category.name); + main_window.set_return_name (current_category.name); } else { - subview_entered (_("Home"), true); + main_window.set_custom_header (null); + main_window.set_return_name (_("Home")); } + + main_window.configure_search (true); } public void reset () {