Skip to content

Commit

Permalink
Move notebook setting keys into a namespace
Browse files Browse the repository at this point in the history
Adds a new `NotebookSettings` namespace to hold notebook settings keys
  • Loading branch information
mjbvz committed Nov 9, 2021
1 parent 8b0720d commit 87ea829
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CATEGORIES } from 'vs/workbench/common/actions';
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { Memento } from 'vs/workbench/common/memento';
import { HAS_OPENED_NOTEBOOK } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { OpenGettingStarted } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
Expand Down Expand Up @@ -45,7 +45,7 @@ export class NotebookGettingStarted extends Disposable implements IWorkbenchCont
hasOpenedNotebook.set(true);
}

const needToShowGettingStarted = _configurationService.getValue(OpenGettingStarted) && !storedValue[hasShownGettingStartedKey];
const needToShowGettingStarted = _configurationService.getValue(NotebookSetting.openGettingStarted) && !storedValue[hasShownGettingStartedKey];
if (!storedValue[hasOpenedNotebookKey] || needToShowGettingStarted) {
const onDidOpenNotebook = () => {
hasOpenedNotebook.set(true);
Expand Down Expand Up @@ -83,7 +83,7 @@ registerAction2(class NotebookClearNotebookLayoutAction extends Action2 {
id: 'workbench.notebook.layout.gettingStarted',
title: localize('workbench.notebook.layout.gettingStarted.label', "Reset notebook getting started"),
f1: true,
precondition: ContextKeyExpr.equals(`config.${OpenGettingStarted}`, true),
precondition: ContextKeyExpr.equals(`config.${NotebookSetting.openGettingStarted}`, true),
category: CATEGORIES.Developer,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/act
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { INotebookActionContext, NOTEBOOK_ACTIONS_CATEGORY } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
import { CellToolbarLocation } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';

const TOGGLE_CELL_TOOLBAR_POSITION = 'notebook.toggleCellToolbarPosition';

Expand All @@ -33,9 +33,9 @@ export class ToggleCellToolbarPositionAction extends Action2 {
// from toolbar
const viewType = editor.textModel.viewType;
const configurationService = accessor.get(IConfigurationService);
const toolbarPosition = configurationService.getValue<string | { [key: string]: string }>(CellToolbarLocation);
const toolbarPosition = configurationService.getValue<string | { [key: string]: string }>(NotebookSetting.cellToolbarLocation);
const newConfig = this.togglePosition(viewType, toolbarPosition);
await configurationService.updateValue(CellToolbarLocation, newConfig);
await configurationService.updateValue(NotebookSetting.cellToolbarLocation, newConfig);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { localize } from 'vs/nls';
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { CellToolbarLocation, CompactView, ConsolidatedRunButton, FocusIndicator, GlobalToolbar, InsertToolbarLocation, ShowCellStatusBar, UndoRedoPerCell } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IWorkbenchAssignmentService } from 'vs/workbench/services/assignment/common/assignmentService';
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
Expand All @@ -22,34 +22,34 @@ export enum NotebookProfileType {

const profiles = {
[NotebookProfileType.default]: {
[FocusIndicator]: 'gutter',
[InsertToolbarLocation]: 'both',
[GlobalToolbar]: true,
[CellToolbarLocation]: { default: 'right' },
[CompactView]: true,
[ShowCellStatusBar]: 'visible',
[ConsolidatedRunButton]: true,
[UndoRedoPerCell]: false
[NotebookSetting.focusIndicator]: 'gutter',
[NotebookSetting.insertToolbarLocation]: 'both',
[NotebookSetting.globalToolbar]: true,
[NotebookSetting.cellToolbarLocation]: { default: 'right' },
[NotebookSetting.compactView]: true,
[NotebookSetting.showCellStatusBar]: 'visible',
[NotebookSetting.consolidatedRunButton]: true,
[NotebookSetting.undoRedoPerCell]: false
},
[NotebookProfileType.jupyter]: {
[FocusIndicator]: 'gutter',
[InsertToolbarLocation]: 'notebookToolbar',
[GlobalToolbar]: true,
[CellToolbarLocation]: { default: 'left' },
[CompactView]: true,
[ShowCellStatusBar]: 'visible',
[ConsolidatedRunButton]: false,
[UndoRedoPerCell]: true
[NotebookSetting.focusIndicator]: 'gutter',
[NotebookSetting.insertToolbarLocation]: 'notebookToolbar',
[NotebookSetting.globalToolbar]: true,
[NotebookSetting.cellToolbarLocation]: { default: 'left' },
[NotebookSetting.compactView]: true,
[NotebookSetting.showCellStatusBar]: 'visible',
[NotebookSetting.consolidatedRunButton]: false,
[NotebookSetting.undoRedoPerCell]: true
},
[NotebookProfileType.colab]: {
[FocusIndicator]: 'border',
[InsertToolbarLocation]: 'betweenCells',
[GlobalToolbar]: false,
[CellToolbarLocation]: { default: 'right' },
[CompactView]: false,
[ShowCellStatusBar]: 'hidden',
[ConsolidatedRunButton]: true,
[UndoRedoPerCell]: false
[NotebookSetting.focusIndicator]: 'border',
[NotebookSetting.insertToolbarLocation]: 'betweenCells',
[NotebookSetting.globalToolbar]: false,
[NotebookSetting.cellToolbarLocation]: { default: 'right' },
[NotebookSetting.compactView]: false,
[NotebookSetting.showCellStatusBar]: 'hidden',
[NotebookSetting.consolidatedRunButton]: true,
[NotebookSetting.undoRedoPerCell]: false
}
};

Expand Down Expand Up @@ -101,13 +101,13 @@ export class NotebookProfileContribution extends Disposable {
return;
} else {
// check if settings are already modified
const focusIndicator = configService.getValue(FocusIndicator);
const insertToolbarPosition = configService.getValue(InsertToolbarLocation);
const globalToolbar = configService.getValue(GlobalToolbar);
// const cellToolbarLocation = configService.getValue(CellToolbarLocation);
const compactView = configService.getValue(CompactView);
const showCellStatusBar = configService.getValue(ShowCellStatusBar);
const consolidatedRunButton = configService.getValue(ConsolidatedRunButton);
const focusIndicator = configService.getValue(NotebookSetting.focusIndicator);
const insertToolbarPosition = configService.getValue(NotebookSetting.insertToolbarLocation);
const globalToolbar = configService.getValue(NotebookSetting.globalToolbar);
// const cellToolbarLocation = configService.getValue(NotebookSetting.cellToolbarLocation);
const compactView = configService.getValue(NotebookSetting.compactView);
const showCellStatusBar = configService.getValue(NotebookSetting.showCellStatusBar);
const consolidatedRunButton = configService.getValue(NotebookSetting.consolidatedRunButton);
if (focusIndicator === 'border'
&& insertToolbarPosition === 'both'
&& globalToolbar === false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { insertCell } from 'vs/workbench/contrib/notebook/browser/controller/cel
import { cellExecutionArgs, CellToolbarOrder, CELL_TITLE_CELL_GROUP_ID, executeNotebookCondition, getContextFromActiveEditor, getContextFromUri, INotebookActionContext, INotebookCellActionContext, INotebookCellToolbarActionContext, INotebookCommandContext, NotebookAction, NotebookCellAction, NotebookMultiCellAction, NOTEBOOK_EDITOR_WIDGET_ACTION_WEIGHT, parseMultiCellExecutionArgs } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
import { CellEditState, CellFocusMode, EXECUTE_CELL_COMMAND_ID, NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_TYPE, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_IS_ACTIVE_EDITOR, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_MISSING_KERNEL_EXTENSION } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons';
import { CellKind, ConsolidatedRunButton, NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, NotebookSetting, NotebookCellExecutionState } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
Expand Down Expand Up @@ -207,15 +207,15 @@ registerAction2(class ExecuteAboveCells extends NotebookMultiCellAction {
id: MenuId.NotebookCellExecute,
when: ContextKeyExpr.and(
executeCondition,
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, true))
ContextKeyExpr.equals(`config.${NotebookSetting.consolidatedRunButton}`, true))
},
{
id: MenuId.NotebookCellTitle,
order: CellToolbarOrder.ExecuteAboveCells,
group: CELL_TITLE_CELL_GROUP_ID,
when: ContextKeyExpr.and(
executeCondition,
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, false))
ContextKeyExpr.equals(`config.${NotebookSetting.consolidatedRunButton}`, false))
}
],
icon: icons.executeAboveIcon
Expand Down Expand Up @@ -253,15 +253,15 @@ registerAction2(class ExecuteCellAndBelow extends NotebookMultiCellAction {
id: MenuId.NotebookCellExecute,
when: ContextKeyExpr.and(
executeCondition,
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, true))
ContextKeyExpr.equals(`config.${NotebookSetting.consolidatedRunButton}`, true))
},
{
id: MenuId.NotebookCellTitle,
order: CellToolbarOrder.ExecuteCellAndBelow,
group: CELL_TITLE_CELL_GROUP_ID,
when: ContextKeyExpr.and(
executeCondition,
ContextKeyExpr.equals(`config.${ConsolidatedRunButton}`, false))
ContextKeyExpr.equals(`config.${NotebookSetting.consolidatedRunButton}`, false))
}
],
icon: icons.executeBelowIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { insertCell } from 'vs/workbench/contrib/notebook/browser/controller/cel
import { INotebookActionContext, NotebookAction } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
import { NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_EDITOR_EDITABLE } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { CellKind, GlobalToolbarShowLabel } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';

const INSERT_CODE_CELL_ABOVE_COMMAND_ID = 'notebook.cell.insertCodeCellAbove';
const INSERT_CODE_CELL_BELOW_COMMAND_ID = 'notebook.cell.insertCodeCellBelow';
Expand Down Expand Up @@ -323,7 +323,7 @@ MenuRegistry.appendMenuItem(MenuId.NotebookToolbar, {
NOTEBOOK_EDITOR_EDITABLE.isEqualTo(true),
ContextKeyExpr.notEquals('config.notebook.insertToolbarLocation', 'betweenCells'),
ContextKeyExpr.notEquals('config.notebook.insertToolbarLocation', 'hidden'),
ContextKeyExpr.notEquals(`config.${GlobalToolbarShowLabel}`, false)
ContextKeyExpr.notEquals(`config.${NotebookSetting.globalToolbarShowLabel}`, false)
)
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { NOTEBOOK_ACTIONS_CATEGORY } from 'vs/workbench/contrib/notebook/browser/controller/coreActions';
import { NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { OpenGettingStarted } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';

Expand All @@ -23,7 +23,7 @@ registerAction2(class NotebookConfigureLayoutAction extends Action2 {
id: 'workbench.notebook.layout.select',
title: localize('workbench.notebook.layout.select.label', "Select between Notebook Layouts"),
f1: true,
precondition: ContextKeyExpr.equals(`config.${OpenGettingStarted}`, true),
precondition: ContextKeyExpr.equals(`config.${NotebookSetting.openGettingStarted}`, true),
category: NOTEBOOK_ACTIONS_CATEGORY,
menu: [
{
Expand All @@ -32,7 +32,7 @@ registerAction2(class NotebookConfigureLayoutAction extends Action2 {
when: ContextKeyExpr.and(
NOTEBOOK_IS_ACTIVE_EDITOR,
ContextKeyExpr.notEquals('config.notebook.globalToolbar', true),
ContextKeyExpr.equals(`config.${OpenGettingStarted}`, true)
ContextKeyExpr.equals(`config.${NotebookSetting.openGettingStarted}`, true)
),
order: 0
},
Expand All @@ -41,7 +41,7 @@ registerAction2(class NotebookConfigureLayoutAction extends Action2 {
group: 'notebookLayout',
when: ContextKeyExpr.and(
ContextKeyExpr.equals('config.notebook.globalToolbar', true),
ContextKeyExpr.equals(`config.${OpenGettingStarted}`, true)
ContextKeyExpr.equals(`config.${NotebookSetting.openGettingStarted}`, true)
),
order: 0
}
Expand Down
Loading

0 comments on commit 87ea829

Please sign in to comment.