From 4926ca91de8b77181afd3de269ab150387fdaaf7 Mon Sep 17 00:00:00 2001 From: oscfdezdz <42654671+oscfdezdz@users.noreply.github.com> Date: Sun, 9 Apr 2023 01:51:54 +0200 Subject: [PATCH] Add custom actions symbolic icons Using gresource file and based on the suggestions for the merge menu made in https://github.com/MightyCreak/diffuse/issues/90. --- data/diffuse.gresource.xml | 11 ++++++++++ .../copy-left-into-selection-symbolic.svg | 2 ++ .../copy-right-into-selection-symbolic.svg | 2 ++ .../actions/copy-selection-left-symbolic.svg | 2 ++ .../actions/copy-selection-right-symbolic.svg | 2 ++ .../actions/new-2way-merge-symbolic.svg | 2 ++ .../actions/new-3way-merge-symbolic.svg | 2 ++ data/meson.build | 8 +++++++ src/diffuse/diffuse.in | 8 +++++++ src/diffuse/window.py | 21 ++++++++----------- 10 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 data/diffuse.gresource.xml create mode 100644 data/icons/hicolor/scalable/actions/copy-left-into-selection-symbolic.svg create mode 100644 data/icons/hicolor/scalable/actions/copy-right-into-selection-symbolic.svg create mode 100644 data/icons/hicolor/scalable/actions/copy-selection-left-symbolic.svg create mode 100644 data/icons/hicolor/scalable/actions/copy-selection-right-symbolic.svg create mode 100644 data/icons/hicolor/scalable/actions/new-2way-merge-symbolic.svg create mode 100644 data/icons/hicolor/scalable/actions/new-3way-merge-symbolic.svg diff --git a/data/diffuse.gresource.xml b/data/diffuse.gresource.xml new file mode 100644 index 0000000..bc602bb --- /dev/null +++ b/data/diffuse.gresource.xml @@ -0,0 +1,11 @@ + + + + icons/hicolor/scalable/actions/new-2way-merge-symbolic.svg + icons/hicolor/scalable/actions/new-3way-merge-symbolic.svg + icons/hicolor/scalable/actions/copy-selection-left-symbolic.svg + icons/hicolor/scalable/actions/copy-selection-right-symbolic.svg + icons/hicolor/scalable/actions/copy-left-into-selection-symbolic.svg + icons/hicolor/scalable/actions/copy-right-into-selection-symbolic.svg + + diff --git a/data/icons/hicolor/scalable/actions/copy-left-into-selection-symbolic.svg b/data/icons/hicolor/scalable/actions/copy-left-into-selection-symbolic.svg new file mode 100644 index 0000000..14dc140 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/copy-left-into-selection-symbolic.svg @@ -0,0 +1,2 @@ + + diff --git a/data/icons/hicolor/scalable/actions/copy-right-into-selection-symbolic.svg b/data/icons/hicolor/scalable/actions/copy-right-into-selection-symbolic.svg new file mode 100644 index 0000000..126d701 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/copy-right-into-selection-symbolic.svg @@ -0,0 +1,2 @@ + + diff --git a/data/icons/hicolor/scalable/actions/copy-selection-left-symbolic.svg b/data/icons/hicolor/scalable/actions/copy-selection-left-symbolic.svg new file mode 100644 index 0000000..55890ed --- /dev/null +++ b/data/icons/hicolor/scalable/actions/copy-selection-left-symbolic.svg @@ -0,0 +1,2 @@ + + diff --git a/data/icons/hicolor/scalable/actions/copy-selection-right-symbolic.svg b/data/icons/hicolor/scalable/actions/copy-selection-right-symbolic.svg new file mode 100644 index 0000000..88a9e9e --- /dev/null +++ b/data/icons/hicolor/scalable/actions/copy-selection-right-symbolic.svg @@ -0,0 +1,2 @@ + + diff --git a/data/icons/hicolor/scalable/actions/new-2way-merge-symbolic.svg b/data/icons/hicolor/scalable/actions/new-2way-merge-symbolic.svg new file mode 100644 index 0000000..35d079d --- /dev/null +++ b/data/icons/hicolor/scalable/actions/new-2way-merge-symbolic.svg @@ -0,0 +1,2 @@ + + diff --git a/data/icons/hicolor/scalable/actions/new-3way-merge-symbolic.svg b/data/icons/hicolor/scalable/actions/new-3way-merge-symbolic.svg new file mode 100644 index 0000000..2fb375c --- /dev/null +++ b/data/icons/hicolor/scalable/actions/new-3way-merge-symbolic.svg @@ -0,0 +1,2 @@ + + diff --git a/data/meson.build b/data/meson.build index 52ed78a..ab3d4d0 100644 --- a/data/meson.build +++ b/data/meson.build @@ -1,4 +1,12 @@ pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name()) +gnome = import('gnome') + +gnome.compile_resources(meson.project_name(), + meson.project_name() + '.gresource.xml', + gresource_bundle: true, + install: true, + install_dir: pkgdatadir, +) if build_machine.system() == 'linux' desktop_file = i18n.merge_file( diff --git a/src/diffuse/diffuse.in b/src/diffuse/diffuse.in index 4a60c6b..7f405a6 100755 --- a/src/diffuse/diffuse.in +++ b/src/diffuse/diffuse.in @@ -19,9 +19,12 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import os import sys import gettext +from gi.repository import Gio + VERSION = '@VERSION@' PKGDATADIR = '@PKGDATADIR@' LOCALEDIR = '@LOCALEDIR@' @@ -34,4 +37,9 @@ gettext.textdomain('diffuse') if __name__ == '__main__': from diffuse import main + + resource = Gio.resource_load( + os.path.join(PKGDATADIR, 'diffuse.gresource')) + Gio.Resource._register(resource) + sys.exit(main.main(VERSION, SYSCONFIGDIR)) diff --git a/src/diffuse/window.py b/src/diffuse/window.py index b3be3af..b1dda3b 100644 --- a/src/diffuse/window.py +++ b/src/diffuse/window.py @@ -914,8 +914,8 @@ class DiffuseWindow(Gtk.ApplicationWindow): # create toolbar hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) button_specs = [ - [DIFFUSE_STOCK_NEW_2WAY_MERGE, self.new_2_way_file_merge_cb, None, _('New 2-Way File Merge')], # noqa: E501 - [DIFFUSE_STOCK_NEW_3WAY_MERGE, self.new_3_way_file_merge_cb, None, _('New 3-Way File Merge')], # noqa: E501 + ['new-2way-merge-symbolic', self.new_2_way_file_merge_cb, None, _('New 2-Way File Merge')], # noqa: E501 + ['new-3way-merge-symbolic', self.new_3_way_file_merge_cb, None, _('New 3-Way File Merge')], # noqa: E501 [], ['system-run-symbolic', self.button_cb, 'realign-all', _('Realign All')], ['go-top-symbolic', self.button_cb, 'first-difference', _('First Difference')], @@ -923,12 +923,12 @@ class DiffuseWindow(Gtk.ApplicationWindow): ['go-down-symbolic', self.button_cb, 'next-difference', _('Next Difference')], ['go-bottom-symbolic', self.button_cb, 'last-difference', _('Last Difference')], [], - ['go-last-symbolic', self.button_cb, 'copy-selection-right', _('Copy Selection Right')], # noqa: E501 - ['go-first-symbolic', self.button_cb, 'copy-selection-left', _('Copy Selection Left')], - ['go-next-symbolic', self.button_cb, 'copy-left-into-selection', _('Copy Left Into Selection')], # noqa: E501 - ['go-previous-symbolic', self.button_cb, 'copy-right-into-selection', _('Copy Right Into Selection')], # noqa: E501 - [DIFFUSE_STOCK_LEFT_RIGHT, self.button_cb, 'merge-from-left-then-right', _('Merge From Left Then Right')], # noqa: E501 - [DIFFUSE_STOCK_RIGHT_LEFT, self.button_cb, 'merge-from-right-then-left', _('Merge From Right Then Left')], # noqa: E501 + ['copy-selection-right-symbolic', self.button_cb, 'copy-selection-right', _('Copy Selection Right')], # noqa: E501 + ['copy-selection-left-symbolic', self.button_cb, 'copy-selection-left', _('Copy Selection Left')], # noqa: E501 + ['copy-left-into-selection-symbolic', self.button_cb, 'copy-left-into-selection', _('Copy Left Into Selection')], # noqa: E501 + ['copy-right-into-selection-symbolic', self.button_cb, 'copy-right-into-selection', _('Copy Right Into Selection')], # noqa: E501 + ['document-revert-rtl-symbolic', self.button_cb, 'merge-from-left-then-right', _('Merge From Left Then Right')], # noqa: E501 + ['document-revert-symbolic', self.button_cb, 'merge-from-right-then-left', _('Merge From Right Then Left')], # noqa: E501 [], ['edit-undo-symbolic', self.button_cb, 'undo', _('Undo')], ['edit-redo-symbolic', self.button_cb, 'redo', _('Redo')], @@ -1811,10 +1811,7 @@ def _append_buttons(box, size, specs): button.set_relief(Gtk.ReliefStyle.NONE) button.set_can_focus(False) image = Gtk.Image() - if icon_name.startswith('diffuse'): - image.set_from_stock(icon_name, size) - else: - image.set_from_icon_name(icon_name, size) + image.set_from_icon_name(icon_name, size) button.add(image) image.show() button.connect('clicked', cb, cb_data)