Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Odotocodot committed Jan 15, 2023
2 parents efdd78b + 9135d48 commit 8079c14
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public static class Constants
public const string SyncIconPath = "Images/refresh.png";
public const string RecentIconPath = "Images/recent.png";
public const string RecentPageIconPath = "Images/recent_page.png";

public const string WarningLogoPath = "Images/warning.png";

public const string StructureKeyword = "nb:\\";
public const string RecentKeyword = "rcntpgs:";
}
Expand Down
Binary file added Images/warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 47 additions & 25 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public List<Result> Query(Query query)
int count = recentPagesCount;
if (query.FirstSearch.Length > Constants.RecentKeyword.Length && int.TryParse(query.FirstSearch[Constants.RecentKeyword.Length..], out int userChosenCount))
count = userChosenCount;

return OneNoteProvider.PageItems.OrderByDescending(pg => pg.LastModified)
.Take(count)
.Select(pg =>
Expand All @@ -112,11 +112,33 @@ public List<Result> Query(Query query)
if (query.FirstSearch.StartsWith(Constants.StructureKeyword))
return notebookExplorer.Explore(query);

//Check for invalid start of query i.e. symbols
if (!char.IsLetterOrDigit(query.Search[0]))
return new List<Result>()
{
new Result
{
Title = "Invalid query",
SubTitle = "The first character of the search must be a letter or a digit",
IcoPath = Constants.WarningLogoPath,
}
};
//Default search
return OneNoteProvider.FindPages(query.Search)
.Select(pg => rc.CreatePageResult(pg,context.API.FuzzySearch(query.Search, pg.Name).MatchData))
.ToList();
var searches = OneNoteProvider.FindPages(query.Search)
.Select(pg => rc.CreatePageResult(pg, context.API.FuzzySearch(query.Search, pg.Name).MatchData));

if (searches.Any())
return searches.ToList();

return new List<Result>
{
new Result
{
Title = "No matches found",
SubTitle = "Try searching something else, or syncing your notebooks.",
IcoPath = Constants.LogoIconPath,
}
};
}

public List<Result> LoadContextMenus(Result selectedResult)
Expand All @@ -138,35 +160,35 @@ public List<Result> LoadContextMenus(Result selectedResult)
lastSelectedNotebook = null;
return true;
};
return new List<Result>{result};
return new List<Result> { result };
case IOneNoteExtSection section:
Result sResult = rc.CreateSectionResult(section, lastSelectedNotebook);
sResult.Title = "Open and sync section";
sResult.SubTitle = section.Name;
sResult.ContextData = null;
sResult.Action = c =>
sResult.Action = c =>
{
section.Pages.OrderByDescending(pg => pg.LastModified)
.First()
.OpenInOneNote();
section.Sync();
lastSelectedNotebook = null;
lastSelectedSection = null;
return true;
section.Pages.OrderByDescending(pg => pg.LastModified)
.First()
.OpenInOneNote();
section.Sync();
lastSelectedNotebook = null;
lastSelectedSection = null;
return true;
};
Result nbResult = rc.CreateNotebookResult(lastSelectedNotebook);
nbResult.Title = "Open and sync notebook";
nbResult.SubTitle = lastSelectedNotebook.Name;
nbResult.Action = c =>
{
lastSelectedNotebook.Sections.First().Pages
.OrderByDescending(pg => pg.LastModified)
.First()
.OpenInOneNote();
lastSelectedNotebook.Sync();
lastSelectedNotebook = null;
lastSelectedSection = null;
return true;
lastSelectedNotebook.Sections.First().Pages
.OrderByDescending(pg => pg.LastModified)
.First()
.OpenInOneNote();
lastSelectedNotebook.Sync();
lastSelectedNotebook = null;
lastSelectedSection = null;
return true;
};
return new List<Result> { sResult, nbResult, };
default:
Expand All @@ -177,17 +199,17 @@ public List<Result> LoadContextMenus(Result selectedResult)
private static string GetLastEdited(TimeSpan diff)
{
string lastEdited = "Last editied ";
if (PluralCheck(diff.TotalDays, "day", ref lastEdited)
|| PluralCheck(diff.TotalHours, "hour", ref lastEdited)
|| PluralCheck(diff.TotalMinutes, "min", ref lastEdited)
if (PluralCheck(diff.TotalDays, "day", ref lastEdited)
|| PluralCheck(diff.TotalHours, "hour", ref lastEdited)
|| PluralCheck(diff.TotalMinutes, "min", ref lastEdited)
|| PluralCheck(diff.TotalSeconds, "sec", ref lastEdited))
return lastEdited;
else
return lastEdited += "Now.";
bool PluralCheck(double totalTime, string timeType, ref string lastEdited)
{
var roundedTime = (int)Math.Round(totalTime);
if(roundedTime > 0)
if (roundedTime > 0)
{
string plural = roundedTime == 1 ? "" : "s";
lastEdited += $"{roundedTime} {timeType}{plural} ago.";
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Name": "OneNote",
"Description": "Search OneNote notes",
"Author": "Odotocodot",
"Version": "1.0.0",
"Version": "1.0.1",
"Language": "csharp",
"Website": "https://github.com/Odotocodot/Flow.Launcher.Plugin.OneNote",
"IcoPath": "Images/logo.png",
Expand Down

0 comments on commit 8079c14

Please sign in to comment.