Skip to content

Commit

Permalink
Merge pull request #516 from vidartf/th-config
Browse files Browse the repository at this point in the history
Add extensions configurator
  • Loading branch information
vidartf committed Mar 9, 2020
2 parents a506b66 + d4f8247 commit a9435d5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
43 changes: 32 additions & 11 deletions nbdime/notebook_ext/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ define([
], function(Jupyter, $, utils) {
"use strict";

// params are updated on config load
var params = {
add_checkpoints_toolbar_button: true,
add_git_toolbar_button: true,
};

// Custom util functions:
var reStripLeading = /^\/+/
var stripLeft = function (string) {
Expand Down Expand Up @@ -120,28 +126,40 @@ define([
help: 'Display nbdiff from git HEAD to currently saved version',
handler : nbGitDiffView
}, 'diff-notebook-git', prefix);
}

// Add both buttons, with label on git button
var btn_group = Jupyter.toolbar.add_buttons_group([
checkpointAction,
{
action: gitAction,
label: 'nbdiff',
}]);
if (isGit && params.add_git_toolbar_button) {
if (params.add_checkpoints_toolbar_button) {
// Add both buttons, with label on git button
var btn_group = Jupyter.toolbar.add_buttons_group([
checkpointAction,
{
action: gitAction,
label: 'nbdiff',
}]);
} else {
// Add only git button, with label on it
var btn_group = Jupyter.toolbar.add_buttons_group([{
action: gitAction,
label: 'nbdiff',
}]);
};

// Tooltip for git button:
btn_group.children(':last-child').attr('title', Jupyter.actions.get(gitAction).help);
} else {
if (typeof btn_group !== 'undefined') {
btn_group.children(':last-child').attr('title', Jupyter.actions.get(gitAction).help);
}
} else if (params.add_checkpoints_toolbar_button) {
// Add only checkpoint button, with label on it
var btn_group = Jupyter.toolbar.add_buttons_group([{
action: checkpointAction,
label: 'nbdiff',
}]);
}

if (serverMissing) {
if (serverMissing) {
setActionEnabledState(checkpointAction, false);
console.error(serverMissingMsg);
}
}

// Tooltip for checkpoint button:
Expand All @@ -159,6 +177,9 @@ define([
// Assume that we don't have git
register(false, error);
});

// Update params:
$.extend(true, params, Jupyter.notebook.config.data.nbdime);
};

return {
Expand Down
16 changes: 16 additions & 0 deletions nbdime/notebook_ext/nbdime.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Type: Jupyter Notebook Extension
Name: nbdime
Description: Tools for diffing and merging of Jupyter notebooks.
Main: index.js
Compatibility: Jupyter 4.x, 5.x
Parameters:

- name: nbdime.add_checkpoints_toolbar_button
description: Add a toolbar button to diff against checkpointed notebook
input_type: checkbox
default: true

- name: nbdime.add_git_toolbar_button
description: Add a toolbar button to diff against most recently git committed notebook
input_type: checkbox
default: true

0 comments on commit a9435d5

Please sign in to comment.