77using Flow . Launcher . Plugin . OneNote . UI . Views ;
88using Humanizer ;
99using Odotocodot . OneNote . Linq ;
10+ using Odotocodot . OneNote . Linq . Abstractions ;
1011
1112namespace Flow . Launcher . Plugin . OneNote
1213{
@@ -19,7 +20,6 @@ public class ResultCreator
1920 private const string PathSeparator = " > " ;
2021 private const string BulletPoint = "\u2022 " ;
2122 private const string TrianglePoint = "\u2023 " ;
22-
2323 private string ActionKeyword => context . CurrentPluginMetadata . ActionKeyword ;
2424 public ResultCreator ( PluginInitContext context , Settings settings , IconProvider iconProvider )
2525 {
@@ -31,7 +31,7 @@ public ResultCreator(PluginInitContext context, Settings settings, IconProvider
3131 private static string GetNicePath ( IOneNoteItem item , string separator = PathSeparator ) =>
3232 item . RelativePath . Replace ( OneNoteApplication . RelativePathSeparator . ToString ( ) , separator ) ;
3333
34- private string GetTitle ( IOneNoteItem item , List < int > highlightData )
34+ private string GetTitle ( IOneNoteItem item , List < int > ? highlightData )
3535 {
3636 string title = item . Name ;
3737 if ( ! item . IsUnread || ! settings . ShowUnread )
@@ -51,8 +51,7 @@ private string GetTitle(IOneNoteItem item, List<int> highlightData)
5151
5252 private string GetAutoCompleteText ( IOneNoteItem item )
5353 => $ "{ ActionKeyword } { settings . Keywords . NotebookExplorer } { GetNicePath ( item , Keywords . NotebookExplorerSeparator ) } { Keywords . NotebookExplorerSeparator } ";
54-
55-
54+
5655 public List < Result > EmptyQuery ( )
5756 {
5857 return new List < Result >
@@ -63,14 +62,16 @@ public List<Result> EmptyQuery()
6362 SubTitle = "Try typing something!" ,
6463 AutoCompleteText = ActionKeyword ,
6564 IcoPath = iconProvider . Search ,
66- Score = 5000 ,
65+ AddSelectedCount = false ,
66+ Score = Result . MaxScore ,
6767 } ,
6868 new Result
6969 {
7070 Title = "View notebook explorer" ,
7171 SubTitle = $ "Type \" { settings . Keywords . NotebookExplorer } \" or select this option to search by notebook structure",
7272 AutoCompleteText = $ "{ ActionKeyword } { settings . Keywords . NotebookExplorer } ",
7373 IcoPath = iconProvider . NotebookExplorer ,
74+ AddSelectedCount = false ,
7475 Score = 2000 ,
7576 Action = _ =>
7677 {
@@ -84,6 +85,7 @@ public List<Result> EmptyQuery()
8485 SubTitle = $ "Type \" { settings . Keywords . RecentPages } \" or select this option to see recently modified pages",
8586 AutoCompleteText = $ "{ ActionKeyword } { settings . Keywords . RecentPages } ",
8687 IcoPath = iconProvider . Recent ,
88+ AddSelectedCount = false ,
8789 Score = - 1000 ,
8890 Action = _ =>
8991 {
@@ -95,6 +97,7 @@ public List<Result> EmptyQuery()
9597 {
9698 Title = "New quick note" ,
9799 IcoPath = iconProvider . QuickNote ,
100+ AddSelectedCount = false ,
98101 Score = - 4000 ,
99102 PreviewPanel = GetNewPagePreviewPanel ( null , null ) ,
100103 Action = _ =>
@@ -108,6 +111,7 @@ public List<Result> EmptyQuery()
108111 {
109112 Title = "Open and sync notebooks" ,
110113 IcoPath = iconProvider . Sync ,
114+ AddSelectedCount = false ,
111115 Score = int . MinValue ,
112116 Action = _ =>
113117 {
@@ -130,45 +134,32 @@ public List<Result> EmptyQuery()
130134 } ;
131135 }
132136
133- public Result CreateOneNoteItemResult ( IOneNoteItem item , bool actionIsAutoComplete , List < int > highlightData = null , int score = 0 )
137+ public Result CreateOneNoteItemResult ( IOneNoteItem item , bool actionIsAutoComplete , List < int > ? highlightData = null , int score = 0 )
134138 {
135- string title = GetTitle ( item , highlightData ) ;
136- string toolTip = string . Empty ;
137- string subTitle = GetNicePath ( item ) ;
138- string autoCompleteText = GetAutoCompleteText ( item ) ;
139-
140- IconGeneratorInfo iconInfo ;
139+ var title = GetTitle ( item , highlightData ) ;
140+ var toolTip = string . Empty ;
141+ var subTitle = GetNicePath ( item ) ;
142+ var autoCompleteText = GetAutoCompleteText ( item ) ;
143+ var iconInfo = new IconGeneratorInfo ( item ) ;
141144
142145 switch ( item )
143146 {
144- case OneNoteNotebook notebook :
147+ case INotebookOrSectionGroup i :
145148 toolTip =
146149 $ """
147150 Last Modified:
148- { TrianglePoint } { notebook . LastModified : F}
151+ { TrianglePoint } { i . LastModified : F}
149152
150153 Contains:
151- { TrianglePoint } { "section group" . ToQuantity ( notebook . SectionGroups . Count ( ) ) }
152- { TrianglePoint } { "section" . ToQuantity ( notebook . Sections . Count ( ) ) }
153- { TrianglePoint } { "page" . ToQuantity ( notebook . GetPages ( ) . Count ( ) ) }
154+ { TrianglePoint } { "section group" . ToQuantity ( i . SectionGroups . Count ( ) ) }
155+ { TrianglePoint } { "section" . ToQuantity ( i . Sections . Count ( ) ) }
156+ { TrianglePoint } { "page" . ToQuantity ( i . GetPages ( ) . Count ( ) ) }
154157 """ ;
155158
156- subTitle = string . Empty ;
157- iconInfo = new IconGeneratorInfo ( notebook ) ;
158- break ;
159- case OneNoteSectionGroup sectionGroup :
160- toolTip =
161- $ """
162- Last Modified:
163- { TrianglePoint } { sectionGroup . LastModified : F}
164-
165- Contains:
166- { TrianglePoint } { "section group" . ToQuantity ( sectionGroup . SectionGroups . Count ( ) ) }
167- { TrianglePoint } { "section" . ToQuantity ( sectionGroup . Sections . Count ( ) ) }
168- { TrianglePoint } { "page" . ToQuantity ( sectionGroup . GetPages ( ) . Count ( ) ) }
169- """ ;
170-
171- iconInfo = new IconGeneratorInfo ( sectionGroup ) ;
159+ if ( i is OneNoteNotebook )
160+ {
161+ subTitle = string . Empty ;
162+ }
172163 break ;
173164 case OneNoteSection section :
174165 if ( section . Encrypted )
@@ -184,8 +175,6 @@ public Result CreateOneNoteItemResult(IOneNoteItem item, bool actionIsAutoComple
184175 Contains:
185176 { TrianglePoint } { "page" . ToQuantity ( section . GetPages ( ) . Count ( ) ) }
186177 """ ;
187-
188- iconInfo = new IconGeneratorInfo ( section ) ;
189178 break ;
190179 case OneNotePage page :
191180 autoCompleteText = actionIsAutoComplete ? autoCompleteText [ ..^ 1 ] : string . Empty ;
@@ -198,10 +187,6 @@ public Result CreateOneNoteItemResult(IOneNoteItem item, bool actionIsAutoComple
198187 { "Created:" , - 15 } { page . Created : F}
199188 { "Last Modified:" , - 15 } { page . LastModified : F}
200189 """ ;
201- iconInfo = new IconGeneratorInfo ( page ) ;
202- break ;
203- default :
204- iconInfo = default ;
205190 break ;
206191 }
207192
@@ -222,7 +207,7 @@ public Result CreateOneNoteItemResult(IOneNoteItem item, bool actionIsAutoComple
222207 context . API . ChangeQuery ( $ "{ autoCompleteText } ", true ) ;
223208 return false ;
224209 }
225-
210+
226211 await Task . Run ( ( ) =>
227212 {
228213 item . Sync ( ) ;
@@ -426,13 +411,12 @@ public List<Result> ContextMenu(Result selectedResult)
426411 return results ;
427412 }
428413
429- public List < Result > NoItemsInCollection ( List < Result > results , IOneNoteItem parent )
414+ public List < Result > NoItemsInCollection ( List < Result > results , IOneNoteItem ? parent )
430415 {
431416 // parent can be null if the collection only contains notebooks.
432417 switch ( parent )
433418 {
434- case OneNoteNotebook :
435- case OneNoteSectionGroup :
419+ case INotebookOrSectionGroup :
436420 // Can create section/section group
437421 results . Add ( NoItemsInCollectionResult ( "section" , iconProvider . NewSection , "(unencrypted) section" ) ) ;
438422 results . Add ( NoItemsInCollectionResult ( "section group" , iconProvider . NewSectionGroup ) ) ;
@@ -448,7 +432,7 @@ public List<Result> NoItemsInCollection(List<Result> results, IOneNoteItem paren
448432
449433 return results ;
450434
451- Result NoItemsInCollectionResult ( string title , string iconPath , string subTitle = null , OneNoteSection section = null )
435+ Result NoItemsInCollectionResult ( string title , string iconPath , string ? subTitle = null , OneNoteSection ? section = null )
452436 {
453437 return new Result
454438 {
@@ -460,7 +444,7 @@ Result NoItemsInCollectionResult(string title, string iconPath, string subTitle
460444 }
461445 }
462446
463- private Lazy < UserControl > GetNewPagePreviewPanel ( OneNoteSection section , string pageTitle ) =>
447+ private Lazy < UserControl > GetNewPagePreviewPanel ( OneNoteSection ? section , string ? pageTitle ) =>
464448 new ( ( ) => new NewOneNotePagePreviewPanel ( context , section , pageTitle ) ) ;
465449
466450 public static List < Result > NoMatchesFound ( )
@@ -469,10 +453,12 @@ public static List<Result> NoMatchesFound()
469453 "Try searching something else, or syncing your notebooks" ,
470454 IconProvider . Logo ) ;
471455 }
472- public List < Result > InvalidQuery ( )
456+ public List < Result > InvalidQuery ( bool includeSubtitle = true )
473457 {
474458 return SingleResult ( "Invalid query" ,
475- "The first character of the search must be a letter or a digit" ,
459+ includeSubtitle
460+ ? "The first character of the search must be a letter or a digit"
461+ : string . Empty ,
476462 iconProvider . Warning ) ;
477463 }
478464 public List < Result > SearchingByTitle ( )
0 commit comments