Skip to content

Commit

Permalink
feat: Adding toast when copying the content to the clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaTechnolog committed Oct 30, 2024
1 parent 8217227 commit c803c2d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/widgets/export_tab/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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::<CarteroWindow>().unwrap(),
None => CarteroWindow::new(&app),
};

window.toast_message("Content copied to the clipboard");
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemPane> {
let pages = self.tabview.pages();
let count = pages.n_items();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c803c2d

Please sign in to comment.