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