Make keyboard shortcuts declaratives

Matthias Bussonnier 10 years ago
parent 3feea61802
commit 05a5d8301e

@ -396,6 +396,11 @@ define([
* Remove the binding of shortcut `sortcut` with its action.
* throw an error if trying to remove a non-exiting shortcut
**/
if(!shortcut){
console.warn('trying to remove empty shortcut');
return;
}
shortcut = normalize_shortcut(shortcut);
if( typeof(shortcut) === 'string'){
shortcut = shortcut.split(',');
@ -404,14 +409,15 @@ define([
* The shortcut error should be explicit here, because it will be
* seen by users.
*/
try
{
var that = this;
try {
this._remove_leaf(shortcut, this._shortcuts);
if (!suppress_help_update) {
// update the keyboard shortcuts notebook help
this.events.trigger('rebuild.QuickHelp');
}
} catch (ex) {
console.warn('shortbut', shortcut, '...',this._shortcuts);
throw new Error('trying to remove a non-existent shortcut', shortcut);
}
};

@ -76,4 +76,4 @@
"notebookApp['" + modulePath + "']});`"].join(' '));
return notebookApp[modulePath];
});
});
});

@ -43,8 +43,7 @@ define([
attachments_preset.push('attachments.edit');
CellToolbar.register_preset('Attachments', attachments_preset, notebook);
console.log('Attachments editing toolbar loaded.');
};
return {'register' : register}
return {'register' : register};
});

@ -44,7 +44,6 @@ define([
example_preset.push('default.rawedit');
CellToolbar.register_preset('Edit Metadata', example_preset, notebook);
console.log('Default extension for cell metadata editing loaded.');
};
return {'register': register};
});

@ -78,7 +78,6 @@ define([
raw_cell_preset.push('raw_cell.select');
CellToolbar.register_preset('Raw Cell Format', raw_cell_preset, notebook);
console.log('Raw Cell Format toolbar preset loaded.');
};
return {'register': register};

@ -39,7 +39,6 @@ define([
slideshow_preset.push('slideshow.select');
CellToolbar.register_preset('Slideshow',slideshow_preset, notebook);
console.log('Slideshow extension for metadata editing loaded.');
};
return {'register': register};
});

@ -169,7 +169,7 @@ define(function(require){
group: ["group", "{{group}} command group"],
searchOnFocus: true,
mustSelectItem: true,
template: '<i class="fa fa-icon {{icon}}"></i>{{display}} <div class="pull-right {{mode_shortcut}}">{{shortcut}}</div>',
template: '<i class="fa fa-icon {{icon}}"></i>{{display}} <div title={{key}} class="pull-right {{mode_shortcut}}">{{shortcut}}</div>',
order: "asc",
source: src,
callback: {

@ -42,6 +42,26 @@ define([
this.edit_shortcuts = new keyboard.ShortcutManager(undefined, options.events, this.actions, this.env);
this.edit_shortcuts.add_shortcuts(this.get_default_common_shortcuts());
this.edit_shortcuts.add_shortcuts(this.get_default_edit_shortcuts());
this.config = options.config;
var that = this;
this.config.loaded.then(function(){
(((that.config.data.keys||{}).edit||{})
.unbind||[])
.forEach(function(u){that.edit_shortcuts.remove_shortcut(u)});
(((that.config.data.keys||{}).command||{})
.unbind||[])
.forEach(function(u){that.command_shortcuts.remove_shortcut(u)});
that.command_shortcuts.add_shortcuts( ((that.config.data.keys||{}).command||{}).bind);
that.edit_shortcuts.add_shortcuts( ((that.config.data.keys||{}).edit ||{}).bind);
}
);
Object.seal(this);
};

@ -84,7 +84,9 @@ require([
var keyboard_manager = new keyboardmanager.KeyboardManager({
pager: pager,
events: events,
actions: acts });
actions: acts,
config: config_section,
});
var save_widget = new savewidget.SaveWidget('span#save_widget', {
events: events,
keyboard_manager: keyboard_manager});

@ -164,6 +164,7 @@ define(function (require) {
Object.seal(this);
};
Notebook.options_default = {
// can be any cell type, or the special values of
// 'above', 'below', or 'selected' to get the value from another cell.
@ -2410,7 +2411,7 @@ define(function (require) {
var cell = cells[i];
cell.remove_unused_attachments();
}
}
};
/**
* Load a notebook from JSON (.ipynb).

@ -189,7 +189,7 @@ define([
doc.append(
'The Jupyter Notebook has two different keyboard input modes. <b>Edit mode</b> '+
'allows you to type code/text into a cell and is indicated by a green cell '+
'border. <b>Command mode</b> binds the keyboard to notebook level actions '+
'border. <b>Command mode</b> binds the keyboard to notebook level commands '+
'and is indicated by a grey cell border with a blue left margin.'
);
element.append(doc);

@ -29,11 +29,12 @@ ul.typeahead-list {
}
.no-shortcut{
display:none;
min-width: 20px;
color: transparent;
}
.command-shortcut:before{
content:"(command)";
content:"(command mode)";
padding-right:3px;
color:@gray-light;
}

@ -81,7 +81,7 @@ function(utils) {
if (this.classname) {
return this.section.data[this.classname] || {};
} else {
return this.section.data
return this.section.data;
}
};
@ -92,7 +92,7 @@ function(utils) {
ConfigWithDefaults.prototype.get = function(key) {
var that = this;
return this.section.loaded.then(function() {
return that._class_data()[key] || that.defaults[key]
return that._class_data()[key] || that.defaults[key];
});
};

Loading…
Cancel
Save