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