Skip to content

Commit ec6ac87

Browse files
authored
Add support for disabled menu items on gtk. (#897)
1 parent 3846a83 commit ec6ac87

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ While some features like the clipboard, menus or file dialogs are not yet availa
6868
- Windows: Termiate app when all windows have closed. ([#763] by [@xStrom])
6969
- macOS: `Application::quit` now quits the run loop instead of killing the process. ([#763] by [@xStrom])
7070
- macOS/GTK/web: `MouseButton::X1` and `MouseButton::X2` clicks are now recognized. ([#843] by [@xStrom])
71+
- GTK: Support disabled menu items ([#897] by [@jneem])
7172

7273
### Visual
7374

@@ -139,8 +140,9 @@ While some features like the clipboard, menus or file dialogs are not yet availa
139140
[#861]: https://github.com/xi-editor/druid/pull/861
140141
[#869]: https://github.com/xi-editor/druid/pull/869
141142
[#878]: https://github.com/xi-editor/druid/pull/878
142-
[#889]: https://github.com/xi-editor/druid/pull/899
143+
[#889]: https://github.com/xi-editor/druid/pull/889
143144
[#894]: https://github.com/xi-editor/druid/pull/894
145+
[#897]: https://github.com/xi-editor/druid/pull/897
144146
[#898]: https://github.com/xi-editor/druid/pull/898
145147

146148
## [0.5.0] - 2020-04-01

druid-shell/src/platform/gtk/menu.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ pub struct Menu {
3232

3333
#[derive(Debug)]
3434
enum MenuItem {
35-
Entry(String, u32, Option<HotKey>),
35+
Entry {
36+
name: String,
37+
id: u32,
38+
key: Option<HotKey>,
39+
enabled: bool,
40+
},
3641
SubMenu(String, Menu),
3742
Separator,
3843
}
@@ -57,12 +62,16 @@ impl Menu {
5762
id: u32,
5863
text: &str,
5964
key: Option<&HotKey>,
60-
_enabled: bool,
65+
enabled: bool,
6166
_selected: bool,
6267
) {
63-
// TODO: implement enabled, selected item
64-
self.items
65-
.push(MenuItem::Entry(strip_access_key(text), id, key.cloned()));
68+
// TODO: implement selected items
69+
self.items.push(MenuItem::Entry {
70+
name: strip_access_key(text),
71+
id,
72+
key: key.cloned(),
73+
enabled,
74+
});
6675
}
6776

6877
pub fn add_separator(&mut self) {
@@ -77,8 +86,14 @@ impl Menu {
7786
) {
7887
for item in self.items {
7988
match item {
80-
MenuItem::Entry(name, id, key) => {
89+
MenuItem::Entry {
90+
name,
91+
id,
92+
key,
93+
enabled,
94+
} => {
8195
let item = GtkMenuItem::new_with_label(&name);
96+
item.set_sensitive(enabled);
8297

8398
if let Some(k) = key {
8499
register_accelerator(&item, accel_group, k);

0 commit comments

Comments
 (0)