Skip to content

Commit cad43ad

Browse files
committed
Nice calendar preview
1 parent 629f4d4 commit cad43ad

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

PasteIntoFile/ClipboardContents.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Net;
1010
using System.Runtime.InteropServices;
11+
using System.Runtime.Serialization;
1112
using System.Text;
1213
using System.Text.RegularExpressions;
1314
using System.Windows.Forms;
@@ -532,6 +533,7 @@ public CalendarContent(string text) : base(text) { }
532533
public static bool IsValidCalendar(string text) {
533534
return text.StartsWith("BEGIN:VCALENDAR");
534535
}
536+
public Ical.Net.Calendar Calendar => Ical.Net.Calendar.Load(Text);
535537
public override void AddTo(IDataObject data) {
536538
foreach (var f in CLIP_FORMATS) {
537539
data.SetData(f, Text);
@@ -540,6 +542,23 @@ public override void AddTo(IDataObject data) {
540542

541543
public override PreviewHolder Preview(string extension) {
542544
switch (extension) {
545+
case "ics":
546+
try {
547+
return PreviewHolder.ForHtml(
548+
"<!DOCTYPE html>\n<html>\n<head>\n<style>\n"
549+
+ "* { font-family: Sans-serif; font-size: small; }\n"
550+
+ "strong { font-size: medium; }\nbody { margin: 0; }\n"
551+
+ "p { background: aliceblue; border: solid silver 1pt; padding: 0.5em; margin: 0.5em; }\n"
552+
+ "</style>\n</head>\n<body>\n"
553+
+ string.Join("\n", Calendar.Events.Select(
554+
e => string.Format("<p>{0}<br/><strong>{1}</strong></p>", e.Start, e.Summary)
555+
))
556+
+ "\n</body>\n</html>\n",
557+
Resources.str_preview_calendar
558+
);
559+
} catch (SerializationException e) {
560+
return PreviewHolder.ForText(Text, Resources.str_preview_calendar);
561+
}
543562
default:
544563
return PreviewHolder.ForText(Text, Resources.str_preview_calendar);
545564
}

PasteIntoFile/PasteIntoFile.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<ItemGroup>
4949
<PackageReference Include="BetterFolderBrowser" Version="1.2.0" />
5050
<PackageReference Include="CommandLineParser" Version="2.9.1" />
51+
<PackageReference Include="Ical.Net" Version="5.0.0-pre.42" />
5152
<PackageReference Include="LINQtoCSV" Version="1.5.0" />
5253
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.2" />
5354
<PackageReference Include="PDFsharp" Version="1.50.5147" />

0 commit comments

Comments
 (0)