Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for disabled menu items on gtk. #897

Merged
merged 4 commits into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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