Show More
@@ -1,74 +1,101 | |||||
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 | 'base/js/namespace', |
|
5 | 'base/js/namespace', | |
6 | 'jquery', |
|
6 | 'jquery', | |
7 | 'base/js/utils', |
|
7 | 'base/js/utils', | |
8 | 'bootstrap', |
|
8 | 'bootstrap', | |
9 | ], function(IPython, $, utils, bootstrap) { |
|
9 | ], function(IPython, $, utils, bootstrap) { | |
10 | "use strict"; |
|
10 | "use strict"; | |
11 |
|
11 | |||
12 | var MenuBar = function (selector, options) { |
|
12 | var MenuBar = function (selector, options) { | |
13 | /** |
|
13 | /** | |
14 | * Constructor |
|
14 | * Constructor | |
15 | * |
|
15 | * | |
16 | * A MenuBar Class to generate the menubar of IPython notebook |
|
16 | * A MenuBar Class to generate the menubar of IPython notebook | |
17 | * |
|
17 | * | |
18 | * Parameters: |
|
18 | * Parameters: | |
19 | * selector: string |
|
19 | * selector: string | |
20 | * options: dictionary |
|
20 | * options: dictionary | |
21 | * Dictionary of keyword arguments. |
|
21 | * Dictionary of keyword arguments. | |
22 | * codemirror: CodeMirror instance |
|
22 | * codemirror: CodeMirror instance | |
23 | * contents: ContentManager instance |
|
23 | * contents: ContentManager instance | |
24 | * events: $(Events) instance |
|
24 | * events: $(Events) instance | |
25 | * base_url : string |
|
25 | * base_url : string | |
26 | * file_path : string |
|
26 | * file_path : string | |
27 | */ |
|
27 | */ | |
28 | options = options || {}; |
|
28 | options = options || {}; | |
29 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); |
|
29 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); | |
30 | this.selector = selector; |
|
30 | this.selector = selector; | |
31 | this.editor = options.editor; |
|
31 | this.editor = options.editor; | |
32 | this.events = options.events; |
|
32 | this.events = options.events; | |
33 |
|
33 | |||
34 | if (this.selector !== undefined) { |
|
34 | if (this.selector !== undefined) { | |
35 | this.element = $(selector); |
|
35 | this.element = $(selector); | |
36 | this.bind_events(); |
|
36 | this.bind_events(); | |
37 | } |
|
37 | } | |
38 | }; |
|
38 | }; | |
39 |
|
39 | |||
40 | MenuBar.prototype.bind_events = function () { |
|
40 | MenuBar.prototype.bind_events = function () { | |
41 | /** |
|
41 | /** | |
42 | * File |
|
42 | * File | |
43 | */ |
|
43 | */ | |
44 | var that = this; |
|
44 | var that = this; | |
45 | var editor = that.editor; |
|
45 | var editor = that.editor; | |
46 | this.element.find('#save-file').click(function () { |
|
46 | this.element.find('#save-file').click(function () { | |
47 | editor.save(); |
|
47 | editor.save(); | |
48 | }); |
|
48 | }); | |
49 |
|
49 | |||
50 | // Edit |
|
50 | // Edit | |
51 | this.element.find('#menu-find').click(function () { |
|
51 | this.element.find('#menu-find').click(function () { | |
52 | editor.codemirror.execCommand("find"); |
|
52 | editor.codemirror.execCommand("find"); | |
53 | }); |
|
53 | }); | |
54 | this.element.find('#menu-replace').click(function () { |
|
54 | this.element.find('#menu-replace').click(function () { | |
55 | editor.codemirror.execCommand("replace"); |
|
55 | editor.codemirror.execCommand("replace"); | |
56 | }); |
|
56 | }); | |
|
57 | this.element.find('#menu-keymap-default').click(function () { | |||
|
58 | editor.update_codemirror_options({ | |||
|
59 | vimMode: false, | |||
|
60 | keyMap: null | |||
|
61 | }); | |||
|
62 | }); | |||
|
63 | this.element.find('#menu-keymap-sublime').click(function () { | |||
|
64 | editor.update_codemirror_options({ | |||
|
65 | vimMode: false, | |||
|
66 | keyMap: 'sublime' | |||
|
67 | }); | |||
|
68 | }); | |||
|
69 | this.element.find('#menu-keymap-emacs').click(function () { | |||
|
70 | editor.update_codemirror_options({ | |||
|
71 | vimMode: false, | |||
|
72 | keyMap: 'emacs' | |||
|
73 | }); | |||
|
74 | }); | |||
|
75 | this.element.find('#menu-keymap-vim').click(function () { | |||
|
76 | editor.update_codemirror_options({ | |||
|
77 | vimMode: true, | |||
|
78 | keyMap: 'vim' | |||
|
79 | }); | |||
|
80 | }); | |||
57 |
|
81 | |||
58 | // View |
|
82 | // View | |
59 | this.element.find('#menu-line-numbers').click(function () { |
|
83 | this.element.find('#menu-line-numbers').click(function () { | |
60 | var current = editor.codemirror.getOption('lineNumbers'); |
|
84 | var current = editor.codemirror.getOption('lineNumbers'); | |
61 | var value = Boolean(1-current); |
|
85 | var value = Boolean(1-current); | |
62 | editor.update_codemirror_options({lineNumbers: value}); |
|
86 | editor.update_codemirror_options({lineNumbers: value}); | |
63 | }); |
|
87 | }); | |
64 |
|
88 | |||
65 | this.events.on("config_changed.Editor", function () { |
|
89 | this.events.on("config_changed.Editor", function () { | |
66 | var lineNumbers = editor.codemirror.getOption('lineNumbers'); |
|
90 | var lineNumbers = editor.codemirror.getOption('lineNumbers'); | |
67 | var text = lineNumbers ? "Hide" : "Show"; |
|
91 | var text = lineNumbers ? "Hide" : "Show"; | |
68 | text = text + " Line Numbers"; |
|
92 | text = text + " Line Numbers"; | |
69 | that.element.find('#menu-line-numbers').find("a").text(text); |
|
93 | that.element.find('#menu-line-numbers').find("a").text(text); | |
|
94 | var keyMap = editor.codemirror.getOption('keyMap') || "default"; | |||
|
95 | that.element.find(".selected-keymap").removeClass("selected-keymap"); | |||
|
96 | that.element.find("#menu-keymap-" + keyMap).addClass("selected-keymap"); | |||
70 | }); |
|
97 | }); | |
71 | }; |
|
98 | }; | |
72 |
|
99 | |||
73 | return {'MenuBar': MenuBar}; |
|
100 | return {'MenuBar': MenuBar}; | |
74 | }); |
|
101 | }); |
@@ -1,72 +1,78 | |||||
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 header %} |
|
18 | {% block header %} | |
19 |
|
19 | |||
20 | <span id="filename">{{ basename }}</span> |
|
20 | <span id="filename">{{ basename }}</span> | |
21 |
|
21 | |||
22 | {% endblock %} |
|
22 | {% endblock %} | |
23 |
|
23 | |||
24 | {% block site %} |
|
24 | {% block site %} | |
25 |
|
25 | |||
26 | <div id="menubar-container" class="container"> |
|
26 | <div id="menubar-container" class="container"> | |
27 | <div id="menubar"> |
|
27 | <div id="menubar"> | |
28 | <div id="menus" class="navbar navbar-default" role="navigation"> |
|
28 | <div id="menus" class="navbar navbar-default" role="navigation"> | |
29 | <div class="container-fluid"> |
|
29 | <div class="container-fluid"> | |
30 | <button type="button" class="btn btn-default navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> |
|
30 | <button type="button" class="btn btn-default navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> | |
31 | <i class="fa fa-bars"></i> |
|
31 | <i class="fa fa-bars"></i> | |
32 | <span class="navbar-text">Menu</span> |
|
32 | <span class="navbar-text">Menu</span> | |
33 | </button> |
|
33 | </button> | |
34 | <ul class="nav navbar-nav navbar-right"> |
|
34 | <ul class="nav navbar-nav navbar-right"> | |
35 | <li id="notification_area"></li> |
|
35 | <li id="notification_area"></li> | |
36 | </ul> |
|
36 | </ul> | |
37 | <div class="navbar-collapse collapse"> |
|
37 | <div class="navbar-collapse collapse"> | |
38 | <ul class="nav navbar-nav"> |
|
38 | <ul class="nav navbar-nav"> | |
39 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">File</a> |
|
39 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">File</a> | |
40 | <ul id="file-menu" class="dropdown-menu"> |
|
40 | <ul id="file-menu" class="dropdown-menu"> | |
41 | <li id="new-file"><a href="#">New</a></li> |
|
41 | <li id="new-file"><a href="#">New</a></li> | |
42 | <li id="save-file"><a href="#">Save</a></li> |
|
42 | <li id="save-file"><a href="#">Save</a></li> | |
43 | </ul> |
|
43 | </ul> | |
44 | </li> |
|
44 | </li> | |
45 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Edit</a> |
|
45 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Edit</a> | |
46 | <ul id="edit-menu" class="dropdown-menu"> |
|
46 | <ul id="edit-menu" class="dropdown-menu"> | |
47 | <li id="menu-find"><a href="#">Find</a></li> |
|
47 | <li id="menu-find"><a href="#">Find</a></li> | |
48 | <li id="menu-replace"><a href="#">Find & Replace</a></li> |
|
48 | <li id="menu-replace"><a href="#">Find & Replace</a></li> | |
|
49 | <li class="divider"></li> | |||
|
50 | <li>Key Map</li> | |||
|
51 | <li id="menu-keymap-default"><a href="#">Default<i class="fa"></i></a></li> | |||
|
52 | <li id="menu-keymap-sublime"><a href="#">Sublime Text<i class="fa"></i></a></li> | |||
|
53 | <li id="menu-keymap-vim"><a href="#">Vim<i class="fa"></i></a></li> | |||
|
54 | <li id="menu-keymap-emacs"><a href="#">emacs<i class="fa"></i></a></li> | |||
49 | </ul> |
|
55 | </ul> | |
50 | </li> |
|
56 | </li> | |
51 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">View</a> |
|
57 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">View</a> | |
52 | <ul id="view-menu" class="dropdown-menu"> |
|
58 | <ul id="view-menu" class="dropdown-menu"> | |
53 | <li id="menu-line-numbers"><a href="#">Hide Line Numbers</a></li> |
|
59 | <li id="menu-line-numbers"><a href="#">Hide Line Numbers</a></li> | |
54 | </ul> |
|
60 | </ul> | |
55 | </li> |
|
61 | </li> | |
56 | </ul> |
|
62 | </ul> | |
57 | </div> |
|
63 | </div> | |
58 | </div> |
|
64 | </div> | |
59 | </div> |
|
65 | </div> | |
60 | </div> |
|
66 | </div> | |
61 | </div> |
|
67 | </div> | |
62 |
|
68 | |||
63 | <div id="texteditor-container" class="container"></div> |
|
69 | <div id="texteditor-container" class="container"></div> | |
64 |
|
70 | |||
65 | {% endblock %} |
|
71 | {% endblock %} | |
66 |
|
72 | |||
67 | {% block script %} |
|
73 | {% block script %} | |
68 |
|
74 | |||
69 | {{super()}} |
|
75 | {{super()}} | |
70 |
|
76 | |||
71 | <script src="{{ static_url("edit/js/main.js") }}" type="text/javascript" charset="utf-8"></script> |
|
77 | <script src="{{ static_url("edit/js/main.js") }}" type="text/javascript" charset="utf-8"></script> | |
72 | {% endblock %} |
|
78 | {% endblock %} |
General Comments 0
You need to be logged in to leave comments.
Login now