809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
1 |
function disable_save_if_safe() |
2 |
{
|
|
3 |
/* If this is defined, this engine supports change notification, so is able
|
|
4 |
* to enable the button again. Disable it for them. */
|
|
5 |
if(editbox.editor.addChangeHandler) |
|
6 |
{
|
|
7 |
var savebutton = document.getElementById("save_button"); |
|
8 |
savebutton.disabled = true; |
|
9 |
}
|
|
10 |
}
|
|
11 |
||
836
by wagrant
Split the editor's Save and Save As functionality. This makes things |
12 |
function save_file(filename) |
221
by mattgiuca
editor: Made saving work. |
13 |
{
|
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
14 |
data = editbox.getCode(); |
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). */
|
|
787
by mattgiuca
fileservice_lib/action.py: |
17 |
do_action("putfile", filename, |
792
by mattgiuca
util.js: ajax_call: Fixed multipart/form-data post request generation. (Syntax |
18 |
{"path":".", "data":data, "overwrite":"true"}, |
19 |
"multipart/form-data", true); |
|
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
20 |
disable_save_if_safe(); |
221
by mattgiuca
editor: Made saving work. |
21 |
}
|
22 |
||
836
by wagrant
Split the editor's Save and Save As functionality. This makes things |
23 |
function save_file_as(default_filename) |
24 |
{
|
|
25 |
filename = prompt('Path to save to:', default_filename); |
|
26 |
/* TODO: Confirm overwriting. */
|
|
27 |
save_file(filename); |
|
28 |
}
|
|
29 |
||
221
by mattgiuca
editor: Made saving work. |
30 |
function edit_text() |
31 |
{
|
|
778
by mattgiuca
editor.js: The Save button now enables when the text is changed, and disables |
32 |
var savebutton = document.getElementById("save_button"); |
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
33 |
savebutton.disabled = false; |
221
by mattgiuca
editor: Made saving work. |
34 |
}
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
35 |
|
806
by William Grant
www/apps/browser/__init__.py: Display the save widget in actions2 for |
36 |
/** Presents the "editor heading" inserting it into a given element at
|
37 |
* the front. Note that the save widget is handled by the Python.
|
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
38 |
*/
|
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
39 |
function present_editorhead(elem, path, handler_type) |
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
40 |
{
|
777
by mattgiuca
browser: Now hides the "More actions" box altogether if the current file is |
41 |
var div = document.getElementById("actions2"); |
221
by mattgiuca
editor: Made saving work. |
42 |
|
43 |
/* Print a warning message if this is not actually a text file.
|
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
44 |
*/
|
45 |
if (handler_type != "text") |
|
46 |
{
|
|
47 |
var warn = dom_make_text_elem("p", |
|
48 |
"Warning: You are editing a binary " + |
|
49 |
"file, which explains any strange characters you may see. If " + |
|
50 |
"you save this file, you could corrupt it."); |
|
51 |
div.appendChild(warn); |
|
52 |
}
|
|
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
53 |
}
|
54 |
||
837
by wagrant
Add a highlighting-language selector to the editor. |
55 |
function highlighting_changed(select) |
56 |
{
|
|
57 |
editbox.edit(editbox.getCode(), select.value); |
|
58 |
}
|
|
59 |
||
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
60 |
/** Presents the text editor.
|
61 |
*/
|
|
62 |
function handle_text(path, text, handler_type) |
|
63 |
{
|
|
64 |
/* Create a textarea with the text in it
|
|
65 |
* (The makings of a primitive editor).
|
|
66 |
*/
|
|
67 |
var files = document.getElementById("filesbody"); |
|
68 |
/* Put our UI at the top */
|
|
69 |
present_editorhead(files, path, handler_type); |
|
70 |
||
71 |
var div = document.createElement("div"); |
|
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
72 |
div.style.height = '100%'; |
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
73 |
files.appendChild(div); |
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
74 |
var txt_elem = dom_make_text_elem("textarea", |
75 |
text.toString()) |
|
76 |
div.appendChild(txt_elem); |
|
77 |
txt_elem.setAttribute("id", "editbox"); |
|
837
by wagrant
Add a highlighting-language selector to the editor. |
78 |
language = language_from_mime(current_file.type); |
810
by William Grant
Merge another bit of killall-editarea - automatic filetype detection. |
79 |
|
80 |
// Assume plaintext if no type can be determined.
|
|
837
by wagrant
Add a highlighting-language selector to the editor. |
81 |
language = language ? language : "text"; |
82 |
document.getElementById("highlighting_select").value = language; |
|
83 |
||
84 |
txt_elem.className = "codepress " + language; |
|
221
by mattgiuca
editor: Made saving work. |
85 |
txt_elem.setAttribute("onchange", "edit_text()"); |
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
86 |
/* TODO: Make CSS height: 100% work */
|
254
by mattgiuca
editor.js: Extended edit box to 35 lines (was too small). |
87 |
txt_elem.setAttribute("rows", "35"); |
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
88 |
CodePress.run(); |
233
by mattgiuca
Added a shaky implementation of EditArea as the text editor. |
89 |
|
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
90 |
/* And set a callback so we know that the editor iframe is loaded so we
|
91 |
* can set a callback so we know when to enable the save button.
|
|
92 |
* We also take this opportunity to disable the save button, if
|
|
93 |
* the browser is likely to reenable it as needed. */
|
|
94 |
editbox.onload = function() {editbox.addChangeHandler(edit_text); |
|
95 |
disable_save_if_safe(); }; |
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
96 |
}
|
97 |
||
810
by William Grant
Merge another bit of killall-editarea - automatic filetype detection. |
98 |
function language_from_mime(mime) |
99 |
{
|
|
100 |
return {'text/x-python': 'python', |
|
101 |
'application/javascript': 'javascript', |
|
102 |
'text/css': 'css', |
|
103 |
'text/plain': 'text', |
|
104 |
'text/html': 'html', |
|
105 |
'application/xhtml+xml': 'html'}[mime]; |
|
106 |
}
|