@@ -8,25 +8,24 @@ namespace Flow.Launcher.Plugin.OneNote.Search
88{
99 public class NotebookExplorer : SearchBase
1010 {
11+ private readonly TitleSearch titleSearch ;
12+ public NotebookExplorer ( PluginInitContext context , Settings settings , ResultCreator resultCreator , TitleSearch titleSearch ) : base ( context ,
13+ settings , resultCreator , ( ) => settings . Keywords . NotebookExplorer )
14+ {
15+ this . titleSearch = titleSearch ;
16+ }
17+
1118 public override List < Result > GetResults ( string query )
1219 {
13- if ( ValidateSearch ( query , out string ? search , out IOneNoteItem ? parent , out IEnumerable < IOneNoteItem > collection ) )
20+ if ( ! ValidateSearch ( query , out string ? search , out IOneNoteItem ? parent , out IEnumerable < IOneNoteItem > collection ) )
1421 return resultCreator . InvalidQuery ( false ) ;
1522
1623 List < Result > results = search switch
1724 {
18- // Empty search so show all in collection
19- string when string . IsNullOrWhiteSpace ( search ) => ShowAll ( parent , collection ) ,
20-
21- // Search by title
22- not null when search . StartsWith ( Keywords . TitleSearch ) && parent is not OneNotePage
23- => TitleSearch . Filter ( search , parent , collection , context , settings , resultCreator ) ,
24-
25- // Scoped search
26- not null when search . StartsWith ( Keywords . ScopedSearch ) && parent is INotebookOrSectionGroup => ScopedSearch ( search , parent ) ,
27-
28- // Default search
29- _ => Explorer ( search , parent , collection ) ,
25+ { } when search . StartsWith ( Keywords . TitleSearch ) && parent is not OneNotePage => titleSearch . Filter ( search , parent , collection ) ,
26+ { } when search . StartsWith ( Keywords . ScopedSearch ) && parent is INotebookOrSectionGroup => ScopedSearch ( search , parent ) ,
27+ { } when ! string . IsNullOrWhiteSpace ( search ) => Explorer ( search , parent , collection ) ,
28+ _ => ShowAll ( parent , collection ) ,
3029 } ;
3130
3231 if ( parent == null )
@@ -36,8 +35,8 @@ not null when search.StartsWith(Keywords.ScopedSearch) && parent is INotebookOrS
3635 result . Title = $ "Open \" { parent . Name } \" in OneNote";
3736 result . SubTitle = search switch
3837 {
39- not null when search . StartsWith ( Keywords . TitleSearch ) => $ "Now searching by title in \" { parent . Name } \" ",
40- not null when search . StartsWith ( Keywords . ScopedSearch ) => $ "Now searching all pages in \" { parent . Name } \" ",
38+ { } when search . StartsWith ( Keywords . TitleSearch ) => $ "Now searching by title in \" { parent . Name } \" ",
39+ { } when search . StartsWith ( Keywords . ScopedSearch ) => $ "Now searching all pages in \" { parent . Name } \" ",
4140 _ => $ "Use \' { Keywords . ScopedSearch } \' to search this item. Use \' { Keywords . TitleSearch } \' to search by title in this item",
4241 } ;
4342
@@ -52,7 +51,6 @@ private bool ValidateSearch(string query, out string? lastSearch, out IOneNoteIt
5251 collection = OneNoteApplication . GetNotebooks ( ) ;
5352
5453 string search = query [ ( query . IndexOf ( Keywords . NotebookExplorer , StringComparison . Ordinal ) + Keywords . NotebookExplorer . Length ) ..] ;
55-
5654 const string separator = Keywords . NotebookExplorerSeparator ;
5755 var currIndex = search . IndexOf ( separator , StringComparison . Ordinal ) ;
5856 var prevIndex = 0 ;
@@ -80,7 +78,7 @@ private List<Result> ShowAll(IOneNoteItem? parent, IEnumerable<IOneNoteItem> col
8078 . Select ( item => resultCreator . CreateOneNoteItemResult ( item , true ) )
8179 . ToList ( ) ;
8280
83- return results . Any ( ) ? results : resultCreator . NoItemsInCollection ( results , parent ) ;
81+ return results . Any ( ) ? results : resultCreator . EmptyCollection ( results , parent ) ;
8482 }
8583
8684 private List < Result > ScopedSearch ( string query , IOneNoteItem parent )
@@ -93,9 +91,11 @@ private List<Result> ScopedSearch(string query, IOneNoteItem parent)
9391
9492 string currentSearch = query [ Keywords . TitleSearch . Length ..] ;
9593
96- return OneNoteApplication . FindPages ( currentSearch , parent )
97- . Select ( pg => resultCreator . CreatePageResult ( pg , currentSearch ) )
98- . ToList ( ) ;
94+ var results = OneNoteApplication . FindPages ( currentSearch , parent )
95+ . Select ( pg => resultCreator . CreatePageResult ( pg , currentSearch ) )
96+ . ToList ( ) ;
97+
98+ return results . Any ( ) ? results : ResultCreator . NoMatchesFound ( ) ;
9999 }
100100
101101 private List < Result > Explorer ( string search , IOneNoteItem ? parent , IEnumerable < IOneNoteItem > collection )
0 commit comments