Skip to content

Commit

Permalink
Added a quickpickmenu to choose folders to display
Browse files Browse the repository at this point in the history
The provided choice are, when relevant  :
* current document folder
*  home folder
* workspace root folders

There is a regression. The quickinput menu allowed to
choose any folder. I don't know if the quickpick menu
can double as a quickinput, meaning accepting the typed
string when no match. If not, one needs an additional entry
to the quickpick menu to launch a quickinput one.
Probably will go with that second option if I am not figure
if the second is possible.
  • Loading branch information
cognominal committed May 31, 2021
1 parent ad93c8a commit 61ce6b5
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import FileItem from './fileItem';
import * as fs from 'fs';
import * as path from 'path';

let win = vscode.window;

export interface ExtensionInternal {
DiredProvider: DiredProvider,
}
Expand All @@ -27,42 +29,45 @@ export function activate(context: vscode.ExtensionContext): ExtensionInternal {
const providerRegistrations = vscode.Disposable.from(
vscode.workspace.registerTextDocumentContentProvider(DiredProvider.scheme, provider),
);
const commandOpen = vscode.commands.registerCommand("extension.dired.open", () => {
let dir = vscode.workspace.rootPath;
const at = vscode.window.activeTextEditor;
if (at) {
if (at.document.uri.scheme === DiredProvider.scheme) {
dir = provider.dirname;
} else {
const doc = at.document;
dir = path.dirname(doc.fileName);

// export function showQuickPick<T extends QuickPickItem>(items: readonly T[] | Thenable<readonly T[]>, options: //// QuickPickOptions & { canPickMany: true; }, token?: CancellationToken): Thenable<T[] | undefined>;


const commandOpen = vscode.commands.registerCommand("extension.dired.open", async () => {
const curFileName = win.activeTextEditor?.document.fileName;
const quickPick = vscode.window.createQuickPick( );
const homedir = require('os').homedir();
let items = new Array();
items.push( { label: homedir, description: 'home folder'} );
items.push( { label: curFileName, description: 'current documentfolder' });
let wspFolders = vscode.workspace.workspaceFolders;
if (wspFolders) {
for (let wsp of wspFolders) {
items.push({label: wsp.uri.path, description: 'workespacefolder' });
}
}
if (!dir) {
dir = require('os').homedir();
const result = await win.showQuickPick(items, {
placeHolder: 'pick a workspace or folder',
});
showDir(result.label);
});

function showDir(path: string) {
if (!path) {
return;
}
if (dir) {
if (!ask_dir) {
provider.openDir(dir);
} else {
vscode.window.showInputBox({ value: dir, valueSelection: [dir.length, dir.length] })
.then((path) => {
if (!path) {
return;
}
if (fs.lstatSync(path).isDirectory()) {
provider.openDir(path);
} else if (fs.lstatSync(path).isFile()) {
const f = new FileItem(path, "", false, true); // Incomplete FileItem just to get URI.
const uri = f.uri;
if (uri) {
provider.showFile(uri);
}
}
});
if (fs.lstatSync(path).isDirectory()) {
provider.openDir(path);
} else if (fs.lstatSync(path).isFile()) {
const f = new FileItem(path, "", false, true); // Incomplete FileItem just to get URI.
const uri = f.uri;
if (uri) {
provider.showFile(uri);
}
}
});

}

const commandEnter = vscode.commands.registerCommand("extension.dired.enter", () => {
provider.enter();
});
Expand Down Expand Up @@ -136,4 +141,4 @@ export function activate(context: vscode.ExtensionContext): ExtensionInternal {
return {
DiredProvider: provider,
};
}
};

0 comments on commit 61ce6b5

Please sign in to comment.