The standard control menus

Post

Posted
Rating:
#1 (In Topic #1322)
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 This has driven me bonkers several times in the last decade! And its back again.

Is there any way to "get at" the standard popup menus for a control? What I want to do is, in the form code, manipulate just one of the menu items. An example being a simple textbox. Among the items is "Delete", now if the textbox contains a primary key I want to disable the Delete menu item. I don't want to have to re-implement the other menu items, Undo/Redo/Cut/Copy/Paste just the Delete.

Has anyone ever managed this?
b

Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
Not sure if this will work for you but may give you some ideas toward solving your problem.

I had the same issue where I wanted to display one of more pop-up menu items and disable the others.

I used this subroutine:

Code (gambas)

  1. Private Sub SetMenuOptions(InMenu As Menu, InName As String, InMode As Boolean)
  2.  
  3.   Dim TmpMnu As Menu
  4.   Dim TmpAry As String[]
  5.   Dim TmpInt As Integer
  6.  
  7.   If InName = "" Then 'Set ALL menus to the required mode.
  8.     For Each TmpMnu In InMenu.Children
  9.       TmpMnu.Enabled = InMode
  10.     Next
  11.   Else 'Set selected menus (by name) to the required mode.
  12.     TmpAry = Split(InName, ",")
  13.     For Each TmpMnu In InMenu.Children
  14.       For TmpInt = 0 To TmpAry.Max
  15.         If String.UCase(TmpMnu.Text) = String.UCase(TmpAry[TmpInt]) Then TmpMnu.Enabled = InMode
  16.       Next
  17.     Next
  18.  

Example of calling the subroutine:

Code (gambas)

  1.   SetMenuOptions(EdtPopup, "Needs Edit,Add Scene", False)
with EdtPopup being the popup menu of the specific component in question.
This would disable the menu optioos 'Needs Edit' & 'Add Scene'

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
I hope I have understood what you are trying to do. Have a look at the attached.

Attachment
Online now: Yes Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
 I don't think it's possible to override single menu actions.

Possibly in a gambas control you could override a single menu method but i would not imagine a c-code toolkit one is possible.

I guess you know how to override the whole menu in the mouse events.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Mmmm maybe I wasn't clear enough.

Following my example textbox. It has a popup menu that is there compliments of the GUI or something inside Gambas itself. I don't know.

If I try to set the form designer control popup menu to a menu that I have defined for the form, then the natural menu disappears and I have to create a) the whole menu and b) the implementation for each item. Let's just take Undo and Redo. The code to achieve that is already there inside the black box. However, if I make a popup menu for the form then if I want to have Undo/Redo items than I have to code handlers for them. I dont want to have to do that!
On the other hand, if I just want to disable the Paste item (for some ridiculous reason) then I am forced into the above - where I have to implement the whole damn menu (or just the parts of it I do want.)

What I want is to do

Code (gambas)

  1. TextBox1.NativeMenu["mnuPaste"].Enabled = False

Pretty simple desire. Surely someone has come across this before. The sheer idea of having to code an Undo/Redo stack in the form is silly.

Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’
 I think i understood.

Maybe Benoit knows a way to hack into it but i can't imagine you can access the toolkit controls inner workings like that because they are inner workings.
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 My brain hurts.
Apparently in GTK this is simple.
In QT5 the problem is well known but un-resolved.
GTK provides access to internal popup menus as a gtk_menu_popup object (which doesn't work with wayland hahahah but who cares.)
There is approximately 2.13 galaxies of web hits regarding this re QT, but I have yet to find an answer. Hence my brain problem. I need a scotch, or two, or

cheers
b

Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’
Sounds like you need to talk to Ben.

If anyone knows how to do it or can provide a way to do it it'll be Benoit :)
Online now: No Back to the top
1 guest and 0 members have just viewed this.