PureBasic Forum
https://www.purebasic.fr/english/

[Done] Problem with menu shortcut CMD+Z
https://www.purebasic.fr/english/viewtopic.php?f=24&t=69715
Page 1 of 1

Author:  Wolfram [ Thu Nov 30, 2017 2:49 pm ]
Post subject:  [Done] Problem with menu shortcut CMD+Z

I write my own undo history, but I can't assign CMD+Z as menu shortcut.

Code:
Global Window_0

Enumeration menu
  #Menu_Undo
EndEnumeration


Procedure OpenWindow_0(x = 0, y = 0, width = 450, height = 160)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CreateMenu(1, WindowID(Window_0) )
  MenuTitle("Edit")
  MenuItem(#Menu_Undo, "Undo"+Chr(9)+"Cmd+Z")
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False
     
    Case #PB_Event_Menu
      Select EventMenu()
        Case #PB_Menu_Quit
          ProcedureReturn #False
        Case #Menu_Undo
          Debug "UNDO"
      EndSelect
     
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False

End

Author:  Shardik [ Thu Nov 30, 2017 9:32 pm ]
Post subject:  Re: Problem with menu shortcut CMD+Z

Wolfram wrote:
but I can't assign CMD+Z as menu shortcut.

Confirmed on MacOS 10.9.5 'Mavericks' with PB 5.45 in ASCII and Unicode mode and with PB 5.61. Selecting the menu entry "Undo" is detected but not pressing <Cmd>+<Z> or <Cmd>+<z>. The combination <Cmd>+<X> or <Cmd>+<Y> is detected correctly.

Author:  Wolfram [ Sun Dec 03, 2017 8:04 pm ]
Post subject:  Re: Problem with menu shortcut CMD+Z

Is it a PB bug or a problem of OSX?

Author:  J. Baker [ Mon Dec 04, 2017 12:46 am ]
Post subject:  Re: Problem with menu shortcut CMD+Z

That's because there's no #PB_Menu_Undo for OS X. You're going to have to create a keyboard shortcut, like so. ;)

Code:
Global Window_0

Enumeration menu
  #Menu_Undo
EndEnumeration


Procedure OpenWindow_0(x = 0, y = 0, width = 450, height = 160)
  Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CreateMenu(1, WindowID(Window_0) )
  MenuTitle("Edit")
  MenuItem(#Menu_Undo, "Undo"+Chr(9)+"Cmd+Z")
  AddKeyboardShortcut(Window_0, #PB_Shortcut_Command | #PB_Shortcut_Z, #Menu_Undo)
EndProcedure

Procedure Window_0_Events(event)
  Select event
    Case #PB_Event_CloseWindow
      ProcedureReturn #False
     
    Case #PB_Event_Menu
      Select EventMenu()
        Case #PB_Menu_Quit
          ProcedureReturn #False
        Case #Menu_Undo
          Debug "UNDO"
      EndSelect
     
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False

End

Author:  Wolfram [ Mon Dec 04, 2017 10:43 am ]
Post subject:  Re: Problem with menu shortcut CMD+Z

Hello J. Baker,

this looks like a workaround to me.
Normally I can create a shortcut directly in the menu like
Code:
MenuItem(#Menu_Undo, "Undo"+Chr(9)+"Cmd+Z")

This works with every key/key combination but not with CMD+Z.

What's the reason of the problem?

Author:  J. Baker [ Mon Dec 04, 2017 7:22 pm ]
Post subject:  Re: Problem with menu shortcut CMD+Z

Wolfram wrote:
Hello J. Baker,

this looks like a workaround to me.
Normally I can create a shortcut directly in the menu like
Code:
MenuItem(#Menu_Undo, "Undo"+Chr(9)+"Cmd+Z")

This works with every key/key combination but not with CMD+Z.

What's the reason of the problem?

You are correct. I had forgotten about that. Maybe Fred had a reason for that or it just wasn't added by accident. :wink:

Author:  Shardik [ Mon Dec 04, 2017 8:52 pm ]
Post subject:  Re: Problem with menu shortcut CMD+Z

Wolfram wrote:
This works with every key/key combination but not with CMD+Z.

It seems to be a bug in PureBasic because the documentation for MenuItem clearly states:
On OS X, when a shortcut is created in the menu, there is no need to call the AddKeyboardShortcut() function with this shortcut.

Author:  Fred [ Fri Apr 26, 2019 4:44 pm ]
Post subject:  Re: Problem with menu shortcut CMD+Z

Fixed.

Author:  kenmo [ Fri Apr 26, 2019 6:57 pm ]
Post subject:  Re: Problem with menu shortcut CMD+Z

Quote:
It seems to be a bug in PureBasic because the documentation for MenuItem clearly states:
On OS X, when a shortcut is created in the menu, there is no need to call the AddKeyboardShortcut() function with this shortcut.


I never knew this! :shock:

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/