-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimerRibbon.cs
72 lines (61 loc) · 3.16 KB
/
TimerRibbon.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
72
using System.Drawing;
using System.Linq;
using MOO = Microsoft.Office.Core;
using Microsoft.Office.Tools.Ribbon;
using Microsoft.Office.Interop.PowerPoint;
using PowerPointTimer.Core;
using System.Threading;
namespace PowerPointTimer
{
public partial class TimerRibbon
{
private void AddTimer_Click(object sender, RibbonControlEventArgs e)
{
// check if the presentation has slides
var app = Globals.ThisAddIn.Application;
if (app.ActivePresentation.Slides.Count > 0)
{
// Get current slide
Slide currentSlide = app.ActiveWindow.View.Slide;
// Add timer to this slide
var textBoxCounter = currentSlide.Shapes.AddTextbox(
MOO.MsoTextOrientation.msoTextOrientationHorizontal,
2, 2, 120, 45);
textBoxCounter.TextFrame.TextRange.Text = Constants.DefaultTimerValue;
textBoxCounter.Tags.Add(Constants.TimerCounter, Constants.TimerCounterValue);
textBoxCounter.TextFrame.TextRange.Font.Color.RGB = ColorTranslator.ToOle(Color.Black);
// Hide it
textBoxCounter.Visible = MOO.MsoTriState.msoFalse;
var textBoxLauncher = currentSlide.Shapes.AddTextbox(
MOO.MsoTextOrientation.msoTextOrientationHorizontal,
10, 10, 120, 45);
textBoxLauncher.TextFrame.TextRange.Text = Constants.DefaultTimerValue;
textBoxLauncher.TextFrame.TextRange.Font.Size = 40;
textBoxLauncher.TextFrame.TextRange.Font.Color.RGB = ColorTranslator.ToOle(Color.Black);
textBoxLauncher.Tags.Add(Constants.TimerLauncher, Constants.TimerLauncherValue);
// Group both Shapes
var range = currentSlide.Shapes.Range(new string[] { textBoxLauncher.Name, textBoxCounter.Name });
var timerShape = range.Group();
timerShape.Tags.Add(Constants.TimerGroup, Constants.TimerGroupValue);
// Add a "bold" animation to triggers the countdown
currentSlide.TimeLine.MainSequence.AddEffect(timerShape.GroupItems.OfType<Shape>().FirstOrDefault<Shape>(s => s.Tags[Constants.TimerLauncher] == Constants.TimerLauncherValue),
MsoAnimEffect.msoAnimEffectBoldFlash, MsoAnimateByLevel.msoAnimateLevelNone,
MsoAnimTriggerType.msoAnimTriggerMixed);
}
}
private void RemoveTimers_Click(object sender, RibbonControlEventArgs e)
{
// Loop in the slide to remove all timers (launcher and actual timers stored in a group)
var app = Globals.ThisAddIn.Application;
if (app.ActivePresentation.Slides.Count > 0)
{
// Get current slide
Slide currentSlide = app.ActiveWindow.View.Slide;
currentSlide.Shapes.OfType<Microsoft.Office.Interop.PowerPoint.Shape>()
.Where(s => s.Tags[Constants.TimerGroup] == Constants.TimerGroupValue)
.ToList()
.ForEach(shape => shape.Delete());
}
}
}
}