mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 09:35:36 -05:00
* Added toggle more actions to cell * Resolve PR comments -- Added INotificationService for notification msg * Reduced ToggleMoreAction to smaller size. So the dropdown could be displayed closer to it instead of at the buttom of the cell.
106 lines
3.1 KiB
TypeScript
106 lines
3.1 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { Action } from 'vs/base/common/actions';
|
|
import { TPromise } from 'vs/base/common/winjs.base';
|
|
import { localize } from 'vs/nls';
|
|
import { CellType } from 'sql/parts/notebook/models/contracts';
|
|
import { NotebookModel } from 'sql/parts/notebook/models/notebookModel';
|
|
import { getErrorMessage } from 'sql/parts/notebook/notebookUtils';
|
|
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
|
|
import { NOTFOUND } from 'dns';
|
|
import { NsfwWatcherService } from 'vs/workbench/services/files/node/watcher/nsfw/nsfwWatcherService';
|
|
|
|
let notebookMoreActionMsg = localize('notebook.failed', "Please select active cell and try again");
|
|
export class RunCellAction extends Action {
|
|
public static ID = 'jobaction.notebookRunCell';
|
|
public static LABEL = 'Run cell';
|
|
|
|
constructor(
|
|
) {
|
|
super(RunCellAction.ID, '', 'toolbarIconRun');
|
|
this.tooltip = localize('runCell', 'Run cell');
|
|
}
|
|
|
|
public run(context: any): TPromise<boolean> {
|
|
return new TPromise<boolean>((resolve, reject) => {
|
|
try {
|
|
resolve(true);
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
export class AddCellAction extends Action {
|
|
constructor(
|
|
id: string, label: string, private cellType: CellType, private isAfter: boolean, private notificationService: INotificationService
|
|
) {
|
|
super(id, label);
|
|
}
|
|
public run(model: NotebookModel): TPromise<boolean> {
|
|
return new TPromise<boolean>((resolve, reject) => {
|
|
try {
|
|
if (!model) {
|
|
return;
|
|
}
|
|
if (model.activeCell === undefined) {
|
|
this.notificationService.notify({
|
|
severity: Severity.Error,
|
|
message: notebookMoreActionMsg
|
|
});
|
|
}
|
|
else {
|
|
let index = model.cells.findIndex((cell) => cell.id === model.activeCell.id);
|
|
if (index !== undefined && this.isAfter) {
|
|
index += 1;
|
|
}
|
|
model.addCell(this.cellType, index);
|
|
}
|
|
} catch (error) {
|
|
let message = getErrorMessage(error);
|
|
|
|
this.notificationService.notify({
|
|
severity: Severity.Error,
|
|
message: message
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
export class DeleteCellAction extends Action {
|
|
constructor(
|
|
id: string, label: string, private cellType: CellType, private isAfter: boolean, private notificationService: INotificationService
|
|
) {
|
|
super(id, label);
|
|
}
|
|
public run(model: NotebookModel): TPromise<boolean> {
|
|
return new TPromise<boolean>((resolve, reject) => {
|
|
try {
|
|
if (!model) {
|
|
return;
|
|
}
|
|
if (model.activeCell === undefined) {
|
|
this.notificationService.notify({
|
|
severity: Severity.Error,
|
|
message: notebookMoreActionMsg
|
|
});
|
|
}
|
|
else {
|
|
model.deleteCell(model.activeCell);
|
|
}
|
|
} catch (error) {
|
|
let message = getErrorMessage(error);
|
|
|
|
this.notificationService.notify({
|
|
severity: Severity.Error,
|
|
message: message
|
|
});
|
|
}
|
|
});
|
|
}
|
|
} |