@@ -3,6 +3,7 @@ import { ICommandPalette } from "@jupyterlab/apputils";
3
3
import { ISettingRegistry , URLExt , PathExt } from "@jupyterlab/coreutils" ;
4
4
import { IDocumentManager } from "@jupyterlab/docmanager" ;
5
5
import { ServerConnection } from "@jupyterlab/services" ;
6
+ import { FileBrowser , IFileBrowserFactory } from '@jupyterlab/filebrowser' ;
6
7
import { CommandRegistry } from "@phosphor/commands" ;
7
8
import { ReadonlyJSONObject } from "@phosphor/coreutils" ;
8
9
import { Message } from "@phosphor/messaging" ;
@@ -17,15 +18,15 @@ interface QuickOpenResponse {
17
18
}
18
19
19
20
/** Makes a HTTP request for the server-side quick open scan */
20
- async function fetchContents ( excludes : string [ ] ) : Promise < QuickOpenResponse > {
21
+ async function fetchContents ( path : string , excludes : string [ ] ) : Promise < QuickOpenResponse > {
21
22
const query = excludes
22
23
. map ( exclude => {
23
24
return "excludes=" + encodeURIComponent ( exclude ) ;
24
25
} )
25
26
. join ( "&" ) ;
26
27
27
28
const settings = ServerConnection . makeSettings ( ) ;
28
- const fullUrl = URLExt . join ( settings . baseUrl , "/api/quickopen" ) + "?" + query ;
29
+ const fullUrl = URLExt . join ( settings . baseUrl , "/api/quickopen" ) + "?" + query + "&path=" + path ;
29
30
const response = await ServerConnection . makeRequest ( fullUrl , { method : "GET" } , settings ) ;
30
31
if ( response . status !== 200 ) {
31
32
throw new ServerConnection . ResponseError ( response ) ;
@@ -40,13 +41,16 @@ async function fetchContents(excludes: string[]): Promise<QuickOpenResponse> {
40
41
class QuickOpenWidget extends CommandPalette {
41
42
private _pathSelected = new Signal < this, string > ( this ) ;
42
43
private _settings : ReadonlyJSONObject ;
44
+ private _fileBrowser : FileBrowser ;
43
45
44
- constructor ( options : CommandPalette . IOptions ) {
46
+ constructor ( factory : IFileBrowserFactory , options : CommandPalette . IOptions ) {
45
47
super ( options ) ;
46
48
47
49
this . id = "jupyterlab-quickopen" ;
48
50
this . title . iconClass = "jp-SideBar-tabIcon jp-SearchIcon" ;
49
51
this . title . caption = "Quick Open" ;
52
+
53
+ this . _fileBrowser = factory . defaultBrowser ;
50
54
}
51
55
52
56
/** Signal when a selected path is activated. */
@@ -66,7 +70,8 @@ class QuickOpenWidget extends CommandPalette {
66
70
super . onActivateRequest ( msg ) ;
67
71
68
72
// Fetch the current contents from the server
69
- let response = await fetchContents ( < string [ ] > this . _settings . excludes ) ;
73
+ let path = this . _settings . relativeSearch ? this . _fileBrowser . model . path : "" ;
74
+ let response = await fetchContents ( path , < string [ ] > this . _settings . excludes ) ;
70
75
71
76
// Remove all paths from the view
72
77
this . clearItems ( ) ;
@@ -99,19 +104,20 @@ class QuickOpenWidget extends CommandPalette {
99
104
const extension : JupyterFrontEndPlugin < void > = {
100
105
id : "@parente/jupyterlab-quickopen:plugin" ,
101
106
autoStart : true ,
102
- requires : [ ICommandPalette , IDocumentManager , ILabShell , ISettingRegistry ] ,
107
+ requires : [ ICommandPalette , IDocumentManager , ILabShell , ISettingRegistry , IFileBrowserFactory ] ,
103
108
activate : async (
104
109
app : JupyterFrontEnd ,
105
110
palette : ICommandPalette ,
106
111
docManager : IDocumentManager ,
107
112
labShell : ILabShell ,
108
- settingRegistry : ISettingRegistry
113
+ settingRegistry : ISettingRegistry ,
114
+ fileBrowserFactory : IFileBrowserFactory
109
115
) => {
110
116
window [ "docManager" ] = docManager ;
111
117
112
118
console . log ( `Activated extension: ${ extension . id } ` ) ;
113
119
const commands : CommandRegistry = new CommandRegistry ( ) ;
114
- const widget : QuickOpenWidget = new QuickOpenWidget ( { commands } ) ;
120
+ const widget : QuickOpenWidget = new QuickOpenWidget ( fileBrowserFactory , { commands } ) ;
115
121
const settings : ISettingRegistry . ISettings = await settingRegistry . load ( extension . id ) ;
116
122
117
123
// Listen for path selection signals and show the selected files in the
0 commit comments