Skip to content

Commit

Permalink
Add support for disabled menu items on gtk. (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem authored May 3, 2020
1 parent 3846a83 commit ec6ac87
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ While some features like the clipboard, menus or file dialogs are not yet availa
- Windows: Termiate app when all windows have closed. ([#763] by [@xStrom])
- macOS: `Application::quit` now quits the run loop instead of killing the process. ([#763] by [@xStrom])
- macOS/GTK/web: `MouseButton::X1` and `MouseButton::X2` clicks are now recognized. ([#843] by [@xStrom])
- GTK: Support disabled menu items ([#897] by [@jneem])

### Visual

Expand Down Expand Up @@ -139,8 +140,9 @@ While some features like the clipboard, menus or file dialogs are not yet availa
[#861]: https://github.com/xi-editor/druid/pull/861
[#869]: https://github.com/xi-editor/druid/pull/869
[#878]: https://github.com/xi-editor/druid/pull/878
[#889]: https://github.com/xi-editor/druid/pull/899
[#889]: https://github.com/xi-editor/druid/pull/889
[#894]: https://github.com/xi-editor/druid/pull/894
[#897]: https://github.com/xi-editor/druid/pull/897
[#898]: https://github.com/xi-editor/druid/pull/898

## [0.5.0] - 2020-04-01
Expand Down
27 changes: 21 additions & 6 deletions druid-shell/src/platform/gtk/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ pub struct Menu {

#[derive(Debug)]
enum MenuItem {
Entry(String, u32, Option<HotKey>),
Entry {
name: String,
id: u32,
key: Option<HotKey>,
enabled: bool,
},
SubMenu(String, Menu),
Separator,
}
Expand All @@ -57,12 +62,16 @@ impl Menu {
id: u32,
text: &str,
key: Option<&HotKey>,
_enabled: bool,
enabled: bool,
_selected: bool,
) {
// TODO: implement enabled, selected item
self.items
.push(MenuItem::Entry(strip_access_key(text), id, key.cloned()));
// TODO: implement selected items
self.items.push(MenuItem::Entry {
name: strip_access_key(text),
id,
key: key.cloned(),
enabled,
});
}

pub fn add_separator(&mut self) {
Expand All @@ -77,8 +86,14 @@ impl Menu {
) {
for item in self.items {
match item {
MenuItem::Entry(name, id, key) => {
MenuItem::Entry {
name,
id,
key,
enabled,
} => {
let item = GtkMenuItem::new_with_label(&name);
item.set_sensitive(enabled);

if let Some(k) = key {
register_accelerator(&item, accel_group, k);
Expand Down

0 comments on commit ec6ac87

Please sign in to comment.