PC Review


Reply
Thread Tools Rate Thread

Customizing Context menu; get duplicates in to-do Bar

 
 
Zeus
Guest
Posts: n/a
 
      7th Jan 2009
I am starting an Add-In which so far just modifies the Context menu. It will
do it one way for an email and another for a task. When right click on an
email in the Inbox viewer pane it works great. If I look at the email on my
To-Do bar then, my custom button has been doubled, also if I look at a task
in the To-Do Bar my entires for that get doubled as well.

Here is my ItemContextMenuDisplay handler:

try
{
mail = Selection[1] as Outlook.MailItem;
task = Selection[1] as Outlook.TaskItem;

if (mail != null && task == null)
{
newTaskButton =
CommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, missing, missing, missing, true) as Microsoft.Office.Core.CommandBarButton;
newTaskButton.Visible = true;
newTaskButton.Caption = createNewTaskPrompt;
newTaskButton.Click += ConvertMailToTaskAction;
}
else if (task != null && mail == null)
{
startWorkButton =
CommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, missing, missing, missing, true) as Microsoft.Office.Core.CommandBarButton;
startWorkButton.Visible = true;
startWorkButton.Caption = startWorkingPrompt;
startWorkButton.Click += startTimerAction;

stopWorkButton =
CommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, missing, missing, missing, true) as Microsoft.Office.Core.CommandBarButton;
stopWorkButton.Visible = true;
stopWorkButton.Caption = stopWorkingPrompt;
stopWorkButton.Click += stopTimerAction;
}
}


and Here is my COntextMenuClose handler:

try
{
if (newTaskButton != null)
{
newTaskButton.Click -= ConvertMailToTaskAction;
newTaskButton = null;
}

if (startWorkButton != null)
{
startWorkButton.Click -= startTimerAction;
startWorkButton = null;
}

if (stopWorkButton != null)
{
stopWorkButton.Click -= stopTimerAction;
stopWorkButton = null;
}

mail = null;
task = null;
}

The same code is behaving different and it just has me baffled. I thought
maybe it was getting run twice and made all sorts of logic to check for its
existence and stuff but nothing has prevent duplicates on my to-do bar.

Can anyone see anything I am doing wrong? Or explain the different behavior
between the to-do bar and inbox viewer pane.



 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      8th Jan 2009
I don't know if either of these things are affecting what you see, but when
you add your buttons assign them unique Tag properties. Also, instead of
trying to assign Selection[1] to both a task and mail item test the item for
Class to see what it actually is. If it's a task and you assign it to a mail
item the try{} block will fail with an exception and go to your catch{}
block.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Zeus" <(E-Mail Removed)> wrote in message
news:4F7FB7BB-1682-4C07-B979-(E-Mail Removed)...
>I am starting an Add-In which so far just modifies the Context menu. It
>will
> do it one way for an email and another for a task. When right click on an
> email in the Inbox viewer pane it works great. If I look at the email on
> my
> To-Do bar then, my custom button has been doubled, also if I look at a
> task
> in the To-Do Bar my entires for that get doubled as well.
>
> Here is my ItemContextMenuDisplay handler:
>
> try
> {
> mail = Selection[1] as Outlook.MailItem;
> task = Selection[1] as Outlook.TaskItem;
>
> if (mail != null && task == null)
> {
> newTaskButton =
> CommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton,
> missing, missing, missing, true) as
> Microsoft.Office.Core.CommandBarButton;
> newTaskButton.Visible = true;
> newTaskButton.Caption = createNewTaskPrompt;
> newTaskButton.Click += ConvertMailToTaskAction;
> }
> else if (task != null && mail == null)
> {
> startWorkButton =
> CommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton,
> missing, missing, missing, true) as
> Microsoft.Office.Core.CommandBarButton;
> startWorkButton.Visible = true;
> startWorkButton.Caption = startWorkingPrompt;
> startWorkButton.Click += startTimerAction;
>
> stopWorkButton =
> CommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton,
> missing, missing, missing, true) as
> Microsoft.Office.Core.CommandBarButton;
> stopWorkButton.Visible = true;
> stopWorkButton.Caption = stopWorkingPrompt;
> stopWorkButton.Click += stopTimerAction;
> }
> }
>
>
> and Here is my COntextMenuClose handler:
>
> try
> {
> if (newTaskButton != null)
> {
> newTaskButton.Click -= ConvertMailToTaskAction;
> newTaskButton = null;
> }
>
> if (startWorkButton != null)
> {
> startWorkButton.Click -= startTimerAction;
> startWorkButton = null;
> }
>
> if (stopWorkButton != null)
> {
> stopWorkButton.Click -= stopTimerAction;
> stopWorkButton = null;
> }
>
> mail = null;
> task = null;
> }
>
> The same code is behaving different and it just has me baffled. I thought
> maybe it was getting run twice and made all sorts of logic to check for
> its
> existence and stuff but nothing has prevent duplicates on my to-do bar.
>
> Can anyone see anything I am doing wrong? Or explain the different
> behavior
> between the to-do bar and inbox viewer pane.
>
>
>


 
Reply With Quote
 
Zeus
Guest
Posts: n/a
 
      8th Jan 2009
Thanks Ken,
I implemented both of your suggestions, they did not fix my issue, but I
appreciate knowing how to do things in the more prescribed manner. I will
make sure to do things this way from now on.

"Ken Slovak - [MVP - Outlook]" wrote:

> I don't know if either of these things are affecting what you see, but when
> you add your buttons assign them unique Tag properties. Also, instead of
> trying to assign Selection[1] to both a task and mail item test the item for
> Class to see what it actually is. If it's a task and you assign it to a mail
> item the try{} block will fail with an exception and go to your catch{}
> block.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Zeus" <(E-Mail Removed)> wrote in message
> news:4F7FB7BB-1682-4C07-B979-(E-Mail Removed)...
> >I am starting an Add-In which so far just modifies the Context menu. It
> >will
> > do it one way for an email and another for a task. When right click on an
> > email in the Inbox viewer pane it works great. If I look at the email on
> > my
> > To-Do bar then, my custom button has been doubled, also if I look at a
> > task
> > in the To-Do Bar my entires for that get doubled as well.
> >
> > Here is my ItemContextMenuDisplay handler:
> >
> > try
> > {
> > mail = Selection[1] as Outlook.MailItem;
> > task = Selection[1] as Outlook.TaskItem;
> >
> > if (mail != null && task == null)
> > {
> > newTaskButton =
> > CommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton,
> > missing, missing, missing, true) as
> > Microsoft.Office.Core.CommandBarButton;
> > newTaskButton.Visible = true;
> > newTaskButton.Caption = createNewTaskPrompt;
> > newTaskButton.Click += ConvertMailToTaskAction;
> > }
> > else if (task != null && mail == null)
> > {
> > startWorkButton =
> > CommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton,
> > missing, missing, missing, true) as
> > Microsoft.Office.Core.CommandBarButton;
> > startWorkButton.Visible = true;
> > startWorkButton.Caption = startWorkingPrompt;
> > startWorkButton.Click += startTimerAction;
> >
> > stopWorkButton =
> > CommandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton,
> > missing, missing, missing, true) as
> > Microsoft.Office.Core.CommandBarButton;
> > stopWorkButton.Visible = true;
> > stopWorkButton.Caption = stopWorkingPrompt;
> > stopWorkButton.Click += stopTimerAction;
> > }
> > }
> >
> >
> > and Here is my COntextMenuClose handler:
> >
> > try
> > {
> > if (newTaskButton != null)
> > {
> > newTaskButton.Click -= ConvertMailToTaskAction;
> > newTaskButton = null;
> > }
> >
> > if (startWorkButton != null)
> > {
> > startWorkButton.Click -= startTimerAction;
> > startWorkButton = null;
> > }
> >
> > if (stopWorkButton != null)
> > {
> > stopWorkButton.Click -= stopTimerAction;
> > stopWorkButton = null;
> > }
> >
> > mail = null;
> > task = null;
> > }
> >
> > The same code is behaving different and it just has me baffled. I thought
> > maybe it was getting run twice and made all sorts of logic to check for
> > its
> > existence and stuff but nothing has prevent duplicates on my to-do bar.
> >
> > Can anyone see anything I am doing wrong? Or explain the different
> > behavior
> > between the to-do bar and inbox viewer pane.
> >
> >
> >

>
>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      9th Jan 2009
I'm not sure then why you are seeing what you're seeing.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Zeus" <(E-Mail Removed)> wrote in message
news:2788AA8B-8481-434A-AB9F-(E-Mail Removed)...
> Thanks Ken,
> I implemented both of your suggestions, they did not fix my issue, but I
> appreciate knowing how to do things in the more prescribed manner. I will
> make sure to do things this way from now on.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unusual situation in customizing right click open with context menu louise Windows XP Customization 7 4th May 2007 04:47 AM
Context Menu - Microsofts standard file context menu =?Utf-8?B?TWFybg==?= Microsoft C# .NET 0 6th Dec 2004 08:49 PM
Context menus and treeviews, suggestions for a NODE sensitive context menu Eric Newton Microsoft Dot NET Framework Forms 4 13th Jan 2004 09:25 PM
Re: Contect Menu Editor (Context Menu Editor / Context Menu Manager) BillR Freeware 5 13th Aug 2003 04:40 AM
Re: Customizing context menus? Kelly Windows XP Customization 2 30th Jul 2003 10:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:00 AM.