Using jupyter-notebook for command prefix.

This commit is contained in:
Brian E. Granger 2015-10-19 15:51:14 -04:00
parent a5e9d96089
commit 8e901e8d0d
8 changed files with 107 additions and 107 deletions

View File

@ -46,7 +46,7 @@ define(function(require){
* 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 the Jupyter notebook are prefixed with `jp-notebook:`.
* 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.
@ -546,13 +546,13 @@ define(function(require){
},
};
// private stuff that prepend `jp-notebook:` 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['jp-notebook:'+subkey] = {};
registry['jp-notebook:'+subkey].help = source[subkey].help||subkey.replace(/-/g,' ');
registry['jp-notebook:'+subkey].help_index = source[subkey].help_index;
registry['jp-notebook:'+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;
};
@ -563,11 +563,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 jp-notebook: 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['jp-notebook:'+key].handler = function(env, event){
final_actions['jupyter-notebook:'+key].handler = function(env, event){
handler(env);
if(event){
event.preventDefault();
@ -584,7 +584,7 @@ define(function(require){
if(custom_ignore.hasOwnProperty(k)){
var handler = _prepare_handler(final_actions, k, custom_ignore);
(function(key, handler){
final_actions['jp-notebook:'+key].handler = function(env, event){
final_actions['jupyter-notebook:'+key].handler = function(env, event){
return handler(env, event);
};
})(k, handler);

View File

@ -62,68 +62,68 @@ define([
*/
KeyboardManager.prototype.get_default_common_shortcuts = function() {
return {
'shift' : 'jp-notebook:ignore',
'shift-enter' : 'jp-notebook:run-cell-and-select-next',
'ctrl-enter' : 'jp-notebook:run-cell',
'alt-enter' : 'jp-notebook:run-cell-and-insert-below',
'shift' : 'jupyter-notebook:ignore',
'shift-enter' : 'jupyter-notebook:run-cell-and-select-next',
'ctrl-enter' : 'jupyter-notebook:run-cell',
'alt-enter' : 'jupyter-notebook:run-cell-and-insert-below',
// cmd on mac, ctrl otherwise
'cmdtrl-s' : 'jp-notebook:save-notebook',
'cmdtrl-s' : 'jupyter-notebook:save-notebook',
};
};
KeyboardManager.prototype.get_default_edit_shortcuts = function() {
return {
'cmdtrl-shift-p' : 'jp-notebook:show-command-palette',
'esc' : 'jp-notebook:enter-command-mode',
'ctrl-m' : 'jp-notebook:enter-command-mode',
'up' : 'jp-notebook:move-cursor-up',
'down' : 'jp-notebook:move-cursor-down',
'ctrl-shift--' : 'jp-notebook:split-cell-at-cursor',
'ctrl-shift-subtract' : 'jp-notebook:split-cell-at-cursor',
'cmdtrl-shift-p' : 'jupyter-notebook:show-command-palette',
'esc' : 'jupyter-notebook:enter-command-mode',
'ctrl-m' : 'jupyter-notebook:enter-command-mode',
'up' : 'jupyter-notebook:move-cursor-up',
'down' : 'jupyter-notebook:move-cursor-down',
'ctrl-shift--' : 'jupyter-notebook:split-cell-at-cursor',
'ctrl-shift-subtract' : 'jupyter-notebook:split-cell-at-cursor',
};
};
KeyboardManager.prototype.get_default_command_shortcuts = function() {
return {
'cmdtrl-shift-p': 'jp-notebook:show-command-palette',
'shift-space': 'jp-notebook:scroll-notebook-up',
'shift-v' : 'jp-notebook:paste-cell-above',
'shift-m' : 'jp-notebook:merge-cells',
'shift-o' : 'jp-notebook:toggle-cell-output-scrolling',
'enter' : 'jp-notebook:enter-edit-mode',
'space' : 'jp-notebook:scroll-notebook-down',
'down' : 'jp-notebook:select-next-cell',
'i,i' : 'jp-notebook:interrupt-kernel',
'0,0' : 'jp-notebook:confirm-restart-kernel',
'd,d' : 'jp-notebook:delete-cell',
'esc': 'jp-notebook:close-pager',
'up' : 'jp-notebook:select-previous-cell',
'k' : 'jp-notebook:select-previous-cell',
'j' : 'jp-notebook:select-next-cell',
'shift-k': 'jp-notebook:extend-marked-cells-above',
'shift-j': 'jp-notebook:extend-marked-cells-below',
'shift-up': 'jp-notebook:extend-marked-cells-above',
'shift-down': 'jp-notebook:extend-marked-cells-below',
'x' : 'jp-notebook:cut-cell',
'c' : 'jp-notebook:copy-cell',
'v' : 'jp-notebook:paste-cell-below',
'a' : 'jp-notebook:insert-cell-above',
'b' : 'jp-notebook:insert-cell-below',
'y' : 'jp-notebook:change-cell-to-code',
'm' : 'jp-notebook:change-cell-to-markdown',
'r' : 'jp-notebook:change-cell-to-raw',
'1' : 'jp-notebook:change-cell-to-heading-1',
'2' : 'jp-notebook:change-cell-to-heading-2',
'3' : 'jp-notebook:change-cell-to-heading-3',
'4' : 'jp-notebook:change-cell-to-heading-4',
'5' : 'jp-notebook:change-cell-to-heading-5',
'6' : 'jp-notebook:change-cell-to-heading-6',
'o' : 'jp-notebook:toggle-cell-output-visibility',
's' : 'jp-notebook:save-notebook',
'l' : 'jp-notebook:toggle-cell-line-numbers',
'h' : 'jp-notebook:show-keyboard-shortcuts',
'z' : 'jp-notebook:undo-cell-deletion',
'q' : 'jp-notebook:close-pager',
'cmdtrl-shift-p': 'jupyter-notebook:show-command-palette',
'shift-space': 'jupyter-notebook:scroll-notebook-up',
'shift-v' : 'jupyter-notebook:paste-cell-above',
'shift-m' : 'jupyter-notebook:merge-cells',
'shift-o' : 'jupyter-notebook:toggle-cell-output-scrolling',
'enter' : 'jupyter-notebook:enter-edit-mode',
'space' : 'jupyter-notebook:scroll-notebook-down',
'down' : 'jupyter-notebook:select-next-cell',
'i,i' : 'jupyter-notebook:interrupt-kernel',
'0,0' : 'jupyter-notebook:confirm-restart-kernel',
'd,d' : 'jupyter-notebook:delete-cell',
'esc': 'jupyter-notebook:close-pager',
'up' : 'jupyter-notebook:select-previous-cell',
'k' : 'jupyter-notebook:select-previous-cell',
'j' : 'jupyter-notebook:select-next-cell',
'shift-k': 'jupyter-notebook:extend-marked-cells-above',
'shift-j': 'jupyter-notebook:extend-marked-cells-below',
'shift-up': 'jupyter-notebook:extend-marked-cells-above',
'shift-down': 'jupyter-notebook:extend-marked-cells-below',
'x' : 'jupyter-notebook:cut-cell',
'c' : 'jupyter-notebook:copy-cell',
'v' : 'jupyter-notebook:paste-cell-below',
'a' : 'jupyter-notebook:insert-cell-above',
'b' : 'jupyter-notebook:insert-cell-below',
'y' : 'jupyter-notebook:change-cell-to-code',
'm' : 'jupyter-notebook:change-cell-to-markdown',
'r' : 'jupyter-notebook:change-cell-to-raw',
'1' : 'jupyter-notebook:change-cell-to-heading-1',
'2' : 'jupyter-notebook:change-cell-to-heading-2',
'3' : 'jupyter-notebook:change-cell-to-heading-3',
'4' : 'jupyter-notebook:change-cell-to-heading-4',
'5' : 'jupyter-notebook:change-cell-to-heading-5',
'6' : 'jupyter-notebook:change-cell-to-heading-6',
'o' : 'jupyter-notebook:toggle-cell-output-visibility',
's' : 'jupyter-notebook:save-notebook',
'l' : 'jupyter-notebook:toggle-cell-line-numbers',
'h' : 'jupyter-notebook:show-keyboard-shortcuts',
'z' : 'jupyter-notebook:undo-cell-deletion',
'q' : 'jupyter-notebook:close-pager',
};
};

View File

@ -32,30 +32,30 @@ define([
MainToolBar.prototype._make = function () {
var grps = [
[
['jp-notebook:save-notebook'],
['jupyter-notebook:save-notebook'],
'save-notbook'
],
[
['jp-notebook:insert-cell-below'],
['jupyter-notebook:insert-cell-below'],
'insert_above_below'],
[
['jp-notebook:cut-cell',
'jp-notebook:copy-cell',
'jp-notebook:paste-cell-below'
['jupyter-notebook:cut-cell',
'jupyter-notebook:copy-cell',
'jupyter-notebook:paste-cell-below'
] ,
'cut_copy_paste'],
[
['jp-notebook:move-cell-up',
'jp-notebook:move-cell-down'
['jupyter-notebook:move-cell-up',
'jupyter-notebook:move-cell-down'
],
'move_up_down'],
[ ['jp-notebook:run-cell-and-select-next',
'jp-notebook:interrupt-kernel',
'jp-notebook:confirm-restart-kernel'
[ ['jupyter-notebook:run-cell-and-select-next',
'jupyter-notebook:interrupt-kernel',
'jupyter-notebook:confirm-restart-kernel'
],
'run_int'],
['<add_celltype_list>'],
[['jp-notebook:show-command-palette']]
[['jupyter-notebook:show-command-palette']]
];
this.construct(grps);
};

View File

@ -203,37 +203,37 @@ define([
});
var id_actions_dict = {
'#find_and_replace' : 'jp-notebook:find-and-replace',
'#save_checkpoint': 'jp-notebook:save-notebook',
'#restart_kernel': 'jp-notebook:confirm-restart-kernel',
'#restart_clear_output': 'jp-notebook:confirm-restart-kernel-and-clear-output',
'#restart_run_all': 'jp-notebook:confirm-restart-kernel-and-run-all-cells',
'#int_kernel': 'jp-notebook:interrupt-kernel',
'#cut_cell': 'jp-notebook:cut-cell',
'#copy_cell': 'jp-notebook:copy-cell',
'#delete_cell': 'jp-notebook:delete-cell',
'#undelete_cell': 'jp-notebook:undo-cell-deletion',
'#split_cell': 'jp-notebook:split-cell-at-cursor',
'#merge_cell_above': 'jp-notebook:merge-cell-with-previous-cell',
'#merge_cell_below': 'jp-notebook:merge-cell-with-next-cell',
'#move_cell_up': 'jp-notebook:move-cell-up',
'#move_cell_down': 'jp-notebook:move-cell-down',
'#toggle_header': 'jp-notebook:toggle-header',
'#toggle_toolbar': 'jp-notebook:toggle-toolbar',
'#insert_cell_above': 'jp-notebook:insert-cell-above',
'#insert_cell_below': 'jp-notebook:insert-cell-below',
'#run_cell': 'jp-notebook:run-cell',
'#run_cell_select_below': 'jp-notebook:run-cell-and-select-next',
'#run_cell_insert_below': 'jp-notebook:run-cell-and-insert-below',
'#run_all_cells': 'jp-notebook:run-all-cells',
'#run_all_cells_above': 'jp-notebook:run-all-cells-above',
'#run_all_cells_below': 'jp-notebook:run-all-cells-below',
'#to_code': 'jp-notebook:change-cell-to-code',
'#to_markdown': 'jp-notebook:change-cell-to-markdown',
'#to_raw': 'jp-notebook:change-cell-to-raw',
'#toggle_current_output': 'jp-notebook:toggle-cell-output-visibility',
'#toggle_current_output_scroll': 'jp-notebook:toggle-cell-output-scrolling',
'#clear_current_output': 'jp-notebook:clear-cell-output',
'#find_and_replace' : 'jupyter-notebook:find-and-replace',
'#save_checkpoint': 'jupyter-notebook:save-notebook',
'#restart_kernel': 'jupyter-notebook:confirm-restart-kernel',
'#restart_clear_output': 'jupyter-notebook:confirm-restart-kernel-and-clear-output',
'#restart_run_all': 'jupyter-notebook:confirm-restart-kernel-and-run-all-cells',
'#int_kernel': 'jupyter-notebook:interrupt-kernel',
'#cut_cell': 'jupyter-notebook:cut-cell',
'#copy_cell': 'jupyter-notebook:copy-cell',
'#delete_cell': 'jupyter-notebook:delete-cell',
'#undelete_cell': 'jupyter-notebook:undo-cell-deletion',
'#split_cell': 'jupyter-notebook:split-cell-at-cursor',
'#merge_cell_above': 'jupyter-notebook:merge-cell-with-previous-cell',
'#merge_cell_below': 'jupyter-notebook:merge-cell-with-next-cell',
'#move_cell_up': 'jupyter-notebook:move-cell-up',
'#move_cell_down': 'jupyter-notebook:move-cell-down',
'#toggle_header': 'jupyter-notebook:toggle-header',
'#toggle_toolbar': 'jupyter-notebook:toggle-toolbar',
'#insert_cell_above': 'jupyter-notebook:insert-cell-above',
'#insert_cell_below': 'jupyter-notebook:insert-cell-below',
'#run_cell': 'jupyter-notebook:run-cell',
'#run_cell_select_below': 'jupyter-notebook:run-cell-and-select-next',
'#run_cell_insert_below': 'jupyter-notebook:run-cell-and-insert-below',
'#run_all_cells': 'jupyter-notebook:run-all-cells',
'#run_all_cells_above': 'jupyter-notebook:run-all-cells-above',
'#run_all_cells_below': 'jupyter-notebook:run-all-cells-below',
'#to_code': 'jupyter-notebook:change-cell-to-code',
'#to_markdown': 'jupyter-notebook:change-cell-to-markdown',
'#to_raw': 'jupyter-notebook:change-cell-to-raw',
'#toggle_current_output': 'jupyter-notebook:toggle-cell-output-visibility',
'#toggle_current_output_scroll': 'jupyter-notebook:toggle-cell-output-scrolling',
'#clear_current_output': 'jupyter-notebook:clear-cell-output',
};
for(var idx in id_actions_dict){

View File

@ -273,7 +273,7 @@ define([
var build_div = function (title, shortcuts) {
// Remove jp-notebook:ignore shortcuts.
// Remove jupyter-notebook:ignore shortcuts.
shortcuts = shortcuts.filter(function(shortcut) {
if (shortcut.help === 'ignore') {
return false;

View File

@ -377,10 +377,10 @@ define(function(require){
}
};
var act_all = keyboard_manager.actions.register(action_all, 'find-and-replace', 'jp-notebook');
var act_all = keyboard_manager.actions.register(action_all, 'find-and-replace', 'jupyter-notebook');
keyboard_manager.command_shortcuts.add_shortcuts({
'f': 'jp-notebook:find-and-replace'
'f': 'jupyter-notebook:find-and-replace'
});
};

View File

@ -66,7 +66,7 @@ casper.notebook_test(function () {
IPython.notebook.select(0);
cell.clear_output();
cell.set_text('a=13; print(a)');
$("button[data-jupyter-action='jp-notebook:run-cell-and-select-next']")[0].click()
$("button[data-jupyter-action='jupyter-notebook:run-cell-and-select-next']")[0].click()
});
this.wait_for_output(0);

View File

@ -30,7 +30,7 @@ casper.notebook_test(function () {
$('#cell_type').val('markdown').change();
var cell = IPython.notebook.get_selected_cell();
cell.set_text('*Baz*');
$("button[data-jupyter-action='jp-notebook:run-cell-and-select-next']")[0].click();
$("button[data-jupyter-action='jupyter-notebook:run-cell-and-select-next']")[0].click();
return cell.get_rendered();
});
this.test.assertEquals(output.trim(), '<p><em>Baz</em></p>', 'Markdown toolbar items work.');