提交 5651fa0a 编写于 作者: B Benjamin Pasero

debt - some 💄

* add a few more readonly to properties
* move IVisibleEditor closer to IEditor
* remove options accessor from IEditor
上级 c5dd0e55
......@@ -65,7 +65,7 @@ export interface IResourceInput extends IBaseResourceInput {
/**
* The resource URI of the resource to open.
*/
resource: URI;
readonly resource: URI;
/**
* The encoding of the text input if known.
......
......@@ -21,20 +21,20 @@ export interface INotificationProperties {
* Sticky notifications are not automatically removed after a certain timeout. By
* default, notifications with primary actions and severity error are always sticky.
*/
sticky?: boolean;
readonly sticky?: boolean;
/**
* Silent notifications are not shown to the user unless the notification center
* is opened. The status bar will still indicate all number of notifications to
* catch some attention.
*/
silent?: boolean;
readonly silent?: boolean;
/**
* Adds an action to never show the notification again. The choice will be persisted
* such as future requests will not cause the notification to show again.
*/
neverShowAgain?: INeverShowAgainOptions;
readonly neverShowAgain?: INeverShowAgainOptions;
}
export enum NeverShowAgainScope {
......@@ -55,19 +55,19 @@ export interface INeverShowAgainOptions {
/**
* The id is used to persist the selection of not showing the notification again.
*/
id: string;
readonly id: string;
/**
* By default the action will show up as primary action. Setting this to true will
* make it a secondary action instead.
*/
isSecondary?: boolean;
readonly isSecondary?: boolean;
/**
* Whether to persist the choice in the current workspace or for all workspaces. By
* default it will be persisted for all workspaces.
*/
scope?: NeverShowAgainScope;
readonly scope?: NeverShowAgainScope;
}
export interface INotification extends INotificationProperties {
......@@ -75,18 +75,18 @@ export interface INotification extends INotificationProperties {
/**
* The severity of the notification. Either `Info`, `Warning` or `Error`.
*/
severity: Severity;
readonly severity: Severity;
/**
* The message of the notification. This can either be a `string` or `Error`. Messages
* can optionally include links in the format: `[text](link)`
*/
message: NotificationMessage;
readonly message: NotificationMessage;
/**
* The source of the notification appears as additional information.
*/
source?: string;
readonly source?: string;
/**
* Actions to show as part of the notification. Primary actions show up as
......@@ -106,7 +106,7 @@ export interface INotification extends INotificationProperties {
* The initial set of progress properties for the notification. To update progress
* later on, access the `INotificationHandle.progress` property.
*/
progress?: INotificationProgressProperties;
readonly progress?: INotificationProgressProperties;
}
export interface INotificationActions {
......@@ -115,14 +115,14 @@ export interface INotificationActions {
* Primary actions show up as buttons as part of the message and will close
* the notification once clicked.
*/
primary?: ReadonlyArray<IAction>;
readonly primary?: ReadonlyArray<IAction>;
/**
* Secondary actions are meant to provide additional configuration or context
* for the notification and will show up less prominent. A notification does not
* close automatically when invoking a secondary action.
*/
secondary?: ReadonlyArray<IAction>;
readonly secondary?: ReadonlyArray<IAction>;
}
export interface INotificationProgressProperties {
......@@ -130,17 +130,17 @@ export interface INotificationProgressProperties {
/**
* Causes the progress bar to spin infinitley.
*/
infinite?: boolean;
readonly infinite?: boolean;
/**
* Indicate the total amount of work.
*/
total?: number;
readonly total?: number;
/**
* Indicate that a specific chunk of work is done.
*/
worked?: number;
readonly worked?: number;
}
export interface INotificationProgress {
......@@ -176,7 +176,7 @@ export interface INotificationHandle {
/**
* Will be fired whenever the visibility of the notification changes.
* A notification can either be visible as toast or inside the notification
* center if it is visible.
* center if it is visible.
*/
readonly onDidChangeVisibility: Event<boolean>;
......@@ -214,19 +214,19 @@ export interface IPromptChoice {
/**
* Label to show for the choice to the user.
*/
label: string;
readonly label: string;
/**
* Primary choices show up as buttons in the notification below the message.
* Secondary choices show up under the gear icon in the header of the notification.
*/
isSecondary?: boolean;
readonly isSecondary?: boolean;
/**
* Whether to keep the notification open after the choice was selected
* by the user. By default, will close the notification upon click.
*/
keepOpen?: boolean;
readonly keepOpen?: boolean;
/**
* Triggered when the user selects the choice.
......@@ -249,13 +249,13 @@ export interface IStatusMessageOptions {
* An optional timeout after which the status message should show. By default
* the status message will show immediately.
*/
showAfter?: number;
readonly showAfter?: number;
/**
* An optional timeout after which the status message is to be hidden. By default
* the status message will not hide until another status message is displayed.
*/
hideAfter?: number;
readonly hideAfter?: number;
}
export enum NotificationsFilter {
......
......@@ -62,10 +62,6 @@ export abstract class BaseEditor extends Panel implements IEditor {
return this._input;
}
get options(): EditorOptions | undefined {
return this._options;
}
get group(): IEditorGroup | undefined {
return this._group;
}
......
......@@ -7,8 +7,8 @@ import * as nls from 'vs/nls';
import * as types from 'vs/base/common/types';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { TextCompareEditorVisibleContext, EditorInput, IEditorIdentifier, IEditorCommandsContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, CloseDirection, IEditor, IEditorInput } from 'vs/workbench/common/editor';
import { IEditorService, IVisibleEditor } from 'vs/workbench/services/editor/common/editorService';
import { TextCompareEditorVisibleContext, EditorInput, IEditorIdentifier, IEditorCommandsContext, ActiveEditorGroupEmptyContext, MultipleEditorGroupsContext, CloseDirection, IEditor, IEditorInput, IVisibleEditor } from 'vs/workbench/common/editor';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { TextDiffEditor } from 'vs/workbench/browser/parts/editor/textDiffEditor';
import { KeyMod, KeyCode, KeyChord } from 'vs/base/common/keyCodes';
......
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { EditorInput, EditorOptions, IVisibleEditor } from 'vs/workbench/common/editor';
import { Dimension, show, hide, addClass } from 'vs/base/browser/dom';
import { Registry } from 'vs/platform/registry/common/platform';
import { IEditorRegistry, Extensions as EditorExtensions, IEditorDescriptor } from 'vs/workbench/browser/editor';
......@@ -14,7 +14,6 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IEditorProgressService, LongRunningOperation } from 'vs/platform/progress/common/progress';
import { IEditorGroupView, DEFAULT_EDITOR_MIN_DIMENSIONS, DEFAULT_EDITOR_MAX_DIMENSIONS } from 'vs/workbench/browser/parts/editor/editor';
import { Emitter } from 'vs/base/common/event';
import { IVisibleEditor } from 'vs/workbench/services/editor/common/editorService';
import { assertIsDefined } from 'vs/base/common/types';
export interface IOpenEditorResult {
......
......@@ -6,7 +6,7 @@
import 'vs/css!./media/editorgroupview';
import { EditorGroup, IEditorOpenOptions, EditorCloseEvent, ISerializedEditorGroup, isSerializedEditorGroup } from 'vs/workbench/common/editor/editorGroup';
import { EditorInput, EditorOptions, GroupIdentifier, SideBySideEditorInput, CloseDirection, IEditorCloseEvent, EditorGroupActiveEditorDirtyContext, IEditor, EditorGroupEditorsCountContext, SaveReason, IEditorPartOptionsChangeEvent, EditorsOrder } from 'vs/workbench/common/editor';
import { EditorInput, EditorOptions, GroupIdentifier, SideBySideEditorInput, CloseDirection, IEditorCloseEvent, EditorGroupActiveEditorDirtyContext, IEditor, EditorGroupEditorsCountContext, SaveReason, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditor } from 'vs/workbench/common/editor';
import { Event, Emitter, Relay } from 'vs/base/common/event';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { addClass, addClasses, Dimension, trackFocus, toggleClass, removeClass, addDisposableListener, EventType, EventHelper, findParentWithClass, clearNode, isAncestor } from 'vs/base/browser/dom';
......@@ -25,7 +25,7 @@ import { EditorProgressIndicator } from 'vs/workbench/services/progress/browser/
import { localize } from 'vs/nls';
import { isPromiseCanceledError } from 'vs/base/common/errors';
import { dispose, MutableDisposable } from 'vs/base/common/lifecycle';
import { Severity, INotificationService, INotificationActions } from 'vs/platform/notification/common/notification';
import { Severity, INotificationService } from 'vs/platform/notification/common/notification';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { RunOnceWorker } from 'vs/base/common/async';
......@@ -42,7 +42,7 @@ import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { isErrorWithActions, IErrorWithActions } from 'vs/base/common/errorsWithActions';
import { IVisibleEditor, IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { withNullAsUndefined, withUndefinedAsNull } from 'vs/base/common/types';
import { hash } from 'vs/base/common/hash';
import { guessMimeTypes } from 'vs/base/common/mime';
......@@ -980,7 +980,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
// Otherwise, show a background notification.
else {
const actions: INotificationActions = { primary: [] };
const actions = { primary: [] as readonly IAction[] };
if (Array.isArray(errorActions)) {
actions.primary = errorActions;
}
......
......@@ -66,17 +66,12 @@ export interface IEditor extends IPanel {
/**
* The assigned input of this editor.
*/
input: IEditorInput | undefined;
/**
* The assigned options of this editor.
*/
options: IEditorOptions | undefined;
readonly input: IEditorInput | undefined;
/**
* The assigned group this editor is showing in.
*/
group: IEditorGroup | undefined;
readonly group: IEditorGroup | undefined;
/**
* The minimum width of this editor.
......@@ -114,6 +109,14 @@ export interface IEditor extends IPanel {
isVisible(): boolean;
}
/**
* Overrides `IEditor` where `input` and `group` are known to be set.
*/
export interface IVisibleEditor extends IEditor {
readonly input: IEditorInput;
readonly group: IEditorGroup;
}
export interface ITextEditor extends IEditor {
/**
......
......@@ -529,16 +529,12 @@ export class NotificationViewItem extends Disposable implements INotificationVie
}
private setActions(actions: INotificationActions = { primary: [], secondary: [] }): void {
if (!Array.isArray(actions.primary)) {
actions.primary = [];
}
if (!Array.isArray(actions.secondary)) {
actions.secondary = [];
}
this._actions = {
primary: Array.isArray(actions.primary) ? actions.primary : [],
secondary: Array.isArray(actions.secondary) ? actions.secondary : []
};
this._actions = actions;
this._expanded = actions.primary.length > 0;
this._expanded = actions.primary && actions.primary.length > 0;
}
get canCollapse(): boolean {
......
......@@ -5,7 +5,7 @@
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IResourceInput, ITextEditorOptions, IEditorOptions, EditorActivation } from 'vs/platform/editor/common/editor';
import { SideBySideEditor as SideBySideEditorChoice, IEditorInput, IEditor, GroupIdentifier, IFileEditorInput, IUntitledTextResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInputFactoryRegistry, Extensions as EditorExtensions, EditorInput, SideBySideEditorInput, IEditorInputWithOptions, isEditorInputWithOptions, EditorOptions, TextEditorOptions, IEditorIdentifier, IEditorCloseEvent, ITextEditor, ITextDiffEditor, ITextSideBySideEditor, IRevertOptions, SaveReason, EditorsOrder, isTextEditor, IWorkbenchEditorConfiguration, toResource } from 'vs/workbench/common/editor';
import { SideBySideEditor as SideBySideEditorChoice, IEditorInput, IEditor, GroupIdentifier, IFileEditorInput, IUntitledTextResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInputFactoryRegistry, Extensions as EditorExtensions, EditorInput, SideBySideEditorInput, IEditorInputWithOptions, isEditorInputWithOptions, EditorOptions, TextEditorOptions, IEditorIdentifier, IEditorCloseEvent, ITextEditor, ITextDiffEditor, ITextSideBySideEditor, IRevertOptions, SaveReason, EditorsOrder, isTextEditor, IWorkbenchEditorConfiguration, toResource, IVisibleEditor } from 'vs/workbench/common/editor';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { Registry } from 'vs/platform/registry/common/platform';
import { ResourceMap } from 'vs/base/common/map';
......@@ -17,7 +17,7 @@ import { URI } from 'vs/base/common/uri';
import { basename, isEqualOrParent, joinPath } from 'vs/base/common/resources';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { IEditorGroupsService, IEditorGroup, GroupsOrder, IEditorReplacement, GroupChangeKind, preferredSideBySideGroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IResourceEditor, SIDE_GROUP, IResourceEditorReplacement, IOpenEditorOverrideHandler, IVisibleEditor, IEditorService, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE, ISaveEditorsOptions, ISaveAllEditorsOptions, IRevertAllEditorsOptions, IBaseSaveRevertAllEditorOptions } from 'vs/workbench/services/editor/common/editorService';
import { IResourceEditor, SIDE_GROUP, IResourceEditorReplacement, IOpenEditorOverrideHandler, IEditorService, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE, ISaveEditorsOptions, ISaveAllEditorsOptions, IRevertAllEditorsOptions, IBaseSaveRevertAllEditorOptions } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Disposable, IDisposable, dispose, toDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { coalesce, distinct } from 'vs/base/common/arrays';
......
......@@ -5,10 +5,9 @@
import { Event } from 'vs/base/common/event';
import { createDecorator, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IEditorInput, IEditor, GroupIdentifier, IEditorInputWithOptions, CloseDirection, IEditorPartOptions, IEditorPartOptionsChangeEvent, EditorsOrder } from 'vs/workbench/common/editor';
import { IEditorInput, IEditor, GroupIdentifier, IEditorInputWithOptions, CloseDirection, IEditorPartOptions, IEditorPartOptionsChangeEvent, EditorsOrder, IVisibleEditor } from 'vs/workbench/common/editor';
import { IEditorOptions, ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IVisibleEditor } from 'vs/workbench/services/editor/common/editorService';
import { IDimension } from 'vs/editor/common/editorCommon';
import { IDisposable } from 'vs/base/common/lifecycle';
......
......@@ -5,7 +5,7 @@
import { createDecorator, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IResourceInput, IEditorOptions, ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { IEditorInput, IEditor, GroupIdentifier, IEditorInputWithOptions, IUntitledTextResourceInput, IResourceDiffInput, IResourceSideBySideInput, ITextEditor, ITextDiffEditor, ITextSideBySideEditor, IEditorIdentifier, ISaveOptions, IRevertOptions, EditorsOrder } from 'vs/workbench/common/editor';
import { IEditorInput, IEditor, GroupIdentifier, IEditorInputWithOptions, IUntitledTextResourceInput, IResourceDiffInput, IResourceSideBySideInput, ITextEditor, ITextDiffEditor, ITextSideBySideEditor, IEditorIdentifier, ISaveOptions, IRevertOptions, EditorsOrder, IVisibleEditor } from 'vs/workbench/common/editor';
import { Event } from 'vs/base/common/event';
import { IEditor as ICodeEditor, IDiffEditor } from 'vs/editor/common/editorCommon';
import { IEditorGroup, IEditorReplacement } from 'vs/workbench/services/editor/common/editorGroupsService';
......@@ -16,8 +16,8 @@ export const IEditorService = createDecorator<IEditorService>('editorService');
export type IResourceEditor = IResourceInput | IUntitledTextResourceInput | IResourceDiffInput | IResourceSideBySideInput;
export interface IResourceEditorReplacement {
editor: IResourceEditor;
replacement: IResourceEditor;
readonly editor: IResourceEditor;
readonly replacement: IResourceEditor;
}
export const ACTIVE_GROUP = -1;
......@@ -39,17 +39,12 @@ export interface IOpenEditorOverride {
override?: Promise<IEditor | undefined>;
}
export interface IVisibleEditor extends IEditor {
input: IEditorInput;
group: IEditorGroup;
}
export interface ISaveEditorsOptions extends ISaveOptions {
/**
* If true, will ask for a location of the editor to save to.
*/
saveAs?: boolean;
readonly saveAs?: boolean;
}
export interface IBaseSaveRevertAllEditorOptions {
......@@ -57,7 +52,7 @@ export interface IBaseSaveRevertAllEditorOptions {
/**
* Whether to include untitled editors as well.
*/
includeUntitled?: boolean;
readonly includeUntitled?: boolean;
}
export interface ISaveAllEditorsOptions extends ISaveEditorsOptions, IBaseSaveRevertAllEditorOptions { }
......
......@@ -87,11 +87,14 @@ export class NotificationService extends Disposable implements INotificationServ
}));
// Insert as primary or secondary action
const actions = notification.actions || { primary: [], secondary: [] };
const actions = {
primary: notification.actions?.primary || [],
secondary: notification.actions?.secondary || []
};
if (!notification.neverShowAgain.isSecondary) {
actions.primary = [neverShowAgainAction, ...(actions.primary || [])]; // action comes first
actions.primary = [neverShowAgainAction, ...actions.primary]; // action comes first
} else {
actions.secondary = [...(actions.secondary || []), neverShowAgainAction]; // actions comes last
actions.secondary = [...actions.secondary, neverShowAgainAction]; // actions comes last
}
notification.actions = actions;
......
......@@ -103,11 +103,9 @@ suite('Workbench base editor', () => {
assert(!e.isVisible());
assert(!e.input);
assert(!e.options);
await e.setInput(input, options, CancellationToken.None);
assert.strictEqual(input, e.input);
assert.strictEqual(options, e.options);
const group = new TestEditorGroupView(1);
e.setVisible(true, group);
assert(e.isVisible());
......@@ -120,7 +118,6 @@ suite('Workbench base editor', () => {
e.setVisible(false, group);
assert(!e.isVisible());
assert(!e.input);
assert(!e.options);
assert(!e.getControl());
});
......
......@@ -10,7 +10,7 @@ import * as resources from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { IEditorInputWithOptions, CloseDirection, IEditorIdentifier, IUntitledTextResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInput, IEditor, IEditorCloseEvent, IEditorPartOptions, IRevertOptions, GroupIdentifier, EditorInput, EditorOptions, EditorsOrder, IFileEditorInput, IEditorInputFactoryRegistry, IEditorInputFactory, Extensions as EditorExtensions, ISaveOptions, IMoveResult, ITextEditor, ITextDiffEditor, ITextSideBySideEditor } from 'vs/workbench/common/editor';
import { IEditorInputWithOptions, CloseDirection, IEditorIdentifier, IUntitledTextResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInput, IEditor, IEditorCloseEvent, IEditorPartOptions, IRevertOptions, GroupIdentifier, EditorInput, EditorOptions, EditorsOrder, IFileEditorInput, IEditorInputFactoryRegistry, IEditorInputFactory, Extensions as EditorExtensions, ISaveOptions, IMoveResult, ITextEditor, ITextDiffEditor, ITextSideBySideEditor, IVisibleEditor } from 'vs/workbench/common/editor';
import { IEditorOpeningEvent, EditorServiceImpl, IEditorGroupView, IEditorGroupsAccessor } from 'vs/workbench/browser/parts/editor/editor';
import { Event, Emitter } from 'vs/base/common/event';
import { IBackupFileService, IResolvedBackup } from 'vs/workbench/services/backup/common/backup';
......@@ -52,7 +52,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations';
import { IDisposable, toDisposable, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, IFindGroupScope, EditorGroupLayout, ICloseEditorOptions, GroupOrientation } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService, IOpenEditorOverrideHandler, IVisibleEditor, ISaveEditorsOptions, IRevertAllEditorsOptions, IResourceEditor, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService';
import { IEditorService, IOpenEditorOverrideHandler, ISaveEditorsOptions, IRevertAllEditorsOptions, IResourceEditor, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { IEditorRegistry, EditorDescriptor, Extensions } from 'vs/workbench/browser/editor';
import { EditorGroup } from 'vs/workbench/common/editor/editorGroup';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册