Skip to content

Commit

Permalink
Merge pull request #554 from mjakeman/oscfdezdz/search-row-expression…
Browse files Browse the repository at this point in the history
…-lookup

search-row: Use GtkExpression lookups in Blueprint
  • Loading branch information
mjakeman authored Feb 5, 2024
2 parents 4090388 + e59dcfc commit 7e2e0f1
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 101 deletions.
156 changes: 87 additions & 69 deletions src/exm-search-row.blp
Original file line number Diff line number Diff line change
@@ -1,73 +1,91 @@
using Gtk 4.0;
using Adw 1;

template $ExmSearchRow : Gtk.ListBoxRow {
styles ["search-row"]

activatable: true;

Gtk.Box header {
styles ["header"]
hexpand: true;
spacing: 10;

Gtk.Grid {
hexpand: true;
column-spacing: 10;

Gtk.Box {
hexpand: true;
orientation: vertical;
valign: center;

Gtk.Label title {
styles ["title"]
ellipsize: end;
xalign: 0;
}

Gtk.Label subtitle {
styles ["subtitle"]
ellipsize: end;
xalign: 0;
}

layout {
row: 0;
column: 1;
}
}

Gtk.Label description_label {
styles ["dim-label"]

margin-top: 5;
single-line-mode: true;
xalign: 0;
wrap: true;
wrap-mode: word_char;
ellipsize: end;
lines: 2;

layout {
row: 1;
column: 1;
}
}
}

$ExmInstallButton install_btn {
valign: center;
halign: end;
}

Gtk.Image {
styles ["expander-row-arrow"]

valign: center;
halign: end;

icon-name: "go-next-symbolic";
}
}
template $ExmSearchRow: Gtk.ListBoxRow {
styles [
"search-row"
]

activatable: true;
action-name: "win.show-detail";

Gtk.Box header {
styles [
"header"
]

hexpand: true;
spacing: 10;

Gtk.Grid {
hexpand: true;
column-spacing: 10;

Gtk.Box {
hexpand: true;
orientation: vertical;
valign: center;

Gtk.Label title {
styles [
"title"
]

ellipsize: end;
xalign: 0;
label: bind template.search-result as <$ExmSearchResult>.name;
}

Gtk.Label subtitle {
styles [
"subtitle"
]

ellipsize: end;
xalign: 0;
label: bind template.search-result as <$ExmSearchResult>.creator;
}

layout {
row: 0;
column: 1;
}
}

Gtk.Label description_label {
styles [
"dim-label"
]

margin-top: 5;
single-line-mode: true;
xalign: 0;
wrap: true;
wrap-mode: word_char;
ellipsize: end;
lines: 2;
label: bind template.search-result as <$ExmSearchResult>.description;

layout {
row: 1;
column: 1;
}
}
}

$ExmInstallButton install_btn {
valign: center;
halign: end;
}

Gtk.Image {
styles [
"expander-row-arrow"
]

valign: center;
halign: end;
icon-name: "go-next-symbolic";
}
}
}
33 changes: 1 addition & 32 deletions src/exm-search-row.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ struct _ExmSearchRow
gboolean is_supported;
gchar *uuid;

GtkLabel *description_label;
ExmInstallButton *install_btn;
GtkLabel *title;
GtkLabel *subtitle;
};

G_DEFINE_FINAL_TYPE (ExmSearchRow, exm_search_row, GTK_TYPE_LIST_BOX_ROW)
Expand Down Expand Up @@ -127,42 +124,17 @@ install_remote (GtkButton *button,
static void
exm_search_row_constructed (GObject *object)
{
// TODO: This big block of property assignments is currently copy/pasted
// from ExmExtension. We can replace this with GtkExpression lookups
// once blueprint-compiler supports expressions.
// (See https://gitlab.gnome.org/jwestman/blueprint-compiler/-/issues/5)

ExmSearchRow *self = EXM_SEARCH_ROW (object);

ExmInstallButtonState install_state;

gchar *uri;
int pk;

gchar *uuid, *name, *creator, *icon_uri, *screenshot_uri, *link, *description;
gchar *uuid;
g_object_get (self->search_result,
"uuid", &uuid,
"name", &name,
"creator", &creator,
"icon", &icon_uri,
"screenshot", &screenshot_uri,
"link", &link,
"description", &description,
"pk", &pk,
NULL);

uri = g_uri_resolve_relative ("https://extensions.gnome.org/",
link,
G_URI_FLAGS_NONE,
NULL);

gtk_actionable_set_action_name (GTK_ACTIONABLE (self), "win.show-detail");
gtk_actionable_set_action_target (GTK_ACTIONABLE (self), "s", uuid);

gtk_label_set_label (self->title, name);
gtk_label_set_label (self->subtitle, creator);
gtk_label_set_label (self->description_label, description);

install_state = self->is_installed
? EXM_INSTALL_BUTTON_STATE_INSTALLED
: (self->is_supported
Expand Down Expand Up @@ -212,10 +184,7 @@ exm_search_row_class_init (ExmSearchRowClass *klass)

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-search-row.ui");

gtk_widget_class_bind_template_child (widget_class, ExmSearchRow, description_label);
gtk_widget_class_bind_template_child (widget_class, ExmSearchRow, install_btn);
gtk_widget_class_bind_template_child (widget_class, ExmSearchRow, title);
gtk_widget_class_bind_template_child (widget_class, ExmSearchRow, subtitle);
}

static void
Expand Down

0 comments on commit 7e2e0f1

Please sign in to comment.