1
+ using NickvisionMoney . GNOME . Helpers ;
1
2
using NickvisionMoney . Shared . Helpers ;
2
3
using System . Runtime . InteropServices ;
3
4
using System . Threading . Tasks ;
@@ -16,76 +17,54 @@ public enum PasswordDialogResponse
16
17
/// <summary>
17
18
/// A dialog for receiving a password
18
19
/// </summary>
19
- public partial class PasswordDialog
20
+ public partial class PasswordDialog : Adw . MessageDialog
20
21
{
21
22
[ LibraryImport ( "libadwaita-1.so.0" , StringMarshalling = StringMarshalling . Utf8 ) ]
22
23
private static partial nint g_main_context_default ( ) ;
23
24
24
25
[ LibraryImport ( "libadwaita-1.so.0" , StringMarshalling = StringMarshalling . Utf8 ) ]
25
26
private static partial void g_main_context_iteration ( nint context , [ MarshalAs ( UnmanagedType . I1 ) ] bool blocking ) ;
26
27
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 ;
30
29
private PasswordDialogResponse _response ;
31
30
32
31
/// <summary>
33
32
/// The password of the dialog
34
33
/// </summary>
35
34
public string Password => _passwordEntry . GetText ( ) ;
36
35
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
+
37
51
/// <summary>
38
52
/// Constructs a MessageDialog
39
53
/// </summary>
40
54
/// <param name="parentWindow">Gtk.Window</param>
41
55
/// <param name="accountTitle">The title of the account requiring the password</param>
42
56
/// <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 )
44
58
{
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
- }
80
59
}
81
60
82
61
/// <summary>
83
62
/// Runs the dialog
84
63
/// </summary>
85
64
public async Task < string ? > RunAsync ( )
86
65
{
87
- _dialog . Show ( ) ;
88
- while ( _dialog . GetVisible ( ) )
66
+ Show ( ) ;
67
+ while ( GetVisible ( ) )
89
68
{
90
69
g_main_context_iteration ( g_main_context_default ( ) , false ) ;
91
70
await Task . Delay ( 50 ) ;
@@ -95,7 +74,7 @@ public PasswordDialog(Gtk.Window parentWindow, string accountTitle, Localizer lo
95
74
{
96
75
password = _passwordEntry . GetText ( ) ;
97
76
}
98
- _dialog . Destroy ( ) ;
77
+ Destroy ( ) ;
99
78
return password ;
100
79
}
101
80
0 commit comments