5
5
6
6
namespace Flow . Launcher . Plugin . OneNote
7
7
{
8
- public class OneNote : IPlugin , IContextMenu
8
+ public class OneNotePlugin : IPlugin , IContextMenu
9
9
{
10
- private static PluginInitContext context ;
10
+ private PluginInitContext context ;
11
11
private bool hasOneNote ;
12
12
private readonly int recentPagesCount = 5 ;
13
- private static IOneNoteExtNotebook lastSelectedNotebook ;
14
- private static IOneNoteExtSection lastSelectedSection ;
13
+ public IOneNoteExtNotebook lastSelectedNotebook ;
14
+ public IOneNoteExtSection lastSelectedSection ;
15
15
16
- public static PluginInitContext Context => context ;
17
- public static IOneNoteExtNotebook LastSelectedNotebook { get => lastSelectedNotebook ; set => lastSelectedNotebook = value ; }
18
- public static IOneNoteExtSection LastSelectedSection { get => lastSelectedSection ; set => lastSelectedSection = value ; }
16
+ private NotebookExplorer notebookExplorer ;
17
+ private ResultCreator rc ;
19
18
20
19
public void Init ( PluginInitContext context )
21
20
{
22
- OneNote . context = context ;
21
+ this . context = context ;
23
22
try
24
23
{
25
24
_ = OneNoteProvider . PageItems . Any ( ) ;
@@ -30,6 +29,8 @@ public void Init(PluginInitContext context)
30
29
hasOneNote = false ;
31
30
return ;
32
31
}
32
+ rc = new ResultCreator ( context , this ) ;
33
+ notebookExplorer = new NotebookExplorer ( context , this , rc ) ;
33
34
}
34
35
35
36
public List < Result > Query ( Query query )
@@ -52,25 +53,25 @@ public List<Result> Query(Query query)
52
53
{
53
54
Title = "Search OneNote pages" ,
54
55
SubTitle = $ "Type \" { Constants . StructureKeyword } \" to search by notebook structure or select this option",
55
- AutoCompleteText = $ "{ Context . CurrentPluginMetadata . ActionKeyword } { Constants . StructureKeyword } ",
56
+ AutoCompleteText = $ "{ context . CurrentPluginMetadata . ActionKeyword } { Constants . StructureKeyword } ",
56
57
IcoPath = Constants . LogoIconPath ,
57
58
Score = 2000 ,
58
59
Action = c =>
59
60
{
60
- Context . API . ChangeQuery ( $ "{ Context . CurrentPluginMetadata . ActionKeyword } { Constants . StructureKeyword } ") ;
61
+ context . API . ChangeQuery ( $ "{ context . CurrentPluginMetadata . ActionKeyword } { Constants . StructureKeyword } ") ;
61
62
return false ;
62
63
} ,
63
64
} ) ;
64
65
results . Add ( new Result
65
66
{
66
67
Title = "See recent pages" ,
67
68
SubTitle = $ "Type \" { Constants . RecentKeyword } \" to see last modified pages or select this option",
68
- AutoCompleteText = $ "{ Context . CurrentPluginMetadata . ActionKeyword } { Constants . RecentKeyword } ",
69
+ AutoCompleteText = $ "{ context . CurrentPluginMetadata . ActionKeyword } { Constants . RecentKeyword } ",
69
70
IcoPath = Constants . RecentIconPath ,
70
71
Score = - 1000 ,
71
72
Action = c =>
72
73
{
73
- Context . API . ChangeQuery ( $ "{ Context . CurrentPluginMetadata . ActionKeyword } { Constants . RecentKeyword } ") ;
74
+ context . API . ChangeQuery ( $ "{ context . CurrentPluginMetadata . ActionKeyword } { Constants . RecentKeyword } ") ;
74
75
return false ;
75
76
} ,
76
77
} ) ;
@@ -98,7 +99,7 @@ public List<Result> Query(Query query)
98
99
. Take ( count )
99
100
. Select ( pg =>
100
101
{
101
- Result result = pg . CreateResult ( ) ;
102
+ Result result = rc . CreatePageResult ( pg ) ;
102
103
result . SubTitle = $ "{ GetLastEdited ( DateTime . Now - pg . LastModified ) } \t { result . SubTitle } ";
103
104
result . IcoPath = Constants . RecentPageIconPath ;
104
105
return result ;
@@ -109,11 +110,11 @@ public List<Result> Query(Query query)
109
110
//Search via notebook structure
110
111
//NOTE: There is no nested sections i.e. there is nothing for the Section Group in the structure
111
112
if ( query . FirstSearch . StartsWith ( Constants . StructureKeyword ) )
112
- return NotebookExplorer . Explore ( query ) ;
113
+ return notebookExplorer . Explore ( query ) ;
113
114
114
115
//Default search
115
116
return OneNoteProvider . FindPages ( query . Search )
116
- . Select ( page => page . CreateResult ( Context . API . FuzzySearch ( query . Search , page . Name ) . MatchData ) )
117
+ . Select ( pg => rc . CreatePageResult ( pg , context . API . FuzzySearch ( query . Search , pg . Name ) . MatchData ) )
117
118
. ToList ( ) ;
118
119
119
120
}
@@ -123,7 +124,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
123
124
switch ( selectedResult . ContextData )
124
125
{
125
126
case IOneNoteExtNotebook notebook :
126
- Result result = notebook . CreateResult ( ) ;
127
+ Result result = rc . CreateNotebookResult ( notebook ) ;
127
128
result . Title = "Open and sync notebook" ;
128
129
result . SubTitle = notebook . Name ;
129
130
result . ContextData = null ;
@@ -134,12 +135,12 @@ public List<Result> LoadContextMenus(Result selectedResult)
134
135
. First ( )
135
136
. OpenInOneNote ( ) ;
136
137
notebook . Sync ( ) ;
137
- LastSelectedNotebook = null ;
138
+ lastSelectedNotebook = null ;
138
139
return true ;
139
140
} ;
140
141
return new List < Result > { result } ;
141
142
case IOneNoteExtSection section :
142
- Result sResult = section . CreateResult ( LastSelectedNotebook ) ;
143
+ Result sResult = rc . CreateSectionResult ( section , lastSelectedNotebook ) ;
143
144
sResult . Title = "Open and sync section" ;
144
145
sResult . SubTitle = section . Name ;
145
146
sResult . ContextData = null ;
@@ -149,22 +150,22 @@ public List<Result> LoadContextMenus(Result selectedResult)
149
150
. First ( )
150
151
. OpenInOneNote ( ) ;
151
152
section . Sync ( ) ;
152
- LastSelectedNotebook = null ;
153
- LastSelectedSection = null ;
153
+ lastSelectedNotebook = null ;
154
+ lastSelectedSection = null ;
154
155
return true ;
155
156
} ;
156
- Result nbResult = lastSelectedNotebook . CreateResult ( ) ;
157
+ Result nbResult = rc . CreateNotebookResult ( lastSelectedNotebook ) ;
157
158
nbResult . Title = "Open and sync notebook" ;
158
159
nbResult . SubTitle = lastSelectedNotebook . Name ;
159
160
nbResult . Action = c =>
160
161
{
161
- LastSelectedNotebook . Sections . First ( ) . Pages
162
+ lastSelectedNotebook . Sections . First ( ) . Pages
162
163
. OrderByDescending ( pg => pg . LastModified )
163
164
. First ( )
164
165
. OpenInOneNote ( ) ;
165
- LastSelectedNotebook . Sync ( ) ;
166
- LastSelectedNotebook = null ;
167
- LastSelectedSection = null ;
166
+ lastSelectedNotebook . Sync ( ) ;
167
+ lastSelectedNotebook = null ;
168
+ lastSelectedSection = null ;
168
169
return true ;
169
170
} ;
170
171
return new List < Result > { sResult , nbResult , } ;
0 commit comments