@@ -9,8 +9,14 @@ public class NotebookExplorer
9
9
{
10
10
private PluginInitContext context ;
11
11
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
+
12
16
private ResultCreator rc ;
13
17
18
+ private List < Result > NoResults => new List < Result > ( ) ;
19
+
14
20
public NotebookExplorer ( PluginInitContext context , OneNotePlugin oneNotePlugin , ResultCreator resultCreator )
15
21
{
16
22
this . context = context ;
@@ -32,14 +38,15 @@ public List<Result> Explore(Query query)
32
38
33
39
if ( string . IsNullOrWhiteSpace ( searchString ) ) // Do a normall notebook search
34
40
{
35
- oneNotePlugin . lastSelectedNotebook = null ;
41
+ LastSelectedNotebook = null ;
36
42
return OneNoteProvider . NotebookItems . Select ( nb => rc . CreateNotebookResult ( nb ) ) . ToList ( ) ;
37
43
}
38
44
39
45
return OneNoteProvider . NotebookItems . Where ( nb =>
40
46
{
41
- if ( oneNotePlugin . lastSelectedNotebook != null && nb . ID == oneNotePlugin . lastSelectedNotebook . ID )
47
+ if ( LastSelectedNotebook != null && nb . ID == LastSelectedNotebook . ID )
42
48
return true ;
49
+
43
50
return TreeQuery ( nb . Name , searchString , out highlightData ) ;
44
51
} )
45
52
. Select ( nb => rc . CreateNotebookResult ( nb , highlightData ) )
@@ -49,65 +56,71 @@ public List<Result> Explore(Query query)
49
56
searchString = searchStrings [ 2 ] ;
50
57
51
58
if ( ! ValidateNotebook ( searchStrings [ 1 ] ) )
52
- return new List < Result > ( ) ;
59
+ return NoResults ;
53
60
54
61
if ( string . IsNullOrWhiteSpace ( searchString ) )
55
62
{
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 ( ) ;
58
67
}
59
- return oneNotePlugin . lastSelectedNotebook . Sections . Where ( s =>
68
+ return LastSelectedNotebook . Sections . Where ( s =>
60
69
{
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 )
62
74
return true ;
75
+
63
76
return TreeQuery ( s . Name , searchString , out highlightData ) ;
64
77
} )
65
- . Select ( s => rc . CreateSectionResult ( s , oneNotePlugin . lastSelectedNotebook , highlightData ) )
78
+ . Select ( s => rc . CreateSectionResult ( s , LastSelectedNotebook , highlightData ) )
66
79
. ToList ( ) ;
67
80
68
81
case 4 : //Searching pages in a section
69
82
searchString = searchStrings [ 3 ] ;
70
83
71
84
if ( ! ValidateNotebook ( searchStrings [ 1 ] ) )
72
- return new List < Result > ( ) ;
85
+ return NoResults ;
73
86
74
87
if ( ! ValidateSection ( searchStrings [ 2 ] ) )
75
- return new List < Result > ( ) ;
88
+ return NoResults ;
76
89
77
90
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 ( ) ;
79
92
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 ) )
82
95
. ToList ( ) ;
83
96
84
97
default :
85
- return new List < Result > ( ) ;
98
+ return NoResults ;
86
99
}
87
100
88
101
}
89
102
90
103
private bool ValidateNotebook ( string notebookName )
91
104
{
92
- if ( oneNotePlugin . lastSelectedNotebook == null )
105
+ if ( LastSelectedNotebook == null )
93
106
{
94
107
var notebook = OneNoteProvider . NotebookItems . FirstOrDefault ( nb => nb . Name == notebookName ) ;
95
108
if ( notebook == null )
96
109
return false ;
97
- oneNotePlugin . lastSelectedNotebook = notebook ;
110
+ LastSelectedNotebook = notebook ;
98
111
return true ;
99
112
}
100
113
return true ;
101
114
}
102
115
103
116
private bool ValidateSection ( string sectionName )
104
117
{
105
- if ( oneNotePlugin . lastSelectedSection == null ) //Check if section is valid
118
+ if ( LastSelectedSection == null ) //Check if section is valid
106
119
{
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 )
109
122
return false ;
110
- oneNotePlugin . lastSelectedSection = section ;
123
+ LastSelectedSection = section ;
111
124
return true ;
112
125
}
113
126
return true ;
0 commit comments