From 1362a441e750a5c23a2235834679e9b5321527fc Mon Sep 17 00:00:00 2001 From: gamosoft_cp Date: Thu, 12 Mar 2015 19:48:43 +0000 Subject: [PATCH] Added option to show/hide completed tasks. Added context menu to delete/complete a task. --- .../AppointmentsControl.Designer.cs | 39 +++++-- Outlook2013TodoAddIn/AppointmentsControl.cs | 105 +++++++++++++++++- .../Forms/FormConfiguration.Designer.cs | 13 +++ .../Forms/FormConfiguration.cs | 12 +- Outlook2013TodoAddIn/OLTaskItem.cs | 5 + .../Properties/Settings.Designer.cs | 12 ++ .../Properties/Settings.settings | 3 + Outlook2013TodoAddIn/ThisAddIn.cs | 1 + Outlook2013TodoAddIn/app.config | 3 + 9 files changed, 181 insertions(+), 12 deletions(-) diff --git a/Outlook2013TodoAddIn/AppointmentsControl.Designer.cs b/Outlook2013TodoAddIn/AppointmentsControl.Designer.cs index 6e4bca2..62b649d 100644 --- a/Outlook2013TodoAddIn/AppointmentsControl.Designer.cs +++ b/Outlook2013TodoAddIn/AppointmentsControl.Designer.cs @@ -40,15 +40,18 @@ this.lstTasks = new System.Windows.Forms.ListView(); this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.ctxMenuTasks = new System.Windows.Forms.ContextMenuStrip(this.components); this.panelCalendar = new System.Windows.Forms.Panel(); this.apptCalendar = new Outlook2013TodoAddIn.CustomCalendar(); - this.ctxMenuTasks = new System.Windows.Forms.ContextMenuStrip(this.components); + this.mnuItemMarkComplete = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuItemDeleteTask = new System.Windows.Forms.ToolStripMenuItem(); this.ctxMenuAppointments.SuspendLayout(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); + this.ctxMenuTasks.SuspendLayout(); this.panelCalendar.SuspendLayout(); this.SuspendLayout(); // @@ -58,20 +61,20 @@ this.mnuItemReplyAllEmail, this.mnuItemDeleteAppointment}); this.ctxMenuAppointments.Name = "ctxMenuAppointments"; - this.ctxMenuAppointments.Size = new System.Drawing.Size(225, 52); + this.ctxMenuAppointments.Size = new System.Drawing.Size(227, 52); // // mnuItemReplyAllEmail // this.mnuItemReplyAllEmail.Name = "mnuItemReplyAllEmail"; - this.mnuItemReplyAllEmail.Size = new System.Drawing.Size(224, 24); + this.mnuItemReplyAllEmail.Size = new System.Drawing.Size(226, 24); this.mnuItemReplyAllEmail.Text = "Reply All With Email"; this.mnuItemReplyAllEmail.Click += new System.EventHandler(this.mnuItemReplyAllEmail_Click); // // mnuItemDeleteAppointment // this.mnuItemDeleteAppointment.Name = "mnuItemDeleteAppointment"; - this.mnuItemDeleteAppointment.Size = new System.Drawing.Size(224, 24); - this.mnuItemDeleteAppointment.Text = "Delete appointment/s"; + this.mnuItemDeleteAppointment.Size = new System.Drawing.Size(226, 24); + this.mnuItemDeleteAppointment.Text = "Delete Appointment/s"; this.mnuItemDeleteAppointment.Click += new System.EventHandler(this.mnuItemDeleteAppointment_Click); // // panel1 @@ -169,6 +172,14 @@ this.columnHeader4.Text = "Subject"; this.columnHeader4.Width = 200; // + // ctxMenuTasks + // + this.ctxMenuTasks.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.mnuItemMarkComplete, + this.mnuItemDeleteTask}); + this.ctxMenuTasks.Name = "ctxMenuTasks"; + this.ctxMenuTasks.Size = new System.Drawing.Size(181, 80); + // // panelCalendar // this.panelCalendar.Controls.Add(this.apptCalendar); @@ -202,10 +213,19 @@ this.apptCalendar.SelectedDateChanged += new System.EventHandler(this.apptCalendar_SelectedDateChanged); this.apptCalendar.ConfigurationButtonClicked += new System.EventHandler(this.apptCalendar_ConfigurationButtonClicked); // - // ctxMenuTasks + // mnuItemMarkComplete // - this.ctxMenuTasks.Name = "ctxMenuTasks"; - this.ctxMenuTasks.Size = new System.Drawing.Size(61, 4); + this.mnuItemMarkComplete.Name = "mnuItemMarkComplete"; + this.mnuItemMarkComplete.Size = new System.Drawing.Size(180, 24); + this.mnuItemMarkComplete.Text = "Mark Complete"; + this.mnuItemMarkComplete.Click += new System.EventHandler(this.mnuItemMarkComplete_Click); + // + // mnuItemDeleteTask + // + this.mnuItemDeleteTask.Name = "mnuItemDeleteTask"; + this.mnuItemDeleteTask.Size = new System.Drawing.Size(180, 24); + this.mnuItemDeleteTask.Text = "Delete Task"; + this.mnuItemDeleteTask.Click += new System.EventHandler(this.mnuItemDeleteTask_Click); // // AppointmentsControl // @@ -220,6 +240,7 @@ this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); + this.ctxMenuTasks.ResumeLayout(false); this.panelCalendar.ResumeLayout(false); this.ResumeLayout(false); @@ -241,6 +262,8 @@ private System.Windows.Forms.Panel panelCalendar; private System.Windows.Forms.ToolStripMenuItem mnuItemDeleteAppointment; private System.Windows.Forms.ContextMenuStrip ctxMenuTasks; + private System.Windows.Forms.ToolStripMenuItem mnuItemMarkComplete; + private System.Windows.Forms.ToolStripMenuItem mnuItemDeleteTask; } diff --git a/Outlook2013TodoAddIn/AppointmentsControl.cs b/Outlook2013TodoAddIn/AppointmentsControl.cs index b87aee8..94290d4 100644 --- a/Outlook2013TodoAddIn/AppointmentsControl.cs +++ b/Outlook2013TodoAddIn/AppointmentsControl.cs @@ -65,6 +65,11 @@ namespace Outlook2013TodoAddIn /// public bool ShowTasks { get; set; } + /// + /// Gets/sets whether to show the completed tasks in the list + /// + public bool ShowCompletedTasks { get; set; } + /// /// Gets/sets the first day of the week for the calendar /// @@ -133,6 +138,12 @@ namespace Outlook2013TodoAddIn // TODO: Shared calendars? } } + + if (!this.ShowCompletedTasks) + { + tasks = tasks.Where(t => !t.Completed).ToList(); + } + // We need to sort them because they may come from different accounts already ordered // Applies sorting by due date tasks.Sort(CompareTasks); @@ -604,6 +615,86 @@ namespace Outlook2013TodoAddIn } } + /// + /// Allows to delete the selected task + /// + /// Sender + /// EventArgs + private void mnuItemDeleteTask_Click(object sender, EventArgs e) + { + if (this.lstTasks.SelectedIndices.Count != 0) + { + OLTaskItem task = this.lstTasks.SelectedItems[0].Tag as OLTaskItem; + if (task != null) + { + if (MessageBox.Show("Are you sure you want to delete this task?", "Delete task", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + if (task.OriginalItem is Outlook.MailItem) + { + Outlook.MailItem mail = task.OriginalItem as Outlook.MailItem; + mail.Delete(); + } + else if (task.OriginalItem is Outlook.ContactItem) + { + Outlook.ContactItem contact = task.OriginalItem as Outlook.ContactItem; + contact.Delete(); + } + else if (task.OriginalItem is Outlook.TaskItem) + { + Outlook.TaskItem t = task.OriginalItem as Outlook.TaskItem; + t.Delete(); + } + else + { + // Do nothing + } + } + // At the end, synchronously "refresh" tasks in case they have changed + this.RetrieveTasks(); + } + } + } + + /// + /// Allows to mark the selected task as completed (clear task flag for regular items) + /// + /// Sender + /// EventArgs + private void mnuItemMarkComplete_Click(object sender, EventArgs e) + { + if (this.lstTasks.SelectedIndices.Count != 0) + { + OLTaskItem task = this.lstTasks.SelectedItems[0].Tag as OLTaskItem; + if (task != null && !task.Completed) // Attempting to complete an already completed task throws an exception + { + if (MessageBox.Show("Are you sure you want to complete this task?", "Mark task as completed/Clear task flag", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + if (task.OriginalItem is Outlook.MailItem) + { + Outlook.MailItem mail = task.OriginalItem as Outlook.MailItem; + mail.ClearTaskFlag(); + } + else if (task.OriginalItem is Outlook.ContactItem) + { + Outlook.ContactItem contact = task.OriginalItem as Outlook.ContactItem; + contact.ClearTaskFlag(); + } + else if (task.OriginalItem is Outlook.TaskItem) + { + Outlook.TaskItem t = task.OriginalItem as Outlook.TaskItem; + t.MarkComplete(); + } + else + { + // Do nothing + } + } + // At the end, synchronously "refresh" tasks in case they have changed + this.RetrieveTasks(); + } + } + } + /// /// Switch to the calendar view when double-clicking a date /// @@ -639,6 +730,7 @@ namespace Outlook2013TodoAddIn this.ShowDayNames = cfg.ShowDayNames; this.ShowWeekNumbers = cfg.ShowWeekNumbers; this.ShowTasks = cfg.ShowTasks; + this.ShowCompletedTasks = cfg.ShowCompletedTasks; this.FirstDayOfWeek = cfg.FirstDayOfWeek; this.RetrieveData(); } @@ -701,16 +793,23 @@ namespace Outlook2013TodoAddIn }); } - e.Graphics.DrawString(task.TaskSubject, new Font(this.Font, FontStyle.Bold), colorBrush, subjectRectangle, leftFormat); + Font mainFont = new Font(this.Font, FontStyle.Bold); + Font subFont = this.Font; + if (task.Completed) + { + mainFont = new Font(this.Font, FontStyle.Bold | FontStyle.Strikeout); + subFont = new Font(this.Font, FontStyle.Strikeout); + } + e.Graphics.DrawString(task.TaskSubject, mainFont, colorBrush, subjectRectangle, leftFormat); if (task.Reminder.Year != Constants.NullYear) { e.Graphics.DrawImage(Properties.Resources.Alert_16xSM, reminderRectangle.Left, reminderRectangle.Top); - e.Graphics.DrawString(task.Reminder.ToString(), this.Font, colorBrush, reminderRectangle.Left + Properties.Resources.Alert_16xSM.Width + horizontalSpacing, reminderRectangle.Top, leftFormat); + e.Graphics.DrawString(task.Reminder.ToString(), subFont, colorBrush, reminderRectangle.Left + Properties.Resources.Alert_16xSM.Width + horizontalSpacing, reminderRectangle.Top, leftFormat); } else if (task.StartDate.Year != Constants.NullYear) { e.Graphics.DrawImage(Properties.Resources.CurrentRow_15x14, reminderRectangle.Left, reminderRectangle.Top); - e.Graphics.DrawString(task.StartDate.ToShortDateString(), this.Font, colorBrush, reminderRectangle.Left + Properties.Resources.CurrentRow_15x14.Width + horizontalSpacing, reminderRectangle.Top, leftFormat); + e.Graphics.DrawString(task.StartDate.ToShortDateString(), subFont, colorBrush, reminderRectangle.Left + Properties.Resources.CurrentRow_15x14.Width + horizontalSpacing, reminderRectangle.Top, leftFormat); } } diff --git a/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs b/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs index 5e8474f..bdb3b0a 100644 --- a/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs +++ b/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs @@ -47,6 +47,7 @@ this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.numRangeEmailAlertsTimeOut = new System.Windows.Forms.NumericUpDown(); this.lblSeconds = new System.Windows.Forms.Label(); + this.chkShowCompletedTasks = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.numRangeDays)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pctBoxPayPal)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numRangeEmailAlertsTimeOut)).BeginInit(); @@ -244,6 +245,16 @@ this.lblSeconds.TabIndex = 23; this.lblSeconds.Text = "seconds"; // + // chkShowCompletedTasks + // + this.chkShowCompletedTasks.AutoSize = true; + this.chkShowCompletedTasks.Location = new System.Drawing.Point(157, 206); + this.chkShowCompletedTasks.Name = "chkShowCompletedTasks"; + this.chkShowCompletedTasks.Size = new System.Drawing.Size(105, 21); + this.chkShowCompletedTasks.TabIndex = 24; + this.chkShowCompletedTasks.Text = "Completed?"; + this.chkShowCompletedTasks.UseVisualStyleBackColor = true; + // // FormConfiguration // this.AcceptButton = this.btnOK; @@ -251,6 +262,7 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btnCancel; this.ClientSize = new System.Drawing.Size(282, 482); + this.Controls.Add(this.chkShowCompletedTasks); this.Controls.Add(this.lblSeconds); this.Controls.Add(this.numRangeEmailAlertsTimeOut); this.Controls.Add(this.pctBoxPayPal); @@ -305,5 +317,6 @@ private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.NumericUpDown numRangeEmailAlertsTimeOut; private System.Windows.Forms.Label lblSeconds; + private System.Windows.Forms.CheckBox chkShowCompletedTasks; } } \ No newline at end of file diff --git a/Outlook2013TodoAddIn/Forms/FormConfiguration.cs b/Outlook2013TodoAddIn/Forms/FormConfiguration.cs index 0244e2e..589cf25 100644 --- a/Outlook2013TodoAddIn/Forms/FormConfiguration.cs +++ b/Outlook2013TodoAddIn/Forms/FormConfiguration.cs @@ -95,6 +95,15 @@ namespace Outlook2013TodoAddIn.Forms set { this.chkShowTasks.Checked = value; } } + /// + /// Gets/sets whether to show the completed tasks in the list + /// + public bool ShowCompletedTasks + { + get { return this.chkShowCompletedTasks.Checked; } + set { this.chkShowCompletedTasks.Checked = value; } + } + /// /// Gets/sets the first day of the week for the calendar /// @@ -131,6 +140,7 @@ namespace Outlook2013TodoAddIn.Forms this.chkShowDayNames.Checked = Properties.Settings.Default.ShowDayNames; this.chkShowWeekNumbers.Checked = Properties.Settings.Default.ShowWeekNumbers; this.chkShowTasks.Checked = Properties.Settings.Default.ShowTasks; + this.chkShowCompletedTasks.Checked = Properties.Settings.Default.ShowCompletedTasks; this.LoadStores(); this.LoadDays(); } @@ -172,7 +182,7 @@ namespace Outlook2013TodoAddIn.Forms Properties.Settings.Default.ShowFriendlyGroupHeaders = this.chkFriendlyGroupHeaders.Checked; Properties.Settings.Default.ShowDayNames = this.chkShowDayNames.Checked; Properties.Settings.Default.ShowWeekNumbers = this.chkShowWeekNumbers.Checked; - Properties.Settings.Default.ShowTasks = this.chkShowTasks.Checked; + Properties.Settings.Default.ShowCompletedTasks = this.chkShowCompletedTasks.Checked; Properties.Settings.Default.FirstDayOfWeek = (System.DayOfWeek)Enum.Parse(typeof(System.DayOfWeek), this.cboFirstDayOfWeek.SelectedValue.ToString()); } diff --git a/Outlook2013TodoAddIn/OLTaskItem.cs b/Outlook2013TodoAddIn/OLTaskItem.cs index f5bb331..47a076f 100644 --- a/Outlook2013TodoAddIn/OLTaskItem.cs +++ b/Outlook2013TodoAddIn/OLTaskItem.cs @@ -21,6 +21,8 @@ namespace Outlook2013TodoAddIn public object OriginalItem { get; set; } public List Categories { get; set; } + public bool Completed { get; set; } + #endregion "Properties" #region "Methods" @@ -46,6 +48,7 @@ namespace Outlook2013TodoAddIn MAPIFolder f = (MAPIFolder)mail.Parent; this.FolderName = f.Name; if (!String.IsNullOrEmpty(mail.Categories)) this.Categories.AddRange(mail.Categories.Split(new char[] { ',' })); + this.Completed = (mail.TaskCompletedDate.Year != Constants.NullYear); } else if (item is Outlook.ContactItem) { @@ -58,6 +61,7 @@ namespace Outlook2013TodoAddIn MAPIFolder f = (MAPIFolder)contact.Parent; this.FolderName = f.Name; if (!String.IsNullOrEmpty(contact.Categories)) this.Categories.AddRange(contact.Categories.Split(new char[] { ',' })); + this.Completed = (contact.TaskCompletedDate.Year != Constants.NullYear); } else if (item is Outlook.TaskItem) { @@ -70,6 +74,7 @@ namespace Outlook2013TodoAddIn MAPIFolder f = (MAPIFolder)task.Parent; this.FolderName = f.Name; if (!String.IsNullOrEmpty(task.Categories)) this.Categories.AddRange(task.Categories.Split(new char[] { ',' })); + this.Completed = task.Complete; } else { diff --git a/Outlook2013TodoAddIn/Properties/Settings.Designer.cs b/Outlook2013TodoAddIn/Properties/Settings.Designer.cs index 0e575ba..a12d51a 100644 --- a/Outlook2013TodoAddIn/Properties/Settings.Designer.cs +++ b/Outlook2013TodoAddIn/Properties/Settings.Designer.cs @@ -177,5 +177,17 @@ namespace Outlook2013TodoAddIn.Properties { this["ShowWeekNumbers"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool ShowCompletedTasks { + get { + return ((bool)(this["ShowCompletedTasks"])); + } + set { + this["ShowCompletedTasks"] = value; + } + } } } diff --git a/Outlook2013TodoAddIn/Properties/Settings.settings b/Outlook2013TodoAddIn/Properties/Settings.settings index a5fd121..188de82 100644 --- a/Outlook2013TodoAddIn/Properties/Settings.settings +++ b/Outlook2013TodoAddIn/Properties/Settings.settings @@ -41,5 +41,8 @@ False + + False + \ No newline at end of file diff --git a/Outlook2013TodoAddIn/ThisAddIn.cs b/Outlook2013TodoAddIn/ThisAddIn.cs index 0c8198e..4938fbc 100644 --- a/Outlook2013TodoAddIn/ThisAddIn.cs +++ b/Outlook2013TodoAddIn/ThisAddIn.cs @@ -49,6 +49,7 @@ namespace Outlook2013TodoAddIn this.AppControl.ShowDayNames = Properties.Settings.Default.ShowDayNames; this.AppControl.ShowWeekNumbers = Properties.Settings.Default.ShowWeekNumbers; this.AppControl.ShowTasks = Properties.Settings.Default.ShowTasks; + this.AppControl.ShowCompletedTasks = Properties.Settings.Default.ShowCompletedTasks; this.AppControl.FirstDayOfWeek = Properties.Settings.Default.FirstDayOfWeek; this.AppControl.NumDays = Properties.Settings.Default.NumDays; // Setting the value will load the appointments diff --git a/Outlook2013TodoAddIn/app.config b/Outlook2013TodoAddIn/app.config index f85f66b..a56c192 100644 --- a/Outlook2013TodoAddIn/app.config +++ b/Outlook2013TodoAddIn/app.config @@ -43,6 +43,9 @@ False + + False +