Reopening a vb-view, how to do? + other

Hi,

I setup a vbview and now would like to close it and the re-open it. I stumbled here over 2 problems:

  • dialogPtr:close() and thendialogPtr:show() does not work. Shouldn’t it at least reopen the thing? Is there a method for “regenerate” or similar?

  • If I want to rebuild it, it throws an error “‘custom_dialog: content view was already added to some other view or dialog.’”

Obviously I did not yet fully understand the logic behind this.

What I want is to regenerate / rebind the dialogue and then reopen it. I already tried to wrap it into a function and calling it recursively, but wasn’t successful.

The third question is, how to target a control itself within the notifier-function? Let say this code:

vb:textfield {
                    value = tostring(data[index]), 
                    width = 80, 
                    tooltip = val.txt, 
                    notifier = function(newValue)
                        if (tonumber(newValue) == nil) then
                            renoise.app():show_error("Only use numeric values in the field "..index.."!")
                        else
                            data[index] = tonumber(newValue)
                            if (callbackRefresh ~= nil) then
                                callbackRefresh(data)
                            end
                        end
                    end,

On error, I also want to reset the value of that textfield. How can I address it in the most easy way? Am I forced to use an id then?

In Javascript afaik “this” always targets the most inner scope, so here this would be super easy (I even can do this.parent etc). In lua it seems that “self” only is available for classes / outer objects?

Yeah, the logic for opening/rebuilding dialogs can be a bit complex.
I’ve had good experiences with the approach used in vLib:
https://github.com/renoise/vLib/blob/master/classes/vDialog.lua#L74

As for how to target a control itself, you just add an ‘id’ property to your element.
Then you can access it from anywhere in that viewbuilder instance, using this syntax:

vb:button{
 id = "my_button",
 notifier = function()
  local the_button = vb.views["my_button"]
  the_button.active = false
 end 
}

But, be aware that once you absolutely need to destroy views with ids if you plan on (re-)building them - an id can be defined only once (it’s unique).

Sometimes, it’s preferable to just make a reference to your vb element, like this:

local my_button = nil

local my_button_handler = function()
  my_button.active = false
end

my_button = vb:button{
 notifier = function()
  my_button_handler()
 end 
}

Both are valid approaches, sometimes one fits better than the other.

Very helpful, thanks!