This repository was archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThisAddIn.cs
More file actions
73 lines (64 loc) · 3.07 KB
/
ThisAddIn.cs
File metadata and controls
73 lines (64 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Outlook;
namespace EmailToProject
{
public partial class EmailToProject
{
private ProjectRequest request;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
request = new ProjectRequest();
Application.ItemContextMenuDisplay += ApplicationItemContextMenuDisplay;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
// Outlook menu item
// This triggers whenever a mailitem is rightclicked, and gets a "selection" object passed which contains all selected items
void ApplicationItemContextMenuDisplay(CommandBar commandBar, Selection selection)
{
var cb = commandBar.Controls.Add(MsoControlType.msoControlButton, missing, missing, missing, true) as CommandBarButton;
if (cb == null) return;
cb.Visible = true;
//cb.Picture = ImageConverter.ImageToPictureDisp(Properties.Resources.Desktop.ToBitmap()); // some icon stored in the resources file
cb.Style = MsoButtonStyle.msoButtonIconAndCaption; // set style to text AND icon
cb.Click += new _CommandBarButtonEvents_ClickEventHandler(AsterixHook); // link click event
// single MailItem item selection only, NOT 0 based
if (selection.Count == 1 && selection[1] is MailItem)
{
var item = (MailItem)selection[1]; // retrieve the selected item
string subject = item.Subject;
cb.Caption = "Import into Projects"; // set caption
cb.Enabled = true; // user selected a single mail item, enable the menu
cb.Parameter = item.EntryID; // this will pass the selected item's identification down when clicked
}
else
{
cb.Caption = "Invalid selection";
cb.Enabled = false;
}
}
private void AsterixHook(CommandBarButton control, ref bool canceldefault)
{
string entryid = control.Parameter; // the outlook entry id clicked by the user
var item = (MailItem)this.Application.Session.GetItemFromID(entryid); // the actual item
new ProjectForm(item, request);
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}