@@ -13,6 +13,7 @@ public class OneNote : IPlugin, IContextMenu
13
13
private readonly string unavailableIconPath = "Images/unavailable.png" ;
14
14
private readonly string syncIconPath = "Images/refresh.png" ;
15
15
private readonly string recentIconPath = "Images/recent.png" ;
16
+ private readonly string recentPageIconPath = "Images/recent_page.png" ;
16
17
17
18
private readonly string structureKeyword = "nb:\\ " ;
18
19
private readonly string recentKeyword = "rcntpgs:" ;
@@ -102,13 +103,17 @@ public List<Result> Query(Query query)
102
103
{
103
104
int count = recentPagesCount ;
104
105
if ( query . FirstSearch . Length > recentKeyword . Length && int . TryParse ( query . FirstSearch [ recentKeyword . Length ..] , out int userChosenCount ) )
105
- {
106
106
count = userChosenCount ;
107
- }
108
-
107
+
109
108
return OneNoteProvider . PageItems . OrderByDescending ( pg => pg . LastModified )
110
- . Select ( pg => CreatePageResult ( pg , null ) )
111
109
. Take ( count )
110
+ . Select ( pg =>
111
+ {
112
+ Result result = CreatePageResult ( pg , null ) ;
113
+ result . SubTitle = $ "{ GetLastEdited ( DateTime . Now - pg . LastModified ) } \t { result . SubTitle } ";
114
+ result . IcoPath = recentPageIconPath ;
115
+ return result ;
116
+ } )
112
117
. ToList ( ) ;
113
118
}
114
119
@@ -350,5 +355,29 @@ private Result CreateNotebookResult(IOneNoteExtNotebook notebook, List<int> high
350
355
} ,
351
356
} ;
352
357
}
358
+ private static string GetLastEdited ( TimeSpan diff )
359
+ {
360
+ string lastEdited = "Last editied " ;
361
+ if ( PluralCheck ( diff . TotalDays , "day" , ref lastEdited )
362
+ || PluralCheck ( diff . TotalHours , "hour" , ref lastEdited )
363
+ || PluralCheck ( diff . TotalMinutes , "min" , ref lastEdited )
364
+ || PluralCheck ( diff . TotalSeconds , "sec" , ref lastEdited ) )
365
+ return lastEdited ;
366
+ else
367
+ return lastEdited += "Now." ;
368
+ bool PluralCheck ( double totalTime , string timeType , ref string lastEdited )
369
+ {
370
+ var roundedTime = ( int ) Math . Round ( totalTime ) ;
371
+ if ( roundedTime > 0 )
372
+ {
373
+ string plural = roundedTime == 1 ? "" : "s" ;
374
+ lastEdited += $ "{ roundedTime } { timeType } { plural } ago.";
375
+ return true ;
376
+ }
377
+ else
378
+ return false ;
379
+
380
+ }
381
+ }
353
382
}
354
383
}
0 commit comments