Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion po/POTFILES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
src/Application.vala
src/Window.vala
src/Utils.vala
src/Utils.vala
src/UndoRedoButtons.vala
48 changes: 48 additions & 0 deletions src/UndoRedoButtons.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2025 William Kelso <wpkelso@posteo.net>
*/

public class UndoRedoButtons : Gtk.Box {

public Gtk.TextBuffer buffer {get; construct;}

public UndoRedoButtons (Gtk.TextBuffer buffer) {
Object (buffer: buffer);
}

construct {
orientation = Gtk.Orientation.HORIZONTAL;
spacing = 0;

var undo = new Gtk.Button.from_icon_name ("edit-undo") {
tooltip_markup = Granite.markup_accel_tooltip (
{"<Ctrl>Z"},
_("Undo last change")
)
};
append (undo);

var redo = new Gtk.Button.from_icon_name ("edit-redo") {
tooltip_markup = Granite.markup_accel_tooltip (
{"<Ctrl><Shift>Z"},
_("Redo last change")
)
};
append (redo);

add_css_class (Granite.STYLE_CLASS_LINKED);

undo.clicked.connect (buffer.undo);
redo.clicked.connect (buffer.redo);

buffer.bind_property ("can_undo",
undo, "sensitive",
GLib.BindingFlags.SYNC_CREATE);

buffer.bind_property ("can_redo",
redo, "sensitive",
GLib.BindingFlags.SYNC_CREATE);

}
}
6 changes: 6 additions & 0 deletions src/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 UndoRedoButtons (buf));

header.pack_end (toolbar_box);

var scrolled_view = new Gtk.ScrolledWindow () {
child = text_view,
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ sources += files(
'Window.vala',
'Application.vala',
'Utils.vala',
'UndoRedoButtons.vala',
)