Show More
@@ -74,11 +74,21 b' function($,' | |||
|
74 | 74 | // which we don't want. |
|
75 | 75 | cm.clearHistory(); |
|
76 | 76 | |
|
77 | // Find and load the highlighting mode | |
|
78 | utils.requireCodeMirrorMode(model.mimetype, function(spec) { | |
|
79 |
|
|
|
80 | cm.setOption('mode', mode); | |
|
81 | }); | |
|
77 | // Find and load the highlighting mode, | |
|
78 | // first by mime-type, then by file extension | |
|
79 | var modeinfo = CodeMirror.findModeByMIME(model.mimetype); | |
|
80 | if (modeinfo.mode === "null") { | |
|
81 | // find by mime failed, use find by ext | |
|
82 | var ext_idx = model.name.lastIndexOf('.'); | |
|
83 | ||
|
84 | if (ext_idx > 0) { | |
|
85 | // CodeMirror.findModeByExtension wants extension without '.' | |
|
86 | modeinfo = CodeMirror.findModeByExtension(model.name.slice(ext_idx + 1)); | |
|
87 | } | |
|
88 | } | |
|
89 | if (modeinfo) { | |
|
90 | that.set_codemirror_mode(modeinfo); | |
|
91 | } | |
|
82 | 92 | that.save_enabled = true; |
|
83 | 93 | that.generation = cm.changeGeneration(); |
|
84 | 94 | that.events.trigger("file_loaded.Editor", model); |
@@ -91,10 +101,18 b' function($,' | |||
|
91 | 101 | ); |
|
92 | 102 | }; |
|
93 | 103 | |
|
104 | Editor.prototype.set_codemirror_mode = function (modeinfo) { | |
|
105 | /** set the codemirror mode from a modeinfo struct */ | |
|
106 | var that = this; | |
|
107 | utils.requireCodeMirrorMode(modeinfo, function () { | |
|
108 | that.codemirror.setOption('mode', modeinfo.mode); | |
|
109 | that.events.trigger("mode_changed.Editor", modeinfo); | |
|
110 | }); | |
|
111 | }; | |
|
112 | ||
|
94 | 113 | Editor.prototype.get_filename = function () { |
|
95 | 114 | return utils.url_path_split(this.file_path)[1]; |
|
96 | ||
|
97 | } | |
|
115 | }; | |
|
98 | 116 | |
|
99 | 117 | Editor.prototype.rename = function (new_name) { |
|
100 | 118 | /** rename the file */ |
@@ -2,12 +2,14 b'' | |||
|
2 | 2 | // Distributed under the terms of the Modified BSD License. |
|
3 | 3 | |
|
4 | 4 | define([ |
|
5 | 'base/js/namespace', | |
|
6 | 5 | 'jquery', |
|
6 | 'base/js/namespace', | |
|
7 | 7 | 'base/js/utils', |
|
8 | 8 | 'base/js/dialog', |
|
9 | 'codemirror/lib/codemirror', | |
|
10 | 'codemirror/mode/meta', | |
|
9 | 11 | 'bootstrap', |
|
10 |
], function( |
|
|
12 | ], function($, IPython, utils, dialog, CodeMirror) { | |
|
11 | 13 | "use strict"; |
|
12 | 14 | |
|
13 | 15 | var MenuBar = function (selector, options) { |
@@ -37,6 +39,7 b' define([' | |||
|
37 | 39 | this.element = $(selector); |
|
38 | 40 | this.bind_events(); |
|
39 | 41 | } |
|
42 | this._load_mode_menu(); | |
|
40 | 43 | Object.seal(this); |
|
41 | 44 | }; |
|
42 | 45 | |
@@ -120,6 +123,36 b' define([' | |||
|
120 | 123 | that.element.find(".selected-keymap").removeClass("selected-keymap"); |
|
121 | 124 | that.element.find("#menu-keymap-" + keyMap).addClass("selected-keymap"); |
|
122 | 125 | }); |
|
126 | ||
|
127 | this.events.on("mode_changed.Editor", function (evt, modeinfo) { | |
|
128 | that.element.find("#current-mode") | |
|
129 | .text(modeinfo.name) | |
|
130 | .attr( | |
|
131 | 'title', | |
|
132 | "The current highlighting mode is " + modeinfo.name | |
|
133 | ); | |
|
134 | }); | |
|
135 | }; | |
|
136 | ||
|
137 | MenuBar.prototype._load_mode_menu = function () { | |
|
138 | var list = this.element.find("#mode-menu"); | |
|
139 | var editor = this.editor; | |
|
140 | function make_set_mode(info) { | |
|
141 | return function () { | |
|
142 | editor.set_codemirror_mode(info); | |
|
143 | }; | |
|
144 | } | |
|
145 | for (var i = 0; i < CodeMirror.modeInfo.length; i++) { | |
|
146 | var info = CodeMirror.modeInfo[i]; | |
|
147 | list.append($("<li>").append( | |
|
148 | $("<a>").attr("href", "#") | |
|
149 | .text(info.name) | |
|
150 | .click(make_set_mode(info)) | |
|
151 | .attr('title', | |
|
152 | "Set highlighting mode to " + info.name | |
|
153 | ) | |
|
154 | )); | |
|
155 | } | |
|
123 | 156 | }; |
|
124 | 157 | |
|
125 | 158 | return {'MenuBar': MenuBar}; |
@@ -6,3 +6,9 b'' | |||
|
6 | 6 | content: @fa-var-check; |
|
7 | 7 | } |
|
8 | 8 | } |
|
9 | ||
|
10 | #mode-menu { | |
|
11 | // truncate mode-menu, so it doesn't get longer than the screen | |
|
12 | overflow: auto; | |
|
13 | max-height: 20em; | |
|
14 | } No newline at end of file |
@@ -8125,6 +8125,10 b' ul#new-notebook-menu {' | |||
|
8125 | 8125 | .selected-keymap i.fa:before { |
|
8126 | 8126 | content: "\f00c"; |
|
8127 | 8127 | } |
|
8128 | #mode-menu { | |
|
8129 | overflow: auto; | |
|
8130 | max-height: 20em; | |
|
8131 | } | |
|
8128 | 8132 | #texteditor-container { |
|
8129 | 8133 | border-bottom: 1px solid #ccc; |
|
8130 | 8134 | } |
@@ -63,7 +63,12 b' data-file-path="{{file_path}}"' | |||
|
63 | 63 | <li id="menu-line-numbers"><a href="#">Hide Line Numbers</a></li> |
|
64 | 64 | </ul> |
|
65 | 65 | </li> |
|
66 | <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Mode</a> | |
|
67 | <ul id="mode-menu" class="dropdown-menu"> | |
|
66 | 68 | </ul> |
|
69 | </li> | |
|
70 | </ul> | |
|
71 | <p id="current-mode" class="navbar-text navbar-right">current mode</p> | |
|
67 | 72 | </div> |
|
68 | 73 | </div> |
|
69 | 74 | </div> |
General Comments 0
You need to be logged in to leave comments.
Login now