mirror of
https://github.com/italicsjenga/muda.git
synced 2025-01-11 20:31:32 +11:00
fix(Windows): dispatch menu event for icon menu item (#53)
* fix(Windows): dispatch menu event for icon menu item * default dispatch to true and improve about dialog
This commit is contained in:
parent
ded3dfaf95
commit
88d352033b
5
.changes/icon-menu-item-dispatch.md
Normal file
5
.changes/icon-menu-item-dispatch.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"muda": "patch"
|
||||||
|
---
|
||||||
|
|
||||||
|
On Windows, fix `MenuEvent` not triggered for `IconMenuItem`.
|
|
@ -1074,17 +1074,17 @@ unsafe extern "system" fn menu_subclass_proc(
|
||||||
if let Some(item) = item {
|
if let Some(item) = item {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
let mut dispatch = false;
|
let mut dispatch = true;
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut item = item.borrow_mut();
|
let mut item = item.borrow_mut();
|
||||||
match item.type_ {
|
|
||||||
MenuItemType::Normal => {
|
|
||||||
dispatch = true;
|
|
||||||
}
|
|
||||||
MenuItemType::Check => {
|
|
||||||
dispatch = true;
|
|
||||||
|
|
||||||
|
if item.type_ == MenuItemType::Predefined {
|
||||||
|
dispatch = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
match item.type_ {
|
||||||
|
MenuItemType::Check => {
|
||||||
let checked = !item.checked;
|
let checked = !item.checked;
|
||||||
item.set_checked(checked);
|
item.set_checked(checked);
|
||||||
}
|
}
|
||||||
|
@ -1112,35 +1112,46 @@ unsafe extern "system" fn menu_subclass_proc(
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
}
|
}
|
||||||
PredfinedMenuItemType::About(Some(metadata)) => {
|
PredfinedMenuItemType::About(Some(metadata)) => {
|
||||||
MessageBoxW(
|
use std::fmt::Write;
|
||||||
hwnd,
|
|
||||||
encode_wide(format!(
|
let mut message = String::new();
|
||||||
r#"
|
if let Some(name) = &metadata.name {
|
||||||
{}
|
let _ = writeln!(&mut message, "Name: {}", name);
|
||||||
version: {}
|
}
|
||||||
authors: {}
|
if let Some(version) = &metadata.version {
|
||||||
license: {}
|
let _ = writeln!(&mut message, "Version: {}", version);
|
||||||
website: {} {}
|
}
|
||||||
{}
|
if let Some(authors) = &metadata.authors {
|
||||||
{}
|
let _ = writeln!(&mut message, "Authors: {}", authors.join(", "));
|
||||||
"#,
|
}
|
||||||
metadata.name.as_deref().unwrap_or_default(),
|
if let Some(license) = &metadata.license {
|
||||||
metadata.version.as_deref().unwrap_or_default(),
|
let _ = writeln!(&mut message, "License: {}", license);
|
||||||
metadata.authors.as_deref().unwrap_or_default().join(","),
|
}
|
||||||
metadata.license.as_deref().unwrap_or_default(),
|
match (&metadata.website_label, &metadata.website) {
|
||||||
metadata.website_label.as_deref().unwrap_or_default(),
|
(Some(label), None) => {
|
||||||
metadata.website.as_deref().unwrap_or_default(),
|
let _ = writeln!(&mut message, "Website: {}", label);
|
||||||
metadata.comments.as_deref().unwrap_or_default(),
|
}
|
||||||
metadata.copyright.as_deref().unwrap_or_default(),
|
(None, Some(url)) => {
|
||||||
))
|
let _ = writeln!(&mut message, "Website: {}", url);
|
||||||
.as_ptr(),
|
}
|
||||||
encode_wide(format!(
|
(Some(label), Some(url)) => {
|
||||||
|
let _ = writeln!(&mut message, "Website: {} {}", label, url);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
if let Some(comments) = &metadata.comments {
|
||||||
|
let _ = writeln!(&mut message, "\n{}", comments);
|
||||||
|
}
|
||||||
|
if let Some(copyright) = &metadata.copyright {
|
||||||
|
let _ = writeln!(&mut message, "\n{}", copyright);
|
||||||
|
}
|
||||||
|
|
||||||
|
let message = encode_wide(message);
|
||||||
|
let title = encode_wide(format!(
|
||||||
"About {}",
|
"About {}",
|
||||||
metadata.name.as_deref().unwrap_or_default()
|
metadata.name.as_deref().unwrap_or_default()
|
||||||
))
|
));
|
||||||
.as_ptr(),
|
MessageBoxW(hwnd, message.as_ptr(), title.as_ptr(), MB_ICONINFORMATION);
|
||||||
MB_ICONINFORMATION,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
Loading…
Reference in a new issue