Fixes trimming and file browser.

Adds a option to stripped_input and stripped_multiline_input to not trim
text. File browser uses these instead of input. File browser also has
it's file listing fixed. Surprised it wasn't fixed sooner.
This commit is contained in:
Carlen White
2017-02-03 07:23:55 -05:00
parent 2b5f8ff7bb
commit fd63d5a085
5 changed files with 58 additions and 41 deletions

View File

@@ -81,14 +81,21 @@
return text //only accepts the text if it has some non-spaces
// Used to get a properly sanitized input, of max_length
/proc/stripped_input(mob/user, message = "", title = "", default = "", max_length=MAX_MESSAGE_LEN)
// no_trim is self explanatory but it prevents the input from being trimed if you intend to parse newlines or whitespace.
/proc/stripped_input(mob/user, message = "", title = "", default = "", max_length=MAX_MESSAGE_LEN, no_trim=FALSE)
var/name = input(user, message, title, default) as text|null
return trim(html_encode(name), max_length) //trim is "outside" because html_encode can expand single symbols into multiple symbols (such as turning < into &lt;)
if(no_trim)
return copytext(html_encode(name), 1, max_length)
else
return trim(html_encode(name), max_length) //trim is "outside" because html_encode can expand single symbols into multiple symbols (such as turning < into &lt;)
// Used to get a properly sanitized multiline input, of max_length
/proc/stripped_multiline_input(mob/user, message = "", title = "", default = "", max_length=MAX_MESSAGE_LEN)
/proc/stripped_multiline_input(mob/user, message = "", title = "", default = "", max_length=MAX_MESSAGE_LEN, no_trim=FALSE)
var/name = input(user, message, title, default) as message|null
return html_encode(trim(name, max_length))
if(no_trim)
return copytext(html_encode(name), 1, max_length)
else
return trim(html_encode(name), max_length)
//Filters out undesirable characters from names
/proc/reject_bad_name(t_in, allow_numbers=0, max_length=MAX_NAME_LEN)

View File

@@ -24,7 +24,7 @@
open_file = params["name"]
if("PRG_newtextfile")
. = 1
var/newname = sanitize(input(usr, "Enter file name or leave blank to cancel:", "File rename"))
var/newname = stripped_input(usr, "Enter file name or leave blank to cancel:", "File rename", max_length=50)
if(!newname)
return 1
if(!HDD)
@@ -69,7 +69,7 @@
var/datum/computer_file/file = HDD.find_file_by_name(params["name"])
if(!file || !istype(file))
return 1
var/newname = sanitize(input(usr, "Enter new file name:", "File rename", file.filename))
var/newname = stripped_input(usr, "Enter new file name:", "File rename", file.filename, max_length=50)
if(file && newname)
file.filename = newname
if("PRG_edit")
@@ -84,7 +84,7 @@
if(F.do_not_edit && (alert("WARNING: This file is not compatible with editor. Editing it may result in permanently corrupted formatting or damaged data consistency. Edit anyway?", "Incompatible File", "No", "Yes") == "No"))
return 1
// 16384 is the limit for file length in characters. Currently, papers have value of 2048 so this is 8 times as long, since we can't edit parts of the file independently.
var/newtext = sanitize(html_decode(input(usr, "Editing file [open_file]. You may use most tags used in paper formatting:", "Text Editor", html_decode(F.stored_data)) as message|null), 16384)
var/newtext = stripped_multiline_input(usr, "Editing file [open_file]. You may use most tags used in paper formatting:", "Text Editor", html_decode(F.stored_data), 16384, TRUE)
if(!newtext)
return
if(F)

View File

@@ -268,7 +268,7 @@
if(href_list["write"])
var/id = href_list["write"]
var/t = stripped_multiline_input("Enter what you want to write:", "Write")
var/t = stripped_multiline_input("Enter what you want to write:", "Write", no_trim=TRUE)
if(!t)
return
var/obj/item/i = usr.get_active_held_item() //Check to see if he still got that darn pen, also check if he's using a crayon or pen.

File diff suppressed because one or more lines are too long

View File

@@ -53,40 +53,50 @@
{{else}}
<h2>Available files (local):</h2>
<table>
<tr><th>File name
<th>File type
<th>File size (GQ)
<th>Operations
<tr>
<th>File name</th>
<th>File type</th>
<th>File size (GQ)</th>
<th>Operations</th>
</tr>
{{#each data.files}}
<tr><td>{{name}}
<td>.{{type}}
<td>{{size}}GQ
<td>
<ui-button action='PRG_openfile' params='{"name": "{{name}}"}'>VIEW</ui-button>
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_deletefile' params='{"name": "{{name}}"}'>DELETE</ui-button>
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_rename' params='{"name": "{{name}}"}'>RENAME</ui-button>
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_clone' params='{"name": "{{name}}"}'>CLONE</ui-button>
{{#if data.usbconnected}}
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_copytousb' params='{"name": "{{name}}"}'>EXPORT</ui-button>
{{/if}}
<tr>
<td>{{name}}</td>
<td>.{{type}}</td>
<td>{{size}}GQ</td>
<td>
<ui-button action='PRG_openfile' params='{"name": "{{name}}"}'>VIEW</ui-button>
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_deletefile' params='{"name": "{{name}}"}'>DELETE</ui-button>
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_rename' params='{"name": "{{name}}"}'>RENAME</ui-button>
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_clone' params='{"name": "{{name}}"}'>CLONE</ui-button>
{{#if data.usbconnected}}
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_copytousb' params='{"name": "{{name}}"}'>EXPORT</ui-button>
{{/if}}
</td>
</tr>
{{/each}}
</table>
{{#if data.usbconnected}}
<h2>Available files (portable device):</h2>
<table>
<tr><th>File name
<th>File type
<th>File size (GQ)
<th>Operations
<tr>
<th>File name</th>
<th>File type</th>
<th>File size (GQ)</th>
<th>Operations</th>
</tr>
{{#each data.usbfiles}}
<tr><td>{{name}}
<td>.{{type}}
<td>{{size}}GQ
<td>
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_usbdeletefile' params='{"name": "{{name}}"}'>DELETE</ui-button>
{{#if data.usbconnected}}
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_copyfromusb' params='{"name": "{{name}}"}'>IMPORT</ui-button>
{{/if}}
<tr>
<td>{{name}}</td>
<td>.{{type}}</td>
<td>{{size}}GQ</td>
<td>
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_usbdeletefile' params='{"name": "{{name}}"}'>DELETE</ui-button>
{{#if data.usbconnected}}
<ui-button state='{{undeletable ? "disabled" : null}}' action='PRG_copyfromusb' params='{"name": "{{name}}"}'>IMPORT</ui-button>
{{/if}}
</td>
</tr>
{{/each}}
</table>
{{/if}}