[fractal] room-history: Reorganize
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] room-history: Reorganize
- Date: Wed, 27 Apr 2022 13:17:43 +0000 (UTC)
commit d175e4409b665bfd7492531fdcd743604aae5dfb
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Sun Apr 24 16:11:50 2022 +0200
room-history: Reorganize
Group clipboard and drag-n-drop methods
Part-of: <https://gitlab.gnome.org/GNOME/fractal/-/merge_requests/1085>
src/session/content/room_history/mod.rs | 196 ++++++++++++++++----------------
1 file changed, 98 insertions(+), 98 deletions(-)
---
diff --git a/src/session/content/room_history/mod.rs b/src/session/content/room_history/mod.rs
index 949189a16..dc258c090 100644
--- a/src/session/content/room_history/mod.rs
+++ b/src/session/content/room_history/mod.rs
@@ -387,65 +387,6 @@ glib::wrapper! {
}
impl RoomHistory {
- async fn read_clipboard(&self) {
- let clipboard = self.clipboard();
- let formats = clipboard.formats();
-
- if formats.contains_type(gdk::Texture::static_type()) {
- // There is an image in the clipboard.
- match clipboard
- .read_value_future(gdk::Texture::static_type(), glib::PRIORITY_DEFAULT)
- .await
- {
- Ok(value) => match value.get::<gdk::Texture>() {
- Ok(texture) => {
- self.send_image(texture).await;
- return;
- }
- Err(error) => warn!("Could not get GdkTexture from value: {error:?}"),
- },
- Err(error) => warn!("Could not get GdkTexture from the clipboard: {error:?}"),
- }
-
- if let Some(window) = self
- .root()
- .as_ref()
- .and_then(|root| root.downcast_ref::<Window>())
- {
- window.add_toast(&Toast::new(&gettext("Error getting image from clipboard")));
- }
- } else if formats.contains_type(gio::File::static_type()) {
- // There is a file in the clipboard.
- match clipboard
- .read_value_future(gio::File::static_type(), glib::PRIORITY_DEFAULT)
- .await
- {
- Ok(value) => match value.get::<gio::File>() {
- Ok(file) => {
- self.send_file(file).await;
- return;
- }
- Err(error) => warn!("Could not get file from value: {error:?}"),
- },
- Err(error) => warn!("Could not get file from the clipboard: {error:?}"),
- }
-
- if let Some(window) = self
- .root()
- .as_ref()
- .and_then(|root| root.downcast_ref::<Window>())
- {
- window.add_toast(&Toast::new(&gettext("Error getting file from clipboard")));
- }
- }
- }
-
- pub fn handle_paste_action(&self) {
- spawn!(glib::clone!(@weak self as obj => async move {
- obj.read_clipboard().await;
- }));
- }
-
pub fn new() -> Self {
glib::Object::new(&[]).expect("Failed to create RoomHistory")
}
@@ -764,45 +705,6 @@ impl RoomHistory {
self.start_loading();
}
- fn setup_drop_target(&self) {
- let priv_ = imp::RoomHistory::from_instance(self);
-
- let target = gtk::DropTarget::new(
- gio::File::static_type(),
- gdk::DragAction::COPY | gdk::DragAction::MOVE,
- );
-
- target.connect_drop(
- clone!(@weak self as obj => @default-return false, move |_, value, _, _| {
- match value.get::<gio::File>() {
- Ok(file) => {
- spawn!(clone!(@weak obj => async move {
- obj.send_file(file).await;
- }));
- true
- }
- Err(error) => {
- warn!("Could not get file from drop: {error:?}");
-
- if let Some(window) = obj
- .root()
- .as_ref()
- .and_then(|root| root.downcast_ref::<Window>())
- {
- window.add_toast(
- &Toast::new(&gettext("Error getting file from drop"))
- );
- }
-
- false
- }
- }
- }),
- );
-
- priv_.drag_overlay.set_drop_target(&target);
- }
-
fn open_emoji(&self) {
self.imp().message_entry.emit_insert_emoji();
}
@@ -960,6 +862,104 @@ impl RoomHistory {
}
}
+ fn setup_drop_target(&self) {
+ let priv_ = imp::RoomHistory::from_instance(self);
+
+ let target = gtk::DropTarget::new(
+ gio::File::static_type(),
+ gdk::DragAction::COPY | gdk::DragAction::MOVE,
+ );
+
+ target.connect_drop(
+ clone!(@weak self as obj => @default-return false, move |_, value, _, _| {
+ match value.get::<gio::File>() {
+ Ok(file) => {
+ spawn!(clone!(@weak obj => async move {
+ obj.send_file(file).await;
+ }));
+ true
+ }
+ Err(error) => {
+ warn!("Could not get file from drop: {error:?}");
+
+ if let Some(window) = obj
+ .root()
+ .as_ref()
+ .and_then(|root| root.downcast_ref::<Window>())
+ {
+ window.add_toast(
+ &Toast::new(&gettext("Error getting file from drop"))
+ );
+ }
+
+ false
+ }
+ }
+ }),
+ );
+
+ priv_.drag_overlay.set_drop_target(&target);
+ }
+
+ async fn read_clipboard(&self) {
+ let clipboard = self.clipboard();
+ let formats = clipboard.formats();
+
+ if formats.contains_type(gdk::Texture::static_type()) {
+ // There is an image in the clipboard.
+ match clipboard
+ .read_value_future(gdk::Texture::static_type(), glib::PRIORITY_DEFAULT)
+ .await
+ {
+ Ok(value) => match value.get::<gdk::Texture>() {
+ Ok(texture) => {
+ self.send_image(texture).await;
+ return;
+ }
+ Err(error) => warn!("Could not get GdkTexture from value: {error:?}"),
+ },
+ Err(error) => warn!("Could not get GdkTexture from the clipboard: {error:?}"),
+ }
+
+ if let Some(window) = self
+ .root()
+ .as_ref()
+ .and_then(|root| root.downcast_ref::<Window>())
+ {
+ window.add_toast(&Toast::new(&gettext("Error getting image from clipboard")));
+ }
+ } else if formats.contains_type(gio::File::static_type()) {
+ // There is a file in the clipboard.
+ match clipboard
+ .read_value_future(gio::File::static_type(), glib::PRIORITY_DEFAULT)
+ .await
+ {
+ Ok(value) => match value.get::<gio::File>() {
+ Ok(file) => {
+ self.send_file(file).await;
+ return;
+ }
+ Err(error) => warn!("Could not get file from value: {error:?}"),
+ },
+ Err(error) => warn!("Could not get file from the clipboard: {error:?}"),
+ }
+
+ if let Some(window) = self
+ .root()
+ .as_ref()
+ .and_then(|root| root.downcast_ref::<Window>())
+ {
+ window.add_toast(&Toast::new(&gettext("Error getting file from clipboard")));
+ }
+ }
+ }
+
+ pub fn handle_paste_action(&self) {
+ spawn!(glib::clone!(@weak self as obj => async move {
+ obj.read_clipboard().await;
+ }));
+ }
+
pub fn item_context_menu(&self) -> >k::PopoverMenu {
self.imp()
.item_context_menu
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]