in src/overlay/toolbar.ts [23:91]
export function initToolbar(
notebook: NotebookPanel,
gatherModel: GatherModel,
codeGatheringExtension: CodeGatheringExtension
): Widget[] {
function _getIndexAfterSpacer(notebook: NotebookPanel) {
let index = 1;
let toolNames = notebook.toolbar.names();
let nextName = toolNames.next();
while (nextName != undefined && nextName != 'spacer') {
index += 1;
nextName = toolNames.next();
}
return index;
}
function _addGatherLabel(notebook: NotebookPanel, insertIndex: number) {
let gatherLabelWidget = new Widget();
let labelLayout = (gatherLabelWidget.layout = new PanelLayout());
let gatherLabel = new Widget({ node: document.createElement('span') });
gatherLabel.addClass('jp-GatherLabel');
gatherLabel.node.textContent = 'Gather to:';
labelLayout.addWidget(gatherLabel);
notebook.toolbar.insertItem(insertIndex, 'gatherLabel', gatherLabelWidget);
return gatherLabelWidget;
}
function _addSpacer(notebook: NotebookPanel, insertIndex: number) {
let gatherSpacer = new Widget();
gatherSpacer.addClass('jp-GatherSpacer');
notebook.toolbar.insertItem(insertIndex, 'gatherSpacer', gatherSpacer);
return gatherSpacer;
}
let widgets = [];
let insertIndex = _getIndexAfterSpacer(notebook);
let label = _addGatherLabel(notebook, insertIndex);
widgets.push(label);
insertIndex += 1;
let buttons = [
new GatherToClipboardButton(
gatherModel,
codeGatheringExtension.gatherToClipboard.bind(codeGatheringExtension)
),
new GatherToNotebookButton(
gatherModel,
codeGatheringExtension.gatherToNotebook.bind(codeGatheringExtension)
),
/*
* The following line adds a button for gathering code to a script.
*/
// new GatherToScriptButton(gatherModel, codeGatheringExtension.gatherToScript.bind(codeGatheringExtension)),
new GatherRevisionsButton(
gatherModel,
codeGatheringExtension.gatherRevisions.bind(codeGatheringExtension)
),
new ClearButton(gatherModel),
];
for (let button of buttons) {
notebook.toolbar.insertItem(insertIndex, button.getName(), button);
widgets.push(button);
insertIndex += 1;
}
let spacer = _addSpacer(notebook, insertIndex);
widgets.push(spacer);
return widgets;
}