2013-03-29 17:00:07 +01:00
|
|
|
|
using Microsoft.Win32;
|
2013-06-27 20:30:15 +02:00
|
|
|
|
using Outlook2013TodoAddIn.Forms;
|
2013-03-29 17:00:07 +01:00
|
|
|
|
using System;
|
2013-04-01 18:03:41 +02:00
|
|
|
|
using System.Drawing;
|
2013-03-29 17:00:07 +01:00
|
|
|
|
using System.Linq;
|
2013-03-30 01:35:37 +01:00
|
|
|
|
using System.Windows.Forms;
|
2013-03-29 17:00:07 +01:00
|
|
|
|
using Office = Microsoft.Office.Core;
|
|
|
|
|
|
|
|
|
|
namespace Outlook2013TodoAddIn
|
|
|
|
|
{
|
2013-03-29 19:03:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class for the add-in
|
|
|
|
|
/// </summary>
|
2013-03-29 17:00:07 +01:00
|
|
|
|
public partial class ThisAddIn
|
|
|
|
|
{
|
2013-03-29 19:03:00 +01:00
|
|
|
|
#region "Properties"
|
2013-03-29 17:00:07 +01:00
|
|
|
|
|
2013-03-29 19:03:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Control with calendar, etc...
|
|
|
|
|
/// </summary>
|
|
|
|
|
public AppointmentsControl AppControl { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Custom task pane
|
|
|
|
|
/// </summary>
|
2013-03-29 17:00:07 +01:00
|
|
|
|
public Microsoft.Office.Tools.CustomTaskPane ToDoTaskPane { get; set; }
|
|
|
|
|
|
2013-03-29 19:03:00 +01:00
|
|
|
|
#endregion "Properties"
|
|
|
|
|
|
|
|
|
|
#region "Methods"
|
2013-03-29 17:00:07 +01:00
|
|
|
|
|
2013-03-29 19:03:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initialize settings upon add-in startup
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">EventArgs</param>
|
2013-03-29 17:00:07 +01:00
|
|
|
|
private void ThisAddIn_Startup(object sender, System.EventArgs e)
|
|
|
|
|
{
|
2013-03-30 01:35:37 +01:00
|
|
|
|
Globals.ThisAddIn.Application.NewMailEx += Application_NewMailEx;
|
2013-03-29 19:03:00 +01:00
|
|
|
|
this.AddRegistryNotification();
|
|
|
|
|
|
|
|
|
|
this.AppControl = new AppointmentsControl();
|
2013-05-01 22:22:27 +02:00
|
|
|
|
this.AppControl.MailAlertsEnabled = Properties.Settings.Default.MailAlertsEnabled;
|
2013-07-18 20:16:35 +02:00
|
|
|
|
this.AppControl.ShowPastAppointments = Properties.Settings.Default.ShowPastAppointments;
|
|
|
|
|
this.AppControl.Accounts = Properties.Settings.Default.Accounts;
|
|
|
|
|
this.AppControl.ShowFriendlyGroupHeaders = Properties.Settings.Default.ShowFriendlyGroupHeaders;
|
2013-07-22 22:12:10 +02:00
|
|
|
|
this.AppControl.ShowTasks = Properties.Settings.Default.ShowTasks;
|
2013-07-24 17:51:16 +02:00
|
|
|
|
this.AppControl.FirstDayOfWeek = Properties.Settings.Default.FirstDayOfWeek;
|
2013-03-29 19:03:00 +01:00
|
|
|
|
this.AppControl.NumDays = Properties.Settings.Default.NumDays; // Setting the value will load the appointments
|
2013-05-03 16:27:19 +02:00
|
|
|
|
|
2013-03-29 19:03:00 +01:00
|
|
|
|
ToDoTaskPane = this.CustomTaskPanes.Add(this.AppControl, "Appointments");
|
2013-03-30 00:31:49 +01:00
|
|
|
|
ToDoTaskPane.Visible = Properties.Settings.Default.Visible;
|
2013-03-29 17:00:07 +01:00
|
|
|
|
ToDoTaskPane.Width = Properties.Settings.Default.Width;
|
|
|
|
|
ToDoTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
|
|
|
|
|
ToDoTaskPane.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
|
|
|
|
|
ToDoTaskPane.VisibleChanged += ToDoTaskPane_VisibleChanged;
|
2013-03-29 19:03:00 +01:00
|
|
|
|
this.AppControl.SizeChanged += appControl_SizeChanged;
|
2013-03-30 00:31:49 +01:00
|
|
|
|
|
2013-05-03 16:27:19 +02:00
|
|
|
|
// Selecting the date will retrieve the appointments
|
|
|
|
|
// Otherwise it'll take the one used when the designer changed!
|
|
|
|
|
this.AppControl.SelectedDate = DateTime.Today;
|
2013-07-22 22:12:10 +02:00
|
|
|
|
// this.AppControl.RetrieveData();
|
2013-05-03 16:27:19 +02:00
|
|
|
|
|
2013-03-30 00:31:49 +01:00
|
|
|
|
Globals.ThisAddIn.Application.ActiveExplorer().Deactivate += ThisAddIn_Deactivate;
|
|
|
|
|
|
|
|
|
|
// TODO: Make sure there are no memory leaks (dispose COM objects)
|
2013-03-29 17:00:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-01 23:04:34 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Process new email
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="EntryIDCollection">ID of the email</param>
|
2013-03-30 01:35:37 +01:00
|
|
|
|
private void Application_NewMailEx(string EntryIDCollection)
|
|
|
|
|
{
|
2013-05-01 22:22:27 +02:00
|
|
|
|
if (Properties.Settings.Default.MailAlertsEnabled)
|
2013-03-30 01:35:37 +01:00
|
|
|
|
{
|
2013-05-01 21:30:43 +02:00
|
|
|
|
|
|
|
|
|
Microsoft.Office.Interop.Outlook.MailItem newMail = Globals.ThisAddIn.Application.Session.GetItemFromID(EntryIDCollection) as Microsoft.Office.Interop.Outlook.MailItem;
|
|
|
|
|
if (newMail != null)
|
|
|
|
|
{
|
|
|
|
|
NewMailAlert nm = new NewMailAlert(newMail, Properties.Settings.Default.DisplayTimeOut);
|
|
|
|
|
// Show the popup without stealing focus
|
|
|
|
|
SoundHelper.sndPlaySoundW(SoundHelper.MailBeep, SoundHelper.SND_NODEFAULT);
|
|
|
|
|
nm.ShowPopup();
|
|
|
|
|
}
|
2013-03-30 01:35:37 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-29 19:03:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Store the new size setting upon resizing
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">EventArgs</param>
|
2013-03-29 17:00:07 +01:00
|
|
|
|
private void appControl_SizeChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Properties.Settings.Default.Width = ToDoTaskPane.Width;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-29 19:03:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Toggle ribbon button's status
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">EventArgs</param>
|
2013-03-29 17:00:07 +01:00
|
|
|
|
private void ToDoTaskPane_VisibleChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-03-30 00:31:49 +01:00
|
|
|
|
// Can't save visibility here because this fires when closing Outlook, and by that time the pane is ALWAYS not visible
|
2013-03-29 17:00:07 +01:00
|
|
|
|
// Properties.Settings.Default.Visible = ToDoTaskPane.Visible;
|
|
|
|
|
TodoRibbonAddIn rbn = Globals.Ribbons.FirstOrDefault(r => r is TodoRibbonAddIn) as TodoRibbonAddIn;
|
|
|
|
|
if (rbn != null)
|
|
|
|
|
{
|
|
|
|
|
rbn.toggleButton1.Checked = ToDoTaskPane.Visible;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-30 00:31:49 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is the alternative to capture the visibility of the pane when shutting down Outlook
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ThisAddIn_Deactivate()
|
|
|
|
|
{
|
|
|
|
|
Properties.Settings.Default.Visible = ToDoTaskPane.Visible;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-29 17:00:07 +01:00
|
|
|
|
/// <summary>
|
2013-03-29 19:03:00 +01:00
|
|
|
|
/// This is not executed by default
|
2013-03-29 17:00:07 +01:00
|
|
|
|
/// http://msdn.microsoft.com/en-us/library/office/ee720183.aspx#OL2010AdditionalShutdownChanges_AddinShutdownChangesinOL2010Beta
|
2013-03-29 19:03:00 +01:00
|
|
|
|
/// We MANUALLY add notification to the registry of each user below
|
2013-03-29 17:00:07 +01:00
|
|
|
|
/// </summary>
|
2013-03-29 19:03:00 +01:00
|
|
|
|
/// <param name="sender">Sender</param>
|
|
|
|
|
/// <param name="e">EventArgs</param>
|
2013-03-29 17:00:07 +01:00
|
|
|
|
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
|
|
|
|
|
{
|
2013-03-29 19:03:00 +01:00
|
|
|
|
// Can't call property setters such as: Properties.Settings.Default.NumDays = XXX because the pane is already disposed.
|
|
|
|
|
// Settings will be set while the app is running and saved here.
|
2013-03-29 17:00:07 +01:00
|
|
|
|
Properties.Settings.Default.Save();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-29 19:03:00 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Implement shutdown notification for this particular add-in
|
|
|
|
|
/// http://msdn.microsoft.com/en-us/library/office/ee720183.aspx#OL2010AdditionalShutdownChanges_AddinShutdownChangesinOL2010Beta
|
|
|
|
|
/// HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\Addins\<ProgID>\[RequireShutdownNotification]=dword:0x1
|
|
|
|
|
/// </summary>
|
2013-03-29 17:00:07 +01:00
|
|
|
|
private void AddRegistryNotification()
|
|
|
|
|
{
|
2013-03-30 00:31:49 +01:00
|
|
|
|
// If the entry is not there when Outlook loads, it will NOT notify the add-in, so the first time won't save the results
|
2013-03-29 17:00:07 +01:00
|
|
|
|
string subKey = @"Software\Microsoft\Office\Outlook\Addins\Outlook2013TodoAddIn";
|
|
|
|
|
RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(subKey, true);
|
|
|
|
|
if (rk == null)
|
|
|
|
|
{
|
|
|
|
|
rk = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(subKey);
|
|
|
|
|
}
|
|
|
|
|
if ((int)rk.GetValue("RequireShutdownNotification", 0) == 0)
|
|
|
|
|
{
|
|
|
|
|
rk.SetValue("RequireShutdownNotification", 1, RegistryValueKind.DWord); // "dword:0x1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-29 19:03:00 +01:00
|
|
|
|
#endregion "Methods"
|
|
|
|
|
|
2013-03-29 17:00:07 +01:00
|
|
|
|
#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 VSTO generated code
|
|
|
|
|
}
|
|
|
|
|
}
|