From c803c2d6665d689a88b105134d254f6ab09337f1 Mon Sep 17 00:00:00 2001 From: Gabriel Guerra Date: Wed, 30 Oct 2024 15:07:35 -0400 Subject: [PATCH] feat: Adding toast when copying the content to the clipboard --- src/widgets/export_tab/code.rs | 10 ++++++++++ src/win.rs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/widgets/export_tab/code.rs b/src/widgets/export_tab/code.rs index 78a20b2..21c68db 100644 --- a/src/widgets/export_tab/code.rs +++ b/src/widgets/export_tab/code.rs @@ -37,6 +37,7 @@ mod imp { use crate::app::CarteroApplication; use crate::widgets::{BaseExportPane, BaseExportPaneImpl, ExportType}; + use crate::win::CarteroWindow; #[derive(Default, CompositeTemplate, Properties)] #[properties(wrapper_type = super::CodeExportPane)] @@ -101,6 +102,15 @@ mod imp { let buf_contents = self.buffer_content(); let contents = String::from_utf8_lossy(buf_contents.as_ref()); clipboard.set_text(contents.as_ref()); + + let app = CarteroApplication::get(); + + let window = match app.active_window() { + Some(window) => window.downcast::().unwrap(), + None => CarteroWindow::new(&app), + }; + + window.toast_message("Content copied to the clipboard"); } } diff --git a/src/win.rs b/src/win.rs index b253860..992042a 100644 --- a/src/win.rs +++ b/src/win.rs @@ -316,6 +316,11 @@ mod imp { self.toaster.add_toast(toast); } + pub(super) fn toast_message(&self, msg: &str) { + let toast = adw::Toast::new(msg); + self.toaster.add_toast(toast); + } + fn get_modified_panes(&self) -> Vec { let pages = self.tabview.pages(); let count = pages.n_items(); @@ -592,6 +597,11 @@ impl CarteroWindow { imp.toast_error(e); } + pub fn toast_message(&self, msg: &str) { + let imp = self.imp(); + imp.toast_message(msg); + } + pub fn sync_open_files(&self) { let imp = self.imp(); imp.save_visible_tabs();