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