@@ -9,8 +9,14 @@ public class NotebookExplorer
99 {
1010 private PluginInitContext context ;
1111 private OneNotePlugin oneNotePlugin ;
12+
13+ private IOneNoteExtNotebook LastSelectedNotebook { get => oneNotePlugin . lastSelectedNotebook ; set => oneNotePlugin . lastSelectedNotebook = value ; }
14+ private IOneNoteExtSection LastSelectedSection { get => oneNotePlugin . lastSelectedSection ; set => oneNotePlugin . lastSelectedSection = value ; }
15+
1216 private ResultCreator rc ;
1317
18+ private List < Result > NoResults => new List < Result > ( ) ;
19+
1420 public NotebookExplorer ( PluginInitContext context , OneNotePlugin oneNotePlugin , ResultCreator resultCreator )
1521 {
1622 this . context = context ;
@@ -32,14 +38,15 @@ public List<Result> Explore(Query query)
3238
3339 if ( string . IsNullOrWhiteSpace ( searchString ) ) // Do a normall notebook search
3440 {
35- oneNotePlugin . lastSelectedNotebook = null ;
41+ LastSelectedNotebook = null ;
3642 return OneNoteProvider . NotebookItems . Select ( nb => rc . CreateNotebookResult ( nb ) ) . ToList ( ) ;
3743 }
3844
3945 return OneNoteProvider . NotebookItems . Where ( nb =>
4046 {
41- if ( oneNotePlugin . lastSelectedNotebook != null && nb . ID == oneNotePlugin . lastSelectedNotebook . ID )
47+ if ( LastSelectedNotebook != null && nb . ID == LastSelectedNotebook . ID )
4248 return true ;
49+
4350 return TreeQuery ( nb . Name , searchString , out highlightData ) ;
4451 } )
4552 . Select ( nb => rc . CreateNotebookResult ( nb , highlightData ) )
@@ -49,65 +56,71 @@ public List<Result> Explore(Query query)
4956 searchString = searchStrings [ 2 ] ;
5057
5158 if ( ! ValidateNotebook ( searchStrings [ 1 ] ) )
52- return new List < Result > ( ) ;
59+ return NoResults ;
5360
5461 if ( string . IsNullOrWhiteSpace ( searchString ) )
5562 {
56- oneNotePlugin . lastSelectedSection = null ;
57- return oneNotePlugin . lastSelectedNotebook . Sections . Select ( s => rc . CreateSectionResult ( s , oneNotePlugin . lastSelectedNotebook ) ) . ToList ( ) ;
63+ LastSelectedSection = null ;
64+ return LastSelectedNotebook . Sections . Where ( s => ! s . Encrypted )
65+ . Select ( s => rc . CreateSectionResult ( s , LastSelectedNotebook ) )
66+ . ToList ( ) ;
5867 }
59- return oneNotePlugin . lastSelectedNotebook . Sections . Where ( s =>
68+ return LastSelectedNotebook . Sections . Where ( s =>
6069 {
61- if ( oneNotePlugin . lastSelectedSection != null && s . ID == oneNotePlugin . lastSelectedSection . ID )
70+ if ( s . Encrypted )
71+ return false ;
72+
73+ if ( LastSelectedSection != null && s . ID == LastSelectedSection . ID )
6274 return true ;
75+
6376 return TreeQuery ( s . Name , searchString , out highlightData ) ;
6477 } )
65- . Select ( s => rc . CreateSectionResult ( s , oneNotePlugin . lastSelectedNotebook , highlightData ) )
78+ . Select ( s => rc . CreateSectionResult ( s , LastSelectedNotebook , highlightData ) )
6679 . ToList ( ) ;
6780
6881 case 4 : //Searching pages in a section
6982 searchString = searchStrings [ 3 ] ;
7083
7184 if ( ! ValidateNotebook ( searchStrings [ 1 ] ) )
72- return new List < Result > ( ) ;
85+ return NoResults ;
7386
7487 if ( ! ValidateSection ( searchStrings [ 2 ] ) )
75- return new List < Result > ( ) ;
88+ return NoResults ;
7689
7790 if ( string . IsNullOrWhiteSpace ( searchString ) )
78- return oneNotePlugin . lastSelectedSection . Pages . Select ( pg => rc . CreatePageResult ( pg , oneNotePlugin . lastSelectedSection , oneNotePlugin . lastSelectedNotebook ) ) . ToList ( ) ;
91+ return LastSelectedSection . Pages . Select ( pg => rc . CreatePageResult ( pg , LastSelectedSection , LastSelectedNotebook ) ) . ToList ( ) ;
7992
80- return oneNotePlugin . lastSelectedSection . Pages . Where ( pg => TreeQuery ( pg . Name , searchString , out highlightData ) )
81- . Select ( pg => rc . CreatePageResult ( pg , oneNotePlugin . lastSelectedSection , oneNotePlugin . lastSelectedNotebook , highlightData ) )
93+ return LastSelectedSection . Pages . Where ( pg => TreeQuery ( pg . Name , searchString , out highlightData ) )
94+ . Select ( pg => rc . CreatePageResult ( pg , LastSelectedSection , LastSelectedNotebook , highlightData ) )
8295 . ToList ( ) ;
8396
8497 default :
85- return new List < Result > ( ) ;
98+ return NoResults ;
8699 }
87100
88101 }
89102
90103 private bool ValidateNotebook ( string notebookName )
91104 {
92- if ( oneNotePlugin . lastSelectedNotebook == null )
105+ if ( LastSelectedNotebook == null )
93106 {
94107 var notebook = OneNoteProvider . NotebookItems . FirstOrDefault ( nb => nb . Name == notebookName ) ;
95108 if ( notebook == null )
96109 return false ;
97- oneNotePlugin . lastSelectedNotebook = notebook ;
110+ LastSelectedNotebook = notebook ;
98111 return true ;
99112 }
100113 return true ;
101114 }
102115
103116 private bool ValidateSection ( string sectionName )
104117 {
105- if ( oneNotePlugin . lastSelectedSection == null ) //Check if section is valid
118+ if ( LastSelectedSection == null ) //Check if section is valid
106119 {
107- var section = oneNotePlugin . lastSelectedNotebook . Sections . FirstOrDefault ( s => s . Name == sectionName ) ;
108- if ( section == null )
120+ var section = LastSelectedNotebook . Sections . FirstOrDefault ( s => s . Name == sectionName ) ;
121+ if ( section == null || section . Encrypted )
109122 return false ;
110- oneNotePlugin . lastSelectedSection = section ;
123+ LastSelectedSection = section ;
111124 return true ;
112125 }
113126 return true ;
0 commit comments