Skip to content

Commit

Permalink
Merge branch 'development' into release
Browse files Browse the repository at this point in the history
Closes #1823
  • Loading branch information
phw198 committed Apr 1, 2024
2 parents 5e9df43 + e227b19 commit c797a82
Show file tree
Hide file tree
Showing 15 changed files with 257 additions and 90 deletions.
34 changes: 28 additions & 6 deletions src/OutlookGoogleCalendarSync/Extensions/MenuButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ public MenuButton() {
}

protected override void OnMouseDown(MouseEventArgs mevent) {
var splitRect = new Rectangle(this.Width - this.SplitWidth, 0, this.SplitWidth, this.Height);
Rectangle splitRect = new Rectangle(this.Width - this.SplitWidth, 0, this.SplitWidth, this.Height);
this.Tag = "";

// Figure out if the button click was on the button itself or the menu split
if (Menu != null && mevent.Button == MouseButtons.Left && splitRect.Contains(mevent.Location)) {
Menu.Show(this, 0, this.Height); // Shows menu under button
//Menu.Show(this, mevent.Location); // Shows menu at click location
if (this.Menu.Visible) {
this.Tag = "CloseRequested";
this.Menu.Hide();
} else {
Menu.Show(this, 0, this.Height); // Shows menu under button
//Menu.Show(this, mevent.Location); // Shows menu at click location
}
} else {
base.OnMouseDown(mevent);
}
Expand All @@ -31,7 +37,7 @@ protected override void OnPaint(PaintEventArgs pEvent) {

if (this.Menu != null && this.SplitWidth > 0) {
// Draw the arrow glyph on the right side of the button
int arrowX = ClientRectangle.Width - 14;
int arrowX = ClientRectangle.Width - (int)(SplitWidth - ((SplitWidth - 7)/2));
int arrowY = ClientRectangle.Height / 2 - 1;

var arrowBrush = Enabled ? SystemBrushes.ControlText : SystemBrushes.ButtonShadow;
Expand All @@ -40,8 +46,8 @@ protected override void OnPaint(PaintEventArgs pEvent) {

// Draw a dashed separator on the left of the arrow
int lineX = ClientRectangle.Width - this.SplitWidth;
int lineYFrom = arrowY - 4;
int lineYTo = arrowY + 8;
int lineYFrom = 6;
int lineYTo = ClientRectangle.Height - 6;
using (var separatorPen = new Pen(Brushes.DarkGray) {
DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
}) {
Expand All @@ -50,4 +56,20 @@ protected override void OnPaint(PaintEventArgs pEvent) {
}
}
}

public partial class ButtonContextMenuStrip : ContextMenuStrip {

public ButtonContextMenuStrip(IContainer container) { }

protected override void OnClosing(ToolStripDropDownClosingEventArgs e) {
if (this.SourceControl is MenuButton) {
MenuButton button = this.SourceControl as MenuButton;
Rectangle dropdownRect = new Rectangle(button.Width - button.SplitWidth, 0, button.SplitWidth, button.Height);
Point relativeMousePosition = button.PointToClient(Cursor.Position);
if (dropdownRect.Contains(relativeMousePosition) && string.IsNullOrEmpty(button.Tag.ToString()))
e.Cancel = true;
button.Tag = "";
}
}
}
}
1 change: 1 addition & 0 deletions src/OutlookGoogleCalendarSync/Forms/ColourMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected override void Dispose(bool disposing) {
if (disposing) {
if (components != null)
components.Dispose();
Forms.Main.Instance.btColourMap.Enabled = true;
OutlookOgcs.Calendar.Disconnect(true);
}
base.Dispose(disposing);
Expand Down
73 changes: 53 additions & 20 deletions src/OutlookGoogleCalendarSync/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion src/OutlookGoogleCalendarSync/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,13 @@ public void Sync_Click(object sender, EventArgs e) {
}
}

private void miSyncDelta_Click(object sender, EventArgs e) {
this.bSyncNow.Text = "Start Sync";
}
private void miSyncFull_Click(object sender, EventArgs e) {
this.bSyncNow.Text = "Start Full Sync";
}

public enum SyncNotes {
DailyQuotaExhaustedInfo,
DailyQuotaExhaustedPreviously,
Expand Down Expand Up @@ -2256,7 +2263,10 @@ private void btColourMap_Click(object sender, EventArgs e) {
return;
}
try {
new Forms.ColourMap().ShowDialog(this);
this.btColourMap.Enabled = false;
using (Forms.ColourMap colourForm = new ColourMap()) {
colourForm.ShowDialog();
}
} catch (System.Exception ex) {
OGCSexception.Analyse(ex);
}
Expand Down
13 changes: 8 additions & 5 deletions src/OutlookGoogleCalendarSync/Forms/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,14 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="msSyncActions.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="msProfileActions.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>403, 17</value>
<value>536, 17</value>
</metadata>
<metadata name="msCategories.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>126, 17</value>
<value>259, 17</value>
</metadata>
<data name="lGoogleAPIInstructions.Text" xml:space="preserve">
<value>To change the Client ID and secret, first disconnect your account
Expand All @@ -132,10 +135,10 @@ You'll need to enable the Calendar API in your project:
</value>
</data>
<metadata name="msColours.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
<value>150, 17</value>
</metadata>
<metadata name="msSettingsActions.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>251, 17</value>
<value>384, 17</value>
</metadata>
<data name="label21.Text" xml:space="preserve">
<value>On the "Google" tab, select the calendar you wish to synchronise.
Expand Down Expand Up @@ -163,7 +166,7 @@ or support further improvements,
any donations would be greatly appreciated!</value>
</data>
<metadata name="trayIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>546, 17</value>
<value>679, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="trayIcon.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
Expand Down
31 changes: 29 additions & 2 deletions src/OutlookGoogleCalendarSync/GoogleOgcs/EventColour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,39 @@ public void Get() {
Colors colours = null;
calendarPalette = new List<Palette>();
eventPalette = new List<Palette>();
int backoff = 0;
try {
colours = GoogleOgcs.Calendar.Instance.Service.Colors.Get().Execute();
while (backoff < GoogleOgcs.Calendar.BackoffLimit) {
try {
colours = GoogleOgcs.Calendar.Instance.Service.Colors.Get().Execute();
break;
} catch (Google.GoogleApiException ex) {
switch (GoogleOgcs.Calendar.HandleAPIlimits(ref ex, null)) {
case GoogleOgcs.Calendar.ApiException.throwException: throw;
case GoogleOgcs.Calendar.ApiException.freeAPIexhausted:
OGCSexception.LogAsFail(ref ex);
OGCSexception.Analyse(ex);
System.ApplicationException aex = new System.ApplicationException(GoogleOgcs.Calendar.Instance.SubscriptionInvite, ex);
OGCSexception.LogAsFail(ref aex);
throw aex;
case GoogleOgcs.Calendar.ApiException.backoffThenRetry:
backoff++;
if (backoff == GoogleOgcs.Calendar.BackoffLimit) {
log.Error("API limit backoff was not successful. Retrieve Event colours failed.");
throw;
} else {
int backoffDelay = (int)Math.Pow(2, backoff);
log.Warn("API rate limit reached. Backing off " + backoffDelay + "sec before retry.");
System.Threading.Thread.Sleep(backoffDelay * 1000);
}
break;
}
}
}
} catch (System.Exception ex) {
log.Error("Failed retrieving calendar Event colours.");
OGCSexception.Analyse(ex);
return;
throw;
}

if (colours == null) log.Warn("No colours found!");
Expand Down
Loading

0 comments on commit c797a82

Please sign in to comment.