Fix some form entries not updating properly

This commit is contained in:
Marvin W 2023-02-07 20:08:18 +01:00
parent 1559a7a603
commit 32ae87a3c4
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
5 changed files with 16 additions and 30 deletions

View file

@ -13,7 +13,7 @@ public class Account : Object {
public Jid full_jid { get; private set; }
public string? password { get; set; }
public string display_name {
owned get { return alias ?? bare_jid.to_string(); }
owned get { return (alias != null && alias.length > 0) ? alias.dup() : bare_jid.to_string(); }
}
public string? alias { get; set; }
public bool enabled { get; set; default = false; }

View file

@ -110,13 +110,8 @@ protected class ConferenceDetailsFragment : Box {
// nick_entry.key_release_event.connect(on_nick_key_release_event);
// password_entry.key_release_event.connect(on_password_key_release_event);
var jid_entry_controller = new EventControllerKey();
jid_entry_controller.key_released.connect(() => { check_if_done(); });
jid_entry.add_controller(jid_entry_controller);
var nick_entry_controller = new EventControllerKey();
nick_entry_controller.key_released.connect(() => { check_if_done(); });
nick_entry.add_controller(nick_entry_controller);
jid_entry.changed.connect(() => { check_if_done(); });
nick_entry.changed.connect(() => { check_if_done(); });
check_if_done();

View file

@ -42,8 +42,8 @@ public class Dialog : Gtk.Dialog {
if (selected_account != null) remove_account(account_row);
});
image_button.clicked.connect(show_select_avatar);
// alias_hybrid.entry.key_release_event.connect(() => { selected_account.alias = alias_hybrid.text; return false; });
// password_hybrid.entry.key_release_event.connect(() => { selected_account.password = password_hybrid.text; return false; });
alias_hybrid.entry.changed.connect(() => { selected_account.alias = alias_hybrid.text; });
password_hybrid.entry.changed.connect(() => { selected_account.password = password_hybrid.text; });
Util.LabelHybridGroup label_hybrid_group = new Util.LabelHybridGroup();
label_hybrid_group.add(alias_hybrid);

View file

@ -35,21 +35,13 @@ public static Widget? get_data_form_field_widget(DataForms.DataForm.Field field)
return null;
case DataForms.DataForm.Type.TEXT_PRIVATE:
DataForms.DataForm.TextPrivateField text_private_field = field as DataForms.DataForm.TextPrivateField;
Entry entry = new Entry() { text=text_private_field.value ?? "", valign=Align.CENTER, visibility=false };
var entry_key_events = new EventControllerKey();
entry_key_events.key_released.connect(() => {
text_private_field.value = entry.text;
});
entry.add_controller(entry_key_events);
PasswordEntry entry = new PasswordEntry() { text=text_private_field.value ?? "", valign=Align.CENTER };
entry.changed.connect(() => { text_private_field.value = entry.text; });
return entry;
case DataForms.DataForm.Type.TEXT_SINGLE:
DataForms.DataForm.TextSingleField text_single_field = field as DataForms.DataForm.TextSingleField;
Entry entry = new Entry() { text=text_single_field.value ?? "", valign=Align.CENTER };
var entry_key_events = new EventControllerKey();
entry_key_events.key_released.connect(() => {
text_single_field.value = entry.text;
});
entry.add_controller(entry_key_events);
entry.changed.connect(() => { text_single_field.value = entry.text; });
return entry;
default:
return null;

View file

@ -40,8 +40,8 @@ public class EntryLabelHybrid : LabelHybrid {
public string text {
get { return entry.text; }
set {
entry.text = value;
set_label_label(value);
entry.text = value.dup();
update_label();
}
}
@ -79,22 +79,21 @@ public class EntryLabelHybrid : LabelHybrid {
if (e == null) return;
entry = e;
base.init(entry);
set_label_label(entry.text);
update_label();
var key_events = new EventControllerKey();
key_events.key_released.connect(on_key_released);
entry.add_controller(key_events);
entry.changed.connect(update_label);
var focus_events = new EventControllerFocus();
focus_events.leave.connect(on_focus_leave);
focus_events.leave.connect(update_label);
entry.add_controller(focus_events);
}
private void on_key_released(uint keyval) {
if (keyval == Gdk.Key.Return) {
show_label();
} else {
set_label_label(entry.text);
}
}
@ -102,12 +101,12 @@ public class EntryLabelHybrid : LabelHybrid {
show_label();
}
private void set_label_label(string value) {
private void update_label() {
if (visibility) {
label.label = value;
label.label = entry.text;
} else {
string filler = "";
for (int i = 0; i < value.length; i++) filler += entry.get_invisible_char().to_string();
for (int i = 0; i < entry.text.length; i++) filler += entry.get_invisible_char().to_string();
label.label = filler;
}
}