Skip to content

Commit

Permalink
Merge pull request #754 from mjakeman/oscfdezdz/fix-browse-page-list
Browse files Browse the repository at this point in the history
browse-page: Preserve scroll position on 'Load More Results'
  • Loading branch information
oscfdezdz authored Dec 20, 2024
2 parents 62f3759 + 8c6616d commit c683d49
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 148 deletions.
6 changes: 3 additions & 3 deletions build-aux/com.mattjakeman.ExtensionManager.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
{
"type" : "git",
"url" : "https://github.com/mjakeman/extension-manager",
"commit" : "db86b87151d9564c22fce34205de999335cb7f5a",
"tag" : "v0.5.0"
"commit" : "62f3759e10cfd21014c805dc75645947569d48a9",
"tag" : "v0.6.0"
}
]
}
]
}
}
288 changes: 143 additions & 145 deletions src/exm-browse-page.blp
Original file line number Diff line number Diff line change
Expand Up @@ -4,181 +4,179 @@ using Adw 1;
template $ExmBrowsePage: Gtk.Widget {
notify::manager => $on_bind_manager();

Gtk.ScrolledWindow {
Adw.StatusPage status_page {
title: _("Search for Extensions");
description: _("Enter a keyword to search 'extensions.gnome.org' for GNOME Shell Extensions");
valign: start;
vexpand: true;

child: Adw.Clamp {
Gtk.Box {
orientation: vertical;

Gtk.Box {
styles [
"linked"
]

Gtk.SearchEntry search_entry {
hexpand: true;
search-delay: 750;
realize => $on_search_entry_realize();
search-changed => $on_search_changed() swapped;
changed => $gtk_widget_grab_focus();

accessibility {
labelled-by: status_page;
}
}
Adw.StatusPage status_page {
title: _("Search for Extensions");
description: _("Enter a keyword to search 'extensions.gnome.org' for GNOME Shell Extensions");
valign: start;
vexpand: true;

// Keep the same order as the ExmSearchSort enum
Gtk.DropDown search_dropdown {
model: StringList {
// Translators: dropdown items for sorting search results
strings [
_("Relevance"),
C_("Sort search results", "Downloads"),
_("Recent"),
_("Name")
]
};
child: Adw.Clamp {
Gtk.Box {
orientation: vertical;

notify::selected => $on_search_changed() swapped;
Gtk.Box {
styles [
"linked"
]

Gtk.SearchEntry search_entry {
hexpand: true;
search-delay: 750;
realize => $on_search_entry_realize();
search-changed => $on_search_changed() swapped;
changed => $gtk_widget_grab_focus();

accessibility {
labelled-by: status_page;
}
}

accessibility {
description: _("Sort search results");
}
// Keep the same order as the ExmSearchSort enum
Gtk.DropDown search_dropdown {
model: StringList {
// Translators: dropdown items for sorting search results
strings [
_("Relevance"),
C_("Sort search results", "Downloads"),
_("Recent"),
_("Name")
]
};

notify::selected => $on_search_changed() swapped;

accessibility {
description: _("Sort search results");
}
}
}

Gtk.Stack search_stack {
Gtk.StackPage {
name: "page_spinner";
Gtk.Stack search_stack {
Gtk.StackPage {
name: "page_spinner";

child: Adw.Spinner {
valign: center;
halign: center;
height-request: 32;
width-request: 32;
};
}
child: Adw.Spinner {
valign: center;
halign: center;
height-request: 32;
width-request: 32;
};
}

Gtk.StackPage {
name: "page_results";
Gtk.StackPage {
name: "page_results";

child: Gtk.Box {
orientation: vertical;
spacing: 12;
child: Gtk.Box {
orientation: vertical;
spacing: 12;

Gtk.ListBox search_results {
styles [
"boxed-list"
]
Gtk.ListBox search_results {
styles [
"boxed-list"
]

selection-mode: none;
}
selection-mode: none;
}

Gtk.ListBox more_results_list {
styles [
"boxed-list"
]
Gtk.ListBox more_results_list {
styles [
"boxed-list"
]

selection-mode: none;
selection-mode: none;

Adw.ButtonRow more_results_btn {
title: _("_Load More Results");
use-underline: true;
activated => $on_load_more_results();
}
Adw.ButtonRow more_results_btn {
title: _("_Load More Results");
use-underline: true;
activated => $on_load_more_results();
}
};
}
}
};
}

Gtk.StackPage {
name: "page_empty";
Gtk.StackPage {
name: "page_empty";

child: Gtk.Box {
orientation: vertical;
margin-start: 12;
margin-end: 12;
margin-top: 36;
margin-bottom: 24;
child: Gtk.Box {
orientation: vertical;
margin-start: 12;
margin-end: 12;
margin-top: 36;
margin-bottom: 24;

Gtk.Image {
styles [
"dim-label"
]
Gtk.Image {
styles [
"dim-label"
]

icon-name: "edit-find-symbolic";
halign: center;
margin-bottom: 24;
pixel-size: 128;
}
icon-name: "edit-find-symbolic";
halign: center;
margin-bottom: 24;
pixel-size: 128;
}

Gtk.Label {
styles [
"title-1"
]
Gtk.Label {
styles [
"title-1"
]

label: _("No Results Found");
margin-bottom: 12;
wrap: true;
wrap-mode: word_char;
}
label: _("No Results Found");
margin-bottom: 12;
wrap: true;
wrap-mode: word_char;
}

Gtk.Label {
label: _("Try a different search");
margin-bottom: 12;
wrap: true;
wrap-mode: word_char;
}
};
}
Gtk.Label {
label: _("Try a different search");
margin-bottom: 12;
wrap: true;
wrap-mode: word_char;
}
};
}

Gtk.StackPage {
name: "page_error";
Gtk.StackPage {
name: "page_error";

child: Gtk.Box {
orientation: vertical;
margin-start: 12;
margin-end: 12;
margin-top: 36;
margin-bottom: 24;
child: Gtk.Box {
orientation: vertical;
margin-start: 12;
margin-end: 12;
margin-top: 36;
margin-bottom: 24;

Gtk.Image {
styles [
"dim-label"
]
Gtk.Image {
styles [
"dim-label"
]

icon-name: "offline-symbolic";
halign: center;
margin-bottom: 24;
pixel-size: 128;
}
icon-name: "offline-symbolic";
halign: center;
margin-bottom: 24;
pixel-size: 128;
}

Gtk.Label {
styles [
"title-1"
]
Gtk.Label {
styles [
"title-1"
]

label: _("Connection Error");
margin-bottom: 12;
wrap: true;
wrap-mode: word_char;
}
label: _("Connection Error");
margin-bottom: 12;
wrap: true;
wrap-mode: word_char;
}

Gtk.Label error_label {
use-markup: true;
margin-bottom: 12;
wrap: true;
wrap-mode: word_char;
}
};
}
Gtk.Label error_label {
use-markup: true;
margin-bottom: 12;
wrap: true;
wrap-mode: word_char;
}
};
}
}
};
}
}
};
}
}
19 changes: 19 additions & 0 deletions src/exm-browse-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct _ExmBrowsePage
GCancellable *cancellable;

// Template Widgets
AdwStatusPage *status_page;
GtkSearchEntry *search_entry;
GtkListBox *search_results;
GtkStack *search_stack;
Expand Down Expand Up @@ -228,6 +229,19 @@ on_next_page_result (GObject *source,

if (G_IS_LIST_MODEL (to_append))
{
GtkWidget *child;
GtkAdjustment *adjustment;
double scroll_pos;

// Save scrolled window position
child = gtk_widget_get_first_child (GTK_WIDGET (self->status_page));
if (child != NULL && GTK_IS_SCROLLED_WINDOW (child))
{
adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (child));
if (adjustment != NULL)
scroll_pos = gtk_adjustment_get_value (adjustment);
}

n_items = g_list_model_get_n_items (G_LIST_MODEL (to_append));

// Append to list model
Expand All @@ -241,6 +255,10 @@ on_next_page_result (GObject *source,
gtk_widget_grab_focus (gtk_widget_get_last_child (GTK_WIDGET (self->search_results)));
}

// Restore scrolled window position
if (adjustment != NULL)
gtk_adjustment_set_value (adjustment, scroll_pos);

// Remove unnecessary model
g_list_store_remove_all (G_LIST_STORE (to_append));
g_clear_object (&to_append);
Expand Down Expand Up @@ -398,6 +416,7 @@ exm_browse_page_class_init (ExmBrowsePageClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, g_strdup_printf ("%s/exm-browse-page.ui", RESOURCE_PATH));
gtk_widget_class_bind_template_child (widget_class, ExmBrowsePage, status_page);
gtk_widget_class_bind_template_child (widget_class, ExmBrowsePage, search_entry);
gtk_widget_class_bind_template_child (widget_class, ExmBrowsePage, search_results);
gtk_widget_class_bind_template_child (widget_class, ExmBrowsePage, search_stack);
Expand Down

0 comments on commit c683d49

Please sign in to comment.