From 547def7bee15c3d18b77d2684a8931f94193ba2a Mon Sep 17 00:00:00 2001 From: lenemter Date: Sun, 12 Mar 2023 19:50:30 +0900 Subject: [PATCH 1/4] Copy shortcut --- src/MainWindow.vala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index de48f131..ff4270fa 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -52,12 +52,14 @@ public class PantheonCalculator.MainWindow : Gtk.ApplicationWindow { public const string ACTION_INSERT = "action-insert"; public const string ACTION_FUNCTION = "action-function"; public const string ACTION_UNDO = "action-undo"; + public const string ACTION_COPY = "action-copy"; private const ActionEntry[] ACTION_ENTRIES = { { ACTION_INSERT, action_insert, "s"}, { ACTION_FUNCTION, action_function, "s"}, { ACTION_CLEAR, action_clear }, - { ACTION_UNDO, undo } + { ACTION_UNDO, undo }, + { ACTION_COPY, copy } }; static construct { @@ -74,6 +76,7 @@ public class PantheonCalculator.MainWindow : Gtk.ApplicationWindow { var application_instance = (Gtk.Application) GLib.Application.get_default (); application_instance.set_accels_for_action (ACTION_PREFIX + ACTION_CLEAR, {"Escape"}); application_instance.set_accels_for_action (ACTION_PREFIX + ACTION_UNDO, {"z"}); + application_instance.set_accels_for_action (ACTION_PREFIX + ACTION_COPY, {"c"}); resizable = false; title = _("Calculator"); @@ -503,6 +506,17 @@ public class PantheonCalculator.MainWindow : Gtk.ApplicationWindow { } } + public void copy () { + unowned var clipboard = display.get_clipboard (); + int start, end; + entry.get_selection_bounds (out start, out end); + var text_selected = end - start != 0; + warning ("%u %d %b", start, end, text_selected); + if(!text_selected) { + warning ("Copying text"); + clipboard.set_text (entry.text); + } + } private void action_insert (SimpleAction action, Variant? variant) { var token = variant.get_string (); int new_position = entry.get_position (); From bf02acfddfce7848e4369d82fe3d6162ecc1fef5 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sun, 12 Mar 2023 19:59:51 +0900 Subject: [PATCH 2/4] Fix --- src/MainWindow.vala | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index ff4270fa..b0b0a4b5 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -507,16 +507,19 @@ public class PantheonCalculator.MainWindow : Gtk.ApplicationWindow { } public void copy () { - unowned var clipboard = display.get_clipboard (); int start, end; entry.get_selection_bounds (out start, out end); var text_selected = end - start != 0; - warning ("%u %d %b", start, end, text_selected); + + // we have to copy text in both cases + // because seems like application action block entry's action if(!text_selected) { - warning ("Copying text"); - clipboard.set_text (entry.text); + entry.get_clipboard ().set_text (entry.text); + } else { + entry.get_clipboard ().set_text (entry.text.slice (start, end)); } } + private void action_insert (SimpleAction action, Variant? variant) { var token = variant.get_string (); int new_position = entry.get_position (); From d4dbccdb09dc45134f47591cbaad40c081a596d2 Mon Sep 17 00:00:00 2001 From: lenemter Date: Sun, 12 Mar 2023 20:00:48 +0900 Subject: [PATCH 3/4] Fix --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index b0b0a4b5..e53a59be 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -512,7 +512,7 @@ public class PantheonCalculator.MainWindow : Gtk.ApplicationWindow { var text_selected = end - start != 0; // we have to copy text in both cases - // because seems like application action block entry's action + // because seems like application action blocks entry's action if(!text_selected) { entry.get_clipboard ().set_text (entry.text); } else { From ce6c94b9280a1cec7096e0554f7f439173e43abf Mon Sep 17 00:00:00 2001 From: lenemter Date: Sun, 12 Mar 2023 20:02:26 +0900 Subject: [PATCH 4/4] Fix lint --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index e53a59be..10ff6928 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -513,7 +513,7 @@ public class PantheonCalculator.MainWindow : Gtk.ApplicationWindow { // we have to copy text in both cases // because seems like application action blocks entry's action - if(!text_selected) { + if (!text_selected) { entry.get_clipboard ().set_text (entry.text); } else { entry.get_clipboard ().set_text (entry.text.slice (start, end));