Skip to content

Commit cb71e43

Browse files
committed
Added no match result
Also fixed some formatting
1 parent 0816114 commit cb71e43

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

Main.cs

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public List<Result> Query(Query query)
9494
int count = recentPagesCount;
9595
if (query.FirstSearch.Length > Constants.RecentKeyword.Length && int.TryParse(query.FirstSearch[Constants.RecentKeyword.Length..], out int userChosenCount))
9696
count = userChosenCount;
97-
97+
9898
return OneNoteProvider.PageItems.OrderByDescending(pg => pg.LastModified)
9999
.Take(count)
100100
.Select(pg =>
@@ -113,10 +113,21 @@ public List<Result> Query(Query query)
113113
return notebookExplorer.Explore(query);
114114

115115
//Default search
116-
return OneNoteProvider.FindPages(query.Search)
117-
.Select(pg => rc.CreatePageResult(pg,context.API.FuzzySearch(query.Search, pg.Name).MatchData))
118-
.ToList();
116+
var searches = OneNoteProvider.FindPages(query.Search)
117+
.Select(pg => rc.CreatePageResult(pg, context.API.FuzzySearch(query.Search, pg.Name).MatchData));
119118

119+
if (searches.Any())
120+
return searches.ToList();
121+
122+
return new List<Result>
123+
{
124+
new Result
125+
{
126+
Title = "No matches found",
127+
SubTitle = "Try searching something else, or syncing your notebooks.",
128+
IcoPath = Constants.LogoIconPath,
129+
}
130+
};
120131
}
121132

122133
public List<Result> LoadContextMenus(Result selectedResult)
@@ -138,35 +149,35 @@ public List<Result> LoadContextMenus(Result selectedResult)
138149
lastSelectedNotebook = null;
139150
return true;
140151
};
141-
return new List<Result>{result};
152+
return new List<Result> { result };
142153
case IOneNoteExtSection section:
143154
Result sResult = rc.CreateSectionResult(section, lastSelectedNotebook);
144155
sResult.Title = "Open and sync section";
145156
sResult.SubTitle = section.Name;
146157
sResult.ContextData = null;
147-
sResult.Action = c =>
158+
sResult.Action = c =>
148159
{
149-
section.Pages.OrderByDescending(pg => pg.LastModified)
150-
.First()
151-
.OpenInOneNote();
152-
section.Sync();
153-
lastSelectedNotebook = null;
154-
lastSelectedSection = null;
155-
return true;
160+
section.Pages.OrderByDescending(pg => pg.LastModified)
161+
.First()
162+
.OpenInOneNote();
163+
section.Sync();
164+
lastSelectedNotebook = null;
165+
lastSelectedSection = null;
166+
return true;
156167
};
157168
Result nbResult = rc.CreateNotebookResult(lastSelectedNotebook);
158169
nbResult.Title = "Open and sync notebook";
159170
nbResult.SubTitle = lastSelectedNotebook.Name;
160171
nbResult.Action = c =>
161172
{
162-
lastSelectedNotebook.Sections.First().Pages
163-
.OrderByDescending(pg => pg.LastModified)
164-
.First()
165-
.OpenInOneNote();
166-
lastSelectedNotebook.Sync();
167-
lastSelectedNotebook = null;
168-
lastSelectedSection = null;
169-
return true;
173+
lastSelectedNotebook.Sections.First().Pages
174+
.OrderByDescending(pg => pg.LastModified)
175+
.First()
176+
.OpenInOneNote();
177+
lastSelectedNotebook.Sync();
178+
lastSelectedNotebook = null;
179+
lastSelectedSection = null;
180+
return true;
170181
};
171182
return new List<Result> { sResult, nbResult, };
172183
default:
@@ -177,17 +188,17 @@ public List<Result> LoadContextMenus(Result selectedResult)
177188
private static string GetLastEdited(TimeSpan diff)
178189
{
179190
string lastEdited = "Last editied ";
180-
if (PluralCheck(diff.TotalDays, "day", ref lastEdited)
181-
|| PluralCheck(diff.TotalHours, "hour", ref lastEdited)
182-
|| PluralCheck(diff.TotalMinutes, "min", ref lastEdited)
191+
if (PluralCheck(diff.TotalDays, "day", ref lastEdited)
192+
|| PluralCheck(diff.TotalHours, "hour", ref lastEdited)
193+
|| PluralCheck(diff.TotalMinutes, "min", ref lastEdited)
183194
|| PluralCheck(diff.TotalSeconds, "sec", ref lastEdited))
184195
return lastEdited;
185196
else
186197
return lastEdited += "Now.";
187198
bool PluralCheck(double totalTime, string timeType, ref string lastEdited)
188199
{
189200
var roundedTime = (int)Math.Round(totalTime);
190-
if(roundedTime > 0)
201+
if (roundedTime > 0)
191202
{
192203
string plural = roundedTime == 1 ? "" : "s";
193204
lastEdited += $"{roundedTime} {timeType}{plural} ago.";

0 commit comments

Comments
 (0)