-
Notifications
You must be signed in to change notification settings - Fork 6
/
ThisAddIn.cs
71 lines (61 loc) · 2.03 KB
/
ThisAddIn.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Office.Interop.PowerPoint;
using PowerPointTimer.Model;
using PowerPointTimer.Util;
namespace PowerPointTimer
{
public partial class ThisAddIn
{
private List<TimerData> _activeTimers = new List<TimerData>();
private void ThisAddIn_Startup(object sender, EventArgs e)
{
this.Application.SlideShowEnd += OnSlideShowEnd;
this.Application.SlideShowNextSlide += OnNextSlide;
}
private void OnNextSlide(SlideShowWindow Wn)
{
// Dispose timers from previous slide
DisposeAllActiveTimers();
// Check activated slide for new timers
Slide activatedSlide = Wn.View.Slide;
_activeTimers = FindTimersOnSlide(activatedSlide)
.Select(timerShape => new TimerData(timerShape))
.ToList();
}
private void OnSlideShowEnd(Presentation Pres)
{
DisposeAllActiveTimers();
}
private void DisposeAllActiveTimers()
{
_activeTimers.ForEach(t => t.Dispose());
_activeTimers.Clear();
}
private IEnumerable<Shape> FindTimersOnSlide(Slide slide)
{
foreach (Shape shape in slide.Shapes)
{
if (shape.Tags[Constants.TimerTagName] == Constants.DigitalTimerTagValue)
{
yield return shape;
}
}
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new EventHandler(ThisAddIn_Startup);
this.Shutdown += new EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}