##// END OF EJS Templates
add download link to editor
Min RK -
Show More
@@ -1,155 +1,160 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 this.element.find('#download-file').click(function () {
78 window.open(utils.url_join_encode(
79 that.base_url, 'files', that.editor.file_path
80 ) + '?download=1');
81 });
77 82
78 83 // Edit
79 84 this.element.find('#menu-find').click(function () {
80 85 editor.codemirror.execCommand("find");
81 86 });
82 87 this.element.find('#menu-replace').click(function () {
83 88 editor.codemirror.execCommand("replace");
84 89 });
85 90 this.element.find('#menu-keymap-default').click(function () {
86 91 editor.update_codemirror_options({
87 92 vimMode: false,
88 93 keyMap: 'default'
89 94 });
90 95 });
91 96 this.element.find('#menu-keymap-sublime').click(function () {
92 97 editor.update_codemirror_options({
93 98 vimMode: false,
94 99 keyMap: 'sublime'
95 100 });
96 101 });
97 102 this.element.find('#menu-keymap-emacs').click(function () {
98 103 editor.update_codemirror_options({
99 104 vimMode: false,
100 105 keyMap: 'emacs'
101 106 });
102 107 });
103 108 this.element.find('#menu-keymap-vim').click(function () {
104 109 editor.update_codemirror_options({
105 110 vimMode: true,
106 111 keyMap: 'vim'
107 112 });
108 113 });
109 114
110 115 // View
111 116 this.element.find('#menu-line-numbers').click(function () {
112 117 var current = editor.codemirror.getOption('lineNumbers');
113 118 var value = Boolean(1-current);
114 119 editor.update_codemirror_options({lineNumbers: value});
115 120 });
116 121
117 122 this.events.on("config_changed.Editor", function () {
118 123 var keyMap = editor.codemirror.getOption('keyMap') || "default";
119 124 that.element.find(".selected-keymap").removeClass("selected-keymap");
120 125 that.element.find("#menu-keymap-" + keyMap).addClass("selected-keymap");
121 126 });
122 127
123 128 this.events.on("mode_changed.Editor", function (evt, modeinfo) {
124 129 that.element.find("#current-mode")
125 130 .text(modeinfo.name)
126 131 .attr(
127 132 'title',
128 133 "The current language is " + modeinfo.name
129 134 );
130 135 });
131 136 };
132 137
133 138 MenuBar.prototype._load_mode_menu = function () {
134 139 var list = this.element.find("#mode-menu");
135 140 var editor = this.editor;
136 141 function make_set_mode(info) {
137 142 return function () {
138 143 editor.set_codemirror_mode(info);
139 144 };
140 145 }
141 146 for (var i = 0; i < CodeMirror.modeInfo.length; i++) {
142 147 var info = CodeMirror.modeInfo[i];
143 148 list.append($("<li>").append(
144 149 $("<a>").attr("href", "#")
145 150 .text(info.name)
146 151 .click(make_set_mode(info))
147 152 .attr('title',
148 153 "Set language to " + info.name
149 154 )
150 155 ));
151 156 }
152 157 };
153 158
154 159 return {'MenuBar': MenuBar};
155 160 });
@@ -1,98 +1,99 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 bodyclasses %}edit_app {{super()}}{% endblock %}
12 12
13 13 {% block params %}
14 14 data-base-url="{{base_url}}"
15 15 data-file-path="{{file_path}}"
16 16 {{super()}}
17 17 {% endblock %}
18 18
19 19 {% block headercontainer %}
20 20
21 21 <span id="save_widget" class="pull-left save_widget">
22 22 <span class="filename"></span>
23 23 <span class="last_modified"></span>
24 24 </span>
25 25
26 26 {% endblock %}
27 27
28 28 {% block header %}
29 29
30 30 <div id="menubar-container" class="container">
31 31 <div id="menubar">
32 32 <div id="menus" class="navbar navbar-default" role="navigation">
33 33 <div class="container-fluid">
34 34 <p class="navbar-text indicator_area">
35 35 <span id="current-mode" >current mode</span>
36 36 </p>
37 37 <button type="button" class="btn btn-default navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
38 38 <i class="fa fa-bars"></i>
39 39 <span class="navbar-text">Menu</span>
40 40 </button>
41 41 <ul class="nav navbar-nav navbar-right">
42 42 <li id="notification_area"></li>
43 43 </ul>
44 44 <div class="navbar-collapse collapse">
45 45 <ul class="nav navbar-nav">
46 46 <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">File</a>
47 47 <ul id="file-menu" class="dropdown-menu">
48 48 <li id="new-file"><a href="#">New</a></li>
49 49 <li id="save-file"><a href="#">Save</a></li>
50 50 <li id="rename-file"><a href="#">Rename</a></li>
51 <li id="download-file"><a href="#">Download</a></li>
51 52 </ul>
52 53 </li>
53 54 <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Edit</a>
54 55 <ul id="edit-menu" class="dropdown-menu">
55 56 <li id="menu-find"><a href="#">Find</a></li>
56 57 <li id="menu-replace"><a href="#">Find &amp; Replace</a></li>
57 58 <li class="divider"></li>
58 59 <li class="dropdown-header">Key Map</li>
59 60 <li id="menu-keymap-default"><a href="#">Default<i class="fa"></i></a></li>
60 61 <li id="menu-keymap-sublime"><a href="#">Sublime Text<i class="fa"></i></a></li>
61 62 <li id="menu-keymap-vim"><a href="#">Vim<i class="fa"></i></a></li>
62 63 <li id="menu-keymap-emacs"><a href="#">emacs<i class="fa"></i></a></li>
63 64 </ul>
64 65 </li>
65 66 <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">View</a>
66 67 <ul id="view-menu" class="dropdown-menu">
67 68 <li id="menu-line-numbers"><a href="#">Toggle Line Numbers</a></li>
68 69 </ul>
69 70 </li>
70 71 <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Language</a>
71 72 <ul id="mode-menu" class="dropdown-menu">
72 73 </ul>
73 74 </li>
74 75 </ul>
75 76 </div>
76 77 </div>
77 78 </div>
78 79 </div>
79 80 </div>
80 81
81 82 <div class="lower-header-bar"></div>
82 83
83 84 {% endblock %}
84 85
85 86 {% block site %}
86 87
87 88 <div id="texteditor-backdrop">
88 89 <div id="texteditor-container" class="container"></div>
89 90 </div>
90 91
91 92 {% endblock %}
92 93
93 94 {% block script %}
94 95
95 96 {{super()}}
96 97
97 98 <script src="{{ static_url("edit/js/main.js") }}" type="text/javascript" charset="utf-8"></script>
98 99 {% endblock %}
General Comments 0
You need to be logged in to leave comments. Login now