##// END OF EJS Templates
allow selecting codemirror keymap in menu
allow selecting codemirror keymap in menu

File last commit:

r19306:46d6da0d
r19306:46d6da0d
Show More
menubar.js
101 lines | 3.3 KiB | application/javascript | JavascriptLexer
Thomas Kluyver
Saving files works
r19012 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'base/js/namespace',
'jquery',
'base/js/utils',
'bootstrap',
], function(IPython, $, utils, bootstrap) {
"use strict";
var MenuBar = function (selector, options) {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* Constructor
*
* A MenuBar Class to generate the menubar of IPython notebook
*
* Parameters:
* selector: string
* options: dictionary
* Dictionary of keyword arguments.
* codemirror: CodeMirror instance
* contents: ContentManager instance
* events: $(Events) instance
* base_url : string
* file_path : string
*/
Thomas Kluyver
Saving files works
r19012 options = options || {};
this.base_url = options.base_url || utils.get_body_data("baseUrl");
this.selector = selector;
Thomas Kluyver
Refactor editor into Editor class
r19013 this.editor = options.editor;
Min RK
editor progress...
r19303 this.events = options.events;
Thomas Kluyver
Saving files works
r19012
if (this.selector !== undefined) {
this.element = $(selector);
this.bind_events();
}
};
MenuBar.prototype.bind_events = function () {
Jonathan Frederic
Ran function comment conversion tool
r19176 /**
* File
*/
Thomas Kluyver
Saving files works
r19012 var that = this;
Min RK
editor progress...
r19303 var editor = that.editor;
this.element.find('#save-file').click(function () {
editor.save();
});
// Edit
this.element.find('#menu-find').click(function () {
editor.codemirror.execCommand("find");
});
this.element.find('#menu-replace').click(function () {
editor.codemirror.execCommand("replace");
});
Min RK
allow selecting codemirror keymap in menu
r19306 this.element.find('#menu-keymap-default').click(function () {
editor.update_codemirror_options({
vimMode: false,
keyMap: null
});
});
this.element.find('#menu-keymap-sublime').click(function () {
editor.update_codemirror_options({
vimMode: false,
keyMap: 'sublime'
});
});
this.element.find('#menu-keymap-emacs').click(function () {
editor.update_codemirror_options({
vimMode: false,
keyMap: 'emacs'
});
});
this.element.find('#menu-keymap-vim').click(function () {
editor.update_codemirror_options({
vimMode: true,
keyMap: 'vim'
});
});
Min RK
editor progress...
r19303
// View
this.element.find('#menu-line-numbers').click(function () {
var current = editor.codemirror.getOption('lineNumbers');
var value = Boolean(1-current);
editor.update_codemirror_options({lineNumbers: value});
});
this.events.on("config_changed.Editor", function () {
var lineNumbers = editor.codemirror.getOption('lineNumbers');
var text = lineNumbers ? "Hide" : "Show";
text = text + " Line Numbers";
that.element.find('#menu-line-numbers').find("a").text(text);
Min RK
allow selecting codemirror keymap in menu
r19306 var keyMap = editor.codemirror.getOption('keyMap') || "default";
that.element.find(".selected-keymap").removeClass("selected-keymap");
that.element.find("#menu-keymap-" + keyMap).addClass("selected-keymap");
Thomas Kluyver
Saving files works
r19012 });
};
return {'MenuBar': MenuBar};
});