Skip to content

Commit eef4120

Browse files
committed
Add support for ICS Calendar files
closes #71
1 parent 6136882 commit eef4120

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

PasteIntoFile/ClipboardContents.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,28 @@ public override void SaveAs(string path, string extension, bool append = false)
543543
}
544544

545545

546+
public class CalendarContent : TextLikeContent {
547+
public static readonly string[] FORMATS = { "text/calendar", "ics", DataFormats.Text };
548+
public static readonly string[] EXTENSIONS = { "ics" };
549+
550+
public CalendarContent(string text) : base(FORMATS, EXTENSIONS, text) { }
551+
552+
public override string Description => string.Format(Resources.str_preview_calendar,
553+
Text.ToUpperInvariant().Split('\n').Count(l => l.Trim().StartsWith("BEGIN:VEVENT")));
554+
555+
public override void AddTo(IDataObject data) {
556+
// Note: Spec says UTF8 is the default, but thunderbird only accepts UTF16 (simply called "Unicode" in .NET)
557+
AddTo(data, Text, Encoding.Unicode);
558+
}
559+
560+
public override void SaveAs(string path, string extension, bool append = false) {
561+
if (append) throw new AppendNotSupportedException();
562+
base.SaveAs(path, extension, append);
563+
}
564+
565+
}
566+
567+
546568
public class FilesContent : BaseContent {
547569
public FilesContent(StringCollection files) {
548570
Data = files;
@@ -792,7 +814,8 @@ public static ClipboardContents FromClipboard() {
792814
if (ReadClipboardString(RtfContent.FORMATS) is string rtf) container.Contents.Add(new RtfContent(rtf));
793815
if (ReadClipboardString(DifContent.FORMATS) is string dif) container.Contents.Add(new DifContent(dif));
794816
if (ReadClipboardString(SvgContent.FORMATS) is string svg) container.Contents.Add(new SvgContent(svg));
795-
817+
if (ReadClipboardString(CalendarContent.FORMATS) is string ics && ics.ToUpperInvariant().StartsWith("BEGIN:VCALENDAR"))
818+
container.Contents.Add(new CalendarContent(ics));
796819

797820
if (Clipboard.ContainsText() && Uri.IsWellFormedUriString(Clipboard.GetText().Trim(), UriKind.Absolute))
798821
container.Contents.Add(new UrlContent(Clipboard.GetText().Trim()));
@@ -932,12 +955,8 @@ public static ClipboardContents FromFile(string path) {
932955
container.Contents.Add(new SvgContent(contents));
933956
if (ext == "csv")
934957
container.Contents.Add(new CsvContent(contents));
935-
if (ext == "dif")
936-
container.Contents.Add(new GenericTextContent(DataFormats.Dif, ext, contents));
937-
if (ext == "rtf")
938-
container.Contents.Add(new GenericTextContent(DataFormats.Rtf, ext, contents));
939-
if (ext == "syk")
940-
container.Contents.Add(new GenericTextContent(DataFormats.SymbolicLink, ext, contents));
958+
if (ext == "ics")
959+
container.Contents.Add(new CalendarContent(contents));
941960
if (DifContent.EXTENSIONS.Contains(ext))
942961
container.Contents.Add(new DifContent(contents));
943962
if (RtfContent.EXTENSIONS.Contains(ext))

PasteIntoFile/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PasteIntoFile/Properties/Resources.de.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,7 @@ Allows to keep application window always on top (in foreground of other windows)
315315
<data name="str_system_language" xml:space="preserve">
316316
<value>Systemsprache</value>
317317
</data>
318+
<data name="str_preview_calendar" xml:space="preserve">
319+
<value>Kalender Vorschau ({0} Termin(e))</value>
320+
</data>
318321
</root>

PasteIntoFile/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,7 @@ Allows to keep application window always on top (in foreground of other windows)
327327
<data name="str_system_language" xml:space="preserve">
328328
<value>System language</value>
329329
</data>
330+
<data name="str_preview_calendar" xml:space="preserve">
331+
<value>Calendar preview ({0} event(s))</value>
332+
</data>
330333
</root>

0 commit comments

Comments
 (0)