Skip to content

Commit be61020

Browse files
authored
Add PopoverMenuItem (#607)
1 parent dd0184e commit be61020

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lib/PopoverMenuItem.vala

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-2.0-or-later
3+
* SPDX-FileCopyrightText: 2017-2023 elementary, Inc. (https://elementary.io)
4+
*/
5+
6+
/**
7+
* PopoverMenuItem is a {@link Gtk.Button} subclass for use as a MenuItem in {@link Gtk.Popover}
8+
*
9+
* It will automatically call {@link Gtk.Popover.popdown} on its parent when clicked
10+
*
11+
* It contains a {@link Granite.AccelLabel} which will automatically show
12+
* accelerators for the {@link GLib.Action} assigned to #this
13+
*
14+
* @since 8.0.0
15+
*/
16+
[Version (since = "8.0.0")]
17+
public class Wingpanel.PopoverMenuItem : Gtk.Button {
18+
/**
19+
* The label for the button
20+
*/
21+
public string text {
22+
set {
23+
child = new Granite.AccelLabel (value) {
24+
action_name = this.action_name
25+
};
26+
27+
update_property (Gtk.AccessibleProperty.LABEL, value, -1);
28+
}
29+
}
30+
31+
class construct {
32+
set_css_name ("modelbutton");
33+
}
34+
35+
construct {
36+
accessible_role = MENU_ITEM;
37+
38+
clicked.connect (() => {
39+
var popover = (Gtk.Popover) get_ancestor (typeof (Gtk.Popover));
40+
if (popover != null) {
41+
popover.popdown ();
42+
}
43+
});
44+
}
45+
}

lib/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ libwingpanel_deps = [
1717
gmodule_dep,
1818
gee_dep,
1919
gtk_dep,
20+
granite_dep
2021
]
2122

2223
libwingpanel_lib = library(
2324
'wingpanel-8',
2425
'Indicator.vala',
2526
'IndicatorManager.vala',
27+
'PopoverMenuItem.vala',
2628
config_header,
2729
dependencies: [libwingpanel_deps, config_vapi],
2830
vala_header: 'wingpanel-8.h',

0 commit comments

Comments
 (0)