Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 39 additions & 182 deletions Pinta.Gui.Addins/AddinInfoView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,46 @@

namespace Pinta.Gui.Addins;

[GObject.Subclass<Adw.Bin>]
[GObject.Subclass<Adw.Bin> (qualifiedName: nameof (AddinInfoView))]
[Gtk.Template<Gtk.AssemblyResource> ("AddinInfoView.ui")]
internal sealed partial class AddinInfoView
{
[Gtk.Connect (nameof (title_label))]
private Gtk.Label title_label;
private Gtk.Label version_label;
private Gtk.Label size_label;
private Gtk.Label repo_label;
[Gtk.Connect (nameof (category_row))]
private Adw.ActionRow category_row;
[Gtk.Connect (nameof (version_row))]
private Adw.ActionRow version_row;
[Gtk.Connect (nameof (author_row))]
private Adw.ActionRow author_row;
[Gtk.Connect (nameof (size_row))]
private Adw.ActionRow size_row;
[Gtk.Connect (nameof (repo_row))]
private Adw.ActionRow repo_row;
[Gtk.Connect (nameof (description_label))]
private Gtk.Label description_label;

[Gtk.Connect (nameof (info_button))]
private Gtk.Button info_button;
[Gtk.Connect (nameof (install_button))]
private Gtk.Button install_button;
[Gtk.Connect (nameof (update_button))]
private Gtk.Button update_button;
[Gtk.Connect (nameof (uninstall_button))]
private Gtk.Button uninstall_button;

[Gtk.Connect (nameof (enable_switch))]
private Gtk.Switch enable_switch;

[Gtk.Connect (nameof (content_box))]
private Gtk.Box content_box;

[Gtk.Connect (nameof (empty_page))]
private Adw.Bin empty_page;

[Gtk.Connect (nameof (view_stack))]
private Adw.ViewStack view_stack;

private AddinListViewItem? current_item;

/// <summary>
Expand All @@ -36,184 +55,26 @@ internal sealed partial class AddinInfoView
private SystemManager system = null!; // NRT - set by factory method.
private IChromeService chrome = null!;

[MemberNotNull (nameof (title_label))]
[MemberNotNull (nameof (version_label))]
[MemberNotNull (nameof (size_label))]
[MemberNotNull (nameof (repo_label))]
[MemberNotNull (nameof (description_label))]
[MemberNotNull (nameof (info_button))]
[MemberNotNull (nameof (install_button))]
[MemberNotNull (nameof (update_button))]
[MemberNotNull (nameof (uninstall_button))]
[MemberNotNull (nameof (enable_switch))]
[MemberNotNull (nameof (content_box))]
[MemberNotNull (nameof (empty_page))]
[MemberNotNull (nameof (view_stack))]
partial void Initialize ()
{
// --- Control creation

Gtk.Label titleLabel = Gtk.Label.New (null);
titleLabel.Halign = Gtk.Align.Start;
titleLabel.AddCssClass (AdwaitaStyles.Title4);

Gtk.Label versionLabel = Gtk.Label.New (null);
versionLabel.Halign = Gtk.Align.Start;
versionLabel.AddCssClass (AdwaitaStyles.Heading);

Gtk.Label sizeLabel = Gtk.Label.New (null);
sizeLabel.Halign = Gtk.Align.Start;
sizeLabel.AddCssClass (AdwaitaStyles.Heading);

Gtk.Label repoLabel = Gtk.Label.New (null);
repoLabel.Halign = Gtk.Align.Start;
repoLabel.AddCssClass (AdwaitaStyles.Heading);

Gtk.Label descriptionLabel = CreateDescriptionLabel ();

Adw.Bin emptyPage = Adw.Bin.New ();

Gtk.Button infoButton = CreateInfoButton ();
Gtk.Button installButton = CreateInstallButton ();
Gtk.Button updateButton = CreateUpdateButton ();
Gtk.Button uninstallButton = CreateUninstallButton ();

Gtk.Switch enableSwitch = CreateEnableSwitch ();

BoxStyle spacedHorizontal = new (
orientation: Gtk.Orientation.Horizontal,
spacing: 6,
cssClass: AdwaitaStyles.Toolbar);
Gtk.Box hbox = GtkExtensions.Box (
spacedHorizontal,
[
enableSwitch,
installButton,
updateButton,
infoButton,
uninstallButton
]
);

BoxStyle spacedVertical = new (
orientation: Gtk.Orientation.Vertical,
spacing: 10);
Gtk.Box contentBox = GtkExtensions.Box (
spacedVertical,
[
titleLabel,
versionLabel,
sizeLabel,
repoLabel,
descriptionLabel,
hbox
]
);
contentBox.SetAllMargins (10);

Adw.ViewStack viewStack = Adw.ViewStack.New ();
viewStack.Add (emptyPage);
viewStack.Add (contentBox);
viewStack.SetVisibleChild (emptyPage);

// --- Gtk.Widget initialization

WidthRequest = 300;

// --- Adwaita.Bin initialization

Child = viewStack;

// --- References to keep

title_label = titleLabel;
version_label = versionLabel;
size_label = sizeLabel;
repo_label = repoLabel;
description_label = descriptionLabel;

info_button = infoButton;
install_button = installButton;
update_button = updateButton;
uninstall_button = uninstallButton;

enable_switch = enableSwitch;

content_box = contentBox;

empty_page = emptyPage;

view_stack = viewStack;
}

internal void Configure (SystemManager system, IChromeService chrome)
{
this.system = system;
this.chrome = chrome;
}

public static new AddinInfoView New () => NewWithProperties ([]);
info_button.OnClicked += (_, _) => HandleInfoButtonClicked ();
install_button.OnClicked += (_, _) => HandleInstallButtonClicked ();
update_button.OnClicked += (_, _) => HandleUpdateButtonClicked ();
uninstall_button.OnClicked += (_, _) => HandleUninstallButtonClicked ();

private Gtk.Switch CreateEnableSwitch ()
{
Gtk.Switch result = Gtk.Switch.New ();
result.Visible = false;
result.OnStateSet += (_, _) => {
enable_switch.OnStateSet += (_, _) => {
HandleEnableSwitched ();
return false;
};
return result;
}

private static Gtk.Label CreateDescriptionLabel ()
{
Gtk.Label result = Gtk.Label.New (null);
result.Halign = Gtk.Align.Start;
result.Hexpand = true;
result.Valign = Gtk.Align.Start;
result.Vexpand = true;
result.Xalign = 0;
result.Wrap = true;
result.AddCssClass (AdwaitaStyles.Body);
return result;
}

private Gtk.Button CreateInfoButton ()
{
Gtk.Button result = Gtk.Button.NewWithLabel (Translations.GetString ("More Information..."));
result.OnClicked += (_, _) => HandleInfoButtonClicked ();
result.Visible = false;
return result;
}

private Gtk.Button CreateInstallButton ()
{
Gtk.Button result = Gtk.Button.NewWithLabel (Translations.GetString ("Install..."));
result.AddCssClass (AdwaitaStyles.SuggestedAction);
result.OnClicked += (_, _) => HandleInstallButtonClicked ();
result.Visible = false;
return result;
}

private Gtk.Button CreateUpdateButton ()
internal void Configure (SystemManager system, IChromeService chrome)
{
Gtk.Button result = Gtk.Button.NewWithLabel (Translations.GetString ("Update..."));
result.AddCssClass (AdwaitaStyles.SuggestedAction);
result.OnClicked += (_, _) => HandleUpdateButtonClicked ();
result.Visible = false;
return result;
this.system = system;
this.chrome = chrome;
}

private Gtk.Button CreateUninstallButton ()
{
Gtk.Button result = Gtk.Button.NewWithLabel (Translations.GetString ("Uninstall..."));
result.AddCssClass (AdwaitaStyles.DestructiveAction);
result.OnClicked += (_, _) => HandleUninstallButtonClicked ();
result.Visible = false;
result.Hexpand = true;
result.Halign = Gtk.Align.End;
return result;
}
public static new AddinInfoView New () => NewWithProperties ([]);

public void Update (AddinListViewItem? item)
{
Expand All @@ -235,20 +96,16 @@ private void ViewExistingItem (AddinListViewItem item)
view_stack.SetVisibleChild (content_box);

title_label.SetLabel (item.Name);
version_label.SetLabel (Translations.GetString ("Version: {0}", item.Version));
category_row.Subtitle = item.Category;
version_row.Subtitle = item.Version;
author_row.Subtitle = item.Author;
description_label.SetLabel (item.Description);

string? download_size = item.DownloadSize;
size_label.Visible = download_size != null;

if (download_size is not null)
size_label.SetLabel (Translations.GetString ("Download size: {0}", download_size));

string? repo_name = item.RepositoryName;
repo_label.Visible = repo_name != null;
size_row.Visible = item.DownloadSize != null;
size_row.Subtitle = item.DownloadSize ?? string.Empty;

if (repo_name is not null)
repo_label.SetLabel (Translations.GetString ("Available in repository: {0}", repo_name));
repo_row.Visible = item.RepositoryName != null;
repo_row.Subtitle = item.RepositoryName ?? string.Empty;

info_button.Visible = !string.IsNullOrEmpty (item.Url);
install_button.Visible = !item.Installed;
Expand Down
Loading
Loading