override context menu and add new menuItem

For users or potential users.
Post Reply
pid_user
Posts: 67
Joined: Thu Jun 04, 2015 9:31 am

override context menu and add new menuItem

Post by pid_user » Tue May 23, 2017 6:08 am

if(Plugins.HookMethod(this,"ContrApptSheet2_MouseDown_start",ContrApptSingle.ClickedAptNum,e))
{
return;
}

with this hookmethod i want to add new menuitem in menuApt contextmenu on RightClick of ContrApptSheet2.I was unable to ovveride contextMenu and add new one item in existing menuApt contextMenu.

Thanks,
Ashok patel

allends
Posts: 235
Joined: Fri Aug 23, 2013 11:29 am

Re: override context menu and add new menuItem

Post by allends » Tue May 23, 2017 8:57 am

So I assume you copied the code from ContrApptSheet2_MouseDown into the plugin and are just adding in a small bit of code to add a menu item correct?
I don't see how that would fail if you made you code similarly to the way the existing code looks.
Allen
Open Dental Software
http://www.opendental.com

User avatar
jsalmon
Posts: 1551
Joined: Tue Nov 30, 2010 12:33 pm
Contact:

Re: override context menu and add new menuItem

Post by jsalmon » Tue May 23, 2017 9:14 am

You shouldn't override it, you need to use the object "Sender" and loop through all it's controls and find "menuApt" and then add to it's MenuItems. Know that your new menu item will get wiped out when the user clicks the Appts module button so you'll probably need to add code that first checks to see if your custom menu item is present and add it only when it is not present.
The best thing about a boolean is even if you are wrong, you are only off by a bit.

Jason Salmon
Open Dental Software
http://www.opendental.com

pid_user
Posts: 67
Joined: Thu Jun 04, 2015 9:31 am

Re: override context menu and add new menuItem

Post by pid_user » Mon May 29, 2017 10:17 pm

I am unable to find control for 'menuApt' only using the object "Sender" and I want add new new menu item in existing and don't want to wiped out existing menuItem. Please help me with this.

Thanks,
Ashok Patel

User avatar
cmcgehee
Posts: 711
Joined: Tue Aug 25, 2015 5:06 pm
Location: Salem, Oregon

Re: override context menu and add new menuItem

Post by cmcgehee » Tue May 30, 2017 8:15 am

The first option you could pursue is to utilize the hookmethod you mentioned to add your own behavior for the ContrApptSheet2_MouseDown method. To access menuApt in your code would look like this:

Code: Select all

public override bool HookMethod(object sender,string hookName,params object[] parameters) {//required method
	switch(hookName){
		case "ContrApptSheet2_MouseDown_start":
			ContrAppt contrAppt=(OpenDental.ContrChart)sender;
			ContextMenu menuApt=(TabControl)contrAppt.Controls.Find("menuApt",true)[0];
			//Now add any items that you want to menuApt
			return true;//You might want to return false here so that the real ContrApptSheet2_MouseDown still runs.
		default:
			return false;//this plugin does not implement the particular hook passed in.
	}
}
Another option is that we could add a hookaddcode for you right before the menuApt is show:

Code: Select all

//Texting
menuApt.MenuItems.Add("-");
menuApt.MenuItems[menuApt.MenuItems.Count-1].Name="Text Div";
menuApt.MenuItems.Add(Lan.g(this,"Send Text"),menuApt_Click);
menuApt.MenuItems[menuApt.MenuItems.Count-1].Name="Send Text";
if(!SmsPhones.IsIntegratedTextingEnabled() && !Programs.IsEnabled(ProgramName.CallFire)) {
	menuApt.MenuItems[menuApt.MenuItems.Count-1].Enabled=false;
}
menuApt.MenuItems.Add(Lan.g(this,"Send Confirmation Text"),menuApt_Click);
menuApt.MenuItems[menuApt.MenuItems.Count-1].Name="Send Confirmation Text";
if(!SmsPhones.IsIntegratedTextingEnabled() && !Programs.IsEnabled(ProgramName.CallFire)) {
	menuApt.MenuItems[menuApt.MenuItems.Count-1].Enabled=false;
}
//menuApt.MenuItems.Add(Lan.g(this,"Send Reminder Text"),menuApt_Click);
//if(!SmsPhones.IsIntegratedTextingEnabled() && !Programs.IsEnabled(ProgramName.CallFire)) {
//	menuApt.MenuItems[menuApt.MenuItems.Count-1].Enabled=false;
//}
Plugins.HookAddCode(this,"ContrApptSheet2_MouseDown_menuApt_right_click");
menuApt.Show(ContrApptSheet2,new Point(e.X,e.Y));
Chris McGehee
Open Dental Software
http://www.opendental.com

pid_user
Posts: 67
Joined: Thu Jun 04, 2015 9:31 am

Re: override context menu and add new menuItem

Post by pid_user » Mon Jun 25, 2018 10:03 am

Please do help add - Plugins.HookAddCode(this,"ContrApptSheet2_MouseDown_menuApt_right_click");. Believe will also need menuApt object to be public to access it.

Another option is that we could add a hookaddcode for you right before the menuApt is show:

Code: Select all

//Texting
menuApt.MenuItems.Add("-");
menuApt.MenuItems[menuApt.MenuItems.Count-1].Name="Text Div";
menuApt.MenuItems.Add(Lan.g(this,"Send Text"),menuApt_Click);
menuApt.MenuItems[menuApt.MenuItems.Count-1].Name="Send Text";
if(!SmsPhones.IsIntegratedTextingEnabled() && !Programs.IsEnabled(ProgramName.CallFire)) {
	menuApt.MenuItems[menuApt.MenuItems.Count-1].Enabled=false;
}
menuApt.MenuItems.Add(Lan.g(this,"Send Confirmation Text"),menuApt_Click);
menuApt.MenuItems[menuApt.MenuItems.Count-1].Name="Send Confirmation Text";
if(!SmsPhones.IsIntegratedTextingEnabled() && !Programs.IsEnabled(ProgramName.CallFire)) {
	menuApt.MenuItems[menuApt.MenuItems.Count-1].Enabled=false;
}
//menuApt.MenuItems.Add(Lan.g(this,"Send Reminder Text"),menuApt_Click);
//if(!SmsPhones.IsIntegratedTextingEnabled() && !Programs.IsEnabled(ProgramName.CallFire)) {
//	menuApt.MenuItems[menuApt.MenuItems.Count-1].Enabled=false;
//}
Plugins.HookAddCode(this,"ContrApptSheet2_MouseDown_menuApt_right_click");
menuApt.Show(ContrApptSheet2,new Point(e.X,e.Y));
[/quote]

User avatar
cmcgehee
Posts: 711
Joined: Tue Aug 25, 2015 5:06 pm
Location: Salem, Oregon

Re: override context menu and add new menuItem

Post by cmcgehee » Mon Jun 25, 2018 4:40 pm

Ashok,

I have added this hook for you. I gave it the name "ContrAppt.MouseDownAppointment_menuApt_right_click" because this section of code has changed since when I originally suggested this hook. You shouldn't need menuApt to be public. You can access it like this:

Code: Select all

OpenDental.ContrAppt contrAppt=(OpenDental.ContrAppt)sender;
ContextMenu menuApt=(ContextMenu)contrAppt.Controls.Find("menuApt",true)[0];
I backported the hook to 18.1.29.
Chris McGehee
Open Dental Software
http://www.opendental.com

pid_user
Posts: 67
Joined: Thu Jun 04, 2015 9:31 am

Re: override context menu and add new menuItem

Post by pid_user » Sat Jul 07, 2018 10:07 pm

cmcgehee wrote:Ashok,

I have added this hook for you. I gave it the name "ContrAppt.MouseDownAppointment_menuApt_right_click" because this section of code has changed since when I originally suggested this hook. You shouldn't need menuApt to be public. You can access it like this:

Code: Select all

OpenDental.ContrAppt contrAppt=(OpenDental.ContrAppt)sender;
ContextMenu menuApt=(ContextMenu)contrAppt.Controls.Find("menuApt",true)[0];
I backported the hook to 18.1.29.
Hi Chris,

Thanks for changes. For some reason I am not able to find menuApt object via code below.

Code: Select all

ContextMenu menuApt=(ContextMenu)contrAppt.Controls.Find("menuApt",true)[0];
To make things simpler, why not pass the menuApt as a parameter. Something like this.

Code: Select all

Plugins.HookAddCode(this,"ContrAppt.MouseDownAppointment_menuApt_right_click", menuApt);
When updated HookAddCode with parameter, I was able to get menuApt and add new menu on the fly. Hope you can help add this change and back port it

User avatar
cmcgehee
Posts: 711
Joined: Tue Aug 25, 2015 5:06 pm
Location: Salem, Oregon

Re: override context menu and add new menuItem

Post by cmcgehee » Mon Jul 09, 2018 8:42 am

Can you share the snippet of code where you're trying to find the menuApt object via Controls.Find? Maybe I can spot why it's not working.
Chris McGehee
Open Dental Software
http://www.opendental.com

pid_user
Posts: 67
Joined: Thu Jun 04, 2015 9:31 am

Re: override context menu and add new menuItem

Post by pid_user » Tue Jul 10, 2018 8:01 am

cmcgehee wrote:Can you share the snippet of code where you're trying to find the menuApt object via Controls.Find? Maybe I can spot why it's not working.

Code: Select all

ContextMenu menuApt=(ContextMenu)contrAppt.Controls.Find("menuApt",true)[0];
I also tried to loop thru recursively into Controls collection still was not able to find menuApt.

User avatar
cmcgehee
Posts: 711
Joined: Tue Aug 25, 2015 5:06 pm
Location: Salem, Oregon

Re: override context menu and add new menuItem

Post by cmcgehee » Tue Jul 10, 2018 9:40 am

Can you share the whole method where you have this line of code?
Chris McGehee
Open Dental Software
http://www.opendental.com

User avatar
jsalmon
Posts: 1551
Joined: Tue Nov 30, 2010 12:33 pm
Contact:

Re: override context menu and add new menuItem

Post by jsalmon » Tue Jul 10, 2018 10:20 am

jsalmon wrote:You shouldn't override it, you need to use the object "Sender" and loop through all it's controls and find "menuApt" and then add to it's MenuItems. Know that your new menu item will get wiped out when the user clicks the Appts module button so you'll probably need to add code that first checks to see if your custom menu item is present and add it only when it is not present.
I was wrong, the object "Sender" doesn't own menuApt. Technically menuApt gets dynamically associated to the ContrApptSheet2 control in a line after the hook method. Chris can simply pass the control into the hook method.
The best thing about a boolean is even if you are wrong, you are only off by a bit.

Jason Salmon
Open Dental Software
http://www.opendental.com

pid_user
Posts: 67
Joined: Thu Jun 04, 2015 9:31 am

Re: override context menu and add new menuItem

Post by pid_user » Tue Jul 10, 2018 2:24 pm

"Technically menuApt gets dynamically associated to the ContrApptSheet2 control in a line after the hook method
"

Thanks Jason for clarification.
Chris can simply pass the control into the hook method
This will be wonderful.

Thanks guys and please do update which version its gets ported back.

pid_user
Posts: 67
Joined: Thu Jun 04, 2015 9:31 am

Re: override context menu and add new menuItem

Post by pid_user » Wed Jul 11, 2018 11:42 am

OD Team,

Any updates on this.

Thanks,
Ashok

User avatar
cmcgehee
Posts: 711
Joined: Tue Aug 25, 2015 5:06 pm
Location: Salem, Oregon

Re: override context menu and add new menuItem

Post by cmcgehee » Wed Jul 11, 2018 12:36 pm

I just now committed the change to the hook. It will be available in 18.1.35.0. Sorry about giving you faulty advice before.
Chris McGehee
Open Dental Software
http://www.opendental.com

pid_user
Posts: 67
Joined: Thu Jun 04, 2015 9:31 am

Re: override context menu and add new menuItem

Post by pid_user » Thu Jul 12, 2018 10:46 am

cmcgehee wrote:I just now committed the change to the hook. It will be available in 18.1.35.0. Sorry about giving you faulty advice before.

Thank You!

Post Reply