menu.rs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. use tauri::{CustomMenuItem, Menu, MenuItem};
  5. pub fn get_menu() -> Vec<Menu> {
  6. let custom_print_menu = MenuItem::Custom(CustomMenuItem::new("Print"));
  7. let other_test_menu = MenuItem::Custom(CustomMenuItem::new("Custom"));
  8. let quit_menu = MenuItem::Custom(CustomMenuItem::new("Quit"));
  9. // macOS require to have at least Copy, Paste, Select all etc..
  10. // to works fine. You should always add them.
  11. #[cfg(any(target_os = "linux", target_os = "macos"))]
  12. let menu = vec![
  13. Menu::new(
  14. // on macOS first menu is always app name
  15. "Tauri API",
  16. vec![
  17. // All's non-custom menu, do NOT return event's
  18. // they are handled by the system automatically
  19. MenuItem::About("Tauri".to_string()),
  20. MenuItem::Services,
  21. MenuItem::Separator,
  22. MenuItem::Hide,
  23. MenuItem::HideOthers,
  24. MenuItem::ShowAll,
  25. MenuItem::Separator,
  26. quit_menu,
  27. ],
  28. ),
  29. Menu::new(
  30. "File",
  31. vec![
  32. custom_print_menu,
  33. MenuItem::Separator,
  34. other_test_menu,
  35. MenuItem::CloseWindow,
  36. ],
  37. ),
  38. Menu::new(
  39. "Edit",
  40. vec![
  41. MenuItem::Undo,
  42. MenuItem::Redo,
  43. MenuItem::Separator,
  44. MenuItem::Cut,
  45. MenuItem::Copy,
  46. MenuItem::Paste,
  47. MenuItem::Separator,
  48. MenuItem::SelectAll,
  49. ],
  50. ),
  51. Menu::new("View", vec![MenuItem::EnterFullScreen]),
  52. Menu::new("Window", vec![MenuItem::Minimize, MenuItem::Zoom]),
  53. Menu::new(
  54. "Help",
  55. vec![MenuItem::Custom(CustomMenuItem::new("Custom help"))],
  56. ),
  57. ];
  58. // Attention, Windows only support custom menu for now.
  59. // If we add any `MenuItem::*` they'll not render
  60. // We need to use custom menu with `Menu::new()` and catch
  61. // the events in the EventLoop.
  62. #[cfg(target_os = "windows")]
  63. let menu = vec![
  64. Menu::new("File", vec![other_test_menu]),
  65. Menu::new("Other menu", vec![quit_menu]),
  66. ];
  67. menu
  68. }