Skip to content

Commit 868bb97

Browse files
authored
Merge pull request #6 from StevenLaan/master
Added relativeSearch functionality
2 parents 031a66b + 3195013 commit 868bb97

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

jupyterlab_quickopen/handler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ def get(self):
7272
contents: File names binned by parent directory
7373
"""
7474
excludes = set(self.get_arguments('excludes'))
75+
current_path = self.get_argument('path')
7576
start_ts = time.time()
76-
contents_by_path = self.scan_disk(self.root_dir, excludes)
77+
if current_path:
78+
full_path = os.path.join(self.root_dir, current_path)
79+
else:
80+
full_path = self.root_dir
81+
contents_by_path = self.scan_disk(full_path, excludes)
7782
delta_ts = time.time() - start_ts
7883
self.write(json_encode({
7984
'scan_seconds': delta_ts,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@jupyterlab/apputils": "^1.0.0",
3636
"@jupyterlab/coreutils": "^3.0.0",
3737
"@jupyterlab/docmanager": "^1.0.0",
38+
"@jupyterlab/filebrowser": "^1.0.1",
3839
"@jupyterlab/services": "^4.0.0",
3940
"@phosphor/messaging": "^1.2.3",
4041
"@phosphor/widgets": "^1.8.1"

schema/plugin.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
"type": "array",
1111
"items": { "type": "string" },
1212
"default": ["node_modules", "__pycache__"]
13+
},
14+
"relativeSearch": {
15+
"title": "Relative Search",
16+
"description": "Whether to search from currently selected directory",
17+
"type": "boolean",
18+
"default": false
1319
}
1420
},
1521
"additionalProperties": false,

src/index.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ICommandPalette } from "@jupyterlab/apputils";
33
import { ISettingRegistry, URLExt, PathExt } from "@jupyterlab/coreutils";
44
import { IDocumentManager } from "@jupyterlab/docmanager";
55
import { ServerConnection } from "@jupyterlab/services";
6+
import { FileBrowser, IFileBrowserFactory } from '@jupyterlab/filebrowser';
67
import { CommandRegistry } from "@phosphor/commands";
78
import { ReadonlyJSONObject } from "@phosphor/coreutils";
89
import { Message } from "@phosphor/messaging";
@@ -17,15 +18,15 @@ interface QuickOpenResponse {
1718
}
1819

1920
/** 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> {
2122
const query = excludes
2223
.map(exclude => {
2324
return "excludes=" + encodeURIComponent(exclude);
2425
})
2526
.join("&");
2627

2728
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;
2930
const response = await ServerConnection.makeRequest(fullUrl, { method: "GET" }, settings);
3031
if (response.status !== 200) {
3132
throw new ServerConnection.ResponseError(response);
@@ -40,13 +41,16 @@ async function fetchContents(excludes: string[]): Promise<QuickOpenResponse> {
4041
class QuickOpenWidget extends CommandPalette {
4142
private _pathSelected = new Signal<this, string>(this);
4243
private _settings: ReadonlyJSONObject;
44+
private _fileBrowser: FileBrowser;
4345

44-
constructor(options: CommandPalette.IOptions) {
46+
constructor(factory: IFileBrowserFactory, options: CommandPalette.IOptions) {
4547
super(options);
4648

4749
this.id = "jupyterlab-quickopen";
4850
this.title.iconClass = "jp-SideBar-tabIcon jp-SearchIcon";
4951
this.title.caption = "Quick Open";
52+
53+
this._fileBrowser = factory.defaultBrowser;
5054
}
5155

5256
/** Signal when a selected path is activated. */
@@ -66,7 +70,8 @@ class QuickOpenWidget extends CommandPalette {
6670
super.onActivateRequest(msg);
6771

6872
// 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);
7075

7176
// Remove all paths from the view
7277
this.clearItems();
@@ -99,19 +104,20 @@ class QuickOpenWidget extends CommandPalette {
99104
const extension: JupyterFrontEndPlugin<void> = {
100105
id: "@parente/jupyterlab-quickopen:plugin",
101106
autoStart: true,
102-
requires: [ICommandPalette, IDocumentManager, ILabShell, ISettingRegistry],
107+
requires: [ICommandPalette, IDocumentManager, ILabShell, ISettingRegistry, IFileBrowserFactory],
103108
activate: async (
104109
app: JupyterFrontEnd,
105110
palette: ICommandPalette,
106111
docManager: IDocumentManager,
107112
labShell: ILabShell,
108-
settingRegistry: ISettingRegistry
113+
settingRegistry: ISettingRegistry,
114+
fileBrowserFactory: IFileBrowserFactory
109115
) => {
110116
window["docManager"] = docManager;
111117

112118
console.log(`Activated extension: ${extension.id}`);
113119
const commands: CommandRegistry = new CommandRegistry();
114-
const widget: QuickOpenWidget = new QuickOpenWidget({ commands });
120+
const widget: QuickOpenWidget = new QuickOpenWidget(fileBrowserFactory, { commands });
115121
const settings: ISettingRegistry.ISettings = await settingRegistry.load(extension.id);
116122

117123
// Listen for path selection signals and show the selected files in the

0 commit comments

Comments
 (0)