@ -1,6 +1,20 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
// How to pick action names:
//
// * First pick a noun and a verb for the action. For example, if the action is "restart kernel," the verb is
// "restart" and the noun is "kernel".
// * Omit terms like "selected" and "active" by default, so "delete-cell", rather than "delete-selected-cell".
// Only provide a scope like "-all-" if it is other than the default "selected" or "active" scope.
// * If an action has a secondary action, separate the secondary action with "-and-", so
// "restart-kernel-and-clear-output".
// * Don't ever use before/after as they have a temporal connotation that is confusing when used in a spatial
// context.
// * Use above/below or previous/next to indicate spacial and sequential relationships.
// * For dialogs, use a verb that indicates what the dialog will accomplish, such as "confirm-restart-kernel".
define ( function ( require ) {
"use strict" ;
@ -27,35 +41,64 @@ define(function(require){
*
* action need to be registered with a * * name * * that can be use to refer to this action .
*
*
* if ` help ` is not provided it will be derived by replacing any dash by space
* in the * * name * * of the action . It is advised to provide a prefix to action name to
* avoid conflict the prefix should be all lowercase and end with a dot ` . `
* in the absence of a prefix the behavior of the action is undefined .
*
* All action provided by Jupyter are prefixed with ` ipython. ` .
* All action provided by the Jupyter notebook are prefixed with ` jupyter-notebook: ` .
*
* One can register extra actions or replace an existing action with another one is possible
* but is considered undefined behavior .
*
* * /
var _actions = {
'toggle-toolbar' : {
help : 'hide/show the toolbar' ,
handler : function ( env ) {
$ ( 'div#maintoolbar' ) . toggle ( ) ;
events . trigger ( 'resize-header.Page' ) ;
'restart-kernel' : {
help : 'restart the kernel (no confirmation dialog)' ,
handler : function ( env ) {
env . notebook . restart _kernel ( { confirm : false } ) ;
} ,
} ,
'confirm-restart-kernel' : {
icon : 'fa-repeat' ,
help _index : 'hb' ,
help : 'restart the kernel (with dialog)' ,
handler : function ( env ) {
env . notebook . restart _kernel ( ) ;
}
} ,
'toggle-header' : {
help : 'hide/show the header' ,
handler : function ( env ) {
$ ( '#header-container' ) . toggle ( ) ;
$ ( '.header-bar' ) . toggle ( ) ;
events . trigger ( 'resize-header.Page' ) ;
'restart-kernel-and-run-all-cells' : {
help : 'restart the kernel, then re-run the whole notebook (no confirmation dialog)' ,
handler : function ( env ) {
env . notebook . restart _run _all ( { confirm : false } ) ;
}
} ,
'confirm-restart-kernel-and-run-all-cells' : {
help : 'restart the kernel, then re-run the whole notebook (with dialog)' ,
handler : function ( env ) {
env . notebook . restart _run _all ( ) ;
}
} ,
'restart-kernel-and-clear-output' : {
help : 'restart the kernel and clear all output (no confirmation dialog)' ,
handler : function ( env ) {
env . notebook . restart _clear _output ( { confirm : false } ) ;
}
} ,
'confirm-restart-kernel-and-clear-output' : {
help : 'restart the kernel and clear all output (with dialog)' ,
handler : function ( env ) {
env . notebook . restart _clear _output ( ) ;
}
} ,
'run-select-next' : {
'interrupt-kernel' : {
icon : 'fa-stop' ,
help _index : 'ha' ,
handler : function ( env ) {
env . notebook . kernel . interrupt ( ) ;
}
} ,
'run-cell-and-select-next' : {
icon : 'fa-step-forward' ,
help : 'run cell, select below' ,
help _index : 'ba' ,
@ -63,14 +106,14 @@ define(function(require){
env . notebook . execute _cell _and _select _below ( ) ;
}
} ,
' execute-in-place ': {
' run-cell ': {
help : 'run cell' ,
help _index : 'bb' ,
handler : function ( env ) {
env . notebook . execute _cell ( ) ;
}
} ,
' execute-and-insert-after ': {
' run-cell-and-insert-below ': {
help : 'run cell, insert below' ,
help _index : 'bc' ,
handler : function ( env ) {
@ -84,43 +127,6 @@ define(function(require){
env . notebook . execute _all _cells ( ) ;
}
} ,
'restart-run-all-dialog' : {
help : 'restart the kernel, then re-run the whole notebook (with dialog)' ,
handler : function ( env ) {
env . notebook . restart _run _all ( ) ;
}
} ,
'restart-clear-output-dialog' : {
help : 'restart the kernel and clear all output (with dialog)' ,
handler : function ( env ) {
env . notebook . restart _clear _output ( ) ;
}
} ,
'restart-dialog' : {
help : 'restart the kernel (with dialog)' ,
help _index : 'bf' ,
handler : function ( env ) {
env . notebook . restart _kernel ( ) ;
} ,
} ,
'restart-run-all' : {
help : 'restart the kernel, then re-run the whole notebook (no confirmation dialog)' ,
handler : function ( env ) {
env . notebook . restart _run _all ( { confirm : false } ) ;
}
} ,
'restart-clear-output' : {
help : 'restart the kernel and clear all output (no confirmation dialog)' ,
handler : function ( env ) {
env . notebook . restart _clear _output ( { confirm : false } ) ;
}
} ,
'restart' : {
help : 'restart the kernel (no confirmation dialog)' ,
handler : function ( env ) {
env . notebook . restart _kernel ( { confirm : false } ) ;
} ,
} ,
'run-all-cells-above' : {
handler : function ( env ) {
env . notebook . execute _cells _above ( ) ;
@ -131,7 +137,7 @@ define(function(require){
env . notebook . execute _cells _below ( ) ;
}
} ,
' go-to -command-mode': {
' enter -command-mode': {
help : 'command mode' ,
help _index : 'aa' ,
handler : function ( env ) {
@ -173,21 +179,21 @@ define(function(require){
}
}
} ,
'extend-marked- previous ' : {
help : 'extend marked above',
'extend-marked- cells-above ' : {
help : 'extend marked cells above',
help _index : 'dc' ,
handler : function ( env ) {
env . notebook . extend _marked ( - 1 ) ;
}
} ,
'extend-marked- next ' : {
help : 'extend marked below',
'extend-marked- cells-below ' : {
help : 'extend marked cells below',
help _index : 'dd' ,
handler : function ( env ) {
env . notebook . extend _marked ( 1 ) ;
}
} ,
'cut- selected- cell' : {
'cut- cell' : {
icon : 'fa-cut' ,
help _index : 'ee' ,
handler : function ( env ) {
@ -196,21 +202,21 @@ define(function(require){
env . notebook . select ( index ) ;
}
} ,
'copy- selected- cell' : {
'copy- cell' : {
icon : 'fa-copy' ,
help _index : 'ef' ,
handler : function ( env ) {
env . notebook . copy _cell ( ) ;
}
} ,
'paste-cell- befor e' : {
'paste-cell- abov e' : {
help : 'paste cell above' ,
help _index : 'eg' ,
handler : function ( env ) {
env . notebook . paste _cell _above ( ) ;
}
} ,
'paste-cell- after ' : {
'paste-cell- below ' : {
help : 'paste cell below' ,
icon : 'fa-paste' ,
help _index : 'eh' ,
@ -218,7 +224,7 @@ define(function(require){
env . notebook . paste _cell _below ( ) ;
}
} ,
'insert-cell- befor e' : {
'insert-cell- abov e' : {
help : 'insert cell above' ,
help _index : 'ec' ,
handler : function ( env ) {
@ -227,7 +233,7 @@ define(function(require){
env . notebook . focus _cell ( ) ;
}
} ,
'insert-cell- after ' : {
'insert-cell- below ' : {
help : 'insert cell below' ,
icon : 'fa-plus' ,
help _index : 'ed' ,
@ -237,110 +243,110 @@ define(function(require){
env . notebook . focus _cell ( ) ;
}
} ,
'change- selected- cell-to-code-cell ' : {
'change- cell-to-code' : {
help : 'to code' ,
help _index : 'ca' ,
handler : function ( env ) {
env . notebook . to _code ( ) ;
}
} ,
'change- selected- cell-to-markdown-cell ' : {
'change- cell-to-markdown' : {
help : 'to markdown' ,
help _index : 'cb' ,
handler : function ( env ) {
env . notebook . to _markdown ( ) ;
}
} ,
'change- selected- cell-to-raw-cell ' : {
'change- cell-to-raw' : {
help : 'to raw' ,
help _index : 'cc' ,
handler : function ( env ) {
env . notebook . to _raw ( ) ;
}
} ,
'change- selected- cell-to-heading-1' : {
'change- cell-to-heading-1' : {
help : 'to heading 1' ,
help _index : 'cd' ,
handler : function ( env ) {
env . notebook . to _heading ( undefined , 1 ) ;
}
} ,
'change- selected- cell-to-heading-2' : {
'change- cell-to-heading-2' : {
help : 'to heading 2' ,
help _index : 'ce' ,
handler : function ( env ) {
env . notebook . to _heading ( undefined , 2 ) ;
}
} ,
'change- selected- cell-to-heading-3' : {
'change- cell-to-heading-3' : {
help : 'to heading 3' ,
help _index : 'cf' ,
handler : function ( env ) {
env . notebook . to _heading ( undefined , 3 ) ;
}
} ,
'change- selected- cell-to-heading-4' : {
'change- cell-to-heading-4' : {
help : 'to heading 4' ,
help _index : 'cg' ,
handler : function ( env ) {
env . notebook . to _heading ( undefined , 4 ) ;
}
} ,
'change- selected- cell-to-heading-5' : {
'change- cell-to-heading-5' : {
help : 'to heading 5' ,
help _index : 'ch' ,
handler : function ( env ) {
env . notebook . to _heading ( undefined , 5 ) ;
}
} ,
'change- selected- cell-to-heading-6' : {
'change- cell-to-heading-6' : {
help : 'to heading 6' ,
help _index : 'ci' ,
handler : function ( env ) {
env . notebook . to _heading ( undefined , 6 ) ;
}
} ,
'toggle- output-visibility-selected-cell ' : {
'toggle- cell- output-visibility' : {
help : 'toggle output' ,
help _index : 'gb' ,
handler : function ( env ) {
env . notebook . toggle _output ( ) ;
}
} ,
'toggle- output-scrolling-selected-cell ' : {
'toggle- cell- output-scrolling' : {
help : 'toggle output scrolling' ,
help _index : 'gc' ,
handler : function ( env ) {
env . notebook . toggle _output _scroll ( ) ;
}
} ,
'clear- output-selected-cell ' : {
'clear- cell- output' : {
handler : function ( env ) {
env . notebook . clear _output ( ) ;
}
} ,
'move- selected- cell-down' : {
'move- cell-down' : {
icon : 'fa-arrow-down' ,
help _index : 'eb' ,
handler : function ( env ) {
env . notebook . move _cell _down ( ) ;
}
} ,
'move- selected- cell-up' : {
'move- cell-up' : {
icon : 'fa-arrow-up' ,
help _index : 'ea' ,
handler : function ( env ) {
env . notebook . move _cell _up ( ) ;
}
} ,
'toggle- line-number- selected-cell ' : {
'toggle- cell- line-numbers' : {
help : 'toggle line numbers' ,
help _index : 'ga' ,
handler : function ( env ) {
env . notebook . cell _toggle _line _numbers ( ) ;
}
} ,
'show-keyboard-shortcut -help-dialog ' : {
'show-keyboard-shortcut s ' : {
help _index : 'ge' ,
handler : function ( env ) {
env . quick _help . show _keyboard _shortcuts ( ) ;
@ -353,21 +359,7 @@ define(function(require){
env . notebook . delete _cell ( ) ;
}
} ,
'interrupt-kernel' : {
icon : 'fa-stop' ,
help _index : 'ha' ,
handler : function ( env ) {
env . notebook . kernel . interrupt ( ) ;
}
} ,
'restart-kernel' : {
icon : 'fa-repeat' ,
help _index : 'hb' ,
handler : function ( env ) {
env . notebook . restart _kernel ( ) ;
}
} ,
'undo-last-cell-deletion' : {
'undo-cell-deletion' : {
help _index : 'ei' ,
handler : function ( env ) {
env . notebook . undelete _cell ( ) ;
@ -375,19 +367,19 @@ define(function(require){
} ,
// TODO reminder
// open an issue, merge with above merge with last cell of notebook if at top.
'merge- selected- cell-with-cell-before ' : {
'merge- cell-with-previous- cell' : {
handler : function ( env ) {
env . notebook . merge _cell _above ( ) ;
}
} ,
'merge- selected- cell-with-cell-after ' : {
'merge- cell-with-next- cell' : {
help : 'merge cell below' ,
help _index : 'ek' ,
handler : function ( env ) {
env . notebook . merge _cell _below ( ) ;
}
} ,
'merge- marked- cells' : {
'merge- cells' : {
help : 'merge marked cells' ,
help _index : 'el' ,
handler : function ( env ) {
@ -400,7 +392,7 @@ define(function(require){
env . pager . collapse ( ) ;
}
} ,
' command-palette': {
' show- command-palette': {
help _index : 'aa' ,
help : 'open the command palette' ,
icon : 'fa-keyboard-o' ,
@ -417,6 +409,35 @@ define(function(require){
env . notebook . get _selected _cell ( ) . marked ^= true ;
}
} ,
'unmark-all-cells' : {
help _index : 'ck' ,
help : 'unmark all cells' ,
handler : function ( env ) {
env . notebook . unmark _all _cells ( ) ;
}
} ,
'mark-all-cells' : {
help _index : 'cl' ,
help : 'mark all cells' ,
handler : function ( env ) {
env . notebook . mark _all _cells ( ) ;
}
} ,
'toggle-toolbar' : {
help : 'hide/show the toolbar' ,
handler : function ( env ) {
$ ( 'div#maintoolbar' ) . toggle ( ) ;
events . trigger ( 'resize-header.Page' ) ;
}
} ,
'toggle-header' : {
help : 'hide/show the header' ,
handler : function ( env ) {
$ ( '#header-container' ) . toggle ( ) ;
$ ( '.header-bar' ) . toggle ( ) ;
events . trigger ( 'resize-header.Page' ) ;
}
}
} ;
/ * *
@ -438,7 +459,7 @@ define(function(require){
return true ;
}
} ,
'move-cursor-up -or-previous-cell ': {
'move-cursor-up ': {
handler : function ( env , event ) {
var index = env . notebook . get _selected _index ( ) ;
var cell = env . notebook . get _cell ( index ) ;
@ -457,7 +478,7 @@ define(function(require){
return false ;
}
} ,
'move-cursor-down -or-next-cell ': {
'move-cursor-down ': {
handler : function ( env , event ) {
var index = env . notebook . get _selected _index ( ) ;
var cell = env . notebook . get _cell ( index ) ;
@ -474,7 +495,7 @@ define(function(require){
return false ;
}
} ,
'scroll- down': {
'scroll- notebook- down': {
handler : function ( env , event ) {
if ( event ) {
event . preventDefault ( ) ;
@ -482,7 +503,7 @@ define(function(require){
return env . notebook . scroll _manager . scroll ( 1 ) ;
} ,
} ,
'scroll- up': {
'scroll- notebook- up': {
handler : function ( env , event ) {
if ( event ) {
event . preventDefault ( ) ;
@ -539,13 +560,13 @@ define(function(require){
} ,
} ;
// private stuff that prepend ` .ipython ` to actions names
// private stuff that prepend ` jupyter-notebook: ` to actions names
// and uniformize/fill in missing pieces in of an action.
var _prepare _handler = function ( registry , subkey , source ) {
registry [ ' ipython. '+ subkey ] = { } ;
registry [ ' ipython. '+ subkey ] . help = source [ subkey ] . help || subkey . replace ( /-/g , ' ' ) ;
registry [ ' ipython. '+ subkey ] . help _index = source [ subkey ] . help _index ;
registry [ ' ipython. '+ subkey ] . icon = source [ subkey ] . icon ;
registry [ ' jupyter-notebook: '+ subkey ] = { } ;
registry [ ' jupyter-notebook: '+ subkey ] . help = source [ subkey ] . help || subkey . replace ( /-/g , ' ' ) ;
registry [ ' jupyter-notebook: '+ subkey ] . help _index = source [ subkey ] . help _index ;
registry [ ' jupyter-notebook: '+ subkey ] . icon = source [ subkey ] . icon ;
return source [ subkey ] . handler ;
} ;
@ -556,11 +577,11 @@ define(function(require){
for ( k in _actions ) {
if ( _actions . hasOwnProperty ( k ) ) {
// Js closure are function level not block level need to wrap in a IIFE
// and append ipython to event name these things do intercept event so are wrapped
// and append jupyter-notebook: to event name these things do intercept event so are wrapped
// in a function that return false.
var handler = _prepare _handler ( final _actions , k , _actions ) ;
( function ( key , handler ) {
final _actions [ ' ipython. '+ key ] . handler = function ( env , event ) {
final _actions [ ' jupyter-notebook: '+ key ] . handler = function ( env , event ) {
handler ( env ) ;
if ( event ) {
event . preventDefault ( ) ;
@ -577,7 +598,7 @@ define(function(require){
if ( custom _ignore . hasOwnProperty ( k ) ) {
var handler = _prepare _handler ( final _actions , k , custom _ignore ) ;
( function ( key , handler ) {
final _actions [ ' ipython. '+ key ] . handler = function ( env , event ) {
final _actions [ ' jupyter-notebook: '+ key ] . handler = function ( env , event ) {
return handler ( env , event ) ;
} ;
} ) ( k , handler ) ;
@ -612,7 +633,7 @@ define(function(require){
name = 'autogenerated-' + String ( action . handler ) ;
}
prefix = prefix || 'auto' ;
var full _name = prefix + ' . '+ name ;
var full _name = prefix + ' : '+ name ;
this . _actions [ full _name ] = action ;
return full _name ;