Skip to content

Commit

Permalink
Use add/remove_css_class where possible (#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Feb 16, 2024
1 parent 321cc06 commit b47a914
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/Dialogs/InstallFailDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class InstallFailDialog : Granite.MessageDialog {

if (package.is_flatpak) {
var repair_button = add_button (_("Repair"), REPAIR_RESPONSE_ID);
repair_button.get_style_context ().add_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
repair_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
}

response.connect ((response) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Dialogs/UninstallConfirmDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public class UninstallConfirmDialog : Granite.MessageDialog {
}

var uninstall_button = add_button (_("Uninstall"), Gtk.ResponseType.ACCEPT);
uninstall_button.get_style_context ().add_class (Granite.STYLE_CLASS_DESTRUCTIVE_ACTION);
uninstall_button.add_css_class (Granite.STYLE_CLASS_DESTRUCTIVE_ACTION);
}
}
2 changes: 1 addition & 1 deletion src/Dialogs/UpgradeFailDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class UpgradeFailDialog : Granite.MessageDialog {

if (package.is_flatpak) {
var repair_button = add_button (_("Repair"), REPAIR_RESPONSE_ID);
repair_button.get_style_context ().add_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
repair_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
}

show_error_details (error_message);
Expand Down
5 changes: 2 additions & 3 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ public class AppCenter.MainWindow : Gtk.ApplicationWindow {

updates_badge = new Gtk.Label ("!");

unowned var badge_context = updates_badge.get_style_context ();
badge_context.add_class (Granite.STYLE_CLASS_BADGE);
badge_context.add_provider (badge_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
updates_badge.add_css_class (Granite.STYLE_CLASS_BADGE);
updates_badge.get_style_context ().add_provider (badge_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

updates_badge_revealer = new Gtk.Revealer () {
can_target = false,
Expand Down
33 changes: 13 additions & 20 deletions src/Views/AppInfoView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public class AppCenter.Views.AppInfoView : AppCenter.AbstractAppContainer {
private bool is_runtime_warning_shown = false;
private bool permissions_shown = false;

private unowned Gtk.StyleContext stack_context;

public bool to_recycle { public get; private set; default = false; }

public AppInfoView (AppCenterCore.Package package) {
Expand Down Expand Up @@ -238,22 +236,22 @@ public class AppCenter.Views.AppInfoView : AppCenter.AbstractAppContainer {
header.append (header_clamp);

unowned var header_context = header.get_style_context ();
header_context.add_class ("banner");
header.add_css_class ("banner");
header_context.add_provider (banner_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
header_context.add_provider (accent_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

unowned var action_button_context = action_button.get_style_context ();
action_button_context.add_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
action_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
action_button_context.add_provider (banner_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
action_button_context.add_provider (accent_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

unowned var open_button_context = open_button.get_style_context ();
open_button_context.add_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
open_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
open_button_context.add_provider (banner_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
open_button_context.add_provider (accent_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

unowned var cancel_button_context = cancel_button.get_style_context ();
cancel_button_context.add_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
cancel_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
cancel_button_context.add_provider (banner_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
cancel_button_context.add_provider (accent_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

Expand Down Expand Up @@ -594,11 +592,9 @@ public class AppCenter.Views.AppInfoView : AppCenter.AbstractAppContainer {
};

var screenshot_not_found = new Gtk.Label (_("Screenshot Not Available"));

unowned var screenshot_not_found_context = screenshot_not_found.get_style_context ();
screenshot_not_found_context.add_provider (accent_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
screenshot_not_found_context.add_class ("screenshot");
screenshot_not_found_context.add_class (Granite.STYLE_CLASS_DIM_LABEL);
screenshot_not_found.get_style_context ().add_provider (accent_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
screenshot_not_found.add_css_class ("screenshot");
screenshot_not_found.add_css_class (Granite.STYLE_CLASS_DIM_LABEL);

screenshot_not_found_clamp = new Adw.Clamp () {
child = screenshot_not_found,
Expand All @@ -612,9 +608,8 @@ public class AppCenter.Views.AppInfoView : AppCenter.AbstractAppContainer {
screenshot_stack.add_child (screenshot_overlay);
screenshot_stack.add_child (screenshot_not_found_clamp);

stack_context = screenshot_stack.get_style_context ();
stack_context.add_class ("loading");
stack_context.add_provider (loading_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
screenshot_stack.add_css_class ("loading");
screenshot_stack.get_style_context ().add_provider (loading_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}

app_description = new Gtk.Label (null) {
Expand Down Expand Up @@ -1123,15 +1118,15 @@ public class AppCenter.Views.AppInfoView : AppCenter.AbstractAppContainer {
Idle.add (() => {
if (screenshot_carousel.n_pages > 0) {
screenshot_stack.visible_child = screenshot_overlay;
stack_context.remove_class ("loading");
screenshot_stack.remove_css_class ("loading");

if (screenshot_carousel.n_pages > 1) {
screenshot_next.visible = true;
screenshot_previous.visible = true;
}
} else {
screenshot_stack.visible_child = screenshot_not_found_clamp;
stack_context.remove_class ("loading");
screenshot_stack.remove_css_class ("loading");
}

return GLib.Source.REMOVE;
Expand All @@ -1151,10 +1146,8 @@ public class AppCenter.Views.AppInfoView : AppCenter.AbstractAppContainer {
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) {
halign = Gtk.Align.CENTER
};

unowned var box_context = box.get_style_context ();
box_context.add_class ("screenshot");
box_context.add_provider (accent_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
box.add_css_class ("screenshot");
box.get_style_context ().add_provider (accent_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

if (caption != null) {
var label = new Gtk.Label (caption) {
Expand Down
2 changes: 1 addition & 1 deletion src/Views/CategoryView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public class AppCenter.CategoryView : Gtk.Box {
var header = new Granite.HeaderLabel (label) {
margin_start = 12
};
header.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);
header.add_css_class (Granite.STYLE_CLASS_H2_LABEL);
append (header);
}
append (flowbox);
Expand Down
8 changes: 3 additions & 5 deletions src/Views/Homepage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,9 @@ public class AppCenter.Homepage : Gtk.Box {
var fun_label = new Gtk.Label (_("Fun &")) {
halign = Gtk.Align.START
};

unowned var fun_label_context = fun_label.get_style_context ();
fun_label_context.add_class (Granite.STYLE_CLASS_ACCENT);
fun_label_context.add_class ("pink");
fun_label_context.add_provider (category_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
fun_label.add_css_class (Granite.STYLE_CLASS_ACCENT);
fun_label.add_css_class ("pink");
fun_label.get_style_context ().add_provider (category_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

var games_label = new Gtk.Label (_("Games"));
games_label.add_css_class (Granite.STYLE_CLASS_ACCENT);
Expand Down
7 changes: 3 additions & 4 deletions src/Widgets/AppContainers/AbstractAppContainer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ public abstract class AppCenter.AbstractAppContainer : Gtk.Box {
}

construct {
unowned var style_context = get_style_context ();
style_context.add_class ("progress-button");
style_context.add_provider (style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
add_css_class ("progress-button");
get_style_context ().add_provider (style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

var provider = new Gtk.CssProvider ();

Expand All @@ -127,7 +126,7 @@ public abstract class AppCenter.AbstractAppContainer : Gtk.Box {

try {
provider.load_from_data (css.data);
style_context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
get_style_context ().add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (Error e) {
critical (e.message);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Widgets/AppContainers/InstalledPackageRowGrid.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public class AppCenter.Widgets.InstalledPackageRowGrid : AbstractPackageRowGrid
valign = Gtk.Align.END,
xalign = 0
};
package_name.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
package_name.add_css_class (Granite.STYLE_CLASS_H3_LABEL);

app_version = new Gtk.Label (null) {
ellipsize = Pango.EllipsizeMode.END,
valign = Gtk.Align.START,
xalign = 0
};
app_version.get_style_context ().add_class (Granite.STYLE_CLASS_DIM_LABEL);
app_version.add_css_class (Granite.STYLE_CLASS_DIM_LABEL);

var release_button = new Gtk.Button.from_icon_name ("dialog-information-symbolic") {
valign = Gtk.Align.CENTER
Expand Down Expand Up @@ -137,7 +137,7 @@ public class AppCenter.Widgets.InstalledPackageRowGrid : AbstractPackageRowGrid
width_chars = 20,
wrap = true
};
releases_title.get_style_context ().add_class ("primary");
releases_title.add_css_class ("primary");

var release_row = new AppCenter.Widgets.ReleaseRow (package.get_newest_release ());

Expand Down
4 changes: 2 additions & 2 deletions src/Widgets/AppContainers/ListPackageRowGrid.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AppCenter.Widgets.ListPackageRowGrid : AbstractPackageRowGrid {
wrap = true,
xalign = 0
};
package_name.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
package_name.add_css_class (Granite.STYLE_CLASS_H3_LABEL);

package_summary = new Gtk.Label (null) {
ellipsize = Pango.EllipsizeMode.END,
Expand All @@ -46,7 +46,7 @@ public class AppCenter.Widgets.ListPackageRowGrid : AbstractPackageRowGrid {
wrap = true,
xalign = 0
};
package_summary.get_style_context ().add_class (Granite.STYLE_CLASS_DIM_LABEL);
package_summary.add_css_class (Granite.STYLE_CLASS_DIM_LABEL);

var grid = new Gtk.Grid () {
column_spacing = 12,
Expand Down
15 changes: 7 additions & 8 deletions src/Widgets/Banner.vala
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public class AppCenter.Widgets.Banner : Gtk.Button {
wrap = true,
xalign = 0
};
name_label.get_style_context ().add_class (Granite.STYLE_CLASS_H1_LABEL);
name_label.add_css_class (Granite.STYLE_CLASS_H1_LABEL);

var summary_label = new Gtk.Label (package.get_summary ()) {
max_width_chars = 50,
use_markup = true,
wrap = true,
xalign = 0
};
summary_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
summary_label.add_css_class (Granite.STYLE_CLASS_H3_LABEL);

string description = "";
if (package.get_description () != null) {
Expand Down Expand Up @@ -91,11 +91,10 @@ public class AppCenter.Widgets.Banner : Gtk.Button {
package_grid.attach (summary_label, 1, 1);
package_grid.attach (description_label, 1, 2);

unowned var style_context = get_style_context ();
style_context.add_class ("banner");
style_context.add_class (Granite.STYLE_CLASS_CARD);
style_context.add_class (Granite.STYLE_CLASS_ROUNDED);
style_context.add_provider (style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
add_css_class ("banner");
add_css_class (Granite.STYLE_CLASS_CARD);
add_css_class (Granite.STYLE_CLASS_ROUNDED);
get_style_context ().add_provider (style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

hexpand = true;
child = package_grid;
Expand All @@ -119,7 +118,7 @@ public class AppCenter.Widgets.Banner : Gtk.Button {

var colored_css = BANNER_STYLE_CSS.printf (bg_color, text_color);
provider.load_from_data (colored_css.data);
style_context.add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
get_style_context ().add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (GLib.Error e) {
critical ("Unable to set accent color: %s", e.message);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Widgets/ReleaseRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ public class AppCenter.Widgets.ReleaseRow : Gtk.Box {
var header_label = new Gtk.Label (format_version (release.get_version ())) {
use_markup = true
};
header_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
header_label.add_css_class (Granite.STYLE_CLASS_H3_LABEL);

var date_label = new Gtk.Label (format_date (release.get_timestamp ())) {
halign = Gtk.Align.START,
hexpand = true
};
date_label.get_style_context ().add_class (Granite.STYLE_CLASS_DIM_LABEL);
date_label.add_css_class (Granite.STYLE_CLASS_DIM_LABEL);

var description_label = new Gtk.Label (format_release_description (release.get_description ())) {
selectable = true,
use_markup = true,
wrap = true,
xalign = 0
};
description_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
description_label.add_css_class (Granite.STYLE_CLASS_H3_LABEL);

var grid = new Gtk.Grid () {
column_spacing = 6,
Expand All @@ -71,7 +71,7 @@ public class AppCenter.Widgets.ReleaseRow : Gtk.Box {
var issue_header = new Gtk.Label (_("Fixed Issues")) {
halign = Gtk.Align.START
};
issue_header.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL);
issue_header.add_css_class (Granite.STYLE_CLASS_H3_LABEL);

append (issue_header);
}
Expand Down

0 comments on commit b47a914

Please sign in to comment.