From 554677e21f0f617418fa4457b18b73266b39ca74 Mon Sep 17 00:00:00 2001 From: gamosoft_cp Date: Mon, 22 Jul 2013 20:12:10 +0000 Subject: [PATCH] Tasks pseudo-logic --- Outlook2013TodoAddIn/AppointmentsControl.cs | 63 +++++++++++++------ .../Forms/FormConfiguration.Designer.cs | 23 +++++-- .../Forms/FormConfiguration.cs | 11 ++++ .../Properties/Settings.Designer.cs | 12 ++++ .../Properties/Settings.settings | 3 + Outlook2013TodoAddIn/ThisAddIn.cs | 3 +- Outlook2013TodoAddIn/app.config | 3 + 7 files changed, 94 insertions(+), 24 deletions(-) diff --git a/Outlook2013TodoAddIn/AppointmentsControl.cs b/Outlook2013TodoAddIn/AppointmentsControl.cs index 89ef6fa..2fd0842 100644 --- a/Outlook2013TodoAddIn/AppointmentsControl.cs +++ b/Outlook2013TodoAddIn/AppointmentsControl.cs @@ -50,6 +50,11 @@ namespace Outlook2013TodoAddIn set { this.apptCalendar.SelectedDate = value; } } + /// + /// Gets/sets whether to show the tasks list + /// + public bool ShowTasks { get; set; } + #endregion "Properties" #region "Methods" @@ -69,33 +74,53 @@ namespace Outlook2013TodoAddIn /// DateRangeEventArgs private void apptCalendar_SelectedDateChanged(object sender, EventArgs e) { - this.RetrieveAppointments(); + this.RetrieveData(); } /// - /// Retrieves tasks for all stores + /// Retrieves appointments and tasks if configured /// - public void RetrieveTasks() + public void RetrieveData() { - // We want tasks for all the accounts - //foreach (Outlook.Store store in Globals.ThisAddIn.Application.Session.Stores) - //{ - // // Get the Outlook to-do folder to retrieve the items - // MessageBox.Show("Store: " + store.DisplayName); - // // TODO: try..catch (public folders times out) - Outlook.Folder todoFolder = - Globals.ThisAddIn.Application.Session.GetDefaultFolder( - Outlook.OlDefaultFolders.olFolderToDo) - as Outlook.Folder; - this.RetrieveTasksForFolder(todoFolder); + this.RetrieveAppointments(); + if (this.ShowTasks) + { + // this.RetrieveTasks(); + } + } + + /// + /// Retrieves tasks for all selected stores + /// + private void RetrieveTasks() + { + List tasks = new List(); + 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 todoFolder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderToDo) as Outlook.Folder; + tasks.AddRange(this.RetrieveTasksForFolder(todoFolder)); + // TODO: Shared calendars? + } + } + // We need to sort them because they may come from different accounts already ordered + // tasks.Sort(CompareTasks); + + //Outlook.Folder todoFolder = + // Globals.ThisAddIn.Application.Session.GetDefaultFolder( + // Outlook.OlDefaultFolders.olFolderToDo) + // as Outlook.Folder; + //this.RetrieveTasksForFolder(todoFolder); } /// /// Retrieves to-do tasks for the folder on the specified store /// /// Outlook folder - private void RetrieveTasksForFolder(Outlook.Folder todoFolder) + private List RetrieveTasksForFolder(Outlook.Folder todoFolder) { + List tasks = new List(); foreach (object item in todoFolder.Items) { if (item is Outlook.MailItem) @@ -124,12 +149,13 @@ namespace Outlook2013TodoAddIn MessageBox.Show("Unknown type"); } } + return tasks; } /// /// Retrieve all appointments for the current configurations for all selected stores /// - public void RetrieveAppointments() + private void RetrieveAppointments() { List appts = new List(); foreach (Outlook.Store store in Globals.ThisAddIn.Application.Session.Stores) @@ -344,7 +370,7 @@ namespace Outlook2013TodoAddIn // Open up the appointment in a new window appt.Display(true); // Modal yes/no } - // At the end, synchronously "refresh" items in case they have changed + // At the end, synchronously "refresh" appointments in case they have changed this.RetrieveAppointments(); } } @@ -411,7 +437,8 @@ namespace Outlook2013TodoAddIn this.ShowPastAppointments = cfg.ShowPastAppointments; this.Accounts = cfg.Accounts; this.ShowFriendlyGroupHeaders = cfg.ShowFriendlyGroupHeaders; - this.RetrieveAppointments(); + this.ShowTasks = cfg.ShowTasks; + this.RetrieveData(); } } } diff --git a/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs b/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs index 6ecfe7b..bf54685 100644 --- a/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs +++ b/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs @@ -37,6 +37,7 @@ this.chkListCalendars = new System.Windows.Forms.CheckedListBox(); this.lblAccounts = new System.Windows.Forms.Label(); this.chkFriendlyGroupHeaders = new System.Windows.Forms.CheckBox(); + this.chkShowTasks = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.numRangeDays)).BeginInit(); this.SuspendLayout(); // @@ -84,7 +85,7 @@ // btnCancel // this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btnCancel.Location = new System.Drawing.Point(168, 291); + this.btnCancel.Location = new System.Drawing.Point(168, 314); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(87, 37); this.btnCancel.TabIndex = 11; @@ -94,7 +95,7 @@ // btnOK // this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; - this.btnOK.Location = new System.Drawing.Point(26, 291); + this.btnOK.Location = new System.Drawing.Point(26, 314); this.btnOK.Name = "btnOK"; this.btnOK.Size = new System.Drawing.Size(87, 37); this.btnOK.TabIndex = 10; @@ -115,7 +116,7 @@ // chkListCalendars // this.chkListCalendars.FormattingEnabled = true; - this.chkListCalendars.Location = new System.Drawing.Point(26, 176); + this.chkListCalendars.Location = new System.Drawing.Point(26, 199); this.chkListCalendars.Name = "chkListCalendars"; this.chkListCalendars.Size = new System.Drawing.Size(229, 106); this.chkListCalendars.TabIndex = 13; @@ -123,7 +124,7 @@ // lblAccounts // this.lblAccounts.AutoSize = true; - this.lblAccounts.Location = new System.Drawing.Point(23, 156); + this.lblAccounts.Location = new System.Drawing.Point(23, 179); this.lblAccounts.Name = "lblAccounts"; this.lblAccounts.Size = new System.Drawing.Size(70, 17); this.lblAccounts.TabIndex = 14; @@ -139,13 +140,24 @@ this.chkFriendlyGroupHeaders.Text = "Show Friendly Headers"; this.chkFriendlyGroupHeaders.UseVisualStyleBackColor = true; // + // chkShowTasks + // + this.chkShowTasks.AutoSize = true; + this.chkShowTasks.Location = new System.Drawing.Point(45, 148); + this.chkShowTasks.Name = "chkShowTasks"; + this.chkShowTasks.Size = new System.Drawing.Size(106, 21); + this.chkShowTasks.TabIndex = 16; + this.chkShowTasks.Text = "Show Tasks"; + this.chkShowTasks.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, 343); + this.ClientSize = new System.Drawing.Size(282, 383); + this.Controls.Add(this.chkShowTasks); this.Controls.Add(this.chkFriendlyGroupHeaders); this.Controls.Add(this.lblAccounts); this.Controls.Add(this.chkListCalendars); @@ -180,5 +192,6 @@ private System.Windows.Forms.CheckedListBox chkListCalendars; private System.Windows.Forms.Label lblAccounts; private System.Windows.Forms.CheckBox chkFriendlyGroupHeaders; + private System.Windows.Forms.CheckBox chkShowTasks; } } \ No newline at end of file diff --git a/Outlook2013TodoAddIn/Forms/FormConfiguration.cs b/Outlook2013TodoAddIn/Forms/FormConfiguration.cs index 231152a..e703455 100644 --- a/Outlook2013TodoAddIn/Forms/FormConfiguration.cs +++ b/Outlook2013TodoAddIn/Forms/FormConfiguration.cs @@ -67,6 +67,15 @@ namespace Outlook2013TodoAddIn.Forms set { this.chkFriendlyGroupHeaders.Checked = value; } } + /// + /// Gets/sets whether to show the tasks list + /// + public bool ShowTasks + { + get { return this.chkShowTasks.Checked; } + set { this.chkShowTasks.Checked = value; } + } + #endregion "Properties" #region "Methods" @@ -90,6 +99,7 @@ namespace Outlook2013TodoAddIn.Forms this.chkMailAlerts.Checked = Properties.Settings.Default.MailAlertsEnabled; this.chkShowPastAppointments.Checked = Properties.Settings.Default.ShowPastAppointments; this.chkFriendlyGroupHeaders.Checked = Properties.Settings.Default.ShowFriendlyGroupHeaders; + this.chkShowTasks.Checked = Properties.Settings.Default.ShowTasks; this.LoadStores(); } @@ -118,6 +128,7 @@ namespace Outlook2013TodoAddIn.Forms Properties.Settings.Default.ShowPastAppointments = this.chkShowPastAppointments.Checked; Properties.Settings.Default.Accounts = this.Accounts; Properties.Settings.Default.ShowFriendlyGroupHeaders = this.chkFriendlyGroupHeaders.Checked; + Properties.Settings.Default.ShowTasks = this.chkShowTasks.Checked; } #endregion "Methods" diff --git a/Outlook2013TodoAddIn/Properties/Settings.Designer.cs b/Outlook2013TodoAddIn/Properties/Settings.Designer.cs index 4175c5b..2ce36a6 100644 --- a/Outlook2013TodoAddIn/Properties/Settings.Designer.cs +++ b/Outlook2013TodoAddIn/Properties/Settings.Designer.cs @@ -117,5 +117,17 @@ namespace Outlook2013TodoAddIn.Properties { this["ShowFriendlyGroupHeaders"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool ShowTasks { + get { + return ((bool)(this["ShowTasks"])); + } + set { + this["ShowTasks"] = value; + } + } } } diff --git a/Outlook2013TodoAddIn/Properties/Settings.settings b/Outlook2013TodoAddIn/Properties/Settings.settings index b849e14..853dd48 100644 --- a/Outlook2013TodoAddIn/Properties/Settings.settings +++ b/Outlook2013TodoAddIn/Properties/Settings.settings @@ -26,5 +26,8 @@ True + + True + \ No newline at end of file diff --git a/Outlook2013TodoAddIn/ThisAddIn.cs b/Outlook2013TodoAddIn/ThisAddIn.cs index c16713d..568872a 100644 --- a/Outlook2013TodoAddIn/ThisAddIn.cs +++ b/Outlook2013TodoAddIn/ThisAddIn.cs @@ -44,6 +44,7 @@ namespace Outlook2013TodoAddIn this.AppControl.ShowPastAppointments = Properties.Settings.Default.ShowPastAppointments; this.AppControl.Accounts = Properties.Settings.Default.Accounts; this.AppControl.ShowFriendlyGroupHeaders = Properties.Settings.Default.ShowFriendlyGroupHeaders; + this.AppControl.ShowTasks = Properties.Settings.Default.ShowTasks; this.AppControl.NumDays = Properties.Settings.Default.NumDays; // Setting the value will load the appointments ToDoTaskPane = this.CustomTaskPanes.Add(this.AppControl, "Appointments"); @@ -57,7 +58,7 @@ namespace Outlook2013TodoAddIn // Selecting the date will retrieve the appointments // Otherwise it'll take the one used when the designer changed! this.AppControl.SelectedDate = DateTime.Today; - // this.AppControl.RetrieveAppointments(); + // this.AppControl.RetrieveData(); Globals.ThisAddIn.Application.ActiveExplorer().Deactivate += ThisAddIn_Deactivate; diff --git a/Outlook2013TodoAddIn/app.config b/Outlook2013TodoAddIn/app.config index 0390c6d..bcdff4c 100644 --- a/Outlook2013TodoAddIn/app.config +++ b/Outlook2013TodoAddIn/app.config @@ -28,6 +28,9 @@ True + + True +