From 5550a287894198963f19a816fa42b32175806a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 5 Sep 2024 15:59:25 -0700 Subject: [PATCH 1/2] Add PopoverMenuitem --- meson.build | 1 + src/MainWindow.vala | 4 ++-- src/Widgets/EntryPopover/DateTime.vala | 2 +- src/Widgets/ListSettingsPopover.vala | 13 ++++-------- src/Widgets/PopoverMenuitem.vala | 29 ++++++++++++++++++++++++++ 5 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 src/Widgets/PopoverMenuitem.vala diff --git a/meson.build b/meson.build index 4ee94be3b..a634abf08 100644 --- a/meson.build +++ b/meson.build @@ -72,6 +72,7 @@ executable( 'src/Widgets/EntryPopover/DateTime.vala', 'src/Widgets/EntryPopover/Generic.vala', 'src/Widgets/EntryPopover/Location.vala', + 'src/Widgets/PopoverMenuitem.vala', 'src/Widgets/ScheduledRow.vala', 'src/Widgets/SourceRow.vala', 'src/Widgets/ScheduledTaskListBox.vala', diff --git a/src/MainWindow.vala b/src/MainWindow.vala index a54f36dd5..b00d46ebb 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -80,7 +80,7 @@ public class Tasks.MainWindow : Hdy.ApplicationWindow { add_tasklist_buttonbox = new Gtk.Box (VERTICAL, 3); - var online_accounts_button = new Gtk.ModelButton () { + var online_accounts_button = new PopoverMenuitem () { text = _("Online Accounts Settings…") }; @@ -389,7 +389,7 @@ public class Tasks.MainWindow : Hdy.ApplicationWindow { } collection_sources.add (collection_source); - var source_button = new Gtk.ModelButton () { + var source_button = new PopoverMenuitem () { text = Util.get_esource_collection_display_name (collection_source), sensitive = Application.model.is_add_task_list_supported (collection_source) }; diff --git a/src/Widgets/EntryPopover/DateTime.vala b/src/Widgets/EntryPopover/DateTime.vala index e74fb968c..151fb9b4b 100644 --- a/src/Widgets/EntryPopover/DateTime.vala +++ b/src/Widgets/EntryPopover/DateTime.vala @@ -42,7 +42,7 @@ public class Tasks.Widgets.EntryPopover.DateTime : Generic { margin_top = 3 }; - var today_button = new Gtk.ModelButton () { + var today_button = new PopoverMenuitem () { text = _("Today") }; diff --git a/src/Widgets/ListSettingsPopover.vala b/src/Widgets/ListSettingsPopover.vala index f7e62e894..e74dbab83 100644 --- a/src/Widgets/ListSettingsPopover.vala +++ b/src/Widgets/ListSettingsPopover.vala @@ -82,15 +82,10 @@ public class Tasks.Widgets.ListSettingsPopover : Gtk.Popover { margin_top = 3 }; - var delete_list_accel_label = new Granite.AccelLabel.from_action_name ( - _("Delete List…"), - MainWindow.ACTION_PREFIX + MainWindow.ACTION_DELETE_SELECTED_LIST - ); - - var delete_list_menuitem = new Gtk.ModelButton (); - delete_list_menuitem.action_name = delete_list_accel_label.action_name; - delete_list_menuitem.get_child ().destroy (); - delete_list_menuitem.add (delete_list_accel_label); + var delete_list_menuitem = new PopoverMenuitem () { + action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_DELETE_SELECTED_LIST, + text = _("Delete List…") + }; delete_list_menuitem.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION); var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) { diff --git a/src/Widgets/PopoverMenuitem.vala b/src/Widgets/PopoverMenuitem.vala new file mode 100644 index 000000000..1fcb4dbad --- /dev/null +++ b/src/Widgets/PopoverMenuitem.vala @@ -0,0 +1,29 @@ +/* + * Copyright 2024 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +class Tasks.PopoverMenuitem : Gtk.Button { + public string text { + set { + child = new Granite.AccelLabel (value) { + action_name = this.action_name + }; + } + } + + class construct { + set_css_name ("modelbutton"); + } + + construct { + set_accessible_role (Atk.Role.MENU_ITEM); + + clicked.connect (() => { + var popover = (Gtk.Popover) get_ancestor (typeof (Gtk.Popover)); + if (popover != null) { + popover.popdown (); + } + }); + } +} From 9f9d78d5c792801a3274cd8e65663c72c5b1b3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 5 Sep 2024 16:03:43 -0700 Subject: [PATCH 2/2] Set accessible label --- src/Widgets/PopoverMenuitem.vala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Widgets/PopoverMenuitem.vala b/src/Widgets/PopoverMenuitem.vala index 1fcb4dbad..bf6dd6589 100644 --- a/src/Widgets/PopoverMenuitem.vala +++ b/src/Widgets/PopoverMenuitem.vala @@ -9,6 +9,8 @@ class Tasks.PopoverMenuitem : Gtk.Button { child = new Granite.AccelLabel (value) { action_name = this.action_name }; + + get_accessible ().accessible_name = value; } }