##// END OF EJS Templates
add File/New in editor
Min RK -
Show More
@@ -1,101 +1,121 b''
1 1 // Copyright (c) IPython Development Team.
2 2 // Distributed under the terms of the Modified BSD License.
3 3
4 4 define([
5 5 'base/js/namespace',
6 6 'jquery',
7 7 'base/js/utils',
8 'base/js/dialog',
8 9 'bootstrap',
9 ], function(IPython, $, utils, bootstrap) {
10 ], function(IPython, $, utils, dialog, bootstrap) {
10 11 "use strict";
11 12
12 13 var MenuBar = function (selector, options) {
13 14 /**
14 15 * Constructor
15 16 *
16 17 * A MenuBar Class to generate the menubar of IPython notebook
17 18 *
18 19 * Parameters:
19 20 * selector: string
20 21 * options: dictionary
21 22 * Dictionary of keyword arguments.
22 23 * codemirror: CodeMirror instance
23 24 * contents: ContentManager instance
24 25 * events: $(Events) instance
25 26 * base_url : string
26 27 * file_path : string
27 28 */
28 29 options = options || {};
29 30 this.base_url = options.base_url || utils.get_body_data("baseUrl");
30 31 this.selector = selector;
31 32 this.editor = options.editor;
32 33 this.events = options.events;
33 34
34 35 if (this.selector !== undefined) {
35 36 this.element = $(selector);
36 37 this.bind_events();
37 38 }
38 39 };
39 40
40 41 MenuBar.prototype.bind_events = function () {
41 /**
42 * File
43 */
44 42 var that = this;
45 43 var editor = that.editor;
44
45 // File
46 this.element.find('#new-file').click(function () {
47 var w = window.open();
48 // Create a new file in the current directory
49 var parent = utils.url_path_split(editor.file_path)[0];
50 editor.contents.new_untitled(parent, {type: "file"}).then(
51 function (data) {
52 w.location = utils.url_join_encode(
53 that.base_url, 'edit', data.path
54 );
55 },
56 function(error) {
57 w.close();
58 dialog.modal({
59 title : 'Creating New File Failed',
60 body : "The error was: " + error.message,
61 buttons : {'OK' : {'class' : 'btn-primary'}}
62 });
63 }
64 );
65 });
46 66 this.element.find('#save-file').click(function () {
47 67 editor.save();
48 68 });
49 69
50 70 // Edit
51 71 this.element.find('#menu-find').click(function () {
52 72 editor.codemirror.execCommand("find");
53 73 });
54 74 this.element.find('#menu-replace').click(function () {
55 75 editor.codemirror.execCommand("replace");
56 76 });
57 77 this.element.find('#menu-keymap-default').click(function () {
58 78 editor.update_codemirror_options({
59 79 vimMode: false,
60 80 keyMap: null
61 81 });
62 82 });
63 83 this.element.find('#menu-keymap-sublime').click(function () {
64 84 editor.update_codemirror_options({
65 85 vimMode: false,
66 86 keyMap: 'sublime'
67 87 });
68 88 });
69 89 this.element.find('#menu-keymap-emacs').click(function () {
70 90 editor.update_codemirror_options({
71 91 vimMode: false,
72 92 keyMap: 'emacs'
73 93 });
74 94 });
75 95 this.element.find('#menu-keymap-vim').click(function () {
76 96 editor.update_codemirror_options({
77 97 vimMode: true,
78 98 keyMap: 'vim'
79 99 });
80 100 });
81 101
82 102 // View
83 103 this.element.find('#menu-line-numbers').click(function () {
84 104 var current = editor.codemirror.getOption('lineNumbers');
85 105 var value = Boolean(1-current);
86 106 editor.update_codemirror_options({lineNumbers: value});
87 107 });
88 108
89 109 this.events.on("config_changed.Editor", function () {
90 110 var lineNumbers = editor.codemirror.getOption('lineNumbers');
91 111 var text = lineNumbers ? "Hide" : "Show";
92 112 text = text + " Line Numbers";
93 113 that.element.find('#menu-line-numbers').find("a").text(text);
94 114 var keyMap = editor.codemirror.getOption('keyMap') || "default";
95 115 that.element.find(".selected-keymap").removeClass("selected-keymap");
96 116 that.element.find("#menu-keymap-" + keyMap).addClass("selected-keymap");
97 117 });
98 118 };
99 119
100 120 return {'MenuBar': MenuBar};
101 121 });
General Comments 0
You need to be logged in to leave comments. Login now