提交 f78c4706 编写于 作者: E Eric Amodio

Fixes #96681 & more

Adds `workbench.workspaceFirstOpen` workspace setting to control applying a default layout
Removes `firstRun` flag from `IDefaultLayout`
Changes `IDefaultEditor` to require a `uri` rather than path+scheme - still supports a fallback until embedders can migrate
Adds `openOnlyIfExists` property to `IDefaultEditor` for better control on if a file should be opened or not
上级 d1cd816e
...@@ -141,6 +141,9 @@ export interface IPathData { ...@@ -141,6 +141,9 @@ export interface IPathData {
// file exists, if false it does not. with // file exists, if false it does not. with
// undefined the state is unknown. // undefined the state is unknown.
exists?: boolean; exists?: boolean;
// Specifies if the file should be only be opened if it exists
openOnlyIfExists?: boolean;
} }
export interface IOpenFileRequest { export interface IOpenFileRequest {
......
...@@ -44,7 +44,7 @@ import { LineNumbersType } from 'vs/editor/common/config/editorOptions'; ...@@ -44,7 +44,7 @@ import { LineNumbersType } from 'vs/editor/common/config/editorOptions';
import { ActivitybarPart } from 'vs/workbench/browser/parts/activitybar/activitybarPart'; import { ActivitybarPart } from 'vs/workbench/browser/parts/activitybar/activitybarPart';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
enum Settings { export enum Settings {
ACTIVITYBAR_VISIBLE = 'workbench.activityBar.visible', ACTIVITYBAR_VISIBLE = 'workbench.activityBar.visible',
STATUSBAR_VISIBLE = 'workbench.statusBar.visible', STATUSBAR_VISIBLE = 'workbench.statusBar.visible',
...@@ -52,6 +52,7 @@ enum Settings { ...@@ -52,6 +52,7 @@ enum Settings {
PANEL_POSITION = 'workbench.panel.defaultLocation', PANEL_POSITION = 'workbench.panel.defaultLocation',
ZEN_MODE_RESTORE = 'zenMode.restore', ZEN_MODE_RESTORE = 'zenMode.restore',
WORKSPACE_FIRST_OPEN = 'workbench.workspaceFirstOpen'
} }
enum Storage { enum Storage {
...@@ -547,7 +548,12 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi ...@@ -547,7 +548,12 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
private applyDefaultLayout(environmentService: IWorkbenchEnvironmentService, storageService: IStorageService) { private applyDefaultLayout(environmentService: IWorkbenchEnvironmentService, storageService: IStorageService) {
const defaultLayout = environmentService.options?.defaultLayout; const defaultLayout = environmentService.options?.defaultLayout;
if (!defaultLayout || !defaultLayout.firstRun) { if (!defaultLayout) {
return;
}
const firstOpen = storageService.getBoolean(Settings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE);
if (!firstOpen) {
return; return;
} }
...@@ -752,14 +758,25 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi ...@@ -752,14 +758,25 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
return []; return [];
} }
private _openedDefaultEditors: boolean = false;
get openedDefaultEditors() {
return this._openedDefaultEditors;
}
private getInitialFilesToOpen(): { filesToOpenOrCreate?: IPath[], filesToDiff?: IPath[] } | undefined { private getInitialFilesToOpen(): { filesToOpenOrCreate?: IPath[], filesToDiff?: IPath[] } | undefined {
const defaultLayout = this.environmentService.options?.defaultLayout; const defaultLayout = this.environmentService.options?.defaultLayout;
if (defaultLayout?.firstRun && defaultLayout?.editors?.length) { if (defaultLayout?.editors?.length && this.storageService.getBoolean(Settings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE)) {
// this._openedDefaultEditors = true;
return { return {
filesToOpenOrCreate: defaultLayout.editors filesToOpenOrCreate: defaultLayout.editors
.sort((a, b) => (a.active ? -1 : 1) - (b.active ? -1 : 1)) .map<IPath>(f => {
.map(f => ({ fileUri: URI.file(f.path).with({ scheme: f.scheme }), inactive: !f.active })) // Support the old path+scheme api until embedders can migrate
if ('path' in f && 'scheme' in f) {
return { fileUri: URI.file((f as any).path).with({ scheme: (f as any).scheme }) };
}
return { fileUri: URI.revive(f.uri), openOnlyIfExists: f.openOnlyIfExists };
})
}; };
} }
......
...@@ -38,7 +38,7 @@ import { FileUserDataProvider } from 'vs/workbench/services/userData/common/file ...@@ -38,7 +38,7 @@ import { FileUserDataProvider } from 'vs/workbench/services/userData/common/file
import { BACKUPS } from 'vs/platform/environment/common/environment'; import { BACKUPS } from 'vs/platform/environment/common/environment';
import { joinPath } from 'vs/base/common/resources'; import { joinPath } from 'vs/base/common/resources';
import { BrowserStorageService } from 'vs/platform/storage/browser/storageService'; import { BrowserStorageService } from 'vs/platform/storage/browser/storageService';
import { IStorageService } from 'vs/platform/storage/common/storage'; import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { getThemeTypeSelector, DARK, HIGH_CONTRAST, LIGHT } from 'vs/platform/theme/common/themeService'; import { getThemeTypeSelector, DARK, HIGH_CONTRAST, LIGHT } from 'vs/platform/theme/common/themeService';
import { registerWindowDriver } from 'vs/platform/driver/browser/driver'; import { registerWindowDriver } from 'vs/platform/driver/browser/driver';
import { BufferLogService } from 'vs/platform/log/common/bufferLog'; import { BufferLogService } from 'vs/platform/log/common/bufferLog';
...@@ -52,6 +52,7 @@ import { coalesce } from 'vs/base/common/arrays'; ...@@ -52,6 +52,7 @@ import { coalesce } from 'vs/base/common/arrays';
import { InMemoryFileSystemProvider } from 'vs/platform/files/common/inMemoryFilesystemProvider'; import { InMemoryFileSystemProvider } from 'vs/platform/files/common/inMemoryFilesystemProvider';
import { WebResourceIdentityService, IResourceIdentityService } from 'vs/platform/resource/common/resourceIdentityService'; import { WebResourceIdentityService, IResourceIdentityService } from 'vs/platform/resource/common/resourceIdentityService';
import { ICommandService } from 'vs/platform/commands/common/commands'; import { ICommandService } from 'vs/platform/commands/common/commands';
import { Settings } from 'vs/workbench/browser/layout';
class BrowserMain extends Disposable { class BrowserMain extends Disposable {
...@@ -65,12 +66,12 @@ class BrowserMain extends Disposable { ...@@ -65,12 +66,12 @@ class BrowserMain extends Disposable {
async open(): Promise<IWorkbench> { async open(): Promise<IWorkbench> {
const services = await this.initServices(); const services = await this.initServices();
// const defaultLayout = this.configuration?.defaultLayout; const firstOpen = services.storageService.getBoolean(Settings.WORKSPACE_FIRST_OPEN, StorageScope.WORKSPACE);
// if (defaultLayout) { if (firstOpen === undefined || firstOpen) {
// defaultLayout.firstRun = services.storageService.get(firstSessionDateStorageKey, StorageScope.GLOBAL) === undefined; services.storageService.store(Settings.WORKSPACE_FIRST_OPEN, !(firstOpen ?? false), StorageScope.WORKSPACE);
// } }
await domContentLoaded(); { await domContentLoaded(); }
mark('willStartWorkbench'); mark('willStartWorkbench');
// Base Theme // Base Theme
......
...@@ -1481,6 +1481,9 @@ export async function pathsToEditors(paths: IPathData[] | undefined, fileService ...@@ -1481,6 +1481,9 @@ export async function pathsToEditors(paths: IPathData[] | undefined, fileService
} }
const exists = (typeof path.exists === 'boolean') ? path.exists : await fileService.exists(resource); const exists = (typeof path.exists === 'boolean') ? path.exists : await fileService.exists(resource);
if (!exists && path.openOnlyIfExists) {
return;
}
const options: ITextEditorOptions = (exists && typeof path.lineNumber === 'number') ? { const options: ITextEditorOptions = (exists && typeof path.lineNumber === 'number') ? {
selection: { selection: {
......
...@@ -44,8 +44,8 @@ import { IRecentlyOpened, isRecentWorkspace, IRecentWorkspace, IRecentFolder, is ...@@ -44,8 +44,8 @@ import { IRecentlyOpened, isRecentWorkspace, IRecentWorkspace, IRecentFolder, is
import { CancellationToken } from 'vs/base/common/cancellation'; import { CancellationToken } from 'vs/base/common/cancellation';
import { IHostService } from 'vs/workbench/services/host/browser/host'; import { IHostService } from 'vs/workbench/services/host/browser/host';
import { IProductService } from 'vs/platform/product/common/productService'; import { IProductService } from 'vs/platform/product/common/productService';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorOptions } from 'vs/platform/editor/common/editor'; import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
const configurationKey = 'workbench.startupEditor'; const configurationKey = 'workbench.startupEditor';
const oldConfigurationKey = 'workbench.welcome.enabled'; const oldConfigurationKey = 'workbench.welcome.enabled';
...@@ -61,13 +61,14 @@ export class WelcomePageContribution implements IWorkbenchContribution { ...@@ -61,13 +61,14 @@ export class WelcomePageContribution implements IWorkbenchContribution {
@IFileService fileService: IFileService, @IFileService fileService: IFileService,
@IWorkspaceContextService contextService: IWorkspaceContextService, @IWorkspaceContextService contextService: IWorkspaceContextService,
@ILifecycleService lifecycleService: ILifecycleService, @ILifecycleService lifecycleService: ILifecycleService,
@IEditorService editorGroupsService: IEditorGroupsService, @IWorkbenchLayoutService layoutService: IWorkbenchLayoutService,
@ICommandService private readonly commandService: ICommandService, @ICommandService private readonly commandService: ICommandService,
) { ) {
const enabled = isWelcomePageEnabled(configurationService, contextService); const enabled = isWelcomePageEnabled(configurationService, contextService);
if (enabled && lifecycleService.startupKind !== StartupKind.ReloadedWindow) { if (enabled && lifecycleService.startupKind !== StartupKind.ReloadedWindow) {
backupFileService.hasBackups().then(hasBackups => { backupFileService.hasBackups().then(hasBackups => {
if (!editorGroupsService.willRestoreEditors && !hasBackups) { // Open the welcome even if we opened a set of default editors
if ((!editorService.activeEditor || layoutService.openedDefaultEditors) && !hasBackups) {
const openWithReadme = configurationService.getValue(configurationKey) === 'readme'; const openWithReadme = configurationService.getValue(configurationKey) === 'readme';
if (openWithReadme) { if (openWithReadme) {
return Promise.all(contextService.getWorkspace().folders.map(folder => { return Promise.all(contextService.getWorkspace().folders.map(folder => {
......
...@@ -224,4 +224,9 @@ export interface IWorkbenchLayoutService extends ILayoutService { ...@@ -224,4 +224,9 @@ export interface IWorkbenchLayoutService extends ILayoutService {
* Returns the next visible view part in a given direction * Returns the next visible view part in a given direction
*/ */
getVisibleNeighborPart(part: Parts, direction: Direction): Parts | undefined; getVisibleNeighborPart(part: Parts, direction: Direction): Parts | undefined;
/**
* True if a default layout with default editors was applied at startup
*/
readonly openedDefaultEditors: boolean;
} }
...@@ -370,6 +370,8 @@ export class TestLayoutService implements IWorkbenchLayoutService { ...@@ -370,6 +370,8 @@ export class TestLayoutService implements IWorkbenchLayoutService {
_serviceBrand: undefined; _serviceBrand: undefined;
openedDefaultEditors = false;
dimension: IDimension = { width: 800, height: 600 }; dimension: IDimension = { width: 800, height: 600 };
container: HTMLElement = window.document.body; container: HTMLElement = window.document.body;
......
...@@ -146,18 +146,14 @@ interface IDefaultPanelLayout { ...@@ -146,18 +146,14 @@ interface IDefaultPanelLayout {
} }
interface IDefaultEditor { interface IDefaultEditor {
path: string; readonly uri: UriComponents;
scheme: string; readonly openOnlyIfExists?: boolean;
active?: boolean;
} }
interface IDefaultLayout { interface IDefaultLayout {
sidebar?: IDefaultSideBarLayout; readonly sidebar?: IDefaultSideBarLayout;
panel?: IDefaultPanelLayout; readonly panel?: IDefaultPanelLayout;
editors?: IDefaultEditor[]; readonly editors?: IDefaultEditor[];
// Internal only
firstRun?: boolean;
} }
interface IWorkbenchConstructionOptions { interface IWorkbenchConstructionOptions {
...@@ -270,6 +266,8 @@ interface IWorkbenchConstructionOptions { ...@@ -270,6 +266,8 @@ interface IWorkbenchConstructionOptions {
*/ */
readonly homeIndicator?: IHomeIndicator; readonly homeIndicator?: IHomeIndicator;
readonly defaultLayout?: IDefaultLayout;
//#endregion //#endregion
...@@ -286,8 +284,6 @@ interface IWorkbenchConstructionOptions { ...@@ -286,8 +284,6 @@ interface IWorkbenchConstructionOptions {
readonly driver?: boolean; readonly driver?: boolean;
//#endregion //#endregion
defaultLayout?: IDefaultLayout;
} }
interface IWorkbench { interface IWorkbench {
...@@ -421,6 +417,7 @@ export { ...@@ -421,6 +417,7 @@ export {
IHomeIndicator, IHomeIndicator,
// Default layout // Default layout
IDefaultEditor,
IDefaultLayout, IDefaultLayout,
IDefaultPanelLayout, IDefaultPanelLayout,
IDefaultSideBarLayout, IDefaultSideBarLayout,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册