Skip to content

Commit 8d8d432

Browse files
committed
GNOME - Port password dialog to Blueprint
1 parent 9855fec commit 8d8d432

File tree

2 files changed

+41
-43
lines changed

2 files changed

+41
-43
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Gtk 4.0;
2+
using Adw 1;
3+
4+
Adw.MessageDialog _root {
5+
default-width: 500;
6+
hide-on-close: true;
7+
8+
Adw.StatusPage {
9+
title: _("EnterPassword");
10+
icon-name: "dialog-password-symbolic";
11+
12+
Adw.PasswordEntryRow _passwordEntry {
13+
title: _("Password.Field");
14+
activates-default: true;
15+
16+
styles ["card"]
17+
}
18+
}
19+
}

NickvisionMoney.GNOME/Controls/PasswordDialog.cs

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using NickvisionMoney.GNOME.Helpers;
12
using NickvisionMoney.Shared.Helpers;
23
using System.Runtime.InteropServices;
34
using System.Threading.Tasks;
@@ -16,76 +17,54 @@ public enum PasswordDialogResponse
1617
/// <summary>
1718
/// A dialog for receiving a password
1819
/// </summary>
19-
public partial class PasswordDialog
20+
public partial class PasswordDialog : Adw.MessageDialog
2021
{
2122
[LibraryImport("libadwaita-1.so.0", StringMarshalling = StringMarshalling.Utf8)]
2223
private static partial nint g_main_context_default();
2324

2425
[LibraryImport("libadwaita-1.so.0", StringMarshalling = StringMarshalling.Utf8)]
2526
private static partial void g_main_context_iteration(nint context, [MarshalAs(UnmanagedType.I1)] bool blocking);
2627

27-
private readonly Adw.MessageDialog _dialog;
28-
private readonly Adw.StatusPage _statusPassword;
29-
private readonly Adw.PasswordEntryRow _passwordEntry;
28+
[Gtk.Connect] private readonly Adw.PasswordEntryRow _passwordEntry;
3029
private PasswordDialogResponse _response;
3130

3231
/// <summary>
3332
/// The password of the dialog
3433
/// </summary>
3534
public string Password => _passwordEntry.GetText();
3635

36+
private PasswordDialog(Gtk.Builder builder, Gtk.Window parent, string accountTitle, Localizer localizer) : base(builder.GetPointer("_root"), false)
37+
{
38+
builder.Connect(this);
39+
//Dialog Settings
40+
SetTransientFor(parent);
41+
_response = PasswordDialogResponse.Cancel;
42+
AddResponse("cancel", localizer["Cancel"]);
43+
AddResponse("suggested", localizer["Unlock"]);
44+
SetResponseAppearance("suggested", Adw.ResponseAppearance.Suggested);
45+
SetCloseResponse("cancel");
46+
SetDefaultResponse("suggested");
47+
OnResponse += (sender, e) => SetResponse(e.Response);
48+
}
49+
50+
3751
/// <summary>
3852
/// Constructs a MessageDialog
3953
/// </summary>
4054
/// <param name="parentWindow">Gtk.Window</param>
4155
/// <param name="accountTitle">The title of the account requiring the password</param>
4256
/// <param name="localizer">The localizer for the app</param>
43-
public PasswordDialog(Gtk.Window parentWindow, string accountTitle, Localizer localizer)
57+
public PasswordDialog(Gtk.Window parent, string accountTitle, Localizer localizer) : this(Builder.FromFile("password_dialog.ui", localizer), parent, accountTitle, localizer)
4458
{
45-
//Dialog Settings
46-
_dialog = Adw.MessageDialog.New(parentWindow, "", "");
47-
_dialog.SetDefaultSize(500, -1);
48-
_dialog.SetHideOnClose(true);
49-
_response = PasswordDialogResponse.Cancel;
50-
_dialog.AddResponse("cancel", localizer["Cancel"]);
51-
_dialog.AddResponse("suggested", localizer["Unlock"]);
52-
_dialog.SetResponseAppearance("suggested", Adw.ResponseAppearance.Suggested);
53-
_dialog.SetCloseResponse("cancel");
54-
_dialog.SetDefaultResponse("suggested");
55-
_dialog.OnResponse += (sender, e) => SetResponse(e.Response);
56-
//Password Page
57-
_statusPassword = Adw.StatusPage.New();
58-
_statusPassword.SetTitle(localizer["EnterPassword"]);
59-
_statusPassword.SetDescription(accountTitle);
60-
_statusPassword.SetIconName("dialog-password-symbolic");
61-
_dialog.SetExtraChild(_statusPassword);
62-
//Password Entry
63-
_passwordEntry = Adw.PasswordEntryRow.New();
64-
_passwordEntry.AddCssClass("card");
65-
_passwordEntry.SetActivatesDefault(true);
66-
_passwordEntry.SetTitle(localizer["Password", "Field"]);
67-
_statusPassword.SetChild(_passwordEntry);
68-
}
69-
70-
public event GObject.SignalHandler<Adw.MessageDialog, Adw.MessageDialog.ResponseSignalArgs> OnResponse
71-
{
72-
add
73-
{
74-
_dialog.OnResponse += value;
75-
}
76-
remove
77-
{
78-
_dialog.OnResponse -= value;
79-
}
8059
}
8160

8261
/// <summary>
8362
/// Runs the dialog
8463
/// </summary>
8564
public async Task<string?> RunAsync()
8665
{
87-
_dialog.Show();
88-
while (_dialog.GetVisible())
66+
Show();
67+
while (GetVisible())
8968
{
9069
g_main_context_iteration(g_main_context_default(), false);
9170
await Task.Delay(50);
@@ -95,7 +74,7 @@ public PasswordDialog(Gtk.Window parentWindow, string accountTitle, Localizer lo
9574
{
9675
password = _passwordEntry.GetText();
9776
}
98-
_dialog.Destroy();
77+
Destroy();
9978
return password;
10079
}
10180

0 commit comments

Comments
 (0)