Extended list viewer now has an edit button (#19706)

Extended list viewer now has an edit button, and the ability to edit the
extended list it's seeing; it's also (opinionately) better formatted.
This commit is contained in:
Fluffy
2024-07-29 22:49:41 +00:00
committed by GitHub
parent 9476f036a0
commit aa20604826
5 changed files with 155 additions and 18 deletions
+64 -5
View File
@@ -1,18 +1,32 @@
/client/proc/view_extended_list(var/list/L)
if(!check_rights(R_VAREDIT|R_DEV)) return
/**
* Used to create a tgui Extended List Viewer
*
* Accepts either an associative list or a flat list
*
* If an associative list is passed, the key is a string and the value the datum
*/
/client/proc/view_extended_list(list/L, datum/original_datum)
if(!check_rights(R_VAREDIT|R_DEV))
return
if(istype(L))
new /datum/tgui_module/list_viewer(L, usr)
new /datum/tgui_module/list_viewer(L, usr, original_datum = original_datum)
/datum/tgui_module/list_viewer
var/list/viewed_list
var/datum/weakref/original_datum_ref
/datum/tgui_module/list_viewer/New(var/list/L, mob/user)
/datum/tgui_module/list_viewer/New(list/L, mob/user, datum/original_datum)
if(istype(L))
viewed_list = L
if(istype(original_datum))
original_datum_ref = WEAKREF(original_datum)
if(!original_datum_ref)
stack_trace("Unable to create a weakref to the original datum, please report this to a developer")
ui_interact(user)
/datum/tgui_module/list_viewer/ui_interact(mob/user, var/datum/tgui/ui)
/datum/tgui_module/list_viewer/ui_interact(mob/user, datum/tgui/ui)
if(!check_rights(R_VAREDIT|R_DEV|R_MOD))
return
@@ -41,3 +55,48 @@
index++
return data
/datum/tgui_module/list_viewer/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return
if(!check_rights(R_VAREDIT|R_DEV))
return
var/client/user_client = ui.user?.client
if(!user_client)
stack_trace("No client found to open entry in, despite having received a request to edit a list, uh oh!")
return
switch(action)
if("open_entry")
var/datum/entry_to_open = null
if(isnum(text2num(params["open_entry_key"])))
entry_to_open = viewed_list[text2num(params["open_entry_key"])]
else
entry_to_open = viewed_list[params["open_entry_key"]]
if(!entry_to_open)
to_chat(usr, "No entry found to open!")
return FALSE
user_client.debug_variables_open(entry_to_open)
return TRUE
if("open_whole_list")
if(tgui_alert(usr, "Opening the whole list in VV might take a long time or cause issues, are you sure?", "Confirm", list("Yes", "No")) != "Yes")
return FALSE
var/datum/original_datum = original_datum_ref.resolve()
if(!original_datum)
tgui_alert(usr, "Unable to open the list, the original datum has been deleted or has never been set.")
return FALSE
user_client.mod_list(viewed_list, original_datum)
return TRUE
+1 -1
View File
@@ -67,7 +67,7 @@
to_chat(usr, "This can only be used on instances of type /list")
return
view_extended_list(L, href_list["varnameview"])
view_extended_list(L, locate(href_list["original_datum"]))
else if(href_list["mob_player_panel"])
if(!check_rights(0)) return
@@ -133,7 +133,7 @@
. += x
return .
/proc/make_view_variables_value(value, varname = "*")
/proc/make_view_variables_value(datum/D, value, varname = "*")
var/vtext = ""
var/debug_type = get_debug_type(value, FALSE)
var/extra = list()
@@ -161,12 +161,12 @@
for (var/index = 1 to L.len)
var/entry = L[index]
if(!isnum(entry) && !isnull(entry) && !(varname in view_variables_no_assoc) && L[entry] != null)
extra += "<li>[index]: [make_view_variables_value(entry)] -> [make_view_variables_value(L[entry])]</li>"
extra += "<li>[index]: [make_view_variables_value(D, entry)] -> [make_view_variables_value(D, L[entry])]</li>"
else
extra += "<li>[index]: [make_view_variables_value(entry)]</li>"
extra += "<li>[index]: [make_view_variables_value(D, entry)]</li>"
extra += "</ul>"
else if(L.len >= 100)
vtext = "([L.len]): <ul><li><a href='?_src_=vars;datumview=\ref[L];varnameview=[varname]'>List too large to display, click to view.</a></ul>"
vtext = "([L.len]): <ul><li><a href='?_src_=vars;datumview=[REF(L)];varnameview=[varname];original_datum=[REF(D)]'>List too large to display, click to view.</a></ul>"
else
vtext = "[value]"
@@ -183,6 +183,6 @@
(<a href='?_src_=vars;datummass=\ref[D];varnamemass=[varname]'>M</a>)
"}
var/valuestr = make_view_variables_value(value, varname)
var/valuestr = make_view_variables_value(D, value, varname)
return "<li>[ecm]<span class='key'>[varname]</span> = [valuestr]</li>"