1790.1.1
by David Coles
Editor: Migrate to CodeMirror. Syntax highlighting hardcoded to Python for the |
1 |
function disable_save() |
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
2 |
{
|
1790.1.1
by David Coles
Editor: Migrate to CodeMirror. Syntax highlighting hardcoded to Python for the |
3 |
var savebutton = document.getElementById("save_button"); |
4 |
savebutton.disabled = true; |
|
5 |
window.onbeforeunload = null; |
|
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
6 |
}
|
7 |
||
836
by wagrant
Split the editor's Save and Save As functionality. This makes things |
8 |
function save_file(filename) |
221
by mattgiuca
editor: Made saving work. |
9 |
{
|
1790.1.1
by David Coles
Editor: Migrate to CodeMirror. Syntax highlighting hardcoded to Python for the |
10 |
if (using_codemirror) |
11 |
data = codemirror.getCode(); |
|
1308.1.4
by William Grant
Get the text to be saved from the textarea if not CodePressing. |
12 |
else
|
13 |
data = document.getElementById("editbox").value; |
|
14 |
||
385
by mattgiuca
browser/editor: Clicking "Save" in the editor does not cause a page refresh |
15 |
/* Do NOT refresh the page contents (causes problems for editarea and is
|
16 |
* unnecessary). */
|
|
906
by wagrant
editor.js: Warn before saving if the open file is an old revision. |
17 |
if (current_file.svnstatus != "revision" || |
18 |
confirm("You are currently viewing an older version of this file. " + |
|
19 |
"Saving will overwrite the current version. " + |
|
20 |
"Are you sure you want to continue?")) |
|
21 |
{
|
|
22 |
do_action("putfile", filename, |
|
23 |
{"path":".", "data":data, "overwrite":"true"}, |
|
1326.1.2
by David Coles
Small refactor of browser's JavaScript to allow do_action to be called from |
24 |
"multipart/form-data"); |
1790.1.1
by David Coles
Editor: Migrate to CodeMirror. Syntax highlighting hardcoded to Python for the |
25 |
disable_save(); |
906
by wagrant
editor.js: Warn before saving if the open file is an old revision. |
26 |
}
|
221
by mattgiuca
editor: Made saving work. |
27 |
}
|
28 |
||
836
by wagrant
Split the editor's Save and Save As functionality. This makes things |
29 |
function save_file_as(default_filename) |
30 |
{
|
|
839
by wagrant
Prompt on Save As if it would overwrite. |
31 |
filename = prompt("Path to save to:", default_filename); |
32 |
if (!filename) return; |
|
33 |
||
34 |
/* The filename will be path_joined with the app name, so needs to not
|
|
35 |
* be absolute, lest it clobber the app name. */
|
|
36 |
if (filename.charAt(0) == "/") filename = filename.substring(1); |
|
37 |
ajax_call(save_file_as_callback, "fileservice", filename, {}, "POST"); |
|
38 |
}
|
|
39 |
||
40 |
function save_file_as_callback(response) |
|
41 |
{
|
|
42 |
if (response.status == 404 || confirm("Are you sure you want to overwrite " + filename + "?")) |
|
43 |
save_file(filename); |
|
836
by wagrant
Split the editor's Save and Save As functionality. This makes things |
44 |
}
|
45 |
||
856
by wagrant
editor.js: Prompt before allowing users to navigate away from a |
46 |
/* Return a warning to be used in window.onbeforeunload. */
|
47 |
function confirm_beforeunload() { |
|
48 |
return 'If you continue, any unsaved changes to the current file will be lost.'; |
|
49 |
}
|
|
50 |
||
221
by mattgiuca
editor: Made saving work. |
51 |
function edit_text() |
52 |
{
|
|
778
by mattgiuca
editor.js: The Save button now enables when the text is changed, and disables |
53 |
var savebutton = document.getElementById("save_button"); |
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
54 |
savebutton.disabled = false; |
856
by wagrant
editor.js: Prompt before allowing users to navigate away from a |
55 |
window.onbeforeunload = confirm_beforeunload; |
221
by mattgiuca
editor: Made saving work. |
56 |
}
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
57 |
|
806
by William Grant
www/apps/browser/__init__.py: Display the save widget in actions2 for |
58 |
/** Presents the "editor heading" inserting it into a given element at
|
59 |
* the front. Note that the save widget is handled by the Python.
|
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
60 |
*/
|
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
61 |
function present_editorhead(elem, path, handler_type) |
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
62 |
{
|
777
by mattgiuca
browser: Now hides the "More actions" box altogether if the current file is |
63 |
var div = document.getElementById("actions2"); |
221
by mattgiuca
editor: Made saving work. |
64 |
|
65 |
/* Print a warning message if this is not actually a text file.
|
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
66 |
*/
|
67 |
if (handler_type != "text") |
|
68 |
{
|
|
69 |
var warn = dom_make_text_elem("p", |
|
70 |
"Warning: You are editing a binary " + |
|
71 |
"file, which explains any strange characters you may see. If " + |
|
72 |
"you save this file, you could corrupt it."); |
|
73 |
div.appendChild(warn); |
|
74 |
}
|
|
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
75 |
}
|
76 |
||
837
by wagrant
Add a highlighting-language selector to the editor. |
77 |
function highlighting_changed(select) |
78 |
{
|
|
79 |
editbox.edit(editbox.getCode(), select.value); |
|
80 |
}
|
|
81 |
||
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
82 |
/** Presents the text editor.
|
83 |
*/
|
|
84 |
function handle_text(path, text, handler_type) |
|
85 |
{
|
|
86 |
/* Create a textarea with the text in it
|
|
87 |
* (The makings of a primitive editor).
|
|
88 |
*/
|
|
89 |
var files = document.getElementById("filesbody"); |
|
90 |
/* Put our UI at the top */
|
|
91 |
present_editorhead(files, path, handler_type); |
|
92 |
||
93 |
var div = document.createElement("div"); |
|
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
94 |
div.style.height = '100%'; |
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
95 |
files.appendChild(div); |
1312
by William Grant
Use textarea.value to set the content of the editor's textarea. |
96 |
var txt_elem = document.createElement("textarea"); |
97 |
txt_elem.value = text.toString(); |
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
98 |
div.appendChild(txt_elem); |
99 |
txt_elem.setAttribute("id", "editbox"); |
|
837
by wagrant
Add a highlighting-language selector to the editor. |
100 |
language = language_from_mime(current_file.type); |
810
by William Grant
Merge another bit of killall-editarea - automatic filetype detection. |
101 |
|
102 |
// Assume plaintext if no type can be determined.
|
|
837
by wagrant
Add a highlighting-language selector to the editor. |
103 |
language = language ? language : "text"; |
104 |
document.getElementById("highlighting_select").value = language; |
|
105 |
||
1308.1.5
by William Grant
Make the save button change handlers behave properly with a textarea. |
106 |
$(txt_elem).change(edit_text); |
107 |
||
108 |
/* This isn't ideal, as Opera seems to fire it even for non-textual keys.
|
|
109 |
* But IE and WebKit don't, so this will behave properly in most browsers.
|
|
110 |
* This makes me sad.
|
|
111 |
*/
|
|
112 |
$(txt_elem).keypress(edit_text); |
|
113 |
||
1308.1.2
by William Grant
Make the editor textarea take up the full size. |
114 |
txt_elem.style.width = "100%"; |
115 |
txt_elem.style.height = "100%"; |
|
856
by wagrant
editor.js: Prompt before allowing users to navigate away from a |
116 |
window.onbeforeunload = confirm_beforeunload; |
117 |
||
1790.1.1
by David Coles
Editor: Migrate to CodeMirror. Syntax highlighting hardcoded to Python for the |
118 |
/* Always use CodeMirror (unless we find a good reason not to!) */
|
119 |
using_codemirror = true; |
|
120 |
||
121 |
if (using_codemirror) |
|
122 |
{
|
|
123 |
/* CodeMirror */
|
|
124 |
using_codemirror = true; |
|
125 |
codemirror = new CodeMirror.fromTextArea(txt_elem, { |
|
126 |
path: mediapath+"codemirror/", |
|
127 |
stylesheet: |
|
128 |
mediapath+"/codemirror/contrib/python/css/pythoncolors.css", |
|
129 |
basefiles: ["js/util.js", |
|
130 |
"js/stringstream.js", |
|
131 |
"js/select.js", |
|
132 |
"js/undo.js", |
|
133 |
"js/editor.js", |
|
134 |
"js/tokenize.js"], |
|
135 |
parserfile: ["contrib/python/js/parsepython.js"], |
|
136 |
onChange: edit_text, |
|
137 |
indentUnit: 4, |
|
138 |
tabMode: "spaces" |
|
139 |
});
|
|
140 |
}
|
|
141 |
||
142 |
/* Not using CodePress, so we can already disable the Save button. */
|
|
143 |
disable_save(); |
|
144 |
||
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
145 |
}
|
146 |
||
810
by William Grant
Merge another bit of killall-editarea - automatic filetype detection. |
147 |
function language_from_mime(mime) |
148 |
{
|
|
149 |
return {'text/x-python': 'python', |
|
1205
by William Grant
Treat application/x-javascript the same as application/javascript. |
150 |
'application/x-javascript': 'javascript', |
810
by William Grant
Merge another bit of killall-editarea - automatic filetype detection. |
151 |
'application/javascript': 'javascript', |
152 |
'text/css': 'css', |
|
153 |
'text/plain': 'text', |
|
154 |
'text/html': 'html', |
|
987
by wagrant
editor: Use HTML highlighting for XML by default. |
155 |
'application/xml': 'html', |
810
by William Grant
Merge another bit of killall-editarea - automatic filetype detection. |
156 |
'application/xhtml+xml': 'html'}[mime]; |
157 |
}
|