Reduce use of Widget.destroy()

On non-toplevel windows, use Container.remove() instead of Widget.destroy()
Needed for migration to GTK4
https://developer.gnome.org/gtk4/unstable/gtk-migrating-3-to-4.html#id-1.7.4.3.17
This commit is contained in:
fiaxh 2021-02-10 18:32:39 -06:00
parent ad031ee333
commit 0626bad8e9
10 changed files with 12 additions and 14 deletions

View file

@ -49,7 +49,7 @@ protected class ConferenceList : FilterableList {
private void remove_conference(Account account, Jid jid) { private void remove_conference(Account account, Jid jid) {
if (widgets.has_key(account) && widgets[account].has_key(jid)) { if (widgets.has_key(account) && widgets[account].has_key(jid)) {
widgets[account][jid].destroy(); remove(widgets[account][jid]);
widgets[account].unset(jid); widgets[account].unset(jid);
} }
} }

View file

@ -48,7 +48,7 @@ public class SelectJidFragment : Gtk.Box {
public void set_filter(string str) { public void set_filter(string str) {
if (entry.text != str) entry.text = str; if (entry.text != str) entry.text = str;
foreach (AddListRow row in added_rows) row.destroy(); foreach (AddListRow row in added_rows) filterable_list.remove(row);
added_rows.clear(); added_rows.clear();
string[] ? values = str == "" ? null : str.split(" "); string[] ? values = str == "" ? null : str.split(" ");

View file

@ -164,7 +164,7 @@ public class ItemMetaDataHeader : Box {
this.reorder_child(unencrypted_image, 3); this.reorder_child(unencrypted_image, 3);
Util.force_error_color(unencrypted_image); Util.force_error_color(unencrypted_image);
} else if (conversation.encryption == Encryption.NONE && unencrypted_image != null) { } else if (conversation.encryption == Encryption.NONE && unencrypted_image != null) {
unencrypted_image.destroy(); this.remove(unencrypted_image);
unencrypted_image = null; unencrypted_image = null;
} }
} }

View file

@ -318,9 +318,8 @@ public class ConversationView : Box, Plugins.ConversationItemCollection, Plugins
private void remove_item(Plugins.MetaConversationItem item) { private void remove_item(Plugins.MetaConversationItem item) {
ConversationItemSkeleton? skeleton = item_item_skeletons[item]; ConversationItemSkeleton? skeleton = item_item_skeletons[item];
if (skeleton != null) { if (skeleton != null) {
widgets[item].destroy(); main.remove(skeleton);
widgets.unset(item); widgets.unset(item);
skeleton.destroy();
item_skeletons.remove(skeleton); item_skeletons.remove(skeleton);
item_item_skeletons.unset(item); item_item_skeletons.unset(item);
@ -356,7 +355,7 @@ public class ConversationView : Box, Plugins.ConversationItemCollection, Plugins
public void remove_notification(Widget widget) { public void remove_notification(Widget widget) {
notification_revealer.reveal_child = false; notification_revealer.reveal_child = false;
widget.destroy(); notifications.remove(widget);
} }
private Widget insert_new(Plugins.MetaConversationItem item) { private Widget insert_new(Plugins.MetaConversationItem item) {
@ -484,11 +483,11 @@ public class ConversationView : Box, Plugins.ConversationItemCollection, Plugins
item_skeletons.clear(); item_skeletons.clear();
item_item_skeletons.clear(); item_item_skeletons.clear();
widgets.clear(); widgets.clear();
main.@foreach((widget) => { widget.destroy(); }); main.@foreach((widget) => { main.remove(widget); });
} }
private void clear_notifications() { private void clear_notifications() {
notifications.@foreach((widget) => { widget.destroy(); }); notifications.@foreach((widget) => { notifications.remove(widget); });
notification_revealer.transition_duration = 0; notification_revealer.transition_duration = 0;
notification_revealer.set_reveal_child(false); notification_revealer.set_reveal_child(false);
} }

View file

@ -47,7 +47,6 @@ class OccupantsWidget : MenuButton, Plugins.ConversationTitlebarWidget {
if (conversation.type_ == Conversation.Type.GROUPCHAT) { if (conversation.type_ == Conversation.Type.GROUPCHAT) {
OccupantMenu.View new_menu = new OccupantMenu.View(stream_interactor, conversation); OccupantMenu.View new_menu = new OccupantMenu.View(stream_interactor, conversation);
set_popover(new_menu); set_popover(new_menu);
if (menu != null) menu.destroy();
menu = new_menu; menu = new_menu;
} }
} }

View file

@ -29,7 +29,7 @@ public class ConversationView : Gtk.Overlay {
white_revealer.visible = true; white_revealer.visible = true;
white_revealer.reveal_child = true; white_revealer.reveal_child = true;
widget.destroy.connect(() => { widget.destroy.connect(() => {
revealer.destroy(); revealer.destroy(); // GTK4: this.remove_overlay(revealer);
white_revealer.reveal_child = false; white_revealer.reveal_child = false;
chat_input.do_focus(); chat_input.do_focus();
}); });

View file

@ -118,7 +118,7 @@ public class GlobalSearch : Overlay {
} }
private void clear_search() { private void clear_search() {
results_box.@foreach((widget) => { widget.destroy(); }); results_box.@foreach((widget) => { results_box.remove(widget); });
loaded_results = 0; loaded_results = 0;
} }

View file

@ -329,7 +329,7 @@ public class AddAccountDialog : Gtk.Dialog {
} }
private void set_register_form(Jid server, Xep.InBandRegistration.Form form) { private void set_register_form(Jid server, Xep.InBandRegistration.Form form) {
form_box.foreach((widget) => { widget.destroy(); }); form_box.foreach((widget) => { form_box.remove(widget); });
register_title.label = _("Register on %s").printf(server.to_string()); register_title.label = _("Register on %s").printf(server.to_string());
if (form.oob != null) { if (form.oob != null) {

View file

@ -128,7 +128,7 @@ public class Dialog : Gtk.Dialog {
ok_button.label = _("Remove"); ok_button.label = _("Remove");
ok_button.get_style_context().add_class("destructive-action"); ok_button.get_style_context().add_class("destructive-action");
if (msg.run() == Gtk.ResponseType.OK) { if (msg.run() == Gtk.ResponseType.OK) {
account_item.destroy(); account_list.remove(account_item);
if (account_item.account.enabled) account_disabled(account_item.account); if (account_item.account.enabled) account_disabled(account_item.account);
account_item.account.remove(); account_item.account.remove();
if (account_list.get_row_at_index(0) != null) { if (account_list.get_row_at_index(0) != null) {

View file

@ -119,7 +119,7 @@ public class View : Popover {
} }
if (jid_menu != null) jid_menu.destroy(); if (jid_menu != null) stack.remove(jid_menu);
stack.add_named(outer_box, "menu"); stack.add_named(outer_box, "menu");
stack.visible_child_name = "menu"; stack.visible_child_name = "menu";
jid_menu = outer_box; jid_menu = outer_box;