Are there any examples of how to do this? I'm struggling to get started with one. :(
Just a few lines would help, adding options to an existing context menu.
TIA
Mike
Printable View
Are there any examples of how to do this? I'm struggling to get started with one. :(
Just a few lines would help, adding options to an existing context menu.
TIA
Mike
So maybe there isn't a way to add additional items to an existing context menu.
I've managed to achieve the same thing by building one from scratch, but it seems like overkill. :(
Mike
Hi Mike,
If it's on Windows, I think you want this:
[CODE]
Use cCJCommandBarSystem.pkg
Class cCJGridItemFrotaMenuItem is a cCJMenuItem
Procedure Construct_Object
Forward Send Construct_Object
Property String psItem "Item"
Property String psFrota "Frota"
Set psCaption to ("Classifica por"*(psFrota(Self))+"/"+(psItem(Self)) )
Set psToolTip to ("Clique p/classificar a lista por"*(Right( (psCaption(Self)),10)) )
Set psDescription to (psToolTip(Self))
Set psImage to "tvindex.bmp"
End_Procedure
Procedure OnExecute Variant vCommandBarControl
String sCaption sBarra sToolTip
Integer iSrv iIndex
Get Server of (Focus(Self)) to iSrv
Get Ordering of iSrv to iIndex
If (iIndex<>2);
Move 2 to iIndex //Por Frota
Else Move 1 to iIndex //Por Item
Set Ordering of iSrv to iIndex
//Considerado aqui: Por Item=Coluna 0 e Por Frota=Coluna 1
Send ChangeOrdering of (Focus(Self)) (iIndex-1) False
Set piOnIdle of iSrv to 1
Move "/" to sBarra
Get psCaption to sCaption
Get psToolTip to sToolTip
Move (Left(sCaption,14)) to sCaption
Move (Left(sToolTip,32)) to sToolTip
If (iIndex=2) Begin
Move (sCaption*((psItem(Self))+sBarra+(psFrota(Self)) ) ) to sCaption
Move (sToolTip*((psItem(Self))+sBarra+(psFrota(Self)) ) ) to sToolTip
End
Else Begin
Move (sCaption*((psFrota(Self))+sBarra+(psItem(Self)) ) ) to sCaption
Move (sToolTip*((psFrota(Self))+sBarra+(psItem(Self)) ) ) to sToolTip
End
Set psCaption to sCaption
Set psToolTip to sToolTip
Set psDescription to sToolTip
End_Procedure
End_Class
Class cCJGridFiltroExcluidosMenuItem is a cCJMenuItem
Procedure Construct_Object
Forward Send Construct_Object
Set psCaption to "Liga/Desliga Excluídos"
Set psToolTip to "Clique p/Ligar/Desligar filtros excluídos"
Set psDescription to "Clique para Ligar/Desligar o filtro de excluídos e PT"
Set psImage to "autoexc.bmp"
End_Procedure
Procedure OnExecute Variant vCommandBarControl
Integer iSrv iAutoExcluido
RowID riTempId
tDataSourceRow[] DataSourceArray
Get Server of (Focus(Self)) to iSrv
Get piAutoExcluido of iSrv to iAutoExcluido
If iAutoExcluido;
Set piAutoExcluido of iSrv to 0
Else Set piAutoExcluido of iSrv to 1 //Exibe excluídos
Send Rebuild_Constraints of iSrv
//Sempre Reset - 08/09/2015
Move False to Found
If (Auto.Recnum>0);
Send Find_By_Recnum of iSrv Auto.File_Number Auto.Recnum
If (Found=False) Begin
Send Request_Find of iSrv First_Record Auto.File_Number -1
If (Found=False) Begin
Get CurrentRowId of iSrv to riTempId
If not (IsNullRowId(riTempId));
Send InitializeData of (Focus(Self)) DataSourceArray
Send Clear of iSrv
End
End
Set piOnIdle of iSrv to 1
End_Procedure
End_Class
[/CODE]
In dbCjGrid:
[CODE]
Function MyCreateHeaderContextMenu Returns Handle
Handle hoMenu hoMenu1
Get Create (RefClass(cCJContextMenu)) to hoMenu
Get Create of hoMenu (RefClass(cCJGridFieldChooserMenuItem)) to hoMenu1
Get Create of hoMenu (RefClass(cCJGridRestoreLayoutMenuItem)) to hoMenu1
Set pbControlBeginGroup of hoMenu1 to True
Get Create of hoMenu (RefClass(cCJGridFreezeColumnMenuItem)) to hoMenu1
Set pbControlBeginGroup of hoMenu1 to True
Get Create of hoMenu (RefClass(cCJGridItemFrotaMenuItem )) to hoMenu1
Set pbControlBeginGroup of hoMenu1 to True
Get Create of hoMenu (RefClass(cCJGridFiltroExcluidosMenuItem)) to hoMenu1
Function_Return hoMenu
End_Function
Procedure Activating
Handle hoContextMenu
Get MyCreateHeaderContextMenu to hoContextMenu
Set phoHeaderContextMenu to hoContextMenu
Forward Send Activating
End_Procedure
Procedure OnIdle
Forward Send OnIdle
If (piOnIdle(oAUTO_DD(Self))) Begin
Set piOnIdle of oAuto_DD to 0
Send TrocaImg
End
End_Procedure
[/CODE]
[ATTACH=CONFIG]15032[/ATTACH]
I take this opportunity to suggest in DF 2022 that the original menu contexts include figures of beauty.
Regards,
Thanks Edgard! :)
I'm pretty much there, but I'll be looking hard at your code.
Mike
This coding is exaggerated where perhaps you don't want to animate the figure and/or controls as per the menu selection.
I agree, that this could have a simpler coding or maybe, we don't know.
I had to crack my head a lot to get the result.
It really works!
But free time means more rest in our minds.:cool:
Take a look at [URL]https://docs.dataaccess.com/dataflexhelp/mergedProjects/VDFClassRef/cCJContextMenu-Event-OnPopupInit.htm[/URL]
:D
Thanks Peter
That was pretty much exactly what I was looking for, I think, but I reached a similar solution a slightly different way (via augmenting Popup). Maybe I'll change my approach to that... or maybe not, as it is working now. ;)
Mike
Actually I did refactor it to use OnPopupInit (just involved changing the procedure name and taking out the Forward Send). :)
Mike