[fractal] Use clone! macro from glib
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] Use clone! macro from glib
- Date: Thu, 9 Jul 2020 06:24:00 +0000 (UTC)
commit 4c425b9a6ccef3063dd2c3b51ff869cd160fb98b
Author: Alejandro DomÃnguez <adomu net-c com>
Date: Sun Jul 5 13:40:37 2020 +0200
Use clone! macro from glib
fractal-gtk/src/actions/global.rs | 54 +++++++++++++---------
fractal-gtk/src/actions/message.rs | 20 ++++----
fractal-gtk/src/app/connect/account.rs | 40 ++++++++--------
fractal-gtk/src/app/connect/direct.rs | 40 ++++++++--------
fractal-gtk/src/app/connect/directory.rs | 12 ++---
fractal-gtk/src/app/connect/headerbar.rs | 4 +-
fractal-gtk/src/app/connect/invite.rs | 46 +++++++++---------
fractal-gtk/src/app/connect/join_room.rs | 12 ++---
fractal-gtk/src/app/connect/leave_room.rs | 8 ++--
fractal-gtk/src/app/connect/markdown.rs | 57 ++++++++++++-----------
fractal-gtk/src/app/connect/new_room.rs | 46 ++++++++++--------
fractal-gtk/src/app/connect/roomlist_search.rs | 8 ++--
fractal-gtk/src/app/connect/send.rs | 8 ++--
fractal-gtk/src/appop/attach.rs | 6 +--
fractal-gtk/src/appop/member.rs | 4 +-
fractal-gtk/src/appop/message.rs | 4 +-
fractal-gtk/src/appop/user.rs | 6 +--
fractal-gtk/src/util.rs | 19 --------
fractal-gtk/src/widgets/autocomplete.rs | 4 +-
fractal-gtk/src/widgets/inline_player.rs | 18 ++++----
fractal-gtk/src/widgets/media_viewer.rs | 64 +++++++++++++++-----------
fractal-gtk/src/widgets/members_list.rs | 6 +--
fractal-gtk/src/widgets/room_settings.rs | 10 ++--
fractal-gtk/src/widgets/roomlist.rs | 9 +++-
24 files changed, 264 insertions(+), 241 deletions(-)
---
diff --git a/fractal-gtk/src/actions/global.rs b/fractal-gtk/src/actions/global.rs
index 1f107619..18af2ec5 100644
--- a/fractal-gtk/src/actions/global.rs
+++ b/fractal-gtk/src/actions/global.rs
@@ -1,4 +1,4 @@
-use crate::clone;
+use glib::clone;
use log::{debug, info};
use std::convert::TryInto;
use std::rc::Rc;
@@ -141,63 +141,71 @@ pub fn new(app: >k::Application, op: &Arc<Mutex<AppOp>>) {
app.quit();
});
- about.connect_activate(clone!(op => move |_, _| op.lock().unwrap().about_dialog() ));
- main_menu.connect_activate(clone!(op => move |_, _| op.lock().unwrap().main_menu() ));
+ about.connect_activate(clone!(@strong op => move |_, _| op.lock().unwrap().about_dialog() ));
+ main_menu.connect_activate(clone!(@strong op => move |_, _| op.lock().unwrap().main_menu() ));
settings.connect_activate(move |_, _| {
info!("SETTINGS");
});
settings.set_enabled(false);
- logout.connect_activate(clone!(op => move |_, _| op.lock().unwrap().logout() ));
- inv.connect_activate(clone!(op => move |_, _| op.lock().unwrap().show_invite_user_dialog() ));
- chat.connect_activate(clone!(op => move |_, _| op.lock().unwrap().show_direct_chat_dialog() ));
- leave.connect_activate(clone!(op => move |_, _| op.lock().unwrap().leave_active_room() ));
- newr.connect_activate(clone!(op => move |_, _| op.lock().unwrap().new_room_dialog() ));
- joinr.connect_activate(clone!(op => move |_, _| op.lock().unwrap().join_to_room_dialog() ));
-
- previous_room.connect_activate(clone!(op => move |_, _| {
+ logout.connect_activate(clone!(@strong op => move |_, _| op.lock().unwrap().logout() ));
+ inv.connect_activate(
+ clone!(@strong op => move |_, _| op.lock().unwrap().show_invite_user_dialog() ),
+ );
+ chat.connect_activate(
+ clone!(@strong op => move |_, _| op.lock().unwrap().show_direct_chat_dialog() ),
+ );
+ leave.connect_activate(
+ clone!(@strong op => move |_, _| op.lock().unwrap().leave_active_room() ),
+ );
+ newr.connect_activate(clone!(@strong op => move |_, _| op.lock().unwrap().new_room_dialog() ));
+ joinr.connect_activate(
+ clone!(@strong op => move |_, _| op.lock().unwrap().join_to_room_dialog() ),
+ );
+
+ previous_room.connect_activate(clone!(@strong op => move |_, _| {
let mut op = op.lock().unwrap();
if let Some(id) = op.roomlist.prev_id() {
op.set_active_room_by_id(id);
}
}));
- next_room.connect_activate(clone!(op => move |_, _| {
+ next_room.connect_activate(clone!(@strong op => move |_, _| {
let mut op = op.lock().unwrap();
if let Some(id) = op.roomlist.next_id() {
op.set_active_room_by_id(id);
}
}));
- prev_unread_room.connect_activate(clone!(op => move |_, _| {
+ prev_unread_room.connect_activate(clone!(@strong op => move |_, _| {
let mut op = op.lock().unwrap();
if let Some(id) = op.roomlist.prev_unread_id() {
op.set_active_room_by_id(id);
}
}));
- next_unread_room.connect_activate(clone!(op => move |_, _| {
+ next_unread_room.connect_activate(clone!(@strong op => move |_, _| {
let mut op = op.lock().unwrap();
if let Some(id) = op.roomlist.next_unread_id() {
op.set_active_room_by_id(id);
}
}));
- first_room.connect_activate(clone!(op => move |_, _| {
+ first_room.connect_activate(clone!(@strong op => move |_, _| {
let mut op = op.lock().unwrap();
if let Some(id) = op.roomlist.first_id() {
op.set_active_room_by_id(id);
}
}));
- last_room.connect_activate(clone!(op => move |_, _| {
+ last_room.connect_activate(clone!(@strong op => move |_, _| {
let mut op = op.lock().unwrap();
if let Some(id) = op.roomlist.last_id() {
op.set_active_room_by_id(id);
}
}));
- older_messages.connect_activate(clone!(op => move |_, _| {
+ older_messages.connect_activate(clone!(@strong op => move |_, _| {
if let Some(ref mut hist) = op.lock().unwrap().history {
hist.page_up();
}
}));
- newer_messages.connect_activate(clone!(op => move |_, _| {
+ newer_messages.connect_activate(clone!(@strong op => move |_, _| {
if let Some(ref mut hist) = op.lock().unwrap().history {
hist.page_down();
}
@@ -206,7 +214,7 @@ pub fn new(app: >k::Application, op: &Arc<Mutex<AppOp>>) {
let back_history = op.lock().unwrap().room_back_history.clone();
let back_weak = Rc::downgrade(&back_history);
- account.connect_activate(clone!(op => move |_, _| {
+ account.connect_activate(clone!(@strong op => move |_, _| {
op.lock().unwrap().show_account_settings_dialog();
let back = upgrade_weak!(back_weak);
@@ -214,7 +222,7 @@ pub fn new(app: >k::Application, op: &Arc<Mutex<AppOp>>) {
}));
let back_weak = Rc::downgrade(&back_history);
- directory.connect_activate(clone!(op => move |_, _| {
+ directory.connect_activate(clone!(@strong op => move |_, _| {
op.lock().unwrap().set_state(AppState::Directory);
let back = upgrade_weak!(back_weak);
@@ -224,7 +232,7 @@ pub fn new(app: >k::Application, op: &Arc<Mutex<AppOp>>) {
/* TODO: We could pass a message to this to highlight it in the room history, might be
* handy when opening the room from a notification */
let back_weak = Rc::downgrade(&back_history);
- open_room.connect_activate(clone!(op => move |_, data| {
+ open_room.connect_activate(clone!(@strong op => move |_, data| {
if let Some(id) = get_room_id(data) {
op.lock().unwrap().set_active_room_by_id(id);
/* This does nothing if fractal is already in focus */
@@ -243,7 +251,7 @@ pub fn new(app: >k::Application, op: &Arc<Mutex<AppOp>>) {
}));
let back_weak = Rc::downgrade(&back_history);
- room_settings.connect_activate(clone!(op => move |_, _| {
+ room_settings.connect_activate(clone!(@strong op => move |_, _| {
op.lock().unwrap().create_room_settings();
let back = upgrade_weak!(back_weak);
@@ -298,7 +306,7 @@ pub fn new(app: >k::Application, op: &Arc<Mutex<AppOp>>) {
}
});
- send_message.connect_activate(clone!(op => move |_, _| {
+ send_message.connect_activate(clone!(@strong op => move |_, _| {
let msg_entry = op.lock().unwrap().ui.sventry.view.clone();
if let Some(buffer) = msg_entry.get_buffer() {
let start = buffer.get_start_iter();
diff --git a/fractal-gtk/src/actions/message.rs b/fractal-gtk/src/actions/message.rs
index d3092b5b..10b3ed45 100644
--- a/fractal-gtk/src/actions/message.rs
+++ b/fractal-gtk/src/actions/message.rs
@@ -1,7 +1,7 @@
use crate::backend::{dw_media, media, room, ContentType, ThreadPool};
-use crate::clone;
use fractal_api::identifiers::RoomId;
use fractal_api::r0::AccessToken;
+use glib::clone;
use log::error;
use std::cell::RefCell;
use std::fs;
@@ -116,7 +116,7 @@ pub fn new(
}
});
- open_with.connect_activate(clone!(server_url => move |_, data| {
+ open_with.connect_activate(clone!(@strong server_url => move |_, data| {
if let Some(m) = get_message(data) {
let url = m.url.unwrap_or_default();
let server_url = server_url.clone();
@@ -137,7 +137,7 @@ pub fn new(
}));
let parent_weak = parent.downgrade();
- save_as.connect_activate(clone!(server_url, thread_pool => move |_, data| {
+ save_as.connect_activate(clone!(@strong server_url, @strong thread_pool => move |_, data| {
if let Some(m) = get_message(data) {
let name = m.body;
let url = m.url.unwrap_or_default();
@@ -148,7 +148,7 @@ pub fn new(
let parent_weak = parent_weak.clone();
gtk::timeout_add(
50,
- clone!(name => move || match rx.try_recv() {
+ clone!(@strong name => move || match rx.try_recv() {
Err(TryRecvError::Empty) => Continue(true),
Err(TryRecvError::Disconnected) => {
let msg = i18n("Could not download the file");
@@ -175,7 +175,7 @@ pub fn new(
}
}));
- copy_image.connect_activate(clone!(server_url => move |_, data| {
+ copy_image.connect_activate(clone!(@strong server_url => move |_, data| {
if let Some(m) = get_message(data) {
let url = m.url.unwrap_or_default();
@@ -252,10 +252,12 @@ pub fn new(
}
});
- load_more_messages.connect_activate(clone!(server_url, access_token => move |_, data| {
- let id = get_room_id(data);
- request_more_messages(server_url.clone(), access_token.clone(), id);
- }));
+ load_more_messages.connect_activate(
+ clone!(@strong server_url, @strong access_token => move |_, data| {
+ let id = get_room_id(data);
+ request_more_messages(server_url.clone(), access_token.clone(), id);
+ }),
+ );
actions
}
diff --git a/fractal-gtk/src/app/connect/account.rs b/fractal-gtk/src/app/connect/account.rs
index 55032a33..4241dcd1 100644
--- a/fractal-gtk/src/app/connect/account.rs
+++ b/fractal-gtk/src/app/connect/account.rs
@@ -1,5 +1,5 @@
-use crate::clone;
use gio::ActionMapExt;
+use glib::clone;
use gtk::prelude::*;
use crate::app::App;
@@ -109,7 +109,7 @@ impl App {
}
let button = name_btn.clone();
- name_entry.connect_property_text_notify(clone!(op => move |w| {
+ name_entry.connect_property_text_notify(clone!(@strong op => move |w| {
if let Some(text) = w.get_text().filter(|text| !text.is_empty()) {
if op.try_lock()
.ok()
@@ -130,7 +130,7 @@ impl App {
let _ = button.emit("clicked", &[]);
});
- name_btn.connect_clicked(clone!(op => move |_w| {
+ name_btn.connect_clicked(clone!(@strong op => move |_w| {
op.lock().unwrap().update_username_account_settings();
}));
@@ -189,47 +189,49 @@ impl App {
}
/* Passsword dialog */
- password_btn.connect_clicked(clone!(op => move |_| {
+ password_btn.connect_clicked(clone!(@strong op => move |_| {
op.lock().unwrap().show_password_dialog();
}));
- password_dialog.connect_delete_event(clone!(op => move |_, _| {
+ password_dialog.connect_delete_event(clone!(@strong op => move |_, _| {
op.lock().unwrap().close_password_dialog();
glib::signal::Inhibit(true)
}));
/* Headerbar */
- cancel_password.connect_clicked(clone!(op => move |_| {
+ cancel_password.connect_clicked(clone!(@strong op => move |_| {
op.lock().unwrap().close_password_dialog();
}));
- confirm_password.connect_clicked(clone!(op => move |_| {
+ confirm_password.connect_clicked(clone!(@strong op => move |_| {
op.lock().unwrap().set_new_password();
op.lock().unwrap().close_password_dialog();
}));
/* Body */
- verify_password.connect_property_text_notify(clone!(builder => move |_| {
+ verify_password.connect_property_text_notify(clone!(@strong builder => move |_| {
validate_password_input(&builder.clone());
}));
- new_password.connect_property_text_notify(clone!(builder => move |_| {
+ new_password.connect_property_text_notify(clone!(@strong builder => move |_| {
validate_password_input(&builder.clone());
}));
- old_password.connect_property_text_notify(clone!(builder => move |_| {
+ old_password.connect_property_text_notify(clone!(@strong builder => move |_| {
validate_password_input(&builder)
}));
- destruction_entry.connect_property_text_notify(clone!(destruction_btn => move |w| {
- if let Some(text) = w.get_text() {
- if text != "" {
- destruction_btn.set_sensitive(true);
- return;
+ destruction_entry.connect_property_text_notify(
+ clone!(@strong destruction_btn => move |w| {
+ if let Some(text) = w.get_text() {
+ if text != "" {
+ destruction_btn.set_sensitive(true);
+ return;
+ }
}
- }
- destruction_btn.set_sensitive(false);
- }));
+ destruction_btn.set_sensitive(false);
+ }),
+ );
- destruction_btn.connect_clicked(clone!(op => move |_| {
+ destruction_btn.connect_clicked(clone!(@strong op => move |_| {
op.lock().unwrap().account_destruction();
}));
}
diff --git a/fractal-gtk/src/app/connect/direct.rs b/fractal-gtk/src/app/connect/direct.rs
index 7558e33c..a577a121 100644
--- a/fractal-gtk/src/app/connect/direct.rs
+++ b/fractal-gtk/src/app/connect/direct.rs
@@ -1,4 +1,4 @@
-use crate::clone;
+use glib::clone;
use gtk::prelude::*;
use glib::source::Continue;
@@ -54,7 +54,7 @@ impl App {
// this is used to cancel the timeout and not search for every key input. We'll wait 500ms
// without key release event to launch the search
let source_id: Arc<Mutex<Option<glib::source::SourceId>>> = Arc::new(Mutex::new(None));
- to_chat_entry.connect_key_release_event(clone!(op => move |entry, _| {
+ to_chat_entry.connect_key_release_event(clone!(@strong op => move |entry, _| {
{
let mut id = source_id.lock().unwrap();
if let Some(sid) = id.take() {
@@ -62,7 +62,7 @@ impl App {
}
}
- let sid = gtk::timeout_add(500, clone!(op, entry, source_id => move || {
+ let sid = gtk::timeout_add(500, clone!(@strong op, @strong entry, @strong source_id => move || {
if let Some(buffer) = entry.get_buffer() {
let start = buffer.get_start_iter();
let end = buffer.get_end_iter();
@@ -82,40 +82,44 @@ impl App {
glib::signal::Inhibit(false)
}));
- to_chat_entry.connect_focus_in_event(clone!(op, to_chat_entry_box => move |_, _| {
- to_chat_entry_box.get_style_context().add_class("message-input-focused");
+ to_chat_entry.connect_focus_in_event(
+ clone!(@strong op, @strong to_chat_entry_box => move |_, _| {
+ to_chat_entry_box.get_style_context().add_class("message-input-focused");
- op.lock().unwrap().remove_invite_user_dialog_placeholder();
+ op.lock().unwrap().remove_invite_user_dialog_placeholder();
- Inhibit(false)
- }));
+ Inhibit(false)
+ }),
+ );
- to_chat_entry.connect_focus_out_event(clone!(op, to_chat_entry_box => move |_, _| {
- to_chat_entry_box.get_style_context().remove_class("message-input-focused");
+ to_chat_entry.connect_focus_out_event(
+ clone!(@strong op, @strong to_chat_entry_box => move |_, _| {
+ to_chat_entry_box.get_style_context().remove_class("message-input-focused");
- op.lock().unwrap().set_invite_user_dialog_placeholder();
+ op.lock().unwrap().set_invite_user_dialog_placeholder();
- Inhibit(false)
- }));
+ Inhibit(false)
+ }),
+ );
if let Some(buffer) = to_chat_entry.get_buffer() {
- buffer.connect_delete_range(clone!( op => move |_, _, _| {
- gtk::idle_add(clone!(op => move || {
+ buffer.connect_delete_range(clone!(@strong op => move |_, _, _| {
+ gtk::idle_add(clone!(@strong op => move || {
op.lock().unwrap().detect_removed_invite();
Continue(false)
}));
}));
}
- dialog.connect_delete_event(clone!(op => move |_, _| {
+ dialog.connect_delete_event(clone!(@strong op => move |_, _| {
op.lock().unwrap().close_direct_chat_dialog();
glib::signal::Inhibit(true)
}));
- cancel.connect_clicked(clone!(op => move |_| {
+ cancel.connect_clicked(clone!(@strong op => move |_| {
op.lock().unwrap().close_direct_chat_dialog();
}));
invite.set_sensitive(false);
- invite.connect_clicked(clone!(op => move |_| {
+ invite.connect_clicked(clone!(@strong op => move |_| {
op.lock().unwrap().start_chat();
}));
}
diff --git a/fractal-gtk/src/app/connect/directory.rs b/fractal-gtk/src/app/connect/directory.rs
index c55c3374..ca27041a 100644
--- a/fractal-gtk/src/app/connect/directory.rs
+++ b/fractal-gtk/src/app/connect/directory.rs
@@ -1,4 +1,4 @@
-use crate::clone;
+use glib::clone;
use crate::i18n::i18n;
@@ -123,7 +123,7 @@ impl App {
op.search_rooms();
});
- default_matrix_server_radio.connect_toggled(clone!(directory_choice_label,
default_matrix_server_radio, protocol_combo, other_homeserver_url_entry => move |_| {
+ default_matrix_server_radio.connect_toggled(clone!(@strong directory_choice_label, @strong
default_matrix_server_radio, @strong protocol_combo, @strong other_homeserver_url_entry => move |_| {
if default_matrix_server_radio.get_active() {
protocol_combo.set_sensitive(false);
other_homeserver_url_entry.set_sensitive(false);
@@ -132,7 +132,7 @@ impl App {
directory_choice_label.set_text(&i18n("Default Matrix Server"));
}));
- other_protocol_radio.connect_toggled(clone!(directory_choice_label, other_protocol_radio,
protocol_combo, protocol_model, other_homeserver_url_entry => move |_| {
+ other_protocol_radio.connect_toggled(clone!(@strong directory_choice_label, @strong
other_protocol_radio, @strong protocol_combo, @strong protocol_model, @strong other_homeserver_url_entry =>
move |_| {
if other_protocol_radio.get_active() {
protocol_combo.set_sensitive(true);
other_homeserver_url_entry.set_sensitive(false);
@@ -151,7 +151,7 @@ impl App {
}));
protocol_combo.connect_changed(
- clone!(directory_choice_label, protocol_combo, protocol_model => move |_| {
+ clone!(@strong directory_choice_label, @strong protocol_combo, @strong protocol_model => move
|_| {
let active = protocol_combo.get_active().map_or(-1, |uint| uint as i32);
let protocol: String = match protocol_model.iter_nth_child(None, active) {
Some(it) => {
@@ -166,7 +166,7 @@ impl App {
);
other_homeserver_radio.connect_toggled(
- clone!(other_homeserver_radio, protocol_combo, other_homeserver_url_entry => move |_| {
+ clone!(@strong other_homeserver_radio, @strong protocol_combo, @strong
other_homeserver_url_entry => move |_| {
if other_homeserver_radio.get_active() {
protocol_combo.set_sensitive(false);
other_homeserver_url_entry.set_sensitive(true);
@@ -175,7 +175,7 @@ impl App {
);
other_homeserver_url_entry.connect_changed(
- clone!(directory_choice_label, other_homeserver_url => move |_| {
+ clone!(@strong directory_choice_label, @strong other_homeserver_url => move |_| {
directory_choice_label.set_text(&other_homeserver_url.get_text());
}),
);
diff --git a/fractal-gtk/src/app/connect/headerbar.rs b/fractal-gtk/src/app/connect/headerbar.rs
index 554e3f43..eaa361e8 100644
--- a/fractal-gtk/src/app/connect/headerbar.rs
+++ b/fractal-gtk/src/app/connect/headerbar.rs
@@ -1,4 +1,4 @@
-use crate::clone;
+use glib::clone;
use gtk::prelude::*;
use crate::app::App;
@@ -30,7 +30,7 @@ impl App {
}
};
- set.connect_property_gtk_decoration_layout_notify(clone!(right_header, left_header, set => move
|_| {
+ set.connect_property_gtk_decoration_layout_notify(clone!(@strong right_header, @strong
left_header, @strong set => move |_| {
if let Some(decor) = set.get_property_gtk_decoration_layout() {
let decor = decor.to_string();
let decor_split: Vec<String> = decor.splitn(2,':').map(|s| s.to_string()).collect();
diff --git a/fractal-gtk/src/app/connect/invite.rs b/fractal-gtk/src/app/connect/invite.rs
index ba23634b..d4281ba5 100644
--- a/fractal-gtk/src/app/connect/invite.rs
+++ b/fractal-gtk/src/app/connect/invite.rs
@@ -1,4 +1,4 @@
-use crate::clone;
+use glib::clone;
use gtk::prelude::*;
use glib::source::Continue;
@@ -25,17 +25,17 @@ impl App {
.get_object::<gtk::Button>("invite_reject")
.expect("Can't find invite_reject in ui file.");
- reject.connect_clicked(clone!(dialog, op => move |_| {
+ reject.connect_clicked(clone!(@strong dialog, @strong op => move |_| {
op.lock().unwrap().accept_inv(false);
dialog.hide();
}));
- dialog.connect_delete_event(clone!(dialog, op => move |_, _| {
+ dialog.connect_delete_event(clone!(@strong dialog, @strong op => move |_, _| {
op.lock().unwrap().accept_inv(false);
dialog.hide();
glib::signal::Inhibit(true)
}));
- accept.connect_clicked(clone!(dialog, op => move |_| {
+ accept.connect_clicked(clone!(@strong dialog, @strong op => move |_| {
op.lock().unwrap().accept_inv(true);
dialog.hide();
}));
@@ -88,7 +88,7 @@ impl App {
// this is used to cancel the timeout and not search for every key input. We'll wait 500ms
// without key release event to launch the search
let source_id: Arc<Mutex<Option<glib::source::SourceId>>> = Arc::new(Mutex::new(None));
- invite_entry.connect_key_release_event(clone!(op => move |entry, _| {
+ invite_entry.connect_key_release_event(clone!(@strong op => move |entry, _| {
{
let mut id = source_id.lock().unwrap();
if let Some(sid) = id.take() {
@@ -96,7 +96,7 @@ impl App {
}
}
- let sid = gtk::timeout_add(500, clone!(op, entry, source_id => move || {
+ let sid = gtk::timeout_add(500, clone!(@strong op, @strong entry, @strong source_id => move || {
if let Some(buffer) = entry.get_buffer() {
let start = buffer.get_start_iter();
let end = buffer.get_end_iter();
@@ -114,40 +114,44 @@ impl App {
glib::signal::Inhibit(false)
}));
- invite_entry.connect_focus_in_event(clone!(op, invite_entry_box => move |_, _| {
- invite_entry_box.get_style_context().add_class("message-input-focused");
+ invite_entry.connect_focus_in_event(
+ clone!(@strong op, @strong invite_entry_box => move |_, _| {
+ invite_entry_box.get_style_context().add_class("message-input-focused");
- op.lock().unwrap().remove_invite_user_dialog_placeholder();
+ op.lock().unwrap().remove_invite_user_dialog_placeholder();
- Inhibit(false)
- }));
+ Inhibit(false)
+ }),
+ );
- invite_entry.connect_focus_out_event(clone!(op, invite_entry_box => move |_, _| {
- invite_entry_box.get_style_context().remove_class("message-input-focused");
+ invite_entry.connect_focus_out_event(
+ clone!(@strong op, @strong invite_entry_box => move |_, _| {
+ invite_entry_box.get_style_context().remove_class("message-input-focused");
- op.lock().unwrap().set_invite_user_dialog_placeholder();
+ op.lock().unwrap().set_invite_user_dialog_placeholder();
- Inhibit(false)
- }));
+ Inhibit(false)
+ }),
+ );
if let Some(buffer) = invite_entry.get_buffer() {
- buffer.connect_delete_range(clone!( op => move |_, _, _| {
- gtk::idle_add(clone!(op => move || {
+ buffer.connect_delete_range(clone!(@strong op => move |_, _, _| {
+ gtk::idle_add(clone!(@strong op => move || {
op.lock().unwrap().detect_removed_invite();
Continue(false)
}));
}));
}
- dialog.connect_delete_event(clone!(op => move |_, _| {
+ dialog.connect_delete_event(clone!(@strong op => move |_, _| {
op.lock().unwrap().close_invite_dialog();
glib::signal::Inhibit(true)
}));
- cancel.connect_clicked(clone!(op => move |_| {
+ cancel.connect_clicked(clone!(@strong op => move |_| {
op.lock().unwrap().close_invite_dialog();
}));
invite.set_sensitive(false);
- invite.connect_clicked(clone!(op => move |_| {
+ invite.connect_clicked(clone!(@strong op => move |_| {
op.lock().unwrap().invite();
}));
}
diff --git a/fractal-gtk/src/app/connect/join_room.rs b/fractal-gtk/src/app/connect/join_room.rs
index 9a78c9b8..e4894b71 100644
--- a/fractal-gtk/src/app/connect/join_room.rs
+++ b/fractal-gtk/src/app/connect/join_room.rs
@@ -1,4 +1,4 @@
-use crate::clone;
+use glib::clone;
use gtk::prelude::*;
use crate::app::App;
@@ -26,30 +26,30 @@ impl App {
.get_object::<gtk::Entry>("join_room_name")
.expect("Can't find join_room_name in ui file.");
- cancel.connect_clicked(clone!(entry, dialog => move |_| {
+ cancel.connect_clicked(clone!(@strong entry, @strong dialog => move |_| {
dialog.hide();
entry.set_text("");
}));
- dialog.connect_delete_event(clone!(entry, dialog => move |_, _| {
+ dialog.connect_delete_event(clone!(@strong entry, @strong dialog => move |_, _| {
dialog.hide();
entry.set_text("");
glib::signal::Inhibit(true)
}));
let op = self.op.clone();
- confirm.connect_clicked(clone!(entry, dialog => move |_| {
+ confirm.connect_clicked(clone!(@strong entry, @strong dialog => move |_| {
dialog.hide();
op.lock().unwrap().join_to_room();
entry.set_text("");
}));
let op = self.op.clone();
- entry.connect_activate(clone!(dialog => move |entry| {
+ entry.connect_activate(clone!(@strong dialog => move |entry| {
dialog.hide();
op.lock().unwrap().join_to_room();
entry.set_text("");
}));
- entry.connect_changed(clone!(confirm => move |entry| {
+ entry.connect_changed(clone!(@strong confirm => move |entry| {
confirm.set_sensitive(entry.get_buffer().get_length() > 0);
}));
}
diff --git a/fractal-gtk/src/app/connect/leave_room.rs b/fractal-gtk/src/app/connect/leave_room.rs
index ea6b566c..d11ca737 100644
--- a/fractal-gtk/src/app/connect/leave_room.rs
+++ b/fractal-gtk/src/app/connect/leave_room.rs
@@ -1,4 +1,4 @@
-use crate::clone;
+use glib::clone;
use gtk::prelude::*;
use crate::app::App;
@@ -21,16 +21,16 @@ impl App {
.get_object::<gtk::Button>("leave_room_confirm")
.expect("Can't find leave_room_confirm in ui file.");
- cancel.connect_clicked(clone!(dialog => move |_| {
+ cancel.connect_clicked(clone!(@strong dialog => move |_| {
dialog.hide();
}));
- dialog.connect_delete_event(clone!(dialog => move |_, _| {
+ dialog.connect_delete_event(clone!(@strong dialog => move |_, _| {
dialog.hide();
glib::signal::Inhibit(true)
}));
let op = self.op.clone();
- confirm.connect_clicked(clone!(dialog => move |_| {
+ confirm.connect_clicked(clone!(@strong dialog => move |_| {
dialog.hide();
op.lock().unwrap().really_leave_active_room();
}));
diff --git a/fractal-gtk/src/app/connect/markdown.rs b/fractal-gtk/src/app/connect/markdown.rs
index 13cbdafa..c18f6555 100644
--- a/fractal-gtk/src/app/connect/markdown.rs
+++ b/fractal-gtk/src/app/connect/markdown.rs
@@ -1,3 +1,4 @@
+use glib::clone;
use gtk::prelude::*;
use sourceview4::prelude::*;
@@ -49,35 +50,37 @@ impl App {
}
}
- markdown_switch.connect_property_active_notify(clone!(markdown_switch => move |_| {
- op.lock().unwrap().md_enabled = markdown_switch.get_active();
+ markdown_switch.connect_property_active_notify(
+ clone!(@strong markdown_switch => move |_| {
+ op.lock().unwrap().md_enabled = markdown_switch.get_active();
- if markdown_switch.get_active() {
- md_img.set_from_icon_name(
- Some("format-indent-more-symbolic"),
- gtk::IconSize::Menu,
- );
- txt.get_style_context().remove_class("dim-label");
- util::set_markdown_schema(true);
+ if markdown_switch.get_active() {
+ md_img.set_from_icon_name(
+ Some("format-indent-more-symbolic"),
+ gtk::IconSize::Menu,
+ );
+ txt.get_style_context().remove_class("dim-label");
+ util::set_markdown_schema(true);
- if let Some(md_lang) = md_lang.clone() {
- buffer.set_highlight_matching_brackets(true);
- buffer.set_language(Some(&md_lang));
- buffer.set_highlight_syntax(true);
- }
- } else {
- md_img.set_from_icon_name(
- Some("format-justify-left-symbolic"),
- gtk::IconSize::Menu,
- );
- txt.get_style_context().add_class("dim-label");
- util::set_markdown_schema(false);
+ if let Some(md_lang) = md_lang.clone() {
+ buffer.set_highlight_matching_brackets(true);
+ buffer.set_language(Some(&md_lang));
+ buffer.set_highlight_syntax(true);
+ }
+ } else {
+ md_img.set_from_icon_name(
+ Some("format-justify-left-symbolic"),
+ gtk::IconSize::Menu,
+ );
+ txt.get_style_context().add_class("dim-label");
+ util::set_markdown_schema(false);
- let lang: Option<&sourceview4::Language> = None;
- buffer.set_highlight_matching_brackets(false);
- buffer.set_language(lang);
- buffer.set_highlight_syntax(false);
- }
- }));
+ let lang: Option<&sourceview4::Language> = None;
+ buffer.set_highlight_matching_brackets(false);
+ buffer.set_language(lang);
+ buffer.set_highlight_syntax(false);
+ }
+ }),
+ );
}
}
diff --git a/fractal-gtk/src/app/connect/new_room.rs b/fractal-gtk/src/app/connect/new_room.rs
index eb675a8b..3783c832 100644
--- a/fractal-gtk/src/app/connect/new_room.rs
+++ b/fractal-gtk/src/app/connect/new_room.rs
@@ -1,4 +1,4 @@
-use crate::clone;
+use glib::clone;
use gtk::prelude::*;
use crate::app::App;
@@ -32,34 +32,40 @@ impl App {
.expect("Can't find private_visibility_button in ui file.");
private.set_active(true);
- cancel.connect_clicked(clone!(entry, dialog, private => move |_| {
- dialog.hide();
- entry.set_text("");
- private.set_active(true);
- }));
- dialog.connect_delete_event(clone!(entry, dialog, private => move |_, _| {
- dialog.hide();
- entry.set_text("");
- private.set_active(true);
- glib::signal::Inhibit(true)
- }));
+ cancel.connect_clicked(
+ clone!(@strong entry, @strong dialog, @strong private => move |_| {
+ dialog.hide();
+ entry.set_text("");
+ private.set_active(true);
+ }),
+ );
+ dialog.connect_delete_event(
+ clone!(@strong entry, @strong dialog, @strong private => move |_, _| {
+ dialog.hide();
+ entry.set_text("");
+ private.set_active(true);
+ glib::signal::Inhibit(true)
+ }),
+ );
let op = self.op.clone();
- confirm.connect_clicked(clone!(entry, dialog, private => move |_| {
- dialog.hide();
- op.lock().unwrap().create_new_room();
- entry.set_text("");
- private.set_active(true);
- }));
+ confirm.connect_clicked(
+ clone!(@strong entry, @strong dialog, @strong private => move |_| {
+ dialog.hide();
+ op.lock().unwrap().create_new_room();
+ entry.set_text("");
+ private.set_active(true);
+ }),
+ );
let op = self.op.clone();
- entry.connect_activate(clone!(dialog => move |entry| {
+ entry.connect_activate(clone!(@strong dialog => move |entry| {
dialog.hide();
op.lock().unwrap().create_new_room();
entry.set_text("");
private.set_active(true);
}));
- entry.connect_changed(clone!(confirm => move |entry| {
+ entry.connect_changed(clone!(@strong confirm => move |entry| {
confirm.set_sensitive(entry.get_buffer().get_length() > 0);
}));
}
diff --git a/fractal-gtk/src/app/connect/roomlist_search.rs b/fractal-gtk/src/app/connect/roomlist_search.rs
index 360db019..68d356a5 100644
--- a/fractal-gtk/src/app/connect/roomlist_search.rs
+++ b/fractal-gtk/src/app/connect/roomlist_search.rs
@@ -1,4 +1,4 @@
-use crate::clone;
+use glib::clone;
use gtk::prelude::*;
use crate::app::App;
@@ -23,17 +23,17 @@ impl App {
.get_object::<gtk::SearchEntry>("room_list_search")
.expect("Can't find room_list_search in ui file.");
- search_btn.connect_toggled(clone!(search_bar => move |btn| {
+ search_btn.connect_toggled(clone!(@strong search_bar => move |btn| {
search_bar.set_search_mode(btn.get_active());
}));
search_bar.connect_property_search_mode_enabled_notify(
- clone!(search_btn => move |headerbar| {
+ clone!(@strong search_btn => move |headerbar| {
search_btn.set_active(headerbar.get_search_mode());
}),
);
- search_entry.connect_search_changed(clone!(op => move |entry| {
+ search_entry.connect_search_changed(clone!(@strong op => move |entry| {
op.lock().unwrap().filter_rooms(
entry.get_text()
.map(|gstr| gstr.to_string())
diff --git a/fractal-gtk/src/app/connect/send.rs b/fractal-gtk/src/app/connect/send.rs
index 6182f301..480d459f 100644
--- a/fractal-gtk/src/app/connect/send.rs
+++ b/fractal-gtk/src/app/connect/send.rs
@@ -1,5 +1,5 @@
use crate::appop::attach;
-use crate::clone;
+use glib::clone;
use gtk::prelude::*;
use sourceview4::BufferExt;
@@ -19,7 +19,7 @@ impl App {
msg_entry_box.set_redraw_on_allocate(true);
if let Some(adjustment) = self.ui.sventry.scroll.get_vadjustment() {
- adjustment.connect_value_changed(clone!(msg_entry => move |adj| {
+ adjustment.connect_value_changed(clone!(@strong msg_entry => move |adj| {
if msg_entry.get_allocated_height() < MAX_INPUT_HEIGHT {
adj.set_value(0.0);
}
@@ -56,13 +56,13 @@ impl App {
attach::paste(op.clone());
});
- msg_entry.connect_focus_in_event(clone!(msg_entry_box => move |_, _| {
+ msg_entry.connect_focus_in_event(clone!(@strong msg_entry_box => move |_, _| {
msg_entry_box.get_style_context().add_class("message-input-focused");
Inhibit(false)
}));
- msg_entry.connect_focus_out_event(clone!(msg_entry_box => move |_, _| {
+ msg_entry.connect_focus_out_event(clone!(@strong msg_entry_box => move |_, _| {
msg_entry_box.get_style_context().remove_class("message-input-focused");
Inhibit(false)
diff --git a/fractal-gtk/src/appop/attach.rs b/fractal-gtk/src/appop/attach.rs
index 0805402f..3f0813aa 100644
--- a/fractal-gtk/src/appop/attach.rs
+++ b/fractal-gtk/src/appop/attach.rs
@@ -1,6 +1,6 @@
-use crate::clone;
use crate::i18n::i18n;
+use glib::clone;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;
@@ -58,11 +58,11 @@ impl AppOp {
headerbar.pack_end(&okbtn);
headerbar.show_all();
- closebtn.connect_clicked(clone!(dialog => move |_| {
+ closebtn.connect_clicked(clone!(@strong dialog => move |_| {
dialog.destroy();
}));
/* FIXME: make this a action */
- okbtn.connect_clicked(clone!(pixb, dialog => move |_| {
+ okbtn.connect_clicked(clone!(@strong pixb, @strong dialog => move |_| {
if let Ok(path) = store_pixbuf(&pixb) {
APPOP!(attach_message, (path))
}
diff --git a/fractal-gtk/src/appop/member.rs b/fractal-gtk/src/appop/member.rs
index 771e9f57..a8f4926a 100644
--- a/fractal-gtk/src/appop/member.rs
+++ b/fractal-gtk/src/appop/member.rs
@@ -1,6 +1,6 @@
use crate::backend::{user, HandleError};
-use crate::clone;
use fractal_api::identifiers::{RoomId, UserId};
+use glib::clone;
use gtk::prelude::*;
use std::collections::HashMap;
@@ -175,7 +175,7 @@ impl AppOp {
w = mb.widget(true);
}
- w.connect_button_press_event(clone!(u => move |_, _| {
+ w.connect_button_press_event(clone!(@strong u => move |_, _| {
/* FIXME: Create Action */
let u = u.clone();
APPOP!(add_to_invite, (u));
diff --git a/fractal-gtk/src/appop/message.rs b/fractal-gtk/src/appop/message.rs
index 16e8a6ee..52d7adb6 100644
--- a/fractal-gtk/src/appop/message.rs
+++ b/fractal-gtk/src/appop/message.rs
@@ -1,5 +1,4 @@
use crate::backend::{room, HandleError};
-use crate::clone;
use crate::types::ExtraContent;
use comrak::{markdown_to_html, ComrakOptions};
use fractal_api::identifiers::{EventId, RoomId};
@@ -7,6 +6,7 @@ use fractal_api::r0::AccessToken;
use fractal_api::url::Url;
use gdk_pixbuf::Pixbuf;
use gio::prelude::FileExt;
+use glib::clone;
use glib::source::Continue;
use gtk::prelude::*;
use lazy_static::lazy_static;
@@ -680,7 +680,7 @@ fn attach_file(baseu: Url, tk: AccessToken, mut msg: Message) {
let query = room::upload_file(baseu.clone(), tk.clone(), &fname).map(|response| {
msg.url = Some(response.content_uri.to_string());
- thread::spawn(clone!(msg => move || send_msg_and_manage(baseu, tk, msg)));
+ thread::spawn(clone!(@strong msg => move || send_msg_and_manage(baseu, tk, msg)));
msg
});
diff --git a/fractal-gtk/src/appop/user.rs b/fractal-gtk/src/appop/user.rs
index 096735c1..588a1182 100644
--- a/fractal-gtk/src/appop/user.rs
+++ b/fractal-gtk/src/appop/user.rs
@@ -1,7 +1,7 @@
use gtk::prelude::*;
use crate::backend::{user, HandleError};
-use crate::clone;
+use glib::clone;
use std::path::PathBuf;
use std::thread;
@@ -20,7 +20,7 @@ impl AppOp {
pub fn get_username(&self) {
let login_data = unwrap_or_unit_return!(self.login_data.clone());
- thread::spawn(clone!(login_data => move || {
+ thread::spawn(clone!(@strong login_data => move || {
match user::get_username(login_data.server_url, login_data.uid) {
Ok(username) => {
APPOP!(set_username, (username));
@@ -31,7 +31,7 @@ impl AppOp {
}
}));
- thread::spawn(clone!(login_data => move || {
+ thread::spawn(clone!(@strong login_data => move || {
match user::get_avatar(login_data.server_url, login_data.uid) {
Ok(path) => {
APPOP!(set_avatar, (path));
diff --git a/fractal-gtk/src/util.rs b/fractal-gtk/src/util.rs
index 4cc23912..f5db5b5b 100644
--- a/fractal-gtk/src/util.rs
+++ b/fractal-gtk/src/util.rs
@@ -41,25 +41,6 @@ macro_rules! glib_thread {
}};
}
-// from https://stackoverflow.com/a/43992218/1592377
-#[macro_export]
-macro_rules! clone {
- (@param _) => ( _ );
- (@param $x:ident) => ( $x );
- ($($n:ident),+ => move || $body:expr) => (
- {
- $( let $n = $n.clone(); )+
- move || $body
- }
- );
- ($($n:ident),+ => move |$($p:tt),+| $body:expr) => (
- {
- $( let $n = $n.clone(); )+
- move |$(clone!(@param $p),)+| $body
- }
- );
-}
-
pub fn cache_dir_path(dir: Option<&str>, name: &str) -> Result<String, Error> {
let path = CACHE_PATH.join(dir.unwrap_or_default());
diff --git a/fractal-gtk/src/widgets/autocomplete.rs b/fractal-gtk/src/widgets/autocomplete.rs
index 212f45cb..ba65caca 100644
--- a/fractal-gtk/src/widgets/autocomplete.rs
+++ b/fractal-gtk/src/widgets/autocomplete.rs
@@ -1,4 +1,4 @@
-use crate::clone;
+use glib::clone;
use log::info;
use std::cell::RefCell;
use std::collections::HashMap;
@@ -278,7 +278,7 @@ impl Autocomplete {
own.borrow_mut().autocomplete_show_popover(list)
};
for (alias, widget) in widget_list.iter() {
- widget.connect_button_press_event(clone!(own, alias => move |_, ev| {
+ widget.connect_button_press_event(clone!(@strong own, @strong alias =>
move |_, ev| {
own.borrow_mut().autocomplete_insert(alias.clone());
if ev.is::<gdk::EventKey>() {
let ev = {
diff --git a/fractal-gtk/src/widgets/inline_player.rs b/fractal-gtk/src/widgets/inline_player.rs
index aa9e9142..eea848cc 100644
--- a/fractal-gtk/src/widgets/inline_player.rs
+++ b/fractal-gtk/src/widgets/inline_player.rs
@@ -18,7 +18,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
use crate::backend::{media, ThreadPool};
-use crate::clone;
+use glib::clone;
use gst::prelude::*;
use gst::ClockTime;
@@ -406,7 +406,7 @@ impl VideoPlayerWidget {
are bigger than they should be. */
gtk::timeout_add(
50,
- clone!(bx, video_width, video_height => move || {
+ clone!(@strong bx, @strong video_width, @strong video_height => move || {
adjust_box_margins_to_video_dimensions(&bx, video_width, video_height);
Continue(false)
}),
@@ -507,7 +507,7 @@ impl<T: MediaPlayer + 'static> PlayerExt for T {
let local_path = player.get_local_path_access();
gtk::timeout_add(
50,
- clone!(player, bx => move || {
+ clone!(@strong player, @strong bx => move || {
match rx.try_recv() {
Err(TryRecvError::Empty) => Continue(true),
Err(TryRecvError::Disconnected) => {
@@ -587,12 +587,12 @@ impl<T: MediaPlayer + 'static> ControlsConnection for T {
let weak = Rc::downgrade(s);
// Connect the play button to the gst Player.
- s.get_controls().unwrap().buttons.play.connect_clicked(clone!(weak => move |_| {
+ s.get_controls().unwrap().buttons.play.connect_clicked(clone!(@strong weak => move |_| {
if let Some(p) = weak.upgrade() { p.play() }
}));
// Connect the pause button to the gst Player.
- s.get_controls().unwrap().buttons.pause.connect_clicked(clone!(weak => move |_| {
+ s.get_controls().unwrap().buttons.pause.connect_clicked(clone!(@strong weak => move |_| {
if let Some(p) = weak.upgrade() { p.pause() }
}));
}
@@ -604,17 +604,17 @@ impl<T: MediaPlayer + 'static> ControlsConnection for T {
let weak = Fragile::new(Rc::downgrade(s));
// Update the duration label and the slider
- s.get_player().connect_duration_changed(clone!(weak => move |_, clock| {
+ s.get_player().connect_duration_changed(clone!(@strong weak => move |_, clock| {
if let Some(p) = weak.get().upgrade() {
p.get_controls().unwrap().timer.on_duration_changed(Duration(clock)) }
}));
// Update the position label and the slider
- s.get_player().connect_position_updated(clone!(weak => move |_, clock| {
+ s.get_player().connect_position_updated(clone!(@strong weak => move |_, clock| {
if let Some(p) = weak.get().upgrade() {
p.get_controls().unwrap().timer.on_position_updated(Position(clock)) }
}));
// Reset the slider to 0 and show a play button
- s.get_player().connect_end_of_stream(clone!(weak => move |_| {
+ s.get_player().connect_end_of_stream(clone!(@strong weak => move |_| {
if let Some(p) = weak.get().upgrade() { p.stop() }
}));
}
@@ -656,7 +656,7 @@ fn create_controls(player: &gst_player::Player) -> PlayerControls {
}
fn connect_update_slider(slider: >k::Scale, player: &gst_player::Player) -> SignalHandlerId {
- slider.connect_value_changed(clone!(player => move |slider| {
+ slider.connect_value_changed(clone!(@strong player => move |slider| {
let value = slider.get_value() as u64;
player.seek(ClockTime::from_seconds(value));
}))
diff --git a/fractal-gtk/src/widgets/media_viewer.rs b/fractal-gtk/src/widgets/media_viewer.rs
index 3d4c0dd9..5d4dc1b2 100644
--- a/fractal-gtk/src/widgets/media_viewer.rs
+++ b/fractal-gtk/src/widgets/media_viewer.rs
@@ -1,7 +1,7 @@
use crate::backend::media;
use crate::backend::ThreadPool;
-use crate::clone;
use fractal_api::r0::AccessToken;
+use glib::clone;
use fragile::Fragile;
use std::cell::RefCell;
@@ -408,7 +408,7 @@ impl Data {
let source_id: Rc<RefCell<Option<glib::source::SourceId>>> = Rc::new(RefCell::new(None));
let first_sid = gtk::timeout_add_seconds(
1,
- clone!(source_id, control_revealer => move || {
+ clone!(@strong source_id, @strong control_revealer => move || {
control_revealer.set_reveal_child(false);
*source_id.borrow_mut() = None;
Continue(false)
@@ -422,7 +422,7 @@ impl Data {
.expect("Cant find media_viewer_box in ui file.");
let player_weak = Rc::downgrade(&player);
media_viewer_box.connect_motion_notify_event(
- clone!( control_revealer, source_id => move |_, _| {
+ clone!(@strong control_revealer, @strong source_id => move |_, _| {
if let Some(player) = player_weak.upgrade() {
control_revealer.set_reveal_child(true);
if let Some(sid) = source_id.borrow_mut().take() {
@@ -430,7 +430,7 @@ impl Data {
}
let new_sid = gtk::timeout_add_seconds(
1,
- clone!(source_id, control_revealer => move || {
+ clone!(@strong source_id, @strong control_revealer => move || {
if player.is_playing() {
control_revealer.set_reveal_child(false);
}
@@ -462,7 +462,7 @@ impl Data {
let player_weak = Rc::downgrade(&player);
self.main_window.connect_key_press_event(
- clone!(control_revealer, source_id => move |_, k| {
+ clone!(@strong control_revealer, @strong source_id => move |_, k| {
if let Some(player) = player_weak.upgrade() {
if player.get_video_widget().get_mapped() {
if let gdk::enums::key::space = k.get_keyval() {
@@ -471,7 +471,7 @@ impl Data {
} else {
let new_sid = gtk::timeout_add_seconds(
1,
- clone!(source_id, control_revealer, player_weak => move || {
+ clone!(@strong source_id, @strong control_revealer, @strong player_weak
=> move || {
if let Some(player) = player_weak.upgrade() {
if player.is_playing() {
control_revealer.set_reveal_child(false);
@@ -497,7 +497,7 @@ impl Data {
let player_weak = Rc::downgrade(&player);
let click_timeout_id = Rc::new(RefCell::new(None));
media_viewer_box.connect_button_press_event(
- clone!(control_revealer, source_id => move |_, e| {
+ clone!(@strong control_revealer, @strong source_id => move |_, e| {
let source_id = source_id.clone();
let revealer = control_revealer.clone();
let pw = player_weak.clone();
@@ -510,13 +510,13 @@ impl Data {
} else {
let sid = gtk::timeout_add(
250,
- clone!(player, click_timeout_id => move || {
+ clone!(@strong player, @strong click_timeout_id => move || {
if player.is_playing() {
revealer.set_reveal_child(true);
} else {
let new_sid = gtk::timeout_add_seconds(
1,
- clone!(source_id, revealer, pw => move || {
+ clone!(@strong source_id, @strong revealer, @strong pw =>
move || {
if let Some(player) = pw.upgrade() {
if player.is_playing() {
revealer.set_reveal_child(false);
@@ -752,43 +752,51 @@ impl MediaViewer {
.get_object::<gtk::Revealer>("headerbar_revealer")
.expect("Can't find headerbar_revealer in ui file.");
- headerbar_revealer.connect_enter_notify_event(clone!(header_hovered => move |_, _| {
- header_hovered.store(true, Ordering::SeqCst);
+ headerbar_revealer.connect_enter_notify_event(
+ clone!(@strong header_hovered => move |_, _| {
+ header_hovered.store(true, Ordering::SeqCst);
- Inhibit(false)
- }));
+ Inhibit(false)
+ }),
+ );
- headerbar_revealer.connect_leave_notify_event(clone!(header_hovered => move |_, _| {
- header_hovered.store(false, Ordering::SeqCst);
+ headerbar_revealer.connect_leave_notify_event(
+ clone!(@strong header_hovered => move |_, _| {
+ header_hovered.store(false, Ordering::SeqCst);
- Inhibit(false)
- }));
+ Inhibit(false)
+ }),
+ );
let previous_media_button = ui
.get_object::<gtk::Button>("previous_media_button")
.expect("Cant find previous_media_button in ui file.");
- previous_media_button.connect_enter_notify_event(clone!(nav_hovered => move |_, _| {
- nav_hovered.store(true, Ordering::SeqCst);
+ previous_media_button.connect_enter_notify_event(
+ clone!(@strong nav_hovered => move |_, _| {
+ nav_hovered.store(true, Ordering::SeqCst);
- Inhibit(false)
- }));
- previous_media_button.connect_leave_notify_event(clone!(nav_hovered => move |_, _| {
- nav_hovered.store(false, Ordering::SeqCst);
+ Inhibit(false)
+ }),
+ );
+ previous_media_button.connect_leave_notify_event(
+ clone!(@strong nav_hovered => move |_, _| {
+ nav_hovered.store(false, Ordering::SeqCst);
- Inhibit(false)
- }));
+ Inhibit(false)
+ }),
+ );
let next_media_button = ui
.get_object::<gtk::Button>("next_media_button")
.expect("Cant find next_media_button in ui file.");
- next_media_button.connect_enter_notify_event(clone!(nav_hovered => move |_, _| {
+ next_media_button.connect_enter_notify_event(clone!(@strong nav_hovered => move |_, _| {
nav_hovered.store(true, Ordering::SeqCst);
Inhibit(false)
}));
- next_media_button.connect_leave_notify_event(clone!(nav_hovered => move |_, _| {
+ next_media_button.connect_leave_notify_event(clone!(@strong nav_hovered => move |_, _| {
nav_hovered.store(false, Ordering::SeqCst);
Inhibit(false)
@@ -831,7 +839,7 @@ impl MediaViewer {
let sid = gtk::timeout_add(
1000,
- clone!(ui, header_hovered, nav_hovered, source_id => move || {
+ clone!(@strong ui, @strong header_hovered, @strong nav_hovered, @strong source_id =>
move || {
let menu_popover_is_visible = ui
.get_object::<gtk::MenuButton>("media_viewer_menu_button")
.expect("Can't find headerbar_revealer in ui file.")
diff --git a/fractal-gtk/src/widgets/members_list.rs b/fractal-gtk/src/widgets/members_list.rs
index ca106158..9b8c6845 100644
--- a/fractal-gtk/src/widgets/members_list.rs
+++ b/fractal-gtk/src/widgets/members_list.rs
@@ -1,5 +1,5 @@
-use crate::clone;
use fractal_api::identifiers::UserId;
+use glib::clone;
use std::cell::RefCell;
use std::collections::hash_map::HashMap;
use std::rc::Rc;
@@ -101,7 +101,7 @@ impl MembersList {
let container = self.container.clone();
let members = self.members.clone();
for (index, member) in members.iter().enumerate() {
- gtk::idle_add(clone!(index, member, container => move || {
+ gtk::idle_add(clone!(@strong index, @strong member, @strong container => move || {
if let Some(w) = container.get_row_at_index(index as i32) {
if w.get_child().is_none() {
w.add(&load_row_content(member.clone()));
@@ -116,7 +116,7 @@ impl MembersList {
fn create_row(member: Member, power_level: Option<i32>) -> Option<gtk::ListBoxRow> {
let row = gtk::ListBoxRow::new();
- row.connect_draw(clone!(member => move |w, _| {
+ row.connect_draw(clone!(@strong member => move |w, _| {
if w.get_child().is_none() {
w.add(&load_row_content(member.clone(), power_level));
}
diff --git a/fractal-gtk/src/widgets/room_settings.rs b/fractal-gtk/src/widgets/room_settings.rs
index 195ab8d8..e0c69bed 100644
--- a/fractal-gtk/src/widgets/room_settings.rs
+++ b/fractal-gtk/src/widgets/room_settings.rs
@@ -1,7 +1,7 @@
use crate::backend::{room, HandleError};
-use crate::clone;
use fractal_api::identifiers::UserId;
use fractal_api::r0::AccessToken;
+use glib::clone;
use std::cell::RefCell;
use std::rc::Rc;
use std::thread;
@@ -126,7 +126,7 @@ impl RoomSettings {
let this: Rc<RefCell<RoomSettings>> = Rc::new(RefCell::new(self.clone()));
let button = name_btn.clone();
- name_entry.connect_property_text_notify(clone!(this => move |w| {
+ name_entry.connect_property_text_notify(clone!(@strong this => move |w| {
let result = this.borrow().validate_room_name(
w.get_text()
.map(|gstr| gstr.to_string())
@@ -135,7 +135,7 @@ impl RoomSettings {
}));
let button = topic_btn.clone();
- topic_entry.connect_property_text_notify(clone!(this => move |w| {
+ topic_entry.connect_property_text_notify(clone!(@strong this => move |w| {
let result = this.borrow().validate_room_topic(
w.get_text()
.map(|gstr| gstr.to_string())
@@ -149,7 +149,7 @@ impl RoomSettings {
let _ = button.emit("clicked", &[]);
});
- name_btn.connect_clicked(clone!(this => move |_| {
+ name_btn.connect_clicked(clone!(@strong this => move |_| {
this.borrow_mut().update_room_name();
}));
@@ -158,7 +158,7 @@ impl RoomSettings {
let _ = button.emit("clicked", &[]);
});
- topic_btn.connect_clicked(clone!(this => move |_| {
+ topic_btn.connect_clicked(clone!(@strong this => move |_| {
this.borrow_mut().update_room_topic();
}));
diff --git a/fractal-gtk/src/widgets/roomlist.rs b/fractal-gtk/src/widgets/roomlist.rs
index 3c88591f..980171b5 100644
--- a/fractal-gtk/src/widgets/roomlist.rs
+++ b/fractal-gtk/src/widgets/roomlist.rs
@@ -1,6 +1,6 @@
-use crate::clone;
use crate::i18n::i18n;
use fractal_api::identifiers::RoomId;
+use glib::clone;
use fractal_api::url::Url;
use gtk::prelude::*;
@@ -90,7 +90,12 @@ impl RoomListGroup {
let expanded = Arc::new(AtomicBool::new(true));
let title_eb = gtk::EventBox::new();
- title_eb.connect_button_press_event(clone!(list, arrow, rev, expanded => move |_, _| {
+ title_eb.connect_button_press_event(clone!(
+ @strong list,
+ @strong arrow,
+ @strong rev,
+ @strong expanded
+ => move |_, _| {
if expanded.load(Ordering::SeqCst) {
arrow.set_from_icon_name(Some("pan-end-symbolic"), gtk::IconSize::SmallToolbar);
rev.set_reveal_child(false);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]