1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT use std::{collections::hash_map::DefaultHasher, hash::Hasher}; use super::MenuId; /// A window menu. #[derive(Debug, Clone)] pub struct Menu<I: MenuId> { pub title: String, pub items: Vec<MenuItem<I>>, } impl<I: MenuId> Menu<I> { /// Creates a new window menu with the given title and items. pub fn new<T: Into<String>>(title: T, items: Vec<MenuItem<I>>) -> Self { Self { title: title.into(), items, } } } /// A custom menu item. #[derive(Debug, Clone)] pub struct CustomMenuItem<I: MenuId> { pub id: I, pub name: String, } impl<I: MenuId> CustomMenuItem<I> { /// Create new custom menu item. pub fn new<T: Into<String>>(id: I, title: T) -> Self { let title = title.into(); Self { id, name: title } } #[doc(hidden)] pub fn id_value(&self) -> u32 { let mut s = DefaultHasher::new(); self.id.hash(&mut s); s.finish() as u32 } } /// System tray menu item. #[derive(Debug, Clone)] #[non_exhaustive] pub enum SystemTrayMenuItem<I: MenuId> { /// A custom menu item. Custom(CustomMenuItem<I>), /// A separator. Separator, } /// A menu item, bound to a pre-defined action or `Custom` emit an event. Note that status bar only /// supports `Custom` menu item variants. And on the menu bar, some platforms might not support some /// of the variants. Unsupported variant will be no-op on such platform. #[derive(Debug, Clone)] #[non_exhaustive] pub enum MenuItem<I: MenuId> { /// A custom menu item.. Custom(CustomMenuItem<I>), /// Shows a standard "About" item /// /// ## Platform-specific /// /// - **Windows / Android / iOS:** Unsupported /// About(String), /// A standard "hide the app" menu item. /// /// ## Platform-specific /// /// - **Windows / Android / iOS:** Unsupported /// Hide, /// A standard "Services" menu item. /// /// ## Platform-specific /// /// - **Windows / Linux / Android / iOS:** Unsupported /// Services, /// A "hide all other windows" menu item. /// /// ## Platform-specific /// /// - **Windows / Linux / Android / iOS:** Unsupported /// HideOthers, /// A menu item to show all the windows for this app. /// /// ## Platform-specific /// /// - **Windows / Linux / Android / iOS:** Unsupported /// ShowAll, /// Close the current window. /// /// ## Platform-specific /// /// - **Windows / Android / iOS:** Unsupported /// CloseWindow, /// A "quit this app" menu icon. /// /// ## Platform-specific /// /// - **Windows / Android / iOS:** Unsupported /// Quit, /// A menu item for enabling copying (often text) from responders. /// /// ## Platform-specific /// /// - **Windows / Android / iOS:** Unsupported /// Copy, /// A menu item for enabling cutting (often text) from responders. /// /// ## Platform-specific /// /// - **Windows / Android / iOS:** Unsupported /// Cut, /// An "undo" menu item; particularly useful for supporting the cut/copy/paste/undo lifecycle /// of events. /// /// ## Platform-specific /// /// - **Windows / Linux / Android / iOS:** Unsupported /// Undo, /// An "redo" menu item; particularly useful for supporting the cut/copy/paste/undo lifecycle /// of events. /// /// ## Platform-specific /// /// - **Windows / Linux / Android / iOS:** Unsupported /// Redo, /// A menu item for selecting all (often text) from responders. /// /// ## Platform-specific /// /// - **Windows / Android / iOS:** Unsupported /// SelectAll, /// A menu item for pasting (often text) into responders. /// /// ## Platform-specific /// /// - **Windows / Android / iOS:** Unsupported /// Paste, /// A standard "enter full screen" item. /// /// ## Platform-specific /// /// - **Windows / Linux / Android / iOS:** Unsupported /// EnterFullScreen, /// An item for minimizing the window with the standard system controls. /// /// ## Platform-specific /// /// - **Windows / Android / iOS:** Unsupported /// Minimize, /// An item for instructing the app to zoom /// /// ## Platform-specific /// /// - **Windows / Linux / Android / iOS:** Unsupported /// Zoom, /// Represents a Separator /// /// ## Platform-specific /// /// - **Windows / Android / iOS:** Unsupported /// Separator, }