-
Notifications
You must be signed in to change notification settings - Fork 16
/
ThisAddIn.cs
executable file
·175 lines (140 loc) · 6.06 KB
/
ThisAddIn.cs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using Outlook = Microsoft.Office.Interop.Outlook;
using Microsoft.Office.Tools.Ribbon;
using System.Threading;
namespace NotifySecurity
{
public partial class ThisAddIn
{
//Outlook.Inspectors inspectors;
Outlook.Explorer currentExplorer = null;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
//new System.Threading.Thread(() =>
//{
CreateRibbonExtensibilityObject();
#region declaration of the new event
currentExplorer = this.Application.ActiveExplorer();
if (currentExplorer == null) return;
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler
(CurrentExplorer_Event);
#endregion
//}).Start();
}
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new Ribbon1();
}
// protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
#region action when a new mail is selected
private void CurrentExplorer_Event()
{
//if (currentExplorer == null) return null
Outlook.MAPIFolder selectedFolder =
this.Application.ActiveExplorer().CurrentFolder;
bool SelectedObjectIsMail = false;
//String expMessage = "Your current folder is " + selectedFolder.Name + ".\n";
// String itemMessage = "Item is unknown.";
try
{
if (this.Application.ActiveExplorer().Selection.Count > 0)
{
Object selObject = this.Application.ActiveExplorer().Selection[1];
if (selObject is Outlook.MailItem)
{
SelectedObjectIsMail = true;
/*
Outlook.MailItem mailItem =
(selObject as Outlook.MailItem);
itemMessage = "The item is an e-mail message." +
" The subject is " + mailItem.Subject + ".";
mailItem.Display(false);
*/
}
else if (selObject is Outlook.ContactItem)
{
/*Outlook.ContactItem contactItem =
(selObject as Outlook.ContactItem);
itemMessage = "The item is a contact." +
" The full name is " + contactItem.Subject + ".";
contactItem.Display(false);
*/
}
else if (selObject is Outlook.AppointmentItem)
{
/*
Outlook.AppointmentItem apptItem =
(selObject as Outlook.AppointmentItem);
itemMessage = "The item is an appointment." +
" The subject is " + apptItem.Subject + ".";
*/
}
else if (selObject is Outlook.TaskItem)
{
/*
Outlook.TaskItem taskItem =
(selObject as Outlook.TaskItem);
itemMessage = "The item is a task. The body is "
+ taskItem.Body + ".";
*/
}
else if (selObject is Outlook.MeetingItem)
{
/*
Outlook.MeetingItem meetingItem =
(selObject as Outlook.MeetingItem);
itemMessage = "The item is a meeting item. " +
"The subject is " + meetingItem.Subject + ".";
*/
}
}
// expMessage = expMessage + itemMessage;
ThisRibbonCollection ribbonCollection =Globals.Ribbons[Globals.ThisAddIn.Application.ActiveInspector()];
if (SelectedObjectIsMail)
{
/* Ribbon1.
ribbonCollection.Ribbon1.comboBox1.Text = "Hello World";
*/
}
}
catch (Exception )
{
// expMessage = ex.Message;
}
// MessageBox.Show(expMessage);
}
#endregion
#region action when a new mail is created
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
if (mailItem != null)
{
if (mailItem.EntryID == null)
{
mailItem.Subject = "This text was added by using code";
mailItem.Body = "This text was added by using code";
}
}
}
#endregion
#region DO NOT TOUCH
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// Note: Outlook no longer raises this event. If you have code that
// must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
}
#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
#endregion
}
}