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