Added initial support for multiple calendars. Added friendly group header names (yesterday, today and tomorrow).
Some minor refactoring.
This commit is contained in:
parent
2fdb65d86f
commit
69a47f6652
@ -1,6 +1,7 @@
|
||||
using Outlook2013TodoAddIn.Forms;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
@ -30,6 +31,16 @@ namespace Outlook2013TodoAddIn
|
||||
/// </summary>
|
||||
public bool ShowPastAppointments { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets a list of all stores/accounts to retrieve information from
|
||||
/// </summary>
|
||||
public StringCollection Accounts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets whether to show friendly group headers (yesterday, today, tomorrow)
|
||||
/// </summary>
|
||||
public bool ShowFriendlyGroupHeaders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the selected calendar date
|
||||
/// </summary>
|
||||
@ -116,17 +127,29 @@ namespace Outlook2013TodoAddIn
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all appointments for the current configurations for all stores
|
||||
/// Retrieve all appointments for the current configurations for all selected stores
|
||||
/// </summary>
|
||||
public void RetrieveAppointments()
|
||||
{
|
||||
//foreach (Outlook.Store store in Globals.ThisAddIn.Application.Session.Stores)
|
||||
List<Outlook.AppointmentItem> appts = new List<Outlook.AppointmentItem>();
|
||||
foreach (Outlook.Store store in Globals.ThisAddIn.Application.Session.Stores)
|
||||
{
|
||||
if (Properties.Settings.Default.Accounts != null && Properties.Settings.Default.Accounts.Contains(store.DisplayName))
|
||||
{
|
||||
Outlook.Folder calFolder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder;
|
||||
appts.AddRange(this.RetrieveAppointmentsForFolder(calFolder));
|
||||
// TODO: Shared calendars?
|
||||
}
|
||||
}
|
||||
// We need to sort them because they may come from different accounts already ordered
|
||||
appts.Sort(CompareAppointments);
|
||||
|
||||
// Get the Outlook folder for the calendar to retrieve the appointments
|
||||
Outlook.Folder calFolder =
|
||||
Globals.ThisAddIn.Application.Session.GetDefaultFolder(
|
||||
Outlook.OlDefaultFolders.olFolderCalendar)
|
||||
as Outlook.Folder;
|
||||
List<Outlook.AppointmentItem> appts = this.RetrieveAppointmentsForFolder(calFolder);
|
||||
//Outlook.Folder calFolder =
|
||||
// Globals.ThisAddIn.Application.Session.GetDefaultFolder(
|
||||
// Outlook.OlDefaultFolders.olFolderCalendar)
|
||||
// as Outlook.Folder;
|
||||
//List<Outlook.AppointmentItem> appts = this.RetrieveAppointmentsForFolder(calFolder);
|
||||
|
||||
// Highlight dates with appointments in the current calendar
|
||||
this.apptCalendar.BoldedDates = appts.Select<Outlook.AppointmentItem, DateTime>(a => a.Start.Date).Distinct().ToArray();
|
||||
@ -150,7 +173,26 @@ namespace Outlook2013TodoAddIn
|
||||
{
|
||||
if (i.Start.Day != sameDay)
|
||||
{
|
||||
grp = new ListViewGroup(i.Start.ToShortDateString(), HorizontalAlignment.Left);
|
||||
string groupHeaderText = i.Start.ToShortDateString();
|
||||
if (this.ShowFriendlyGroupHeaders)
|
||||
{
|
||||
int daysDiff = (int)(i.Start.Date - DateTime.Today).TotalDays;
|
||||
switch (daysDiff)
|
||||
{
|
||||
case -1:
|
||||
groupHeaderText = Constants.Yesterday + ": " + groupHeaderText;
|
||||
break;
|
||||
case 0:
|
||||
groupHeaderText = Constants.Today + ": " + groupHeaderText;
|
||||
break;
|
||||
case 1:
|
||||
groupHeaderText = Constants.Tomorrow + ": " + groupHeaderText;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
grp = new ListViewGroup(groupHeaderText, HorizontalAlignment.Left);
|
||||
this.listView1.Groups.Add(grp); // TODO: Style it?
|
||||
sameDay = i.Start.Day;
|
||||
};
|
||||
@ -192,6 +234,17 @@ namespace Outlook2013TodoAddIn
|
||||
this.apptCalendar.UpdateCalendar();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Comparer method to sort appointments based on start date/time
|
||||
/// </summary>
|
||||
/// <param name="x">First appointment</param>
|
||||
/// <param name="y">Second appointment</param>
|
||||
/// <returns></returns>
|
||||
private static int CompareAppointments(Outlook.AppointmentItem x, Outlook.AppointmentItem y)
|
||||
{
|
||||
return x.Start.CompareTo(y.Start);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all appointments for the current configurations for a specific folder
|
||||
/// </summary>
|
||||
@ -320,7 +373,7 @@ namespace Outlook2013TodoAddIn
|
||||
}
|
||||
}
|
||||
mail.Body = Environment.NewLine + Environment.NewLine + appt.Body;
|
||||
mail.Subject = "RE: " + appt.Subject;
|
||||
mail.Subject = Constants.SubjectRE + ": " + appt.Subject;
|
||||
mail.Display();
|
||||
}
|
||||
}
|
||||
@ -356,6 +409,8 @@ namespace Outlook2013TodoAddIn
|
||||
this.NumDays = cfg.NumDays;
|
||||
this.MailAlertsEnabled = cfg.MailAlertsEnabled;
|
||||
this.ShowPastAppointments = cfg.ShowPastAppointments;
|
||||
this.Accounts = cfg.Accounts;
|
||||
this.ShowFriendlyGroupHeaders = cfg.ShowFriendlyGroupHeaders;
|
||||
this.RetrieveAppointments();
|
||||
}
|
||||
}
|
||||
|
42
Outlook2013TodoAddIn/Constants.cs
Normal file
42
Outlook2013TodoAddIn/Constants.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Outlook2013TodoAddIn
|
||||
{
|
||||
/// <summary>
|
||||
/// New class to localize some texts and get some constants, pending proper resource localization
|
||||
/// </summary>
|
||||
public class Constants
|
||||
{
|
||||
#region "Variables"
|
||||
|
||||
/// <summary>
|
||||
/// Today
|
||||
/// </summary>
|
||||
public const string Today = "Today";
|
||||
|
||||
/// <summary>
|
||||
/// Yesterday
|
||||
/// </summary>
|
||||
public const string Yesterday = "Yesterday";
|
||||
|
||||
/// <summary>
|
||||
/// Tomorrow
|
||||
/// </summary>
|
||||
public const string Tomorrow = "Tomorrow";
|
||||
|
||||
/// <summary>
|
||||
/// Reply header prefix for the subject
|
||||
/// </summary>
|
||||
public const string SubjectRE = "RE";
|
||||
|
||||
/// <summary>
|
||||
/// Follow Up email flag (can't be changed)
|
||||
/// </summary>
|
||||
public const string FollowUp = "Follow up";
|
||||
|
||||
#endregion "Variables"
|
||||
}
|
||||
}
|
@ -266,7 +266,7 @@ namespace Outlook2013TodoAddIn
|
||||
{
|
||||
// All controls are previously created, just need to update labels, etc...
|
||||
this.lnkCurrentRange.Text = this.SelectedDate.ToString("MMM yyyy");
|
||||
this.lnkToday.Text = "Today: " + DateTime.Today.ToShortDateString();
|
||||
this.lnkToday.Text = Constants.Today + ": " + DateTime.Today.ToShortDateString();
|
||||
|
||||
string[] daysOfWeek = Enum.GetNames(typeof(DayOfWeek));
|
||||
string sFirstDayOfWeek = Enum.GetName(typeof(DayOfWeek), this.FirstDayOfWeek);
|
||||
|
@ -34,13 +34,16 @@
|
||||
this.btnCancel = new System.Windows.Forms.Button();
|
||||
this.btnOK = new System.Windows.Forms.Button();
|
||||
this.chkShowPastAppointments = new System.Windows.Forms.CheckBox();
|
||||
this.chkListCalendars = new System.Windows.Forms.CheckedListBox();
|
||||
this.lblAccounts = new System.Windows.Forms.Label();
|
||||
this.chkFriendlyGroupHeaders = new System.Windows.Forms.CheckBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numRangeDays)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// chkMailAlerts
|
||||
//
|
||||
this.chkMailAlerts.AutoSize = true;
|
||||
this.chkMailAlerts.Location = new System.Drawing.Point(59, 134);
|
||||
this.chkMailAlerts.Location = new System.Drawing.Point(45, 94);
|
||||
this.chkMailAlerts.Name = "chkMailAlerts";
|
||||
this.chkMailAlerts.Size = new System.Drawing.Size(143, 21);
|
||||
this.chkMailAlerts.TabIndex = 8;
|
||||
@ -50,7 +53,7 @@
|
||||
// lblRangeDays
|
||||
//
|
||||
this.lblRangeDays.AutoSize = true;
|
||||
this.lblRangeDays.Location = new System.Drawing.Point(55, 60);
|
||||
this.lblRangeDays.Location = new System.Drawing.Point(55, 29);
|
||||
this.lblRangeDays.Name = "lblRangeDays";
|
||||
this.lblRangeDays.Size = new System.Drawing.Size(44, 17);
|
||||
this.lblRangeDays.TabIndex = 7;
|
||||
@ -58,7 +61,7 @@
|
||||
//
|
||||
// numRangeDays
|
||||
//
|
||||
this.numRangeDays.Location = new System.Drawing.Point(115, 58);
|
||||
this.numRangeDays.Location = new System.Drawing.Point(115, 27);
|
||||
this.numRangeDays.Maximum = new decimal(new int[] {
|
||||
30,
|
||||
0,
|
||||
@ -81,7 +84,7 @@
|
||||
// btnCancel
|
||||
//
|
||||
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.btnCancel.Location = new System.Drawing.Point(169, 181);
|
||||
this.btnCancel.Location = new System.Drawing.Point(168, 291);
|
||||
this.btnCancel.Name = "btnCancel";
|
||||
this.btnCancel.Size = new System.Drawing.Size(87, 37);
|
||||
this.btnCancel.TabIndex = 11;
|
||||
@ -91,7 +94,7 @@
|
||||
// btnOK
|
||||
//
|
||||
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
|
||||
this.btnOK.Location = new System.Drawing.Point(27, 181);
|
||||
this.btnOK.Location = new System.Drawing.Point(26, 291);
|
||||
this.btnOK.Name = "btnOK";
|
||||
this.btnOK.Size = new System.Drawing.Size(87, 37);
|
||||
this.btnOK.TabIndex = 10;
|
||||
@ -102,20 +105,50 @@
|
||||
// chkShowPastAppointments
|
||||
//
|
||||
this.chkShowPastAppointments.AutoSize = true;
|
||||
this.chkShowPastAppointments.Location = new System.Drawing.Point(59, 98);
|
||||
this.chkShowPastAppointments.Location = new System.Drawing.Point(45, 67);
|
||||
this.chkShowPastAppointments.Name = "chkShowPastAppointments";
|
||||
this.chkShowPastAppointments.Size = new System.Drawing.Size(186, 21);
|
||||
this.chkShowPastAppointments.TabIndex = 12;
|
||||
this.chkShowPastAppointments.Text = "Show Past Appointments";
|
||||
this.chkShowPastAppointments.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// chkListCalendars
|
||||
//
|
||||
this.chkListCalendars.FormattingEnabled = true;
|
||||
this.chkListCalendars.Location = new System.Drawing.Point(26, 176);
|
||||
this.chkListCalendars.Name = "chkListCalendars";
|
||||
this.chkListCalendars.Size = new System.Drawing.Size(229, 106);
|
||||
this.chkListCalendars.TabIndex = 13;
|
||||
//
|
||||
// lblAccounts
|
||||
//
|
||||
this.lblAccounts.AutoSize = true;
|
||||
this.lblAccounts.Location = new System.Drawing.Point(23, 156);
|
||||
this.lblAccounts.Name = "lblAccounts";
|
||||
this.lblAccounts.Size = new System.Drawing.Size(70, 17);
|
||||
this.lblAccounts.TabIndex = 14;
|
||||
this.lblAccounts.Text = "Accounts:";
|
||||
//
|
||||
// chkFriendlyGroupHeaders
|
||||
//
|
||||
this.chkFriendlyGroupHeaders.AutoSize = true;
|
||||
this.chkFriendlyGroupHeaders.Location = new System.Drawing.Point(45, 121);
|
||||
this.chkFriendlyGroupHeaders.Name = "chkFriendlyGroupHeaders";
|
||||
this.chkFriendlyGroupHeaders.Size = new System.Drawing.Size(176, 21);
|
||||
this.chkFriendlyGroupHeaders.TabIndex = 15;
|
||||
this.chkFriendlyGroupHeaders.Text = "Show Friendly Headers";
|
||||
this.chkFriendlyGroupHeaders.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormConfiguration
|
||||
//
|
||||
this.AcceptButton = this.btnOK;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CancelButton = this.btnCancel;
|
||||
this.ClientSize = new System.Drawing.Size(282, 253);
|
||||
this.ClientSize = new System.Drawing.Size(282, 343);
|
||||
this.Controls.Add(this.chkFriendlyGroupHeaders);
|
||||
this.Controls.Add(this.lblAccounts);
|
||||
this.Controls.Add(this.chkListCalendars);
|
||||
this.Controls.Add(this.chkShowPastAppointments);
|
||||
this.Controls.Add(this.btnCancel);
|
||||
this.Controls.Add(this.btnOK);
|
||||
@ -144,5 +177,8 @@
|
||||
private System.Windows.Forms.Button btnCancel;
|
||||
private System.Windows.Forms.Button btnOK;
|
||||
private System.Windows.Forms.CheckBox chkShowPastAppointments;
|
||||
private System.Windows.Forms.CheckedListBox chkListCalendars;
|
||||
private System.Windows.Forms.Label lblAccounts;
|
||||
private System.Windows.Forms.CheckBox chkFriendlyGroupHeaders;
|
||||
}
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Outlook = Microsoft.Office.Interop.Outlook;
|
||||
|
||||
namespace Outlook2013TodoAddIn.Forms
|
||||
{
|
||||
@ -40,6 +42,31 @@ namespace Outlook2013TodoAddIn.Forms
|
||||
set { this.chkShowPastAppointments.Checked = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets a list of all stores/accounts to retrieve information from
|
||||
/// </summary>
|
||||
public StringCollection Accounts
|
||||
{
|
||||
get
|
||||
{
|
||||
StringCollection col = new StringCollection();
|
||||
foreach (object item in this.chkListCalendars.CheckedItems)
|
||||
{
|
||||
col.Add(item.ToString());
|
||||
}
|
||||
return col;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets/sets whether to show friendly group headers (yesterday, today, tomorrow)
|
||||
/// </summary>
|
||||
public bool ShowFriendlyGroupHeaders
|
||||
{
|
||||
get { return this.chkFriendlyGroupHeaders.Checked; }
|
||||
set { this.chkFriendlyGroupHeaders.Checked = value; }
|
||||
}
|
||||
|
||||
#endregion "Properties"
|
||||
|
||||
#region "Methods"
|
||||
@ -62,6 +89,21 @@ namespace Outlook2013TodoAddIn.Forms
|
||||
this.numRangeDays.Value = Properties.Settings.Default.NumDays;
|
||||
this.chkMailAlerts.Checked = Properties.Settings.Default.MailAlertsEnabled;
|
||||
this.chkShowPastAppointments.Checked = Properties.Settings.Default.ShowPastAppointments;
|
||||
this.chkFriendlyGroupHeaders.Checked = Properties.Settings.Default.ShowFriendlyGroupHeaders;
|
||||
this.LoadStores();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads all the stores (accounts) in the current session
|
||||
/// </summary>
|
||||
private void LoadStores()
|
||||
{
|
||||
foreach (Outlook.Store store in Globals.ThisAddIn.Application.Session.Stores)
|
||||
{
|
||||
bool itemChecked = Properties.Settings.Default.Accounts != null && Properties.Settings.Default.Accounts.Contains(store.DisplayName);
|
||||
int index = this.chkListCalendars.Items.Add(store.DisplayName, itemChecked);
|
||||
// TODO: Use StoreID instead?
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -74,6 +116,8 @@ namespace Outlook2013TodoAddIn.Forms
|
||||
Properties.Settings.Default.NumDays = this.numRangeDays.Value;
|
||||
Properties.Settings.Default.MailAlertsEnabled = this.chkMailAlerts.Checked;
|
||||
Properties.Settings.Default.ShowPastAppointments = this.chkShowPastAppointments.Checked;
|
||||
Properties.Settings.Default.Accounts = this.Accounts;
|
||||
Properties.Settings.Default.ShowFriendlyGroupHeaders = this.chkFriendlyGroupHeaders.Checked;
|
||||
}
|
||||
|
||||
#endregion "Methods"
|
||||
|
@ -129,7 +129,7 @@ namespace Outlook2013TodoAddIn.Forms
|
||||
private void btnFlag_Click(object sender, EventArgs e)
|
||||
{
|
||||
//Microsoft.Office.Interop.Outlook.OlFlagIcon.olYellowFlagIcon
|
||||
this.Email.FlagRequest = "Follow up";
|
||||
this.Email.FlagRequest = Constants.FollowUp;
|
||||
this.Email.Save();
|
||||
this.Close();
|
||||
}
|
||||
|
@ -183,6 +183,7 @@
|
||||
can be found.
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="CustomCalendar.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
|
25
Outlook2013TodoAddIn/Properties/Settings.Designer.cs
generated
25
Outlook2013TodoAddIn/Properties/Settings.Designer.cs
generated
@ -1,7 +1,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.18046
|
||||
// Runtime Version:4.0.30319.18051
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
@ -94,5 +94,28 @@ namespace Outlook2013TodoAddIn.Properties {
|
||||
this["ShowPastAppointments"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
public global::System.Collections.Specialized.StringCollection Accounts {
|
||||
get {
|
||||
return ((global::System.Collections.Specialized.StringCollection)(this["Accounts"]));
|
||||
}
|
||||
set {
|
||||
this["Accounts"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("True")]
|
||||
public bool ShowFriendlyGroupHeaders {
|
||||
get {
|
||||
return ((bool)(this["ShowFriendlyGroupHeaders"]));
|
||||
}
|
||||
set {
|
||||
this["ShowFriendlyGroupHeaders"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,5 +20,11 @@
|
||||
<Setting Name="ShowPastAppointments" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
<Setting Name="Accounts" Type="System.Collections.Specialized.StringCollection" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="ShowFriendlyGroupHeaders" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
@ -41,7 +41,9 @@ namespace Outlook2013TodoAddIn
|
||||
|
||||
this.AppControl = new AppointmentsControl();
|
||||
this.AppControl.MailAlertsEnabled = Properties.Settings.Default.MailAlertsEnabled;
|
||||
this.AppControl.ShowPastAppointments = Properties.Settings.Default.ShowPastAppointments;
|
||||
this.AppControl.ShowPastAppointments = Properties.Settings.Default.ShowPastAppointments;
|
||||
this.AppControl.Accounts = Properties.Settings.Default.Accounts;
|
||||
this.AppControl.ShowFriendlyGroupHeaders = Properties.Settings.Default.ShowFriendlyGroupHeaders;
|
||||
this.AppControl.NumDays = Properties.Settings.Default.NumDays; // Setting the value will load the appointments
|
||||
|
||||
ToDoTaskPane = this.CustomTaskPanes.Add(this.AppControl, "Appointments");
|
||||
|
@ -25,6 +25,9 @@
|
||||
<setting name="ShowPastAppointments" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
<setting name="ShowFriendlyGroupHeaders" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
</Outlook2013TodoAddIn.Properties.Settings>
|
||||
</userSettings>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
|
||||
|
Loading…
Reference in New Issue
Block a user