Skip to content

Commit b7822d3

Browse files
committed
Small refactor
1 parent ef9f4b7 commit b7822d3

File tree

4 files changed

+41
-33
lines changed

4 files changed

+41
-33
lines changed

Constants.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
namespace Flow.Launcher.Plugin.OneNote
22
{
3-
public static class Constants
3+
public static class Icons
44
{
5-
public const string LogoIconPath = "Images/logo.png";
6-
public const string UnavailableIconPath = "Images/unavailable.png";
7-
public const string SyncIconPath = "Images/refresh.png";
8-
public const string RecentIconPath = "Images/recent.png";
9-
public const string RecentPageIconPath = "Images/recent_page.png";
10-
public const string WarningLogoPath = "Images/warning.png";
11-
12-
public const string StructureKeyword = "nb:\\";
13-
public const string RecentKeyword = "rcntpgs:";
5+
6+
public const string Logo = "Images/logo.png";
7+
public const string Unavailable = "Images/unavailable.png";
8+
public const string Sync = "Images/refresh.png";
9+
public const string Recent = "Images/recent.png";
10+
public const string RecentPage = "Images/recent_page.png";
11+
public const string Warning = "Images/warning.png";
12+
13+
public const string Section = "Images/section.png";
14+
public const string Notebook = "Images/section.png";
15+
}
16+
public static class Keywords
17+
{
18+
public const string NotebookExplorer = "nb:\\";
19+
public const string RecentPages = "rcntpgs:";
1420
}
1521
}

Main.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public List<Result> Query(Query query)
4242
new Result
4343
{
4444
Title = "OneNote is not installed.",
45-
IcoPath = Constants.UnavailableIconPath
45+
IcoPath = Icons.Unavailable
4646
}
4747
};
4848
}
@@ -52,33 +52,33 @@ public List<Result> Query(Query query)
5252
results.Add(new Result
5353
{
5454
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,
55+
SubTitle = $"Type \"{Keywords.NotebookExplorer}\" to search by notebook structure or select this option",
56+
AutoCompleteText = $"{query.ActionKeyword} {Keywords.NotebookExplorer}",
57+
IcoPath = Icons.Logo,
5858
Score = 2000,
5959
Action = c =>
6060
{
61-
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeyword} {Constants.StructureKeyword}");
61+
context.API.ChangeQuery($"{query.ActionKeyword} {Keywords.NotebookExplorer}");
6262
return false;
6363
},
6464
});
6565
results.Add(new Result
6666
{
6767
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,
68+
SubTitle = $"Type \"{Keywords.RecentPages}\" to see last modified pages or select this option",
69+
AutoCompleteText = $"{query.ActionKeyword} {Keywords.RecentPages}",
70+
IcoPath = Icons.Recent,
7171
Score = -1000,
7272
Action = c =>
7373
{
74-
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeyword} {Constants.RecentKeyword}");
74+
context.API.ChangeQuery($"{query.ActionKeyword} {Keywords.RecentPages}");
7575
return false;
7676
},
7777
});
7878
results.Add(new Result
7979
{
8080
Title = "Open and sync notebooks",
81-
IcoPath = Constants.SyncIconPath,
81+
IcoPath = Icons.Sync,
8282
Score = int.MinValue,
8383
Action = c =>
8484
{
@@ -88,12 +88,14 @@ public List<Result> Query(Query query)
8888
return false;
8989
}
9090
});
91+
92+
9193
return results;
9294
}
93-
if (query.FirstSearch.StartsWith(Constants.RecentKeyword))
95+
if (query.FirstSearch.StartsWith(Keywords.RecentPages))
9496
{
9597
int count = recentPagesCount;
96-
if (query.FirstSearch.Length > Constants.RecentKeyword.Length && int.TryParse(query.FirstSearch[Constants.RecentKeyword.Length..], out int userChosenCount))
98+
if (query.FirstSearch.Length > Keywords.RecentPages.Length && int.TryParse(query.FirstSearch[Keywords.RecentPages.Length..], out int userChosenCount))
9799
count = userChosenCount;
98100

99101
return OneNoteProvider.PageItems.OrderByDescending(pg => pg.LastModified)
@@ -102,15 +104,15 @@ public List<Result> Query(Query query)
102104
{
103105
Result result = rc.CreatePageResult(pg);
104106
result.SubTitle = $"{GetLastEdited(DateTime.Now - pg.LastModified)}\t{result.SubTitle}";
105-
result.IcoPath = Constants.RecentPageIconPath;
107+
result.IcoPath = Icons.RecentPage;
106108
return result;
107109
})
108110
.ToList();
109111
}
110112

111113
//Search via notebook structure
112114
//NOTE: There is no nested sections i.e. there is nothing for the Section Group in the structure
113-
if (query.FirstSearch.StartsWith(Constants.StructureKeyword))
115+
if (query.FirstSearch.StartsWith(Keywords.NotebookExplorer))
114116
return notebookExplorer.Explore(query);
115117

116118
//Check for invalid start of query i.e. symbols
@@ -121,7 +123,7 @@ public List<Result> Query(Query query)
121123
{
122124
Title = "Invalid query",
123125
SubTitle = "The first character of the search must be a letter or a digit",
124-
IcoPath = Constants.WarningLogoPath,
126+
IcoPath = Icons.Warning,
125127
}
126128
};
127129
//Default search
@@ -137,7 +139,7 @@ public List<Result> Query(Query query)
137139
{
138140
Title = "No matches found",
139141
SubTitle = "Try searching something else, or syncing your notebooks.",
140-
IcoPath = Constants.LogoIconPath,
142+
IcoPath = Icons.Logo,
141143
}
142144
};
143145
}

OneNoteItemInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public class OneNoteItemInfo
1616
public OneNoteItemInfo(string folderName, string iconName, PluginInitContext context)
1717
{
1818
icons = new Dictionary<Color, string>();
19-
iconDirectory = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, "Images/" + folderName);
20-
baseIconPath = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, "Images/" + iconName);
19+
iconDirectory = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, folderName);
20+
baseIconPath = Path.Combine(context.CurrentPluginMetadata.PluginDirectory, iconName);
2121
Directory.CreateDirectory(iconDirectory);
2222
foreach (var imagePath in Directory.GetFiles(iconDirectory))
2323
{

ResultCreator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public ResultCreator(PluginInitContext context, OneNotePlugin oneNotePlugin)
2020
{
2121
this.context = context;
2222
this.oneNotePlugin = oneNotePlugin;
23-
notebookInfo = new OneNoteItemInfo("NotebookIcons", "notebook.png", context);
24-
sectionInfo = new OneNoteItemInfo("SectionIcons", "section.png", context);
23+
notebookInfo = new OneNoteItemInfo("Images/NotebookIcons", Icons.Notebook, context);
24+
sectionInfo = new OneNoteItemInfo("Images/SectionIcons", Icons.Section, context);
2525
}
2626

2727
private string GetNicePath(IOneNoteSection section, IOneNoteNotebook notebook, bool isPage)
@@ -52,7 +52,7 @@ public Result CreatePageResult(IOneNotePage page, IOneNoteSection section, IOneN
5252
SubTitle = path,
5353
TitleToolTip = $"Created: {page.DateTime}\nLast Modified: {page.LastModified}",
5454
SubTitleToolTip = path,
55-
IcoPath = Constants.LogoIconPath,
55+
IcoPath = Icons.Logo,
5656
ContextData = page,
5757
TitleHighlightData = highlightingData,
5858
Action = c =>
@@ -78,7 +78,7 @@ public Result CreateSectionResult(IOneNoteExtSection section, IOneNoteExtNoteboo
7878
Action = c =>
7979
{
8080
LastSelectedSection = section;
81-
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeyword} {Constants.StructureKeyword}{LastSelectedNotebook.Name}\\{section.Name}\\");
81+
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeyword} {Keywords.NotebookExplorer}{LastSelectedNotebook.Name}\\{section.Name}\\");
8282
return false;
8383
},
8484
};
@@ -95,7 +95,7 @@ public Result CreateNotebookResult(IOneNoteExtNotebook notebook, List<int> highl
9595
Action = c =>
9696
{
9797
LastSelectedNotebook = notebook;
98-
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeyword} {Constants.StructureKeyword}{notebook.Name}\\");
98+
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeyword} {Keywords.NotebookExplorer}{notebook.Name}\\");
9999
return false;
100100
},
101101
};

0 commit comments

Comments
 (0)