diff --git a/po/POTFILES b/po/POTFILES index 5b1199c..ff1c16f 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -1,3 +1,4 @@ src/Application.vala src/Window.vala -src/Utils.vala \ No newline at end of file +src/Utils.vala +src/CutCopyPasteButtons.vala \ No newline at end of file diff --git a/src/CutCopyPasteButtons.vala b/src/CutCopyPasteButtons.vala new file mode 100644 index 0000000..09dbd22 --- /dev/null +++ b/src/CutCopyPasteButtons.vala @@ -0,0 +1,49 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2025 William Kelso + */ + +public class CutCopyPasteButtons : Gtk.Box { + + public Gtk.TextView textview {get; construct;} + + public CutCopyPasteButtons (Gtk.TextView textview) { + Object (textview: textview); + } + + construct { + orientation = Gtk.Orientation.HORIZONTAL; + spacing = 0; + + var cut = new Gtk.Button.from_icon_name ("edit-cut") { + tooltip_markup = Granite.markup_accel_tooltip ( + {"X"}, + _("Cut selected text") + ) + }; + + var copy = new Gtk.Button.from_icon_name ("edit-copy") { + tooltip_markup = Granite.markup_accel_tooltip ( + {"C"}, + _("Copy selected text") + ) + }; + + var paste = new Gtk.Button.from_icon_name ("edit-paste") { + tooltip_markup = Granite.markup_accel_tooltip ( + {"V"}, + _("Paste from clipboard") + ) + }; + + append (cut); + append (copy); + append (paste); + + add_css_class (Granite.STYLE_CLASS_LINKED); + + cut.clicked.connect (() => {textview.cut_clipboard ();}); + copy.clicked.connect (() => {textview.copy_clipboard ();}); + paste.clicked.connect (() => {textview.paste_clipboard ();}); + } +} diff --git a/src/Window.vala b/src/Window.vala index 60e1481..7bc20a0 100644 --- a/src/Window.vala +++ b/src/Window.vala @@ -65,6 +65,12 @@ public class AppWindow : Gtk.Window { buf = text_view.buffer; buf.text = ""; + // TODO: use Granite.Box (HORIZONTAL, HALF) when granite-7.7.0 is released + var toolbar_box = new Gtk.Box (HORIZONTAL, 8); + + toolbar_box.append (new CutCopyPasteButtons (text_view)); + + header.pack_end (toolbar_box); var scrolled_view = new Gtk.ScrolledWindow () { child = text_view, diff --git a/src/meson.build b/src/meson.build index f5f77ac..7b7c756 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,4 +2,5 @@ sources += files( 'Window.vala', 'Application.vala', 'Utils.vala', + 'CutCopyPasteButtons.vala' )