From 5c726838d751a042f5871f9775698f8e62d980ca Mon Sep 17 00:00:00 2001 From: Paul Woolcock <11843015+phw198@users.noreply.github.com> Date: Sun, 26 Sep 2021 14:14:21 +0100 Subject: [PATCH] Improved updating of the "test map" dropdowns Bugfixes --- .../Forms/ColourMap.Designer.cs | 6 ++---- src/OutlookGoogleCalendarSync/Forms/ColourMap.cs | 15 ++++++++++++++- src/OutlookGoogleCalendarSync/Forms/MainForm.cs | 3 +-- .../GoogleOgcs/EventColour.cs | 12 ++++++++---- .../OutlookOgcs/OutlookCalendar.cs | 2 +- .../SettingsStore/Settings.cs | 16 +++++++--------- src/OutlookGoogleCalendarSync/Sync/Timer.cs | 8 +++++--- 7 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/OutlookGoogleCalendarSync/Forms/ColourMap.Designer.cs b/src/OutlookGoogleCalendarSync/Forms/ColourMap.Designer.cs index 7579c25a..e4658419 100644 --- a/src/OutlookGoogleCalendarSync/Forms/ColourMap.Designer.cs +++ b/src/OutlookGoogleCalendarSync/Forms/ColourMap.Designer.cs @@ -84,8 +84,6 @@ private void InitializeComponent() { // // ddOutlookColour // - this.ddOutlookColour.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); this.ddOutlookColour.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; this.ddOutlookColour.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.ddOutlookColour.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -100,8 +98,6 @@ private void InitializeComponent() { // // ddGoogleColour // - this.ddGoogleColour.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); this.ddGoogleColour.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; this.ddGoogleColour.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.ddGoogleColour.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -132,6 +128,7 @@ private void InitializeComponent() { this.colourGridView.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.colourGridView_CellClick); this.colourGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.colourGridView_CellEndEdit); this.colourGridView.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.colourGridView_CellEnter); + this.colourGridView.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.colourGridView_CellValueChanged); this.colourGridView.EditingControlShowing += new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler(this.colourGridView_EditingControlShowing); this.colourGridView.SelectionChanged += new System.EventHandler(this.colourGridView_SelectionChanged); // @@ -173,6 +170,7 @@ private void InitializeComponent() { this.Name = "ColourMap"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Custom Colour Mapping"; + this.Shown += new System.EventHandler(this.ColourMap_Shown); ((System.ComponentModel.ISupportInitialize)(this.colourGridView)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/src/OutlookGoogleCalendarSync/Forms/ColourMap.cs b/src/OutlookGoogleCalendarSync/Forms/ColourMap.cs index b00506a5..2e1e82f3 100644 --- a/src/OutlookGoogleCalendarSync/Forms/ColourMap.cs +++ b/src/OutlookGoogleCalendarSync/Forms/ColourMap.cs @@ -24,6 +24,10 @@ public ColourMap() { OutlookOgcs.Calendar.Disconnect(true); } + private void ColourMap_Shown(object sender, EventArgs e) { + ddOutlookColour_SelectedIndexChanged(null, null); + } + private void loadConfig() { try { if (Forms.Main.Instance.ActiveCalendarProfile.ColourMaps.Count > 0) colourGridView.Rows.Clear(); @@ -38,7 +42,7 @@ private void loadConfig() { if (ddGoogleColour.Items.Count > 0) ddGoogleColour.SelectedIndex = 0; - } catch (System.Exception ex) { + } catch (System.Exception ex) { OGCSexception.Analyse("Populating gridview cells from Settings.", ex); } } @@ -257,5 +261,14 @@ private void colourGridView_SelectionChanged(object sender, EventArgs e) { OGCSexception.Analyse(ex); } } + + private void colourGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) { + if (!this.Visible) return; + + if (colourGridView.CurrentCell.ColumnIndex == 0) + ddGoogleColour_SelectedIndexChanged(null, null); + else if (colourGridView.CurrentCell.ColumnIndex == 1) + ddOutlookColour_SelectedIndexChanged(null, null); + } } } diff --git a/src/OutlookGoogleCalendarSync/Forms/MainForm.cs b/src/OutlookGoogleCalendarSync/Forms/MainForm.cs index 90a23838..344f96cc 100644 --- a/src/OutlookGoogleCalendarSync/Forms/MainForm.cs +++ b/src/OutlookGoogleCalendarSync/Forms/MainForm.cs @@ -295,7 +295,6 @@ public void UpdateGUIsettings_Profile() { theFolder = (MAPIFolder)OutlookOgcs.Calendar.ReleaseObject(theFolder); } } - theFolders = (Folders)OutlookOgcs.Calendar.ReleaseObject(theFolders); ddMailboxName.Items.AddRange(folderIDs.Keys.ToArray()); ddMailboxName.SelectedItem = profile.MailboxName; @@ -588,7 +587,7 @@ private void applyProxy() { } private void buildAvailabilityDropdown() { - SettingsStore.Calendar profile = Settings.Instance.ProfileInPlay(); + SettingsStore.Calendar profile = Forms.Main.Instance.ActiveCalendarProfile; try { this.ddAvailabilty.SelectedIndexChanged -= new System.EventHandler(this.ddAvailabilty_SelectedIndexChanged); ddAvailabilty.DataSource = null; diff --git a/src/OutlookGoogleCalendarSync/GoogleOgcs/EventColour.cs b/src/OutlookGoogleCalendarSync/GoogleOgcs/EventColour.cs index cc7e2d44..28d6eec7 100644 --- a/src/OutlookGoogleCalendarSync/GoogleOgcs/EventColour.cs +++ b/src/OutlookGoogleCalendarSync/GoogleOgcs/EventColour.cs @@ -15,7 +15,7 @@ public enum Type { Event } private Type colourType = Type.Event; - public String Id { get; } + public String Id { get; internal set; } private String hexValue; public String HexValue { @@ -41,13 +41,17 @@ public String HexValue { private Color rgbValue; public Color RgbValue { get { - if (UseWebAppColours) - return OutlookOgcs.Categories.Map.RgbColour(HexValue); + if (UseWebAppColours) { + if (rgbConvertedFromHex.IsEmpty && HexValue != null) rgbConvertedFromHex = OutlookOgcs.Categories.Map.RgbColour(HexValue); + return rgbConvertedFromHex; + } return rgbValue; } internal set { rgbValue = value; } } + private Color rgbConvertedFromHex; + public String Name { get { String name = ""; @@ -178,7 +182,7 @@ public List ActivePalette { if (profile.UseGoogleCalendar.ColourId == "0") { GoogleOgcs.Calendar.Instance.GetCalendars(); - profile.UseGoogleCalendar.ColourId = GoogleOgcs.Calendar.Instance.CalendarList.Find(c => c.Id == profile.UseGoogleCalendar.Id).ColourId; + profile.UseGoogleCalendar.ColourId = GoogleOgcs.Calendar.Instance.CalendarList.Find(c => c.Id == profile.UseGoogleCalendar.Id)?.ColourId ?? "0"; } //Palette currentCal = calendarPalette.Find(p => p.Id == profile.UseGoogleCalendar.ColourId); diff --git a/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs b/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs index 62628e67..a17640bf 100644 --- a/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs +++ b/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs @@ -947,7 +947,7 @@ private String getColour(String gColourId, String oColour) { public String GetCategoryColour(String gColourId, Boolean createMissingCategory = true) { OlCategoryColor? outlookColour = null; - SettingsStore.Calendar profile = Sync.Engine.Calendar.Instance.Profile; + SettingsStore.Calendar profile = Settings.Instance.ProfileInPlay(); if (profile.ColourMaps.Count > 0) { KeyValuePair kvp = profile.ColourMaps.FirstOrDefault(cm => cm.Value == gColourId); if (kvp.Key != null) { diff --git a/src/OutlookGoogleCalendarSync/SettingsStore/Settings.cs b/src/OutlookGoogleCalendarSync/SettingsStore/Settings.cs index da9b01a0..81533e4e 100644 --- a/src/OutlookGoogleCalendarSync/SettingsStore/Settings.cs +++ b/src/OutlookGoogleCalendarSync/SettingsStore/Settings.cs @@ -350,12 +350,6 @@ public void LogSettings() { log.Info(" Custom Timezone Mapping:-"); TimezoneMaps.ToList().ForEach(tz => log.Info(" " + tz.Key + " => " + tz.Value)); } - log.Info(" Disconnect Between Sync: " + DisconnectOutlookBetweenSync); - if (TimezoneMaps.Count > 0) { - log.Info(" Custom Timezone Mapping:-"); - TimezoneMaps.ToList().ForEach(tz => log.Info(" " + tz.Key + " => " + tz.Value)); - } - log.Info("GOOGLE SETTINGS:-"); log.Info(" Personal API Keys: " + UsingPersonalAPIkeys()); log.Info(" Client Identifier: " + PersonalClientIdentifier); @@ -436,7 +430,8 @@ public SettingsStore.Calendar ProfileInPlay() { StackTrace stackTrace = new StackTrace(); StackFrame[] stackFrames = stackTrace.GetFrames().Reverse().ToArray(); - String[] FormMethods = new String[] { "updateGUIsettings", "UpdateGUIsettings_Profile", "b__0", "miCatRefresh_Click", "GetMyGoogleCalendars_Click" }; + String[] FormMethods = new String[] { "updateGUIsettings", "UpdateGUIsettings_Profile", "b__0", "miCatRefresh_Click", "GetMyGoogleCalendars_Click", + "btColourMap_Click", "ColourPicker_Enter", "ddGoogleColour_SelectedIndexChanged" }; String[] TimerMethods = new String[] { "OnTick" }; foreach (StackFrame frame in stackFrames) { @@ -446,8 +441,11 @@ public SettingsStore.Calendar ProfileInPlay() { else if (TimerMethods.Contains(frame.GetMethod().Name)) return Sync.Engine.Calendar.Instance.Profile; } - log.Warn(stackFrames.ToString()); - return null; + String stackString = ""; + stackFrames.Reverse().ToList().ForEach(sf => stackString += sf.GetMethod().Name + " < "); + log.Warn(stackString); + log.Error("Unknown profile being referenced."); + return Forms.Main.Instance.ActiveCalendarProfile; } /// diff --git a/src/OutlookGoogleCalendarSync/Sync/Timer.cs b/src/OutlookGoogleCalendarSync/Sync/Timer.cs index f1c34c56..fbd62e3e 100644 --- a/src/OutlookGoogleCalendarSync/Sync/Timer.cs +++ b/src/OutlookGoogleCalendarSync/Sync/Timer.cs @@ -18,7 +18,6 @@ public DateTime? NextSyncDate { DateTime theDate = (DateTime)nextSyncDate; var profile = owningProfile as SettingsStore.Calendar; NextSyncDateText = theDate.ToLongDateString() + " @ " + theDate.ToLongTimeString() + (profile.OutlookPush ? " + Push" : ""); - log.Info("Next sync scheduled for " + NextSyncDateText); } } } @@ -40,6 +39,9 @@ public SyncTimer(Object owningProfile) { this.Tick += new EventHandler(ogcsTimer_Tick); this.Interval = int.MaxValue; + if (owningProfile is SettingsStore.Calendar) + this.LastSyncDate = (owningProfile as SettingsStore.Calendar).LastSyncDate; + SetNextSync(); } @@ -82,9 +84,10 @@ public void SetNextSync(int delayMins, Boolean fromNow = false, Boolean calculat if (syncInterval != 0) { DateTime now = DateTime.Now; - this.nextSyncDate = fromNow ? now.AddMinutes(delayMins) : LastSyncDate.AddMinutes(delayMins); + this.nextSyncDate = fromNow ? now.AddMinutes(delayMins) : this.LastSyncDate.AddMinutes(delayMins); if (calculateInterval) CalculateInterval(); else this.NextSyncDate = this.nextSyncDate; + log.Info("Next sync scheduled for " + this.NextSyncDateText); } else { this.NextSyncDateText = "Inactive"; Activate(false); @@ -108,7 +111,6 @@ public void CalculateInterval() { else this.Interval = (int)Math.Min((interval * 60000), int.MaxValue); this.NextSyncDate = now.AddMilliseconds(this.Interval); - return; } Activate(true); }