Skip to content

Commit

Permalink
Activate only the appropriate pairing options
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jun 17, 2019
1 parent ffbdc24 commit abafe01
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
28 changes: 19 additions & 9 deletions jupytext/nbextension/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ define([
checkAutosave();
}

function jupytext_pair(formats, text) {
return $('<li/>').append($('<a/>')
function jupytext_pair(formats, text, active) {
return $('<li/>')
.addClass(active ? null : 'disabled')
.append($('<a/>')
.attr('id', 'jupytext_pair_' + formats.replace(':', '_').replace(',', '_'))
.text(text)
.attr('title',
Expand Down Expand Up @@ -137,14 +139,22 @@ define([
JupytextActions.append($('<li/>').addClass('divider'));
JupytextActions.append(toggle_autosave);
JupytextActions.append($('<li/>').addClass('divider'));
JupytextActions.append(jupytext_pair('ipynb,auto:light', 'Pair Notebook with light Script'));
JupytextActions.append(jupytext_pair('ipynb,auto:percent', 'Pair Notebook with percent Script'));
JupytextActions.append(jupytext_pair('ipynb,auto:hydrogen', 'Pair Notebook with Hydrogen Script'));
JupytextActions.append(jupytext_pair('ipynb,md', 'Pair Notebook with Markdown'));
JupytextActions.append(jupytext_pair('ipynb,Rmd', 'Pair Notebook with R Markdown'));
JupytextActions.append(jupytext_pair('custom', 'Custom pairing'));

var notebook_extension = Jupyter.notebook.notebook_path.split('.').pop();
var active = (notebook_extension === 'ipynb' || (notebook_extension != 'md' && notebook_extension != 'Rmd'));
JupytextActions.append(jupytext_pair('ipynb,auto:light', 'Pair Notebook with light Script', active));
JupytextActions.append(jupytext_pair('ipynb,auto:percent', 'Pair Notebook with percent Script', active));
JupytextActions.append(jupytext_pair('ipynb,auto:hydrogen', 'Pair Notebook with Hydrogen Script', active));

active = (notebook_extension === 'ipynb' || notebook_extension === 'md');
JupytextActions.append(jupytext_pair('ipynb,md', 'Pair Notebook with Markdown', active));

active = (notebook_extension === 'ipynb' || notebook_extension === 'Rmd');
JupytextActions.append(jupytext_pair('ipynb,Rmd', 'Pair Notebook with R Markdown', active));

JupytextActions.append(jupytext_pair('custom', 'Custom pairing', true));
JupytextActions.append($('<li/>').addClass('divider'));
JupytextActions.append(jupytext_pair('none', 'Unpair notebook'));
JupytextActions.append(jupytext_pair('none', 'Unpair notebook', true));

$('#jupytext_sub_menu').after('<li class="divider"/>');

Expand Down
12 changes: 12 additions & 0 deletions packages/labextension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ const extension: JupyterLabPlugin<void> = {

return jupytext_formats == formats;
},
isEnabled: () => {
if (formats == "custom" || formats == "none")
return true;
const notebook_extension: string = notebook_tracker.currentWidget.context.path.split('.').pop();
if (notebook_extension == "ipynb")
return true;
if (notebook_extension == "md")
return formats == "ipynb,md";
if (notebook_extension == "Rmd")
return formats == "ipynb,Rmd";
return formats != "ipynb,md" && formats != "ipynb,Rmd";
},
execute: () => {
console.log("Jupytext: executing command=" + command);
if (formats == "custom") {
Expand Down

0 comments on commit abafe01

Please sign in to comment.