mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 01:49:55 -05:00
Open file dialog should start in the directory for the current active file (fixes #1210)
This commit is contained in:
@@ -307,10 +307,16 @@ export class VSCodeMenu {
|
||||
newFile = this.createMenuItem(nls.localize({ key: 'miNewFile', comment: ['&& denotes a mnemonic'] }, "&&New File"), 'workbench.action.files.newUntitledFile');
|
||||
}
|
||||
|
||||
let open = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miOpen', comment: ['&& denotes a mnemonic'] }, "&&Open...")), accelerator: this.getAccelerator('workbench.action.files.openFileFolder'), click: () => this.windowsManager.openFileFolderPicker() });
|
||||
let openFile = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miOpenFile', comment: ['&& denotes a mnemonic'] }, "&&Open File...")), accelerator: this.getAccelerator('workbench.action.files.openFile'), click: () => this.windowsManager.openFilePicker() });
|
||||
let open = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miOpen', comment: ['&& denotes a mnemonic'] }, "&&Open...")), accelerator: this.getAccelerator('workbench.action.files.openFileFolder'), click: () => this.windowsManager.openFileFolderPicker() });
|
||||
let openFolder = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miOpenFolder', comment: ['&& denotes a mnemonic'] }, "Open &&Folder...")), accelerator: this.getAccelerator('workbench.action.files.openFolder'), click: () => this.windowsManager.openFolderPicker() });
|
||||
|
||||
let openFile: Electron.MenuItem;
|
||||
if (hasNoWindows) {
|
||||
openFile = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miOpenFile', comment: ['&& denotes a mnemonic'] }, "&&Open File...")), accelerator: this.getAccelerator('workbench.action.files.openFile'), click: () => this.windowsManager.openFilePicker() });
|
||||
} else {
|
||||
openFile = this.createMenuItem(nls.localize({ key: 'miOpenFile', comment: ['&& denotes a mnemonic'] }, "&&Open File..."), 'workbench.action.files.openFile');
|
||||
}
|
||||
|
||||
let openRecentMenu = new Menu();
|
||||
this.setOpenRecentMenu(openRecentMenu);
|
||||
let openRecent = new MenuItem({ label: mnemonicLabel(nls.localize({ key: 'miOpenRecent', comment: ['&& denotes a mnemonic'] }, "Open &&Recent")), submenu: openRecentMenu, enabled: openRecentMenu.items.length > 0 });
|
||||
|
||||
@@ -70,6 +70,8 @@ interface ILogEntry {
|
||||
interface INativeOpenDialogOptions {
|
||||
pickFolders?: boolean;
|
||||
pickFiles?: boolean;
|
||||
path?: string;
|
||||
forceNewWindow?: boolean;
|
||||
}
|
||||
|
||||
export const IWindowsService = createDecorator<IWindowsService>('windowsService');
|
||||
@@ -222,10 +224,10 @@ export class WindowsManager implements IWindowsService {
|
||||
}
|
||||
});
|
||||
|
||||
ipc.on('vscode:openFilePicker', () => {
|
||||
ipc.on('vscode:openFilePicker', (event, forceNewWindow?: boolean, path?: string) => {
|
||||
this.logService.log('IPC#vscode-openFilePicker');
|
||||
|
||||
this.openFilePicker();
|
||||
this.openFilePicker(forceNewWindow, path);
|
||||
});
|
||||
|
||||
ipc.on('vscode:openFolderPicker', (event, forceNewWindow?: boolean) => {
|
||||
@@ -1007,27 +1009,27 @@ export class WindowsManager implements IWindowsService {
|
||||
}
|
||||
|
||||
public openFileFolderPicker(forceNewWindow?: boolean): void {
|
||||
this.doPickAndOpen({ pickFolders: true, pickFiles: true }, forceNewWindow);
|
||||
this.doPickAndOpen({ pickFolders: true, pickFiles: true , forceNewWindow});
|
||||
}
|
||||
|
||||
public openFilePicker(forceNewWindow?: boolean): void {
|
||||
this.doPickAndOpen({ pickFiles: true }, forceNewWindow);
|
||||
public openFilePicker(forceNewWindow?: boolean, path?: string): void {
|
||||
this.doPickAndOpen({ pickFiles: true, forceNewWindow, path });
|
||||
}
|
||||
|
||||
public openFolderPicker(forceNewWindow?: boolean): void {
|
||||
this.doPickAndOpen({ pickFolders: true }, forceNewWindow);
|
||||
this.doPickAndOpen({ pickFolders: true, forceNewWindow });
|
||||
}
|
||||
|
||||
private doPickAndOpen(options: INativeOpenDialogOptions, forceNewWindow?: boolean): void {
|
||||
private doPickAndOpen(options: INativeOpenDialogOptions): void {
|
||||
this.getFileOrFolderPaths(options, (paths: string[]) => {
|
||||
if (paths && paths.length) {
|
||||
this.open({ cli: this.envService.cliArgs, pathsToOpen: paths, forceNewWindow });
|
||||
this.open({ cli: this.envService.cliArgs, pathsToOpen: paths, forceNewWindow: options.forceNewWindow });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getFileOrFolderPaths(options: INativeOpenDialogOptions, clb: (paths: string[]) => void): void {
|
||||
let workingDir = this.storageService.getItem<string>(WindowsManager.workingDirPickerStorageKey);
|
||||
let workingDir = options.path || this.storageService.getItem<string>(WindowsManager.workingDirPickerStorageKey);
|
||||
let focussedWindow = this.getFocusedWindow();
|
||||
|
||||
let pickerProperties: string[];
|
||||
|
||||
@@ -43,7 +43,7 @@ export class GlobalRevealInOSAction extends Action {
|
||||
public static LABEL = platform.isWindows ? nls.localize('revealActiveFileInWindows', "Reveal Active File in Windows Explorer") : (platform.isMacintosh ? nls.localize('revealActiveFileInMac', "Reveal Active File in Finder") : nls.localize('openActiveFileContainer', "Open Containing Folder of Active File"));
|
||||
|
||||
constructor(
|
||||
id:string,
|
||||
id: string,
|
||||
label: string,
|
||||
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
|
||||
@IMessageService private messageService: IMessageService
|
||||
@@ -87,7 +87,7 @@ export class GlobalCopyPathAction extends Action {
|
||||
public static LABEL = nls.localize('copyPathOfActive', "Copy Path of Active File");
|
||||
|
||||
constructor(
|
||||
id:string,
|
||||
id: string,
|
||||
label: string,
|
||||
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
|
||||
@IMessageService private messageService: IMessageService
|
||||
@@ -129,10 +129,23 @@ export class BaseOpenAction extends Action {
|
||||
export const OPEN_FILE_ID = 'workbench.action.files.openFile';
|
||||
export const OPEN_FILE_LABEL = nls.localize('openFile', "Open File...");
|
||||
|
||||
export class OpenFileAction extends BaseOpenAction {
|
||||
export class OpenFileAction extends Action {
|
||||
|
||||
constructor(id: string, label: string) {
|
||||
super(id, label, 'vscode:openFilePicker');
|
||||
constructor(id: string, label: string, @IWorkbenchEditorService private editorService: IWorkbenchEditorService) {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(): TPromise<any> {
|
||||
const fileInput = asFileEditorInput(this.editorService.getActiveEditorInput(), true);
|
||||
|
||||
// Handle in browser process
|
||||
if (fileInput) {
|
||||
ipc.send('vscode:openFilePicker', false, paths.dirname(fileInput.getResource().fsPath));
|
||||
} else {
|
||||
ipc.send('vscode:openFilePicker');
|
||||
}
|
||||
|
||||
return TPromise.as(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +157,6 @@ export class OpenFolderAction extends BaseOpenAction {
|
||||
constructor(id: string, label: string) {
|
||||
super(id, label, 'vscode:openFolderPicker');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const OPEN_FILE_FOLDER_ID = 'workbench.action.files.openFileFolder';
|
||||
@@ -163,7 +175,7 @@ export class ShowOpenedFileInNewWindow extends Action {
|
||||
public static LABEL = nls.localize('openFileInNewWindow', "Open Active File in New Window");
|
||||
|
||||
constructor(
|
||||
id:string,
|
||||
id: string,
|
||||
label: string,
|
||||
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
|
||||
@IMessageService private messageService: IMessageService
|
||||
|
||||
Reference in New Issue
Block a user