Skip to content

Instantly share code, notes, and snippets.

@JokerMartini
Created April 7, 2016 18:22
Show Gist options
  • Save JokerMartini/59732efbd7b5d1fdeabe19f15f731b97 to your computer and use it in GitHub Desktop.
Save JokerMartini/59732efbd7b5d1fdeabe19f15f731b97 to your computer and use it in GitHub Desktop.
Maxscript: Example demonstrates a way to rename list items using a popup dialog.
clearListener()
try (destroyDialog ::rlGroupsList) Catch()
rollout rlGroupsList "Groups"
(
local Groups = #("test","candy","mike")
local index = undefined
button uiAdd "Add"
multilistbox uiGroupsList ""
fn SetNewName str:"" =
(
append Groups str
uiGroupsList.items = Groups
)
fn IsUniqueString strArr:#() str:"" =
(
for s in strArr do
(
if (matchPattern s pattern:str ignorecase:true) AND str != "" AND str != " " do
(
return false
)
)
return true
)
fn NameInput =
(
rollout rlNameInput "Group Name"
(
dotnetcontrol uiName "Textbox" text:"" width:140 pos:[10,10]
on uiName keyUp s e do
(
if not (IsUniqueString strArr:Groups str:uiName.text) then
(
uiName.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB 255 0 0
)
else
(
uiName.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB 0 0 0
if e.KeyCode == e.KeyCode.Enter do
(
SetNewName str:uiName.text
try(DestroyDialog ::rlNameInput)catch()
)
)
if e.KeyCode == e.KeyCode.Escape do
(
try(DestroyDialog ::rlNameInput)catch()
)
)
on rlNameInput open do
(
setfocus uiName
)
)
createDialog rlNameInput 160 50 modal:true
)
fn RenameGroup =
(
if index != unsupplied do
(
rollout rlNameInput "Group Name"
(
dotnetcontrol uiName "Textbox" text:"" width:140 pos:[10,10]
on uiName keyUp s e do
(
if not (IsUniqueString strArr:Groups str:uiName.text) then
(
uiName.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB 255 0 0
)
else
(
uiName.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB 0 0 0
if e.KeyCode == e.KeyCode.Enter do
(
Groups[index] = uiName.text
uiGroupsList.items = Groups
try(DestroyDialog ::rlNameInput)catch()
)
)
if e.KeyCode == e.KeyCode.Escape do
(
try(DestroyDialog ::rlNameInput)catch()
)
)
on rlNameInput open do
(
uiName.text = Groups[index]
setfocus uiName
uiName.SelectionStart = 0
uiName.SelectionLength = uiName.text.count
)
)
createDialog rlNameInput 160 50 modal:true
)
)
on uiGroupsList doubleClicked idx do
(
if idx >= 1 do
(
index = idx
RenameGroup()
)
)
on uiAdd pressed do
(
NameInput()
)
on rlGroupsList open do
(
uiGroupsList.items = Groups
)
)
createDialog rlGroupsList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment