@@ -42,57 +42,68 @@ public List<Result> Query(Query query)
42
42
new Result
43
43
{
44
44
Title = "OneNote is not installed." ,
45
- IcoPath = Constants . UnavailableIconPath
45
+ IcoPath = Icons . Unavailable
46
46
}
47
47
} ;
48
48
}
49
49
if ( string . IsNullOrEmpty ( query . Search ) )
50
50
{
51
- var results = new List < Result > ( ) ;
52
- results . Add ( new Result
51
+ return new List < Result > ( )
53
52
{
54
- Title = "Search OneNote pages" ,
55
- SubTitle = $ "Type \" { Constants . StructureKeyword } \" to search by notebook structure or select this option",
56
- AutoCompleteText = $ "{ context . CurrentPluginMetadata . ActionKeyword } { Constants . StructureKeyword } ",
57
- IcoPath = Constants . LogoIconPath ,
58
- Score = 2000 ,
59
- Action = c =>
53
+ new Result
60
54
{
61
- context . API . ChangeQuery ( $ "{ context . CurrentPluginMetadata . ActionKeyword } { Constants . StructureKeyword } ") ;
62
- return false ;
55
+ Title = "Search OneNote pages" ,
56
+ SubTitle = $ "Type \" { Keywords . NotebookExplorer } \" or select this option to search by notebook structure ",
57
+ AutoCompleteText = $ "{ query . ActionKeyword } { Keywords . NotebookExplorer } ",
58
+ IcoPath = Icons . Logo ,
59
+ Score = 2000 ,
60
+ Action = c =>
61
+ {
62
+ context . API . ChangeQuery ( $ "{ query . ActionKeyword } { Keywords . NotebookExplorer } ") ;
63
+ return false ;
64
+ } ,
63
65
} ,
64
- } ) ;
65
- results . Add ( new Result
66
- {
67
- Title = "See recent pages" ,
68
- SubTitle = $ "Type \" { Constants . RecentKeyword } \" to see last modified pages or select this option",
69
- AutoCompleteText = $ "{ context . CurrentPluginMetadata . ActionKeyword } { Constants . RecentKeyword } ",
70
- IcoPath = Constants . RecentIconPath ,
71
- Score = - 1000 ,
72
- Action = c =>
66
+ new Result
73
67
{
74
- context . API . ChangeQuery ( $ "{ context . CurrentPluginMetadata . ActionKeyword } { Constants . RecentKeyword } ") ;
75
- return false ;
68
+ Title = "See recent pages" ,
69
+ SubTitle = $ "Type \" { Keywords . RecentPages } \" or select this option to see recently modified pages",
70
+ AutoCompleteText = $ "{ query . ActionKeyword } { Keywords . RecentPages } ",
71
+ IcoPath = Icons . Recent ,
72
+ Score = - 1000 ,
73
+ Action = c =>
74
+ {
75
+ context . API . ChangeQuery ( $ "{ query . ActionKeyword } { Keywords . RecentPages } ") ;
76
+ return false ;
77
+ } ,
76
78
} ,
77
- } ) ;
78
- results . Add ( new Result
79
- {
80
- Title = "Open and sync notebooks" ,
81
- IcoPath = Constants . SyncIconPath ,
82
- Score = int . MinValue ,
83
- Action = c =>
79
+ new Result
84
80
{
85
- OneNoteProvider . PageItems . First ( ) . OpenInOneNote ( ) ;
86
- OneNoteProvider . NotebookItems . Sync ( ) ;
87
- return false ;
88
- }
89
- } ) ;
90
- return results ;
81
+ Title = "New quick note" ,
82
+ IcoPath = Icons . NewPage ,
83
+ Score = - 4000 ,
84
+ Action = c =>
85
+ {
86
+ ScipBeExtensions . CreateAndOpenPage ( ) ;
87
+ return true ;
88
+ }
89
+ } ,
90
+ new Result
91
+ {
92
+ Title = "Open and sync notebooks" ,
93
+ IcoPath = Icons . Sync ,
94
+ Score = int . MinValue ,
95
+ Action = c =>
96
+ {
97
+ OneNoteProvider . NotebookItems . OpenAndSync ( OneNoteProvider . PageItems . First ( ) ) ;
98
+ return false ;
99
+ }
100
+ } ,
101
+ } ;
91
102
}
92
- if ( query . FirstSearch . StartsWith ( Constants . RecentKeyword ) )
103
+ if ( query . FirstSearch . StartsWith ( Keywords . RecentPages ) )
93
104
{
94
105
int count = recentPagesCount ;
95
- if ( query . FirstSearch . Length > Constants . RecentKeyword . Length && int . TryParse ( query . FirstSearch [ Constants . RecentKeyword . Length ..] , out int userChosenCount ) )
106
+ if ( query . FirstSearch . Length > Keywords . RecentPages . Length && int . TryParse ( query . FirstSearch [ Keywords . RecentPages . Length ..] , out int userChosenCount ) )
96
107
count = userChosenCount ;
97
108
98
109
return OneNoteProvider . PageItems . OrderByDescending ( pg => pg . LastModified )
@@ -101,15 +112,15 @@ public List<Result> Query(Query query)
101
112
{
102
113
Result result = rc . CreatePageResult ( pg ) ;
103
114
result . SubTitle = $ "{ GetLastEdited ( DateTime . Now - pg . LastModified ) } \t { result . SubTitle } ";
104
- result . IcoPath = Constants . RecentPageIconPath ;
115
+ result . IcoPath = Icons . RecentPage ;
105
116
return result ;
106
117
} )
107
118
. ToList ( ) ;
108
119
}
109
120
110
121
//Search via notebook structure
111
122
//NOTE: There is no nested sections i.e. there is nothing for the Section Group in the structure
112
- if ( query . FirstSearch . StartsWith ( Constants . StructureKeyword ) )
123
+ if ( query . FirstSearch . StartsWith ( Keywords . NotebookExplorer ) )
113
124
return notebookExplorer . Explore ( query ) ;
114
125
115
126
//Check for invalid start of query i.e. symbols
@@ -120,7 +131,7 @@ public List<Result> Query(Query query)
120
131
{
121
132
Title = "Invalid query" ,
122
133
SubTitle = "The first character of the search must be a letter or a digit" ,
123
- IcoPath = Constants . WarningLogoPath ,
134
+ IcoPath = Icons . Warning ,
124
135
}
125
136
} ;
126
137
//Default search
@@ -136,13 +147,14 @@ public List<Result> Query(Query query)
136
147
{
137
148
Title = "No matches found" ,
138
149
SubTitle = "Try searching something else, or syncing your notebooks." ,
139
- IcoPath = Constants . LogoIconPath ,
150
+ IcoPath = Icons . Logo ,
140
151
}
141
152
} ;
142
153
}
143
154
144
155
public List < Result > LoadContextMenus ( Result selectedResult )
145
156
{
157
+ List < Result > results = new List < Result > ( ) ;
146
158
switch ( selectedResult . ContextData )
147
159
{
148
160
case IOneNoteExtNotebook notebook :
@@ -152,26 +164,20 @@ public List<Result> LoadContextMenus(Result selectedResult)
152
164
result . ContextData = null ;
153
165
result . Action = c =>
154
166
{
155
- notebook . Sections . First ( ) . Pages
156
- . OrderByDescending ( pg => pg . LastModified )
157
- . First ( )
158
- . OpenInOneNote ( ) ;
159
- notebook . Sync ( ) ;
167
+ notebook . OpenAndSync ( ) ;
160
168
lastSelectedNotebook = null ;
161
169
return true ;
162
170
} ;
163
- return new List < Result > { result } ;
171
+ results . Add ( result ) ;
172
+ break ;
164
173
case IOneNoteExtSection section :
165
174
Result sResult = rc . CreateSectionResult ( section , lastSelectedNotebook ) ;
166
175
sResult . Title = "Open and sync section" ;
167
176
sResult . SubTitle = section . Name ;
168
177
sResult . ContextData = null ;
169
178
sResult . Action = c =>
170
179
{
171
- section . Pages . OrderByDescending ( pg => pg . LastModified )
172
- . First ( )
173
- . OpenInOneNote ( ) ;
174
- section . Sync ( ) ;
180
+ section . OpenAndSync ( ) ;
175
181
lastSelectedNotebook = null ;
176
182
lastSelectedSection = null ;
177
183
return true ;
@@ -181,31 +187,29 @@ public List<Result> LoadContextMenus(Result selectedResult)
181
187
nbResult . SubTitle = lastSelectedNotebook . Name ;
182
188
nbResult . Action = c =>
183
189
{
184
- lastSelectedNotebook . Sections . First ( ) . Pages
185
- . OrderByDescending ( pg => pg . LastModified )
186
- . First ( )
187
- . OpenInOneNote ( ) ;
188
- lastSelectedNotebook . Sync ( ) ;
190
+ lastSelectedNotebook . OpenAndSync ( ) ;
189
191
lastSelectedNotebook = null ;
190
192
lastSelectedSection = null ;
191
193
return true ;
192
194
} ;
193
- return new List < Result > { sResult , nbResult , } ;
194
- default :
195
- return new List < Result > ( ) ;
195
+ results . Add ( sResult ) ;
196
+ results . Add ( nbResult ) ;
197
+ break ;
196
198
}
199
+ return results ;
197
200
}
198
201
199
202
private static string GetLastEdited ( TimeSpan diff )
200
203
{
201
- string lastEdited = "Last editied " ;
204
+ string lastEdited = "Last edited " ;
202
205
if ( PluralCheck ( diff . TotalDays , "day" , ref lastEdited )
203
206
|| PluralCheck ( diff . TotalHours , "hour" , ref lastEdited )
204
207
|| PluralCheck ( diff . TotalMinutes , "min" , ref lastEdited )
205
208
|| PluralCheck ( diff . TotalSeconds , "sec" , ref lastEdited ) )
206
209
return lastEdited ;
207
210
else
208
211
return lastEdited += "Now." ;
212
+
209
213
bool PluralCheck ( double totalTime , string timeType , ref string lastEdited )
210
214
{
211
215
var roundedTime = ( int ) Math . Round ( totalTime ) ;
0 commit comments