Problem creating menuItem "copy" with cocoa

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Problem creating menuItem "copy" with cocoa

Post by Wolfram »

If I add the "copy" menuItem by using cocoa and the window is opened with #PB_Window_Invisible, I get automatic a menuItem "Special Characters…"
This is only happened if the window is invisible while I'm creating the menu and only at menuItem "copy".
The count of menuItems is 1 this means the separator and the item "Special Characters…" isn't count.

Any idea why this is happened?
How can I remove this item?

Code: Select all

Global Window_0

ImportC ""
  sel_registerName(MethodName.P-ASCII)
EndImport

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 | #PB_Window_Invisible)
  
  CreateMenu(0, WindowID(Window_0))
  
  If MenuTitle("Edit")
    MenuArray = MenuID(0)
    MenuTitle = CocoaMessage(0, MenuArray, "objectAtIndex:",0)
    
    CocoaMessage(0, MenuTitle, "addItemWithTitle:$", @"Copy", "action:", sel_registerName("copy:"), "keyEquivalent:$", @"c")
;     CocoaMessage(0, MenuTitle, "addItemWithTitle:$", @"Paste", "action:", sel_registerName("paste:"), "keyEquivalent:$", @"v")
    Debug "count of menuItems " +CocoaMessage(0, MenuTitle, "numberOfItems")
    
  EndIf
  
        
  HideWindow(Window_0, #False)
  
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
      EndSelect
      
    Case #PB_Event_Gadget
      Select EventGadget()
          
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

OpenWindow_0()

Repeat
  event = WaitWindowEvent()
Until Window_0_Events(event) = #False
macOS Catalina 10.15.7
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Problem creating menuItem "copy" with cocoa

Post by wilbert »

The OS adds these items itself.

According to some info I found online you can modify this behavior like this

Code: Select all

UserDefaults = CocoaMessage(0, 0, "NSUserDefaults standardUserDefaults")
CocoaMessage(0, UserDefaults, "setBool:", #YES, "forKey:$", @"NSDisabledDictationMenuItem")
CocoaMessage(0, UserDefaults, "setBool:", #YES, "forKey:$", @"NSDisabledCharacterPaletteMenuItem")
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Problem creating menuItem "copy" with cocoa

Post by Keya »

or i wonder if simply changing "Copy" to "Copy " might fool it :) (or possibly use the 'fake space' Chr(160) instead of true space 32/0x20) ... guessing probably not though :)
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Problem creating menuItem "copy" with cocoa

Post by wilbert »

Keya wrote:or i wonder if simply changing "Copy" to "Copy " might fool it :) (or possibly use the 'fake space' Chr(160) instead of true space 32/0x20) ... guessing probably not though :)
It's the selector "copy:" which seems to trigger the behavior and changing that, it won't call the right method :?
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply