add new line break feature to file edit #6365

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
si458
2024-09-08 20:11:06 +01:00
parent 516a14b4ca
commit 6fe30b7730
3 changed files with 2349 additions and 2218 deletions

View File

@@ -217,6 +217,13 @@
<div id=dialog2 style="">
<div id=id_dialogOptions></div>
</div>
<div id=dialog4 style="">
<input id="d4WrapButton" type="button" value="Wrap On" onclick="d4ToggleWrap()" />
<input id="d4SizeButton" type="button" value="Small" onclick="d4ToggleSize()" />
<input id="d4EncodingButton" type="button" value="Raw" onclick="d4ToggleEncoding()" />
<input id="d4LineBreakButton" type="button" value="Windows" onclick="d4ToggleLineBreak()" />
<textarea id=d4editorarea autocomplete="off" style="height:calc(100vh - 286px);width:100%;overflow:scroll;resize:none;white-space:pre"></textarea>
</div>
<div id=dialog7 style="">
<div id="d7meshkvm">
<h4>Agent Remote Desktop</h4>
@@ -340,6 +347,16 @@
setupTerminal();
setupFiles();
// Set the file editor
d4EditWrapVal = Number(getstore('editorWrap', 0));
d4EditSizeVal = Number(getstore('editorSize', 0));
d4EditEncodingVal = Number(getstore('editorEncoding', 0));
d4EditLineBreakVal = Number(getstore('editorLineBreak', 0));
d4ToggleWrap(true);
d4ToggleSize(true);
d4ToggleEncoding(true);
d4ToggleLineBreak(true);
// Set the document title
if (nodeName.length > 0) { document.title += ' - ' + nodeName; }
@@ -2030,6 +2047,8 @@
if (gdownloadFile.tag == 'viewer') {
// View the file in the dialog box
setDialogMode(4, EscapeHtml(gdownloadFile.file), 3, p13editSaveBack, null, gdownloadFile.file);
QV('d4EncodingButton', true);
QV('d4LineBreakButton', true);
QS('dialog').width = 'auto';
QS('dialog').bottom = '80px';
QS('dialog').top = QS('dialog').left = QS('dialog').right = '100px';
@@ -2046,6 +2065,9 @@
var d4EditWrapVal = 0;
var d4EditSizeVal = 0;
var d4EditEncodingVal = 0;
var d4EditLineBreakVal = 0;
function d4ToggleWrap(update) {
if (!update) { d4EditWrapVal = ++d4EditWrapVal % 2; }
Q('d4WrapButton').value = ["Wrap: ON", "Wrap: OFF"][d4EditWrapVal];
@@ -2061,8 +2083,38 @@
putstore('editorSize', d4EditSizeVal);
}
function d4ToggleEncoding(update) {
if (!update) {
d4EditEncodingVal = ++d4EditEncodingVal % 2;
if (d4EditEncodingVal == 1) {
Q('d4editorarea').value = decode_utf8(Q('d4editorarea').value);
} else {
Q('d4editorarea').value = encode_utf8(Q('d4editorarea').value);
}
}
Q('d4EncodingButton').value = ["Encoding: RAW","Encoding: UTF8"][d4EditEncodingVal];
putstore('editorEncoding', d4EditEncodingVal);
}
function d4ToggleLineBreak(update) {
if (!update) {
d4EditLineBreakVal = ++d4EditLineBreakVal % 3;
}
Q('d4LineBreakButton').value = ["Line Break: Windows (CR LF)","Line Break: Linux (LF)","Line Break: Mac (CR)"][d4EditLineBreakVal];
putstore('editorLineBreak', d4EditLineBreakVal);
}
function p13editSaveBack(b, tag) {
var data = new TextEncoder().encode(Q('d4editorarea').value);
var data;
var value = Q('d4editorarea').value;
value = d4EditLineBreakVal === 0 ? value.replace(/\r?\n|\r/g, '\r\n') : // Windows
d4EditLineBreakVal === 2 ? value.replace(/\r\n|\n/g, '\r') : // Mac
value.replace(/\r\n|\r/g, '\n'); // Linux
if (d4EditEncodingVal == 1) {
data = new TextEncoder().encode(value); // UTF8 encoding
} else {
data = new TextEncoder().encode(decode_utf8(value)); // RAW encoding
}
p13uploadFileContinue(1, [{ name: tag, size: data.byteLength, type: 'text/plain', xdata: data }]);
}
@@ -2260,6 +2312,27 @@
xxcurrentView = x;
}
function putstore(name, val) {
try {
if ((typeof (localStorage) === 'undefined') || (localStorage.getItem(name) == val)) return;
if (val == null) { localStorage.removeItem(name); } else { localStorage.setItem(name, val); }
} catch (ex) { }
if (name[0] != '_') {
var s = {};
try {
for (var i = 0, len = localStorage.length; i < len; ++i) {
var k = localStorage.key(i);
if (k[0] != '_') {
s[k] = localStorage.getItem(k);
if ((k != 'desktopsettings') && (k != 'stars') && (k != 'deskKeyShortcuts') && (k != 'deskStrings') && (k != 'cmdopt') && (typeof s[k] == 'string') && (s[k].length > 64)) { delete s[k]; }
}
}
} catch (ex) {}
// meshserver.send({ action: 'userWebState', state: JSON.stringify(s) });
}
}
function getstore(name, val) { try { if (typeof (localStorage) === 'undefined') return val; var v = localStorage.getItem(name); if ((v == null) || (v == null)) return val; return v; } catch (e) { return val; } }
function messagebox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t, 1); }
function statusbox(t, m) { setSessionActivity(); QH('id_dialogMessage', m); setDialogMode(1, t); }
function haltEvent(e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }