chore: typo

This commit is contained in:
Amr Bashir 2023-07-27 19:44:50 +03:00
parent c7ec320738
commit 22f2405bb9
No known key found for this signature in database
GPG key ID: BBD7A47A2003FF33
4 changed files with 119 additions and 119 deletions

View file

@ -30,27 +30,27 @@ unsafe impl IsMenuItem for PredefinedMenuItem {
impl PredefinedMenuItem { impl PredefinedMenuItem {
/// Separator menu item /// Separator menu item
pub fn separator() -> PredefinedMenuItem { pub fn separator() -> PredefinedMenuItem {
PredefinedMenuItem::new::<&str>(PredfinedMenuItemType::Separator, None) PredefinedMenuItem::new::<&str>(PredefinedMenuItemType::Separator, None)
} }
/// Copy menu item /// Copy menu item
pub fn copy(text: Option<&str>) -> PredefinedMenuItem { pub fn copy(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Copy, text) PredefinedMenuItem::new(PredefinedMenuItemType::Copy, text)
} }
/// Cut menu item /// Cut menu item
pub fn cut(text: Option<&str>) -> PredefinedMenuItem { pub fn cut(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Cut, text) PredefinedMenuItem::new(PredefinedMenuItemType::Cut, text)
} }
/// Paste menu item /// Paste menu item
pub fn paste(text: Option<&str>) -> PredefinedMenuItem { pub fn paste(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Paste, text) PredefinedMenuItem::new(PredefinedMenuItemType::Paste, text)
} }
/// SelectAll menu item /// SelectAll menu item
pub fn select_all(text: Option<&str>) -> PredefinedMenuItem { pub fn select_all(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::SelectAll, text) PredefinedMenuItem::new(PredefinedMenuItemType::SelectAll, text)
} }
/// Undo menu item /// Undo menu item
@ -59,7 +59,7 @@ impl PredefinedMenuItem {
/// ///
/// - **Windows / Linux:** Unsupported. /// - **Windows / Linux:** Unsupported.
pub fn undo(text: Option<&str>) -> PredefinedMenuItem { pub fn undo(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Undo, text) PredefinedMenuItem::new(PredefinedMenuItemType::Undo, text)
} }
/// Redo menu item /// Redo menu item
/// ///
@ -67,7 +67,7 @@ impl PredefinedMenuItem {
/// ///
/// - **Windows / Linux:** Unsupported. /// - **Windows / Linux:** Unsupported.
pub fn redo(text: Option<&str>) -> PredefinedMenuItem { pub fn redo(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Redo, text) PredefinedMenuItem::new(PredefinedMenuItemType::Redo, text)
} }
/// Minimize window menu item /// Minimize window menu item
@ -76,7 +76,7 @@ impl PredefinedMenuItem {
/// ///
/// - **Linux:** Unsupported. /// - **Linux:** Unsupported.
pub fn minimize(text: Option<&str>) -> PredefinedMenuItem { pub fn minimize(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Minimize, text) PredefinedMenuItem::new(PredefinedMenuItemType::Minimize, text)
} }
/// Maximize window menu item /// Maximize window menu item
@ -85,7 +85,7 @@ impl PredefinedMenuItem {
/// ///
/// - **Linux:** Unsupported. /// - **Linux:** Unsupported.
pub fn maximize(text: Option<&str>) -> PredefinedMenuItem { pub fn maximize(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Maximize, text) PredefinedMenuItem::new(PredefinedMenuItemType::Maximize, text)
} }
/// Fullscreen menu item /// Fullscreen menu item
@ -94,7 +94,7 @@ impl PredefinedMenuItem {
/// ///
/// - **Windows / Linux:** Unsupported. /// - **Windows / Linux:** Unsupported.
pub fn fullscreen(text: Option<&str>) -> PredefinedMenuItem { pub fn fullscreen(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Fullscreen, text) PredefinedMenuItem::new(PredefinedMenuItemType::Fullscreen, text)
} }
/// Hide window menu item /// Hide window menu item
@ -103,7 +103,7 @@ impl PredefinedMenuItem {
/// ///
/// - **Linux:** Unsupported. /// - **Linux:** Unsupported.
pub fn hide(text: Option<&str>) -> PredefinedMenuItem { pub fn hide(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Hide, text) PredefinedMenuItem::new(PredefinedMenuItemType::Hide, text)
} }
/// Hide other windows menu item /// Hide other windows menu item
@ -112,7 +112,7 @@ impl PredefinedMenuItem {
/// ///
/// - **Linux:** Unsupported. /// - **Linux:** Unsupported.
pub fn hide_others(text: Option<&str>) -> PredefinedMenuItem { pub fn hide_others(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::HideOthers, text) PredefinedMenuItem::new(PredefinedMenuItemType::HideOthers, text)
} }
/// Show all app windows menu item /// Show all app windows menu item
@ -121,7 +121,7 @@ impl PredefinedMenuItem {
/// ///
/// - **Windows / Linux:** Unsupported. /// - **Windows / Linux:** Unsupported.
pub fn show_all(text: Option<&str>) -> PredefinedMenuItem { pub fn show_all(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::ShowAll, text) PredefinedMenuItem::new(PredefinedMenuItemType::ShowAll, text)
} }
/// Close window menu item /// Close window menu item
@ -130,7 +130,7 @@ impl PredefinedMenuItem {
/// ///
/// - **Linux:** Unsupported. /// - **Linux:** Unsupported.
pub fn close_window(text: Option<&str>) -> PredefinedMenuItem { pub fn close_window(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::CloseWindow, text) PredefinedMenuItem::new(PredefinedMenuItemType::CloseWindow, text)
} }
/// Quit app menu item /// Quit app menu item
@ -139,12 +139,12 @@ impl PredefinedMenuItem {
/// ///
/// - **Linux:** Unsupported. /// - **Linux:** Unsupported.
pub fn quit(text: Option<&str>) -> PredefinedMenuItem { pub fn quit(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Quit, text) PredefinedMenuItem::new(PredefinedMenuItemType::Quit, text)
} }
/// About app menu item /// About app menu item
pub fn about(text: Option<&str>, metadata: Option<AboutMetadata>) -> PredefinedMenuItem { pub fn about(text: Option<&str>, metadata: Option<AboutMetadata>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::About(metadata), text) PredefinedMenuItem::new(PredefinedMenuItemType::About(metadata), text)
} }
/// Services menu item /// Services menu item
@ -153,10 +153,10 @@ impl PredefinedMenuItem {
/// ///
/// - **Windows / Linux:** Unsupported. /// - **Windows / Linux:** Unsupported.
pub fn services(text: Option<&str>) -> PredefinedMenuItem { pub fn services(text: Option<&str>) -> PredefinedMenuItem {
PredefinedMenuItem::new(PredfinedMenuItemType::Services, text) PredefinedMenuItem::new(PredefinedMenuItemType::Services, text)
} }
fn new<S: AsRef<str>>(item: PredfinedMenuItemType, text: Option<S>) -> Self { fn new<S: AsRef<str>>(item: PredefinedMenuItemType, text: Option<S>) -> Self {
Self(Rc::new(RefCell::new( Self(Rc::new(RefCell::new(
crate::platform_impl::MenuChild::new_predefined( crate::platform_impl::MenuChild::new_predefined(
item, item,
@ -213,7 +213,7 @@ fn test_about_metadata() {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[non_exhaustive] #[non_exhaustive]
#[allow(clippy::large_enum_variant)] #[allow(clippy::large_enum_variant)]
pub(crate) enum PredfinedMenuItemType { pub(crate) enum PredefinedMenuItemType {
Separator, Separator,
Copy, Copy,
Cut, Cut,
@ -234,84 +234,84 @@ pub(crate) enum PredfinedMenuItemType {
None, None,
} }
impl Default for PredfinedMenuItemType { impl Default for PredefinedMenuItemType {
fn default() -> Self { fn default() -> Self {
Self::None Self::None
} }
} }
impl PredfinedMenuItemType { impl PredefinedMenuItemType {
pub(crate) fn text(&self) -> &str { pub(crate) fn text(&self) -> &str {
match self { match self {
PredfinedMenuItemType::Separator => "", PredefinedMenuItemType::Separator => "",
PredfinedMenuItemType::Copy => "&Copy", PredefinedMenuItemType::Copy => "&Copy",
PredfinedMenuItemType::Cut => "Cu&t", PredefinedMenuItemType::Cut => "Cu&t",
PredfinedMenuItemType::Paste => "&Paste", PredefinedMenuItemType::Paste => "&Paste",
PredfinedMenuItemType::SelectAll => "Select &All", PredefinedMenuItemType::SelectAll => "Select &All",
PredfinedMenuItemType::Undo => "Undo", PredefinedMenuItemType::Undo => "Undo",
PredfinedMenuItemType::Redo => "Redo", PredefinedMenuItemType::Redo => "Redo",
PredfinedMenuItemType::Minimize => "&Minimize", PredefinedMenuItemType::Minimize => "&Minimize",
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
PredfinedMenuItemType::Maximize => "Zoom", PredefinedMenuItemType::Maximize => "Zoom",
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
PredfinedMenuItemType::Maximize => "Ma&ximize", PredefinedMenuItemType::Maximize => "Ma&ximize",
PredfinedMenuItemType::Fullscreen => "Toggle Full Screen", PredefinedMenuItemType::Fullscreen => "Toggle Full Screen",
PredfinedMenuItemType::Hide => "&Hide", PredefinedMenuItemType::Hide => "&Hide",
PredfinedMenuItemType::HideOthers => "Hide Others", PredefinedMenuItemType::HideOthers => "Hide Others",
PredfinedMenuItemType::ShowAll => "Show All", PredefinedMenuItemType::ShowAll => "Show All",
#[cfg(windows)] #[cfg(windows)]
PredfinedMenuItemType::CloseWindow => "Close", PredefinedMenuItemType::CloseWindow => "Close",
#[cfg(not(windows))] #[cfg(not(windows))]
PredfinedMenuItemType::CloseWindow => "C&lose Window", PredefinedMenuItemType::CloseWindow => "C&lose Window",
#[cfg(windows)] #[cfg(windows)]
PredfinedMenuItemType::Quit => "&Exit", PredefinedMenuItemType::Quit => "&Exit",
#[cfg(not(windows))] #[cfg(not(windows))]
PredfinedMenuItemType::Quit => "&Quit", PredefinedMenuItemType::Quit => "&Quit",
PredfinedMenuItemType::About(_) => "&About", PredefinedMenuItemType::About(_) => "&About",
PredfinedMenuItemType::Services => "Services", PredefinedMenuItemType::Services => "Services",
PredfinedMenuItemType::None => "", PredefinedMenuItemType::None => "",
} }
} }
pub(crate) fn accelerator(&self) -> Option<Accelerator> { pub(crate) fn accelerator(&self) -> Option<Accelerator> {
match self { match self {
PredfinedMenuItemType::Copy => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyC)), PredefinedMenuItemType::Copy => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyC)),
PredfinedMenuItemType::Cut => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyX)), PredefinedMenuItemType::Cut => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyX)),
PredfinedMenuItemType::Paste => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyV)), PredefinedMenuItemType::Paste => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyV)),
PredfinedMenuItemType::Undo => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyZ)), PredefinedMenuItemType::Undo => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyZ)),
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
PredfinedMenuItemType::Redo => Some(Accelerator::new( PredefinedMenuItemType::Redo => Some(Accelerator::new(
Some(CMD_OR_CTRL | Modifiers::SHIFT), Some(CMD_OR_CTRL | Modifiers::SHIFT),
Code::KeyZ, Code::KeyZ,
)), )),
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
PredfinedMenuItemType::Redo => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyY)), PredefinedMenuItemType::Redo => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyY)),
PredfinedMenuItemType::SelectAll => { PredefinedMenuItemType::SelectAll => {
Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyA)) Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyA))
} }
PredfinedMenuItemType::Minimize => { PredefinedMenuItemType::Minimize => {
Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyM)) Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyM))
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
PredfinedMenuItemType::Fullscreen => Some(Accelerator::new( PredefinedMenuItemType::Fullscreen => Some(Accelerator::new(
Some(Modifiers::META | Modifiers::CONTROL), Some(Modifiers::META | Modifiers::CONTROL),
Code::KeyF, Code::KeyF,
)), )),
PredfinedMenuItemType::Hide => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyH)), PredefinedMenuItemType::Hide => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyH)),
PredfinedMenuItemType::HideOthers => Some(Accelerator::new( PredefinedMenuItemType::HideOthers => Some(Accelerator::new(
Some(CMD_OR_CTRL | Modifiers::ALT), Some(CMD_OR_CTRL | Modifiers::ALT),
Code::KeyH, Code::KeyH,
)), )),
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
PredfinedMenuItemType::CloseWindow => { PredefinedMenuItemType::CloseWindow => {
Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyW)) Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyW))
} }
#[cfg(not(target_os = "macos"))] #[cfg(not(target_os = "macos"))]
PredfinedMenuItemType::CloseWindow => { PredefinedMenuItemType::CloseWindow => {
Some(Accelerator::new(Some(Modifiers::ALT), Code::F4)) Some(Accelerator::new(Some(Modifiers::ALT), Code::F4))
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
PredfinedMenuItemType::Quit => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyQ)), PredefinedMenuItemType::Quit => Some(Accelerator::new(Some(CMD_OR_CTRL), Code::KeyQ)),
_ => None, _ => None,
} }
} }

View file

@ -32,12 +32,12 @@ macro_rules! return_if_predefined_item_not_supported {
match (&child_.type_, &child_.predefined_item_type) { match (&child_.type_, &child_.predefined_item_type) {
( (
crate::MenuItemType::Predefined, crate::MenuItemType::Predefined,
PredfinedMenuItemType::Separator PredefinedMenuItemType::Separator
| PredfinedMenuItemType::Copy | PredefinedMenuItemType::Copy
| PredfinedMenuItemType::Cut | PredefinedMenuItemType::Cut
| PredfinedMenuItemType::Paste | PredefinedMenuItemType::Paste
| PredfinedMenuItemType::SelectAll | PredefinedMenuItemType::SelectAll
| PredfinedMenuItemType::About(_), | PredefinedMenuItemType::About(_),
) => {} ) => {}
( (
crate::MenuItemType::Submenu crate::MenuItemType::Submenu
@ -365,7 +365,7 @@ pub struct MenuChild {
gtk_accelerator: Option<(gdk::ModifierType, u32)>, gtk_accelerator: Option<(gdk::ModifierType, u32)>,
// predefined menu item fields // predefined menu item fields
predefined_item_type: PredfinedMenuItemType, predefined_item_type: PredefinedMenuItemType,
// check menu item fields // check menu item fields
checked: Rc<AtomicBool>, checked: Rc<AtomicBool>,
@ -409,7 +409,7 @@ impl MenuChild {
} }
} }
pub(crate) fn new_predefined(item_type: PredfinedMenuItemType, text: Option<String>) -> Self { pub(crate) fn new_predefined(item_type: PredefinedMenuItemType, text: Option<String>) -> Self {
Self { Self {
text: text.unwrap_or_else(|| item_type.text().to_string()), text: text.unwrap_or_else(|| item_type.text().to_string()),
enabled: true, enabled: true,
@ -935,13 +935,13 @@ impl MenuChild {
}; };
let item = match predefined_item_type { let item = match predefined_item_type {
PredfinedMenuItemType::Separator => { PredefinedMenuItemType::Separator => {
gtk::SeparatorMenuItem::new().upcast::<gtk::MenuItem>() gtk::SeparatorMenuItem::new().upcast::<gtk::MenuItem>()
} }
PredfinedMenuItemType::Copy PredefinedMenuItemType::Copy
| PredfinedMenuItemType::Cut | PredefinedMenuItemType::Cut
| PredfinedMenuItemType::Paste | PredefinedMenuItemType::Paste
| PredfinedMenuItemType::SelectAll => { | PredefinedMenuItemType::SelectAll => {
let item = make_item(); let item = make_item();
let (mods, key) = let (mods, key) =
parse_accelerator(&predefined_item_type.accelerator().unwrap()).unwrap(); parse_accelerator(&predefined_item_type.accelerator().unwrap()).unwrap();
@ -959,7 +959,7 @@ impl MenuChild {
}); });
item item
} }
PredfinedMenuItemType::About(metadata) => { PredefinedMenuItemType::About(metadata) => {
let item = make_item(); let item = make_item();
register_accel(&item); register_accel(&item);
item.connect_activate(move |_| { item.connect_activate(move |_| {
@ -1230,14 +1230,14 @@ fn show_context_menu(
} }
} }
impl PredfinedMenuItemType { impl PredefinedMenuItemType {
#[cfg(feature = "libxdo")] #[cfg(feature = "libxdo")]
fn xdo_keys(&self) -> &str { fn xdo_keys(&self) -> &str {
match self { match self {
PredfinedMenuItemType::Copy => "ctrl+c", PredefinedMenuItemType::Copy => "ctrl+c",
PredfinedMenuItemType::Cut => "ctrl+X", PredefinedMenuItemType::Cut => "ctrl+X",
PredfinedMenuItemType::Paste => "ctrl+v", PredefinedMenuItemType::Paste => "ctrl+v",
PredfinedMenuItemType::SelectAll => "ctrl+a", PredefinedMenuItemType::SelectAll => "ctrl+a",
_ => unreachable!(), _ => unreachable!(),
} }
} }

View file

@ -177,7 +177,7 @@ pub struct MenuChild {
accelerator: Option<Accelerator>, accelerator: Option<Accelerator>,
// predefined menu item fields // predefined menu item fields
predefined_item_type: PredfinedMenuItemType, predefined_item_type: PredefinedMenuItemType,
// check menu item fields // check menu item fields
checked: bool, checked: bool,
@ -236,20 +236,20 @@ impl MenuChild {
} }
} }
pub(crate) fn new_predefined(item_type: PredfinedMenuItemType, text: Option<String>) -> Self { pub(crate) fn new_predefined(item_type: PredefinedMenuItemType, text: Option<String>) -> Self {
let text = strip_mnemonic(text.unwrap_or_else(|| { let text = strip_mnemonic(text.unwrap_or_else(|| {
match item_type { match item_type {
PredfinedMenuItemType::About(_) => { PredefinedMenuItemType::About(_) => {
format!("About {}", unsafe { app_name_string() }.unwrap_or_default()) format!("About {}", unsafe { app_name_string() }.unwrap_or_default())
.trim() .trim()
.to_string() .to_string()
} }
PredfinedMenuItemType::Hide => { PredefinedMenuItemType::Hide => {
format!("Hide {}", unsafe { app_name_string() }.unwrap_or_default()) format!("Hide {}", unsafe { app_name_string() }.unwrap_or_default())
.trim() .trim()
.to_string() .to_string()
} }
PredfinedMenuItemType::Quit => { PredefinedMenuItemType::Quit => {
format!("Quit {}", unsafe { app_name_string() }.unwrap_or_default()) format!("Quit {}", unsafe { app_name_string() }.unwrap_or_default())
.trim() .trim()
.to_string() .to_string()
@ -611,13 +611,13 @@ impl MenuChild {
pub fn create_ns_item_for_predefined_menu_item(&mut self, menu_id: u32) -> crate::Result<id> { pub fn create_ns_item_for_predefined_menu_item(&mut self, menu_id: u32) -> crate::Result<id> {
let item_type = &self.predefined_item_type; let item_type = &self.predefined_item_type;
let ns_menu_item = match item_type { let ns_menu_item = match item_type {
PredfinedMenuItemType::Separator => unsafe { PredefinedMenuItemType::Separator => unsafe {
NSMenuItem::separatorItem(nil).autorelease() NSMenuItem::separatorItem(nil).autorelease()
}, },
_ => create_ns_menu_item(&self.text, item_type.selector(), &self.accelerator)?, _ => create_ns_menu_item(&self.text, item_type.selector(), &self.accelerator)?,
}; };
if let PredfinedMenuItemType::About(_) = self.predefined_item_type { if let PredefinedMenuItemType::About(_) = self.predefined_item_type {
unsafe { unsafe {
let _: () = msg_send![ns_menu_item, setTarget: ns_menu_item]; let _: () = msg_send![ns_menu_item, setTarget: ns_menu_item];
let _: () = msg_send![ns_menu_item, setTag:self.id()]; let _: () = msg_send![ns_menu_item, setTag:self.id()];
@ -632,7 +632,7 @@ impl MenuChild {
if !self.enabled { if !self.enabled {
let () = msg_send![ns_menu_item, setEnabled: NO]; let () = msg_send![ns_menu_item, setEnabled: NO];
} }
if let PredfinedMenuItemType::Services = self.predefined_item_type { if let PredefinedMenuItemType::Services = self.predefined_item_type {
// we have to assign an empty menu as the app's services menu, and macOS will populate it // we have to assign an empty menu as the app's services menu, and macOS will populate it
let services_menu = NSMenu::new(nil).autorelease(); let services_menu = NSMenu::new(nil).autorelease();
let () = msg_send![NSApp(), setServicesMenu: services_menu]; let () = msg_send![NSApp(), setServicesMenu: services_menu];
@ -724,28 +724,28 @@ impl MenuChild {
} }
} }
impl PredfinedMenuItemType { impl PredefinedMenuItemType {
pub(crate) fn selector(&self) -> Option<Sel> { pub(crate) fn selector(&self) -> Option<Sel> {
match self { match self {
PredfinedMenuItemType::Separator => None, PredefinedMenuItemType::Separator => None,
PredfinedMenuItemType::Copy => Some(selector("copy:")), PredefinedMenuItemType::Copy => Some(selector("copy:")),
PredfinedMenuItemType::Cut => Some(selector("cut:")), PredefinedMenuItemType::Cut => Some(selector("cut:")),
PredfinedMenuItemType::Paste => Some(selector("paste:")), PredefinedMenuItemType::Paste => Some(selector("paste:")),
PredfinedMenuItemType::SelectAll => Some(selector("selectAll:")), PredefinedMenuItemType::SelectAll => Some(selector("selectAll:")),
PredfinedMenuItemType::Undo => Some(selector("undo:")), PredefinedMenuItemType::Undo => Some(selector("undo:")),
PredfinedMenuItemType::Redo => Some(selector("redo:")), PredefinedMenuItemType::Redo => Some(selector("redo:")),
PredfinedMenuItemType::Minimize => Some(selector("performMiniaturize:")), PredefinedMenuItemType::Minimize => Some(selector("performMiniaturize:")),
PredfinedMenuItemType::Maximize => Some(selector("performZoom:")), PredefinedMenuItemType::Maximize => Some(selector("performZoom:")),
PredfinedMenuItemType::Fullscreen => Some(selector("toggleFullScreen:")), PredefinedMenuItemType::Fullscreen => Some(selector("toggleFullScreen:")),
PredfinedMenuItemType::Hide => Some(selector("hide:")), PredefinedMenuItemType::Hide => Some(selector("hide:")),
PredfinedMenuItemType::HideOthers => Some(selector("hideOtherApplications:")), PredefinedMenuItemType::HideOthers => Some(selector("hideOtherApplications:")),
PredfinedMenuItemType::ShowAll => Some(selector("unhideAllApplications:")), PredefinedMenuItemType::ShowAll => Some(selector("unhideAllApplications:")),
PredfinedMenuItemType::CloseWindow => Some(selector("performClose:")), PredefinedMenuItemType::CloseWindow => Some(selector("performClose:")),
PredfinedMenuItemType::Quit => Some(selector("terminate:")), PredefinedMenuItemType::Quit => Some(selector("terminate:")),
// manual implementation in `fire_menu_item_click` // manual implementation in `fire_menu_item_click`
PredfinedMenuItemType::About(_) => Some(selector("fireMenuItemAction:")), PredefinedMenuItemType::About(_) => Some(selector("fireMenuItemAction:")),
PredfinedMenuItemType::Services => None, PredefinedMenuItemType::Services => None,
PredfinedMenuItemType::None => None, PredefinedMenuItemType::None => None,
} }
} }
} }
@ -838,7 +838,7 @@ extern "C" fn fire_menu_item_click(this: &Object, _: Sel, _item: id) {
let ptr: usize = *this.get_ivar(BLOCK_PTR); let ptr: usize = *this.get_ivar(BLOCK_PTR);
let item = ptr as *mut &mut MenuChild; let item = ptr as *mut &mut MenuChild;
if let PredfinedMenuItemType::About(about_meta) = &(*item).predefined_item_type { if let PredefinedMenuItemType::About(about_meta) = &(*item).predefined_item_type {
match about_meta { match about_meta {
Some(about_meta) => { Some(about_meta) => {
unsafe fn mkstr(s: &str) -> id { unsafe fn mkstr(s: &str) -> id {

View file

@ -11,7 +11,7 @@ pub(crate) use self::icon::WinIcon as PlatformIcon;
use crate::{ use crate::{
accelerator::Accelerator, accelerator::Accelerator,
icon::{Icon, NativeIcon}, icon::{Icon, NativeIcon},
items::PredfinedMenuItemType, items::PredefinedMenuItemType,
util::{AddOp, Counter}, util::{AddOp, Counter},
AboutMetadata, CheckMenuItem, IconMenuItem, IsMenuItem, MenuEvent, MenuItem, MenuItemType, AboutMetadata, CheckMenuItem, IconMenuItem, IsMenuItem, MenuEvent, MenuItem, MenuItemType,
Position, PredefinedMenuItem, Submenu, Position, PredefinedMenuItem, Submenu,
@ -64,8 +64,8 @@ macro_rules! inner_menu_child_and_flags {
let child = &item.0; let child = &item.0;
let child_ = child.borrow(); let child_ = child.borrow();
match child_.predefined_item_type { match child_.predefined_item_type {
PredfinedMenuItemType::None => return Ok(()), PredefinedMenuItemType::None => return Ok(()),
PredfinedMenuItemType::Separator => { PredefinedMenuItemType::Separator => {
flags |= MF_SEPARATOR; flags |= MF_SEPARATOR;
} }
_ => { _ => {
@ -381,7 +381,7 @@ pub(crate) struct MenuChild {
accelerator: Option<Accelerator>, accelerator: Option<Accelerator>,
// predefined menu item fields // predefined menu item fields
predefined_item_type: PredfinedMenuItemType, predefined_item_type: PredefinedMenuItemType,
// check menu item fields // check menu item fields
checked: bool, checked: bool,
@ -424,7 +424,7 @@ impl MenuChild {
} }
} }
pub fn new_predefined(item_type: PredfinedMenuItemType, text: Option<String>) -> Self { pub fn new_predefined(item_type: PredefinedMenuItemType, text: Option<String>) -> Self {
Self { Self {
type_: MenuItemType::Predefined, type_: MenuItemType::Predefined,
text: text.unwrap_or_else(|| item_type.text().to_string()), text: text.unwrap_or_else(|| item_type.text().to_string()),
@ -943,29 +943,29 @@ unsafe extern "system" fn menu_subclass_proc(
item.set_checked(checked); item.set_checked(checked);
} }
MenuItemType::Predefined => match &item.predefined_item_type { MenuItemType::Predefined => match &item.predefined_item_type {
PredfinedMenuItemType::Copy => execute_edit_command(EditCommand::Copy), PredefinedMenuItemType::Copy => execute_edit_command(EditCommand::Copy),
PredfinedMenuItemType::Cut => execute_edit_command(EditCommand::Cut), PredefinedMenuItemType::Cut => execute_edit_command(EditCommand::Cut),
PredfinedMenuItemType::Paste => execute_edit_command(EditCommand::Paste), PredefinedMenuItemType::Paste => execute_edit_command(EditCommand::Paste),
PredfinedMenuItemType::SelectAll => { PredefinedMenuItemType::SelectAll => {
execute_edit_command(EditCommand::SelectAll) execute_edit_command(EditCommand::SelectAll)
} }
PredfinedMenuItemType::Separator => {} PredefinedMenuItemType::Separator => {}
PredfinedMenuItemType::Minimize => { PredefinedMenuItemType::Minimize => {
ShowWindow(hwnd, SW_MINIMIZE); ShowWindow(hwnd, SW_MINIMIZE);
} }
PredfinedMenuItemType::Maximize => { PredefinedMenuItemType::Maximize => {
ShowWindow(hwnd, SW_MAXIMIZE); ShowWindow(hwnd, SW_MAXIMIZE);
} }
PredfinedMenuItemType::Hide => { PredefinedMenuItemType::Hide => {
ShowWindow(hwnd, SW_HIDE); ShowWindow(hwnd, SW_HIDE);
} }
PredfinedMenuItemType::CloseWindow => { PredefinedMenuItemType::CloseWindow => {
SendMessageW(hwnd, WM_CLOSE, 0, 0); SendMessageW(hwnd, WM_CLOSE, 0, 0);
} }
PredfinedMenuItemType::Quit => { PredefinedMenuItemType::Quit => {
PostQuitMessage(0); PostQuitMessage(0);
} }
PredfinedMenuItemType::About(Some(ref metadata)) => { PredefinedMenuItemType::About(Some(ref metadata)) => {
show_about_dialog(hwnd, metadata) show_about_dialog(hwnd, metadata)
} }