Show More
@@ -1,159 +1,155 | |||||
1 | // Copyright (c) IPython Development Team. |
|
1 | // Copyright (c) IPython Development Team. | |
2 | // Distributed under the terms of the Modified BSD License. |
|
2 | // Distributed under the terms of the Modified BSD License. | |
3 |
|
3 | |||
4 | define([ |
|
4 | define([ | |
5 | 'jquery', |
|
5 | 'jquery', | |
6 | 'base/js/namespace', |
|
6 | 'base/js/namespace', | |
7 | 'base/js/utils', |
|
7 | 'base/js/utils', | |
8 | 'base/js/dialog', |
|
8 | 'base/js/dialog', | |
9 | 'codemirror/lib/codemirror', |
|
9 | 'codemirror/lib/codemirror', | |
10 | 'codemirror/mode/meta', |
|
10 | 'codemirror/mode/meta', | |
11 | 'bootstrap', |
|
11 | 'bootstrap', | |
12 | ], function($, IPython, utils, dialog, CodeMirror) { |
|
12 | ], function($, IPython, utils, dialog, CodeMirror) { | |
13 | "use strict"; |
|
13 | "use strict"; | |
14 |
|
14 | |||
15 | var MenuBar = function (selector, options) { |
|
15 | var MenuBar = function (selector, options) { | |
16 | /** |
|
16 | /** | |
17 | * Constructor |
|
17 | * Constructor | |
18 | * |
|
18 | * | |
19 | * A MenuBar Class to generate the menubar of IPython notebook |
|
19 | * A MenuBar Class to generate the menubar of IPython notebook | |
20 | * |
|
20 | * | |
21 | * Parameters: |
|
21 | * Parameters: | |
22 | * selector: string |
|
22 | * selector: string | |
23 | * options: dictionary |
|
23 | * options: dictionary | |
24 | * Dictionary of keyword arguments. |
|
24 | * Dictionary of keyword arguments. | |
25 | * codemirror: CodeMirror instance |
|
25 | * codemirror: CodeMirror instance | |
26 | * contents: ContentManager instance |
|
26 | * contents: ContentManager instance | |
27 | * events: $(Events) instance |
|
27 | * events: $(Events) instance | |
28 | * base_url : string |
|
28 | * base_url : string | |
29 | * file_path : string |
|
29 | * file_path : string | |
30 | */ |
|
30 | */ | |
31 | options = options || {}; |
|
31 | options = options || {}; | |
32 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); |
|
32 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); | |
33 | this.selector = selector; |
|
33 | this.selector = selector; | |
34 | this.editor = options.editor; |
|
34 | this.editor = options.editor; | |
35 | this.events = options.events; |
|
35 | this.events = options.events; | |
36 | this.save_widget = options.save_widget; |
|
36 | this.save_widget = options.save_widget; | |
37 |
|
37 | |||
38 | if (this.selector !== undefined) { |
|
38 | if (this.selector !== undefined) { | |
39 | this.element = $(selector); |
|
39 | this.element = $(selector); | |
40 | this.bind_events(); |
|
40 | this.bind_events(); | |
41 | } |
|
41 | } | |
42 | this._load_mode_menu(); |
|
42 | this._load_mode_menu(); | |
43 | Object.seal(this); |
|
43 | Object.seal(this); | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 | MenuBar.prototype.bind_events = function () { |
|
46 | MenuBar.prototype.bind_events = function () { | |
47 | var that = this; |
|
47 | var that = this; | |
48 | var editor = that.editor; |
|
48 | var editor = that.editor; | |
49 |
|
49 | |||
50 | // File |
|
50 | // File | |
51 | this.element.find('#new-file').click(function () { |
|
51 | this.element.find('#new-file').click(function () { | |
52 | var w = window.open(); |
|
52 | var w = window.open(); | |
53 | // Create a new file in the current directory |
|
53 | // Create a new file in the current directory | |
54 | var parent = utils.url_path_split(editor.file_path)[0]; |
|
54 | var parent = utils.url_path_split(editor.file_path)[0]; | |
55 | editor.contents.new_untitled(parent, {type: "file"}).then( |
|
55 | editor.contents.new_untitled(parent, {type: "file"}).then( | |
56 | function (data) { |
|
56 | function (data) { | |
57 | w.location = utils.url_join_encode( |
|
57 | w.location = utils.url_join_encode( | |
58 | that.base_url, 'edit', data.path |
|
58 | that.base_url, 'edit', data.path | |
59 | ); |
|
59 | ); | |
60 | }, |
|
60 | }, | |
61 | function(error) { |
|
61 | function(error) { | |
62 | w.close(); |
|
62 | w.close(); | |
63 | dialog.modal({ |
|
63 | dialog.modal({ | |
64 | title : 'Creating New File Failed', |
|
64 | title : 'Creating New File Failed', | |
65 | body : "The error was: " + error.message, |
|
65 | body : "The error was: " + error.message, | |
66 | buttons : {'OK' : {'class' : 'btn-primary'}} |
|
66 | buttons : {'OK' : {'class' : 'btn-primary'}} | |
67 | }); |
|
67 | }); | |
68 | } |
|
68 | } | |
69 | ); |
|
69 | ); | |
70 | }); |
|
70 | }); | |
71 | this.element.find('#save-file').click(function () { |
|
71 | this.element.find('#save-file').click(function () { | |
72 | editor.save(); |
|
72 | editor.save(); | |
73 | }); |
|
73 | }); | |
74 | this.element.find('#rename-file').click(function () { |
|
74 | this.element.find('#rename-file').click(function () { | |
75 | that.save_widget.rename(); |
|
75 | that.save_widget.rename(); | |
76 | }); |
|
76 | }); | |
77 |
|
77 | |||
78 | // Edit |
|
78 | // Edit | |
79 | this.element.find('#menu-find').click(function () { |
|
79 | this.element.find('#menu-find').click(function () { | |
80 | editor.codemirror.execCommand("find"); |
|
80 | editor.codemirror.execCommand("find"); | |
81 | }); |
|
81 | }); | |
82 | this.element.find('#menu-replace').click(function () { |
|
82 | this.element.find('#menu-replace').click(function () { | |
83 | editor.codemirror.execCommand("replace"); |
|
83 | editor.codemirror.execCommand("replace"); | |
84 | }); |
|
84 | }); | |
85 | this.element.find('#menu-keymap-default').click(function () { |
|
85 | this.element.find('#menu-keymap-default').click(function () { | |
86 | editor.update_codemirror_options({ |
|
86 | editor.update_codemirror_options({ | |
87 | vimMode: false, |
|
87 | vimMode: false, | |
88 | keyMap: 'default' |
|
88 | keyMap: 'default' | |
89 | }); |
|
89 | }); | |
90 | }); |
|
90 | }); | |
91 | this.element.find('#menu-keymap-sublime').click(function () { |
|
91 | this.element.find('#menu-keymap-sublime').click(function () { | |
92 | editor.update_codemirror_options({ |
|
92 | editor.update_codemirror_options({ | |
93 | vimMode: false, |
|
93 | vimMode: false, | |
94 | keyMap: 'sublime' |
|
94 | keyMap: 'sublime' | |
95 | }); |
|
95 | }); | |
96 | }); |
|
96 | }); | |
97 | this.element.find('#menu-keymap-emacs').click(function () { |
|
97 | this.element.find('#menu-keymap-emacs').click(function () { | |
98 | editor.update_codemirror_options({ |
|
98 | editor.update_codemirror_options({ | |
99 | vimMode: false, |
|
99 | vimMode: false, | |
100 | keyMap: 'emacs' |
|
100 | keyMap: 'emacs' | |
101 | }); |
|
101 | }); | |
102 | }); |
|
102 | }); | |
103 | this.element.find('#menu-keymap-vim').click(function () { |
|
103 | this.element.find('#menu-keymap-vim').click(function () { | |
104 | editor.update_codemirror_options({ |
|
104 | editor.update_codemirror_options({ | |
105 | vimMode: true, |
|
105 | vimMode: true, | |
106 | keyMap: 'vim' |
|
106 | keyMap: 'vim' | |
107 | }); |
|
107 | }); | |
108 | }); |
|
108 | }); | |
109 |
|
109 | |||
110 | // View |
|
110 | // View | |
111 | this.element.find('#menu-line-numbers').click(function () { |
|
111 | this.element.find('#menu-line-numbers').click(function () { | |
112 | var current = editor.codemirror.getOption('lineNumbers'); |
|
112 | var current = editor.codemirror.getOption('lineNumbers'); | |
113 | var value = Boolean(1-current); |
|
113 | var value = Boolean(1-current); | |
114 | editor.update_codemirror_options({lineNumbers: value}); |
|
114 | editor.update_codemirror_options({lineNumbers: value}); | |
115 | }); |
|
115 | }); | |
116 |
|
116 | |||
117 | this.events.on("config_changed.Editor", function () { |
|
117 | this.events.on("config_changed.Editor", function () { | |
118 | var lineNumbers = editor.codemirror.getOption('lineNumbers'); |
|
|||
119 | var text = lineNumbers ? "Hide" : "Show"; |
|
|||
120 | text = text + " Line Numbers"; |
|
|||
121 | that.element.find('#menu-line-numbers').find("a").text(text); |
|
|||
122 | var keyMap = editor.codemirror.getOption('keyMap') || "default"; |
|
118 | var keyMap = editor.codemirror.getOption('keyMap') || "default"; | |
123 | that.element.find(".selected-keymap").removeClass("selected-keymap"); |
|
119 | that.element.find(".selected-keymap").removeClass("selected-keymap"); | |
124 | that.element.find("#menu-keymap-" + keyMap).addClass("selected-keymap"); |
|
120 | that.element.find("#menu-keymap-" + keyMap).addClass("selected-keymap"); | |
125 | }); |
|
121 | }); | |
126 |
|
122 | |||
127 | this.events.on("mode_changed.Editor", function (evt, modeinfo) { |
|
123 | this.events.on("mode_changed.Editor", function (evt, modeinfo) { | |
128 | that.element.find("#current-mode") |
|
124 | that.element.find("#current-mode") | |
129 | .text(modeinfo.name) |
|
125 | .text(modeinfo.name) | |
130 | .attr( |
|
126 | .attr( | |
131 | 'title', |
|
127 | 'title', | |
132 | "The current highlighting mode is " + modeinfo.name |
|
128 | "The current highlighting mode is " + modeinfo.name | |
133 | ); |
|
129 | ); | |
134 | }); |
|
130 | }); | |
135 | }; |
|
131 | }; | |
136 |
|
132 | |||
137 | MenuBar.prototype._load_mode_menu = function () { |
|
133 | MenuBar.prototype._load_mode_menu = function () { | |
138 | var list = this.element.find("#mode-menu"); |
|
134 | var list = this.element.find("#mode-menu"); | |
139 | var editor = this.editor; |
|
135 | var editor = this.editor; | |
140 | function make_set_mode(info) { |
|
136 | function make_set_mode(info) { | |
141 | return function () { |
|
137 | return function () { | |
142 | editor.set_codemirror_mode(info); |
|
138 | editor.set_codemirror_mode(info); | |
143 | }; |
|
139 | }; | |
144 | } |
|
140 | } | |
145 | for (var i = 0; i < CodeMirror.modeInfo.length; i++) { |
|
141 | for (var i = 0; i < CodeMirror.modeInfo.length; i++) { | |
146 | var info = CodeMirror.modeInfo[i]; |
|
142 | var info = CodeMirror.modeInfo[i]; | |
147 | list.append($("<li>").append( |
|
143 | list.append($("<li>").append( | |
148 | $("<a>").attr("href", "#") |
|
144 | $("<a>").attr("href", "#") | |
149 | .text(info.name) |
|
145 | .text(info.name) | |
150 | .click(make_set_mode(info)) |
|
146 | .click(make_set_mode(info)) | |
151 | .attr('title', |
|
147 | .attr('title', | |
152 | "Set highlighting mode to " + info.name |
|
148 | "Set highlighting mode to " + info.name | |
153 | ) |
|
149 | ) | |
154 | )); |
|
150 | )); | |
155 | } |
|
151 | } | |
156 | }; |
|
152 | }; | |
157 |
|
153 | |||
158 | return {'MenuBar': MenuBar}; |
|
154 | return {'MenuBar': MenuBar}; | |
159 | }); |
|
155 | }); |
@@ -1,92 +1,92 | |||||
1 | {% extends "page.html" %} |
|
1 | {% extends "page.html" %} | |
2 |
|
2 | |||
3 | {% block title %}{{page_title}}{% endblock %} |
|
3 | {% block title %}{{page_title}}{% endblock %} | |
4 |
|
4 | |||
5 | {% block stylesheet %} |
|
5 | {% block stylesheet %} | |
6 | <link rel="stylesheet" href="{{ static_url('components/codemirror/lib/codemirror.css') }}"> |
|
6 | <link rel="stylesheet" href="{{ static_url('components/codemirror/lib/codemirror.css') }}"> | |
7 | <link rel="stylesheet" href="{{ static_url('components/codemirror/addon/dialog/dialog.css') }}"> |
|
7 | <link rel="stylesheet" href="{{ static_url('components/codemirror/addon/dialog/dialog.css') }}"> | |
8 | {{super()}} |
|
8 | {{super()}} | |
9 | {% endblock %} |
|
9 | {% endblock %} | |
10 |
|
10 | |||
11 | {% block params %} |
|
11 | {% block params %} | |
12 |
|
12 | |||
13 | data-base-url="{{base_url}}" |
|
13 | data-base-url="{{base_url}}" | |
14 | data-file-path="{{file_path}}" |
|
14 | data-file-path="{{file_path}}" | |
15 |
|
15 | |||
16 | {% endblock %} |
|
16 | {% endblock %} | |
17 |
|
17 | |||
18 | {% block headercontainer %} |
|
18 | {% block headercontainer %} | |
19 |
|
19 | |||
20 | <span id="save_widget" class="pull-left save_widget"> |
|
20 | <span id="save_widget" class="pull-left save_widget"> | |
21 | <span class="filename"></span> |
|
21 | <span class="filename"></span> | |
22 | <span class="last_modified"></span> |
|
22 | <span class="last_modified"></span> | |
23 | </span> |
|
23 | </span> | |
24 |
|
24 | |||
25 | {% endblock %} |
|
25 | {% endblock %} | |
26 |
|
26 | |||
27 | {% block header %} |
|
27 | {% block header %} | |
28 |
|
28 | |||
29 | <div id="menubar-container" class="container"> |
|
29 | <div id="menubar-container" class="container"> | |
30 | <div id="menubar"> |
|
30 | <div id="menubar"> | |
31 | <div id="menus" class="navbar navbar-default" role="navigation"> |
|
31 | <div id="menus" class="navbar navbar-default" role="navigation"> | |
32 | <div class="container-fluid"> |
|
32 | <div class="container-fluid"> | |
33 | <button type="button" class="btn btn-default navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> |
|
33 | <button type="button" class="btn btn-default navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> | |
34 | <i class="fa fa-bars"></i> |
|
34 | <i class="fa fa-bars"></i> | |
35 | <span class="navbar-text">Menu</span> |
|
35 | <span class="navbar-text">Menu</span> | |
36 | </button> |
|
36 | </button> | |
37 | <ul class="nav navbar-nav navbar-right"> |
|
37 | <ul class="nav navbar-nav navbar-right"> | |
38 | <li id="notification_area"></li> |
|
38 | <li id="notification_area"></li> | |
39 | </ul> |
|
39 | </ul> | |
40 | <div class="navbar-collapse collapse"> |
|
40 | <div class="navbar-collapse collapse"> | |
41 | <ul class="nav navbar-nav"> |
|
41 | <ul class="nav navbar-nav"> | |
42 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">File</a> |
|
42 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">File</a> | |
43 | <ul id="file-menu" class="dropdown-menu"> |
|
43 | <ul id="file-menu" class="dropdown-menu"> | |
44 | <li id="new-file"><a href="#">New</a></li> |
|
44 | <li id="new-file"><a href="#">New</a></li> | |
45 | <li id="save-file"><a href="#">Save</a></li> |
|
45 | <li id="save-file"><a href="#">Save</a></li> | |
46 | <li id="rename-file"><a href="#">Rename</a></li> |
|
46 | <li id="rename-file"><a href="#">Rename</a></li> | |
47 | </ul> |
|
47 | </ul> | |
48 | </li> |
|
48 | </li> | |
49 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Edit</a> |
|
49 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Edit</a> | |
50 | <ul id="edit-menu" class="dropdown-menu"> |
|
50 | <ul id="edit-menu" class="dropdown-menu"> | |
51 | <li id="menu-find"><a href="#">Find</a></li> |
|
51 | <li id="menu-find"><a href="#">Find</a></li> | |
52 | <li id="menu-replace"><a href="#">Find & Replace</a></li> |
|
52 | <li id="menu-replace"><a href="#">Find & Replace</a></li> | |
53 | <li class="divider"></li> |
|
53 | <li class="divider"></li> | |
54 | <li class="dropdown-header">Key Map</li> |
|
54 | <li class="dropdown-header">Key Map</li> | |
55 | <li id="menu-keymap-default"><a href="#">Default<i class="fa"></i></a></li> |
|
55 | <li id="menu-keymap-default"><a href="#">Default<i class="fa"></i></a></li> | |
56 | <li id="menu-keymap-sublime"><a href="#">Sublime Text<i class="fa"></i></a></li> |
|
56 | <li id="menu-keymap-sublime"><a href="#">Sublime Text<i class="fa"></i></a></li> | |
57 | <li id="menu-keymap-vim"><a href="#">Vim<i class="fa"></i></a></li> |
|
57 | <li id="menu-keymap-vim"><a href="#">Vim<i class="fa"></i></a></li> | |
58 | <li id="menu-keymap-emacs"><a href="#">emacs<i class="fa"></i></a></li> |
|
58 | <li id="menu-keymap-emacs"><a href="#">emacs<i class="fa"></i></a></li> | |
59 | </ul> |
|
59 | </ul> | |
60 | </li> |
|
60 | </li> | |
61 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">View</a> |
|
61 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">View</a> | |
62 | <ul id="view-menu" class="dropdown-menu"> |
|
62 | <ul id="view-menu" class="dropdown-menu"> | |
63 |
<li id="menu-line-numbers"><a href="#"> |
|
63 | <li id="menu-line-numbers"><a href="#">Toggle Line Numbers</a></li> | |
64 | </ul> |
|
64 | </ul> | |
65 | </li> |
|
65 | </li> | |
66 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Mode</a> |
|
66 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Mode</a> | |
67 | <ul id="mode-menu" class="dropdown-menu"> |
|
67 | <ul id="mode-menu" class="dropdown-menu"> | |
68 | </ul> |
|
68 | </ul> | |
69 | </li> |
|
69 | </li> | |
70 | </ul> |
|
70 | </ul> | |
71 | <p id="current-mode" class="navbar-text navbar-right">current mode</p> |
|
71 | <p id="current-mode" class="navbar-text navbar-right">current mode</p> | |
72 | </div> |
|
72 | </div> | |
73 | </div> |
|
73 | </div> | |
74 | </div> |
|
74 | </div> | |
75 | </div> |
|
75 | </div> | |
76 | </div> |
|
76 | </div> | |
77 |
|
77 | |||
78 | {% endblock %} |
|
78 | {% endblock %} | |
79 |
|
79 | |||
80 | {% block site %} |
|
80 | {% block site %} | |
81 |
|
81 | |||
82 |
|
82 | |||
83 | <div id="texteditor-container" class="container"></div> |
|
83 | <div id="texteditor-container" class="container"></div> | |
84 |
|
84 | |||
85 | {% endblock %} |
|
85 | {% endblock %} | |
86 |
|
86 | |||
87 | {% block script %} |
|
87 | {% block script %} | |
88 |
|
88 | |||
89 | {{super()}} |
|
89 | {{super()}} | |
90 |
|
90 | |||
91 | <script src="{{ static_url("edit/js/main.js") }}" type="text/javascript" charset="utf-8"></script> |
|
91 | <script src="{{ static_url("edit/js/main.js") }}" type="text/javascript" charset="utf-8"></script> | |
92 | {% endblock %} |
|
92 | {% endblock %} |
General Comments 0
You need to be logged in to leave comments.
Login now