Skip to content

Commit 8079c14

Browse files
committed
Merge branch 'dev'
2 parents efdd78b + 9135d48 commit 8079c14

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

Constants.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ public static class Constants
77
public const string SyncIconPath = "Images/refresh.png";
88
public const string RecentIconPath = "Images/recent.png";
99
public const string RecentPageIconPath = "Images/recent_page.png";
10-
10+
public const string WarningLogoPath = "Images/warning.png";
11+
1112
public const string StructureKeyword = "nb:\\";
1213
public const string RecentKeyword = "rcntpgs:";
1314
}

Images/warning.png

1.95 KB
Loading

Main.cs

Lines changed: 47 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 =>
@@ -112,11 +112,33 @@ public List<Result> Query(Query query)
112112
if (query.FirstSearch.StartsWith(Constants.StructureKeyword))
113113
return notebookExplorer.Explore(query);
114114

115+
//Check for invalid start of query i.e. symbols
116+
if (!char.IsLetterOrDigit(query.Search[0]))
117+
return new List<Result>()
118+
{
119+
new Result
120+
{
121+
Title = "Invalid query",
122+
SubTitle = "The first character of the search must be a letter or a digit",
123+
IcoPath = Constants.WarningLogoPath,
124+
}
125+
};
115126
//Default search
116-
return OneNoteProvider.FindPages(query.Search)
117-
.Select(pg => rc.CreatePageResult(pg,context.API.FuzzySearch(query.Search, pg.Name).MatchData))
118-
.ToList();
127+
var searches = OneNoteProvider.FindPages(query.Search)
128+
.Select(pg => rc.CreatePageResult(pg, context.API.FuzzySearch(query.Search, pg.Name).MatchData));
119129

130+
if (searches.Any())
131+
return searches.ToList();
132+
133+
return new List<Result>
134+
{
135+
new Result
136+
{
137+
Title = "No matches found",
138+
SubTitle = "Try searching something else, or syncing your notebooks.",
139+
IcoPath = Constants.LogoIconPath,
140+
}
141+
};
120142
}
121143

122144
public List<Result> LoadContextMenus(Result selectedResult)
@@ -138,35 +160,35 @@ public List<Result> LoadContextMenus(Result selectedResult)
138160
lastSelectedNotebook = null;
139161
return true;
140162
};
141-
return new List<Result>{result};
163+
return new List<Result> { result };
142164
case IOneNoteExtSection section:
143165
Result sResult = rc.CreateSectionResult(section, lastSelectedNotebook);
144166
sResult.Title = "Open and sync section";
145167
sResult.SubTitle = section.Name;
146168
sResult.ContextData = null;
147-
sResult.Action = c =>
169+
sResult.Action = c =>
148170
{
149-
section.Pages.OrderByDescending(pg => pg.LastModified)
150-
.First()
151-
.OpenInOneNote();
152-
section.Sync();
153-
lastSelectedNotebook = null;
154-
lastSelectedSection = null;
155-
return true;
171+
section.Pages.OrderByDescending(pg => pg.LastModified)
172+
.First()
173+
.OpenInOneNote();
174+
section.Sync();
175+
lastSelectedNotebook = null;
176+
lastSelectedSection = null;
177+
return true;
156178
};
157179
Result nbResult = rc.CreateNotebookResult(lastSelectedNotebook);
158180
nbResult.Title = "Open and sync notebook";
159181
nbResult.SubTitle = lastSelectedNotebook.Name;
160182
nbResult.Action = c =>
161183
{
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;
184+
lastSelectedNotebook.Sections.First().Pages
185+
.OrderByDescending(pg => pg.LastModified)
186+
.First()
187+
.OpenInOneNote();
188+
lastSelectedNotebook.Sync();
189+
lastSelectedNotebook = null;
190+
lastSelectedSection = null;
191+
return true;
170192
};
171193
return new List<Result> { sResult, nbResult, };
172194
default:
@@ -177,17 +199,17 @@ public List<Result> LoadContextMenus(Result selectedResult)
177199
private static string GetLastEdited(TimeSpan diff)
178200
{
179201
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)
202+
if (PluralCheck(diff.TotalDays, "day", ref lastEdited)
203+
|| PluralCheck(diff.TotalHours, "hour", ref lastEdited)
204+
|| PluralCheck(diff.TotalMinutes, "min", ref lastEdited)
183205
|| PluralCheck(diff.TotalSeconds, "sec", ref lastEdited))
184206
return lastEdited;
185207
else
186208
return lastEdited += "Now.";
187209
bool PluralCheck(double totalTime, string timeType, ref string lastEdited)
188210
{
189211
var roundedTime = (int)Math.Round(totalTime);
190-
if(roundedTime > 0)
212+
if (roundedTime > 0)
191213
{
192214
string plural = roundedTime == 1 ? "" : "s";
193215
lastEdited += $"{roundedTime} {timeType}{plural} ago.";

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "OneNote",
55
"Description": "Search OneNote notes",
66
"Author": "Odotocodot",
7-
"Version": "1.0.0",
7+
"Version": "1.0.1",
88
"Language": "csharp",
99
"Website": "https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote",
1010
"IcoPath": "Images/logo.png",

0 commit comments

Comments
 (0)