Skip to content

Commit 77bd875

Browse files
committed
Smol refactor
1 parent 0ddf65a commit 77bd875

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

Main.cs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class OneNote : IPlugin, IContextMenu
1414
private readonly string syncIconPath = "Images/refresh.png";
1515
private readonly string recentIconPath = "Images/recent.png";
1616

17-
private readonly string structureKeyword = "nb\\";
17+
private readonly string structureKeyword = "nb:\\";
1818
private readonly string recentKeyword = "rcntpgs:";
1919
private readonly int recentPagesCount = 5;
2020

@@ -107,7 +107,7 @@ public List<Result> Query(Query query)
107107
}
108108

109109
return OneNoteProvider.PageItems.OrderByDescending(pg => pg.LastModified)
110-
.Select(pg => GetResultFromPage(pg, null))
110+
.Select(pg => CreatePageResult(pg, null))
111111
.Take(count)
112112
.ToList();
113113
}
@@ -129,7 +129,7 @@ public List<Result> Query(Query query)
129129
if (string.IsNullOrWhiteSpace(searchString)) // Do a normall notebook search
130130
{
131131
lastSelectedNotebook = null;
132-
return OneNoteProvider.NotebookItems.Select(nb => GetResultFromNotebook(nb)).ToList();
132+
return OneNoteProvider.NotebookItems.Select(nb => CreateNotebookResult(nb)).ToList();
133133
}
134134

135135
return OneNoteProvider.NotebookItems.Where(nb =>
@@ -138,7 +138,7 @@ public List<Result> Query(Query query)
138138
return true;
139139
return TreeQuery(nb.Name, searchString, out highlightData);
140140
})
141-
.Select(nb => GetResultFromNotebook(nb, highlightData))
141+
.Select(nb => CreateNotebookResult(nb, highlightData))
142142
.ToList();
143143

144144
case 3://Full query for section not complete e.g nb\User Notebook\Happine
@@ -150,15 +150,15 @@ public List<Result> Query(Query query)
150150
if (string.IsNullOrWhiteSpace(searchString))
151151
{
152152
lastSelectedSection = null;
153-
return lastSelectedNotebook.Sections.Select(s => GetResultsFromSection(s, lastSelectedNotebook)).ToList();
153+
return lastSelectedNotebook.Sections.Select(s => CreateSectionResult(s, lastSelectedNotebook)).ToList();
154154
}
155155
return lastSelectedNotebook.Sections.Where(s =>
156156
{
157157
if (lastSelectedSection != null && s.ID == lastSelectedSection.ID)
158158
return true;
159159
return TreeQuery(s.Name, searchString, out highlightData);
160160
})
161-
.Select(s => GetResultsFromSection(s, lastSelectedNotebook, highlightData))
161+
.Select(s => CreateSectionResult(s, lastSelectedNotebook, highlightData))
162162
.ToList();
163163

164164
case 4://Searching pages in a section
@@ -171,10 +171,10 @@ public List<Result> Query(Query query)
171171
return new List<Result>();
172172

173173
if (string.IsNullOrWhiteSpace(searchString))
174-
return lastSelectedSection.Pages.Select(pg => GetResultFromPage(pg, lastSelectedSection, lastSelectedNotebook)).ToList();
174+
return lastSelectedSection.Pages.Select(pg => CreatePageResult(pg, lastSelectedSection, lastSelectedNotebook)).ToList();
175175

176176
return lastSelectedSection.Pages.Where(pg => TreeQuery(pg.Name, searchString, out highlightData))
177-
.Select(pg => GetResultFromPage(pg, lastSelectedSection, lastSelectedNotebook, highlightData))
177+
.Select(pg => CreatePageResult(pg, lastSelectedSection, lastSelectedNotebook, highlightData))
178178
.ToList();
179179

180180
default:
@@ -184,7 +184,7 @@ public List<Result> Query(Query query)
184184

185185
//Default search
186186
return OneNoteProvider.FindPages(query.Search)
187-
.Select(page => GetResultFromPage(page, context.API.FuzzySearch(query.Search, page.Name).MatchData))
187+
.Select(page => CreatePageResult(page, context.API.FuzzySearch(query.Search, page.Name).MatchData))
188188
.ToList();
189189

190190
bool TreeQuery(string itemName, string searchString, out List<int> highlightData)
@@ -230,15 +230,29 @@ public List<Result> LoadContextMenus(Result selectedResult)
230230
section.Sync();
231231
return true;
232232
}
233-
}};
233+
},
234+
new Result
235+
{
236+
Title = "One and sync notebook",
237+
SubTitle = lastSelectedNotebook.Name,
238+
IcoPath = notebookInfo.GetIcon(lastSelectedNotebook.Color.Value),
239+
Action = c =>
240+
{
241+
lastSelectedNotebook.Sections.First().Pages
242+
.OrderByDescending(pg => pg.LastModified)
243+
.First()
244+
.OpenInOneNote();
245+
lastSelectedNotebook.Sync();
246+
return true;
247+
}
248+
}
249+
};
234250

235251
default:
236252
return new List<Result>();
237253
}
238254
}
239255

240-
241-
242256
private bool ValidateNotebook(string notebookName)
243257
{
244258
if (lastSelectedNotebook == null)
@@ -265,12 +279,12 @@ private bool ValidateSection(string sectionName)
265279
return true;
266280
}
267281

268-
private Result GetResultFromPage(IOneNoteExtPage page, List<int> highlightingData)
282+
private Result CreatePageResult(IOneNoteExtPage page, List<int> highlightingData)
269283
{
270-
return GetResultFromPage(page, page.Section, page.Notebook, highlightingData);
284+
return CreatePageResult(page, page.Section, page.Notebook, highlightingData);
271285
}
272286

273-
private Result GetResultFromPage(IOneNotePage page, IOneNoteSection section, IOneNoteNotebook notebook, List<int> highlightingData = null)
287+
private Result CreatePageResult(IOneNotePage page, IOneNoteSection section, IOneNoteNotebook notebook, List<int> highlightingData = null)
274288
{
275289
var sectionPath = section.Path;
276290
var index = sectionPath.IndexOf(notebook.Name);
@@ -294,7 +308,7 @@ private Result GetResultFromPage(IOneNotePage page, IOneNoteSection section, IOn
294308
};
295309
}
296310

297-
private Result GetResultsFromSection(IOneNoteExtSection section, IOneNoteExtNotebook notebook, List<int> highlightData = null)
311+
private Result CreateSectionResult(IOneNoteExtSection section, IOneNoteExtNotebook notebook, List<int> highlightData = null)
298312
{
299313
var sectionPath = section.Path;
300314
var index = sectionPath.IndexOf(notebook.Name);
@@ -315,7 +329,7 @@ private Result GetResultsFromSection(IOneNoteExtSection section, IOneNoteExtNote
315329
};
316330
}
317331

318-
private Result GetResultFromNotebook(IOneNoteExtNotebook notebook, List<int> highlightData = null)
332+
private Result CreateNotebookResult(IOneNoteExtNotebook notebook, List<int> highlightData = null)
319333
{
320334
return new Result
321335
{

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ A OneNote plugin for the [Flow launcher](https://github.com/Flow-Launcher/Flow.L
88
| Keyword | Description |
99
|---------------------------------|----------------------|
1010
| `` on {onenote search query} `` | Search onenote pages |
11-
| `` on nb\ `` | Navigate notebooks, sections and pages explorer style |
12-
| `` on rcntpgs: `` | View recently modified pages |
11+
| `` on nb:\ `` | Navigate notebooks, sections and pages explorer style |
12+
| `` on rcntpgs: `` | View recently modified pages |
1313

1414
Acknowledgements
1515
======

0 commit comments

Comments
 (0)