hide nav buttons for non-book notebooks (#6377)

* hide nav buttons for non-book notebooks

* updated buttons for all themes

* changed foregroundColor to buttonForegroundColor
This commit is contained in:
Lucy Zhang
2019-07-16 16:26:03 -07:00
committed by GitHub
parent caff76b723
commit 43bd7268e8
6 changed files with 61 additions and 24 deletions

View File

@@ -693,6 +693,10 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements
$registerNavigationProvider(providerId: string, handle: number): void { $registerNavigationProvider(providerId: string, handle: number): void {
this._notebookService.registerNavigationProvider({ this._notebookService.registerNavigationProvider({
providerId: providerId, providerId: providerId,
hasNavigation: true,
getNavigation: async (uri) => {
return await this._proxy.$getNavigation(handle, uri);
},
onNext: async (uri) => { onNext: async (uri) => {
let result = await this._proxy.$getNavigation(handle, uri); let result = await this._proxy.$getNavigation(handle, uri);
if (result) { if (result) {

View File

@@ -19,7 +19,7 @@
<placeholder-cell-component [cellModel]="cell" [model]="model"> <placeholder-cell-component [cellModel]="cell" [model]="model">
</placeholder-cell-component> </placeholder-cell-component>
</div> </div>
<div class="book-nav" #bookNav> <div class="book-nav" #bookNav [style.visibility]="navigationVisibility">
</div> </div>
</div> </div>
</div> </div>

View File

@@ -26,7 +26,7 @@ import { AngularDisposable } from 'sql/base/node/lifecycle';
import { CellTypes, CellType } from 'sql/workbench/parts/notebook/models/contracts'; import { CellTypes, CellType } from 'sql/workbench/parts/notebook/models/contracts';
import { ICellModel, IModelFactory, INotebookModel, NotebookContentChange } from 'sql/workbench/parts/notebook/models/modelInterfaces'; import { ICellModel, IModelFactory, INotebookModel, NotebookContentChange } from 'sql/workbench/parts/notebook/models/modelInterfaces';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement'; import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { INotebookService, INotebookParams, INotebookManager, INotebookEditor, INotebookSection, DEFAULT_NOTEBOOK_PROVIDER, SQL_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/common/notebookService'; import { INotebookService, INotebookParams, INotebookManager, INotebookEditor, INotebookSection, DEFAULT_NOTEBOOK_PROVIDER, SQL_NOTEBOOK_PROVIDER, INavigationProvider } from 'sql/workbench/services/notebook/common/notebookService';
import { IBootstrapParams } from 'sql/platform/bootstrap/node/bootstrapService'; import { IBootstrapParams } from 'sql/platform/bootstrap/node/bootstrapService';
import { NotebookModel } from 'sql/workbench/parts/notebook/models/notebookModel'; import { NotebookModel } from 'sql/workbench/parts/notebook/models/notebookModel';
import { ModelFactory } from 'sql/workbench/parts/notebook/models/modelFactory'; import { ModelFactory } from 'sql/workbench/parts/notebook/models/modelFactory';
@@ -55,6 +55,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { Button } from 'sql/base/browser/ui/button/button'; import { Button } from 'sql/base/browser/ui/button/button';
import { attachButtonStyler } from 'sql/platform/theme/common/styler'; import { attachButtonStyler } from 'sql/platform/theme/common/styler';
import { isUndefinedOrNull } from 'vs/base/common/types'; import { isUndefinedOrNull } from 'vs/base/common/types';
import { Color } from 'vs/base/common/color';
export const NOTEBOOK_SELECTOR: string = 'notebook-component'; export const NOTEBOOK_SELECTOR: string = 'notebook-component';
@@ -81,7 +82,8 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
private _runAllCellsAction: RunAllCellsAction; private _runAllCellsAction: RunAllCellsAction;
private _providerRelatedActions: IAction[] = []; private _providerRelatedActions: IAction[] = [];
private _scrollTop: number; private _scrollTop: number;
private _navProvider: INavigationProvider;
private navigationResult: nb.NavigationResult;
constructor( constructor(
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,
@@ -133,12 +135,9 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
this._register(this.themeService.onDidColorThemeChange(this.updateTheme, this)); this._register(this.themeService.onDidColorThemeChange(this.updateTheme, this));
this.updateTheme(this.themeService.getColorTheme()); this.updateTheme(this.themeService.getColorTheme());
this.initActionBar(); this.initActionBar();
if (this.contextKeyService.getContextKeyValue('isDevelopment') &&
this.contextKeyService.getContextKeyValue('bookOpened')) {
this.initNavSection();
}
this.setScrollPosition(); this.setScrollPosition();
this.doLoad(); this.doLoad();
this.initNavSection();
} }
ngOnDestroy() { ngOnDestroy() {
@@ -441,10 +440,30 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
} }
protected initNavSection(): void { protected initNavSection(): void {
this.addButton(localize('previousButtonLabel', "Previous"), this._navProvider = this.notebookService.getNavigationProvider(this._notebookParams.notebookUri);
() => this.previousPage());
this.addButton(localize('nextButtonLabel', "Next"), if (this.contextKeyService.getContextKeyValue('isDevelopment') &&
() => this.nextPage()); this.contextKeyService.getContextKeyValue('bookOpened') &&
this._navProvider) {
this.addButton(localize('previousButtonLabel', "< Previous"),
() => this.previousPage());
this.addButton(localize('nextButtonLabel', "Next >"),
() => this.nextPage());
this._navProvider.getNavigation(this._notebookParams.notebookUri).then(result => {
this.navigationResult = result;
this.detectChanges();
}, err => {
console.log(err);
});
}
}
public get navigationVisibility(): 'hidden' | 'visible' {
if (this.navigationResult) {
return this.navigationResult.hasNavigation ? 'visible' : 'hidden';
}
return 'hidden';
} }
private addButton(label: string, onDidClick?: () => void): void { private addButton(label: string, onDidClick?: () => void): void {
@@ -455,8 +474,6 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
if (onDidClick) { if (onDidClick) {
this._register(button.onDidClick(onDidClick)); this._register(button.onDidClick(onDidClick));
} }
this._register(attachButtonStyler(button, this.themeService));
} }
private actionItemProvider(action: Action): IActionViewItem { private actionItemProvider(action: Action): IActionViewItem {
@@ -612,9 +629,8 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
public async nextPage(): Promise<void> { public async nextPage(): Promise<void> {
try { try {
let navProvider = this.notebookService.getNavigationProvider(this.model.notebookUri); if (this._navProvider) {
if (navProvider) { this._navProvider.onNext(this.model.notebookUri);
navProvider.onNext(this.model.notebookUri);
} }
} catch (error) { } catch (error) {
this.notificationService.error(notebookUtils.getErrorMessage(error)); this.notificationService.error(notebookUtils.getErrorMessage(error));
@@ -623,9 +639,8 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
public previousPage() { public previousPage() {
try { try {
let navProvider = this.notebookService.getNavigationProvider(this.model.notebookUri); if (this._navProvider) {
if (navProvider) { this._navProvider.onPrevious(this.model.notebookUri);
navProvider.onPrevious(this.model.notebookUri);
} }
} catch (error) { } catch (error) {
this.notificationService.error(notebookUtils.getErrorMessage(error)); this.notificationService.error(notebookUtils.getErrorMessage(error));

View File

@@ -129,11 +129,11 @@
.notebookEditor .book-nav { .notebookEditor .book-nav {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: flex-start;
margin: 5px; margin: 25px;
} }
.notebookEditor .book-nav .dialog-message-button { .notebookEditor .book-nav .dialog-message-button {
min-width: 60px; min-width: 100px;
margin-right: 10px; margin-right: 10px;
} }

View File

@@ -6,7 +6,7 @@ import 'vs/css!./notebook';
import { registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService'; import { registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
import { SIDE_BAR_BACKGROUND, SIDE_BAR_SECTION_HEADER_BACKGROUND, EDITOR_GROUP_HEADER_TABS_BACKGROUND } from 'vs/workbench/common/theme'; import { SIDE_BAR_BACKGROUND, SIDE_BAR_SECTION_HEADER_BACKGROUND, EDITOR_GROUP_HEADER_TABS_BACKGROUND } from 'vs/workbench/common/theme';
import { activeContrastBorder, contrastBorder, buttonBackground, textLinkForeground, textLinkActiveForeground, textPreformatForeground, textBlockQuoteBackground, textBlockQuoteBorder } from 'vs/platform/theme/common/colorRegistry'; import { activeContrastBorder, contrastBorder, buttonBackground, textLinkForeground, textLinkActiveForeground, textPreformatForeground, textBlockQuoteBackground, textBlockQuoteBorder, buttonForeground } from 'vs/platform/theme/common/colorRegistry';
import { editorLineHighlight, editorLineHighlightBorder } from 'vs/editor/common/view/editorColorRegistry'; import { editorLineHighlight, editorLineHighlightBorder } from 'vs/editor/common/view/editorColorRegistry';
import { IDisposable } from 'vs/base/common/lifecycle'; import { IDisposable } from 'vs/base/common/lifecycle';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -21,6 +21,22 @@ export function registerNotebookThemes(overrideEditorThemeSetting: boolean, conf
let darkBoxShadow = '0px 4px 6px 0px rgba(0, 0, 0, 1)'; let darkBoxShadow = '0px 4px 6px 0px rgba(0, 0, 0, 1)';
let addBorderToInactiveCodeCells = true; let addBorderToInactiveCodeCells = true;
// Book Navigation Buttons
const buttonForegroundColor = theme.getColor(buttonForeground);
const buttonBackgroundColor = theme.getColor(buttonBackground);
if (buttonForegroundColor && buttonBackgroundColor) {
collector.addRule(`
.notebookEditor .book-nav .dialog-message-button .monaco-text-button {
border-color: ${buttonBackgroundColor} !important;
background-color: ${buttonForegroundColor} !important;
color: ${buttonBackgroundColor} !important;
border-width: 1px;
border-style: solid;
}
`);
}
// Active border // Active border
const activeBorder = theme.getColor(buttonBackground); const activeBorder = theme.getColor(buttonBackground);
if (activeBorder) { if (activeBorder) {
@@ -254,4 +270,4 @@ export function registerNotebookThemes(overrideEditorThemeSetting: boolean, conf
${getBareResultsGridInfoStyles(rawOptions)} ${getBareResultsGridInfoStyles(rawOptions)}
}`); }`);
}); });
} }

View File

@@ -156,6 +156,8 @@ export interface INotebookEditor {
export interface INavigationProvider { export interface INavigationProvider {
providerId: string; providerId: string;
hasNavigation: boolean;
getNavigation(uri: URI): Thenable<azdata.nb.NavigationResult>;
onNext(uri: URI): void; onNext(uri: URI): void;
onPrevious(uri: URI): void; onPrevious(uri: URI): void;
} }