Skip to content

Commit

Permalink
Send toast when text copied
Browse files Browse the repository at this point in the history
  • Loading branch information
ryonakano committed Nov 23, 2023
1 parent c3b9f87 commit c9ee0f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/

public class MainWindow : Gtk.ApplicationWindow {
private Granite.Toast toast;

public MainWindow (Application app) {
Object (
application: app,
Expand Down Expand Up @@ -34,6 +36,12 @@ public class MainWindow : Gtk.ApplicationWindow {
main_box.append (separator);
main_box.append (result_combo_entry);

toast = new Granite.Toast (_("Text copied!"));

var overlay = new Gtk.Overlay ();
overlay.add_overlay (main_box);
overlay.add_overlay (toast);

var preferences_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6) {
margin_top = 12,
margin_bottom = 12,
Expand All @@ -56,8 +64,15 @@ public class MainWindow : Gtk.ApplicationWindow {
header.pack_end (preferences_button);
set_titlebar (header);

child = main_box;
child = overlay;

source_combo_entry.source_view.grab_focus ();

source_combo_entry.text_copied.connect (show_toast);
result_combo_entry.text_copied.connect (show_toast);
}

private void show_toast () {
toast.send_notification ();
}
}
3 changes: 3 additions & 0 deletions src/Widgets/ComboEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/

public class Widgets.ComboEntry : Gtk.Grid {
public signal void text_copied ();

public string id { get; construct; }
public string description { get; construct; }
public bool editable { get; construct; }
Expand Down Expand Up @@ -112,6 +114,7 @@ public class Widgets.ComboEntry : Gtk.Grid {

copy_clipboard_button.clicked.connect (() => {
get_clipboard ().set_text (source_buffer.text);
text_copied ();
});

var gtk_settings = Gtk.Settings.get_default ();
Expand Down

0 comments on commit c9ee0f3

Please sign in to comment.