actions.gd 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. extends Node
  2. func _on_OpenShellWeb_pressed():
  3. OS.shell_open("https://example.com")
  4. func _on_OpenShellFolder_pressed():
  5. var path = OS.get_environment("HOME")
  6. if path == "":
  7. # Windows-specific.
  8. path = OS.get_environment("USERPROFILE")
  9. if OS.get_name() == "macOS":
  10. # MacOS-specific.
  11. path = "file://" + path
  12. OS.shell_open(path)
  13. func _on_ChangeWindowTitle_pressed():
  14. DisplayServer.window_set_title("Modified window title. Unicode characters for testing: é € × Ù ¨")
  15. func _on_ChangeWindowIcon_pressed():
  16. var image = Image.create(128, 128, false, Image.FORMAT_RGB8)
  17. image.fill(Color(1, 0.6, 0.3))
  18. DisplayServer.set_icon(image)
  19. func _on_MoveWindowToForeground_pressed():
  20. DisplayServer.window_set_title("Will move window to foreground in 5 seconds, try unfocusing the window...")
  21. await get_tree().create_timer(5).timeout
  22. DisplayServer.window_move_to_foreground()
  23. # Restore the previous window title.
  24. DisplayServer.window_set_title(ProjectSettings.get_setting("application/config/name"))
  25. func _on_RequestAttention_pressed():
  26. DisplayServer.window_set_title("Will request attention in 5 seconds, try unfocusing the window...")
  27. await get_tree().create_timer(5).timeout
  28. DisplayServer.window_request_attention()
  29. # Restore the previous window title.
  30. DisplayServer.window_set_title(ProjectSettings.get_setting("application/config/name"))
  31. func _on_VibrateDeviceShort_pressed():
  32. Input.vibrate_handheld(200)
  33. func _on_VibrateDeviceLong_pressed():
  34. Input.vibrate_handheld(1000)
  35. func _on_AddGlobalMenuItems_pressed():
  36. # Add a menu to the main menu bar.
  37. DisplayServer.global_menu_add_submenu_item("_main", "Hello", "_main/Hello")
  38. DisplayServer.global_menu_add_item(
  39. "_main/Hello",
  40. "World",
  41. func(tag): print("Clicked main 1 " + str(tag)),
  42. func(tag): print("Key main 1 " + str(tag)),
  43. null,
  44. KEY_MASK_META + KEY_1
  45. )
  46. DisplayServer.global_menu_add_separator("_main/Hello")
  47. DisplayServer.global_menu_add_item("_main/Hello", "World2", func(tag): print("Clicked main 2 " + str(tag)))
  48. # Add a menu to the Dock context menu.
  49. DisplayServer.global_menu_add_submenu_item("_dock", "Hello", "_dock/Hello")
  50. DisplayServer.global_menu_add_item("_dock/Hello", "World", func(tag): print("Clicked dock 1 " + str(tag)))
  51. DisplayServer.global_menu_add_separator("_dock/Hello")
  52. DisplayServer.global_menu_add_item("_dock/Hello", "World2", func(tag): print("Clicked dock 2 " + str(tag)))
  53. func _on_RemoveGlobalMenuItem_pressed():
  54. DisplayServer.global_menu_remove_item("_main/Hello", 2)
  55. DisplayServer.global_menu_remove_item("_main/Hello", 1)
  56. DisplayServer.global_menu_remove_item("_main/Hello", 0)
  57. DisplayServer.global_menu_remove_item("_main", 0)
  58. DisplayServer.global_menu_remove_item("_dock/Hello", 2)
  59. DisplayServer.global_menu_remove_item("_dock/Hello", 1)
  60. DisplayServer.global_menu_remove_item("_dock/Hello", 0)
  61. DisplayServer.global_menu_remove_item("_dock", 0)
  62. func _on_GetClipboard_pressed():
  63. OS.alert("Clipboard contents:\n\n%s" % DisplayServer.clipboard_get())
  64. func _on_SetClipboard_pressed():
  65. DisplayServer.clipboard_set("Modified clipboard contents. Unicode characters for testing: é € × Ù ¨")
  66. func _on_DisplayAlert_pressed():
  67. OS.alert("Hello from Godot! Close this dialog to resume the main window.")
  68. func _on_KillCurrentProcess_pressed():
  69. OS.kill(OS.get_process_id())