Skip to content

Commit fa327fa

Browse files
committed
Replace Gtk.Entry + peek button with Gtk.PasswordEntry
1 parent 03057d1 commit fa327fa

File tree

1 file changed

+8
-32
lines changed

1 file changed

+8
-32
lines changed

src/MainView.vala

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ public class Obliviate.MainView : Gtk.Overlay {
2323
private Granite.Toast toast;
2424

2525
private Gtk.Entry site;
26-
private Gtk.Entry cipher_key;
27-
private Gtk.Entry generated_pass;
28-
private Gtk.ToggleButton show_generated_pass;
26+
private Gtk.PasswordEntry cipher_key;
27+
private Gtk.PasswordEntry generated_pass;
2928
private Gtk.Button copy_btn;
3029
private Gtk.Button copy_without_symbols_btn;
3130
private Gtk.Label clearing_label;
@@ -68,42 +67,23 @@ public class Obliviate.MainView : Gtk.Overlay {
6867
margin_end = 4
6968
};
7069

71-
// TODO: replace with Gtk.PasswordEntry after updating to Gtk4
72-
cipher_key = new Gtk.Entry () {
73-
visibility = false,
74-
caps_lock_warning = true,
75-
input_purpose = Gtk.InputPurpose.PASSWORD,
70+
cipher_key = new Gtk.PasswordEntry () {
71+
show_peek_icon = true,
7672
placeholder_text = _ ("correct horse battery staple"),
7773
width_chars = 24
7874
};
7975

8076
cipher_key.changed.connect (handle_generate_password);
8177

82-
var show_cipher_key = new Gtk.ToggleButton () {
83-
active = true,
84-
tooltip_text = _ ("Show or hide the cipher key")
85-
};
86-
87-
show_cipher_key.add (new Gtk.Image.from_icon_name ("image-red-eye-symbolic", Gtk.IconSize.BUTTON));
88-
show_cipher_key.bind_property ("active", cipher_key, "visibility", BindingFlags.INVERT_BOOLEAN);
89-
90-
this.generated_pass = new Gtk.Entry () {
91-
visibility = false,
78+
this.generated_pass = new Gtk.PasswordEntry () {
79+
show_peek_icon = true,
9280
editable = false,
93-
sensitive = false
81+
sensitive = false,
82+
width_chars = 24
9483
};
9584

9685
this.generated_pass.add_css_class (Granite.STYLE_CLASS_FLAT);
9786

98-
show_generated_pass = new Gtk.ToggleButton () {
99-
active = true,
100-
tooltip_text = _ ("Show or hide the password"),
101-
sensitive = false
102-
};
103-
104-
show_generated_pass.set_icon_name ("image-red-eye-symbolic");
105-
show_generated_pass.bind_property ("active", generated_pass, "visibility", BindingFlags.INVERT_BOOLEAN);
106-
10787
copy_btn = new Gtk.Button.with_label (_ ("Copy")) {
10888
sensitive = false
10989
};
@@ -156,12 +136,10 @@ public class Obliviate.MainView : Gtk.Overlay {
156136

157137
grid.attach (cipher_key_label, 0, 2, 1, 1);
158138
grid.attach_next_to (cipher_key, cipher_key_label, Gtk.PositionType.RIGHT);
159-
grid.attach_next_to (show_cipher_key, cipher_key, Gtk.PositionType.RIGHT);
160139

161140
grid.attach_next_to (equals_label, cipher_key, Gtk.PositionType.BOTTOM);
162141

163142
grid.attach_next_to (generated_pass, equals_label, Gtk.PositionType.BOTTOM);
164-
grid.attach_next_to (show_generated_pass, generated_pass, Gtk.PositionType.RIGHT);
165143
grid.attach_next_to (button_box, generated_pass, Gtk.PositionType.BOTTOM);
166144

167145
clipboard = this.get_clipboard ();
@@ -170,15 +148,13 @@ public class Obliviate.MainView : Gtk.Overlay {
170148
private void handle_generate_password () {
171149
if (site.text.length == 0 || cipher_key.text.length == 0) {
172150
generated_pass.text = "";
173-
show_generated_pass.sensitive = false;
174151
copy_btn.sensitive = false;
175152
copy_without_symbols_btn.sensitive = false;
176153
return;
177154
}
178155

179156
try {
180157
generated_pass.text = Service.derive_password (cipher_key.text, site.text.down ());
181-
show_generated_pass.sensitive = true;
182158
copy_btn.sensitive = true;
183159
copy_without_symbols_btn.sensitive = true;
184160
animate_password ();

0 commit comments

Comments
 (0)