88using System . Linq ;
99using System . Net ;
1010using System . Runtime . InteropServices ;
11+ using System . Runtime . Serialization ;
1112using System . Text ;
1213using System . Text . RegularExpressions ;
1314using 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; }\n body { 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 }
0 commit comments