Potential address bar / script add-ins bug?

I've been working on implementing a script add-in similar to RegExpColumns by wowbagger. I only discovered that add-in a few days after I had my own idea. But I also did want something simpler / light-weight so I can easier tweak everything to my own personal needs. So currently my script looks as follows:

function ConfigureRegex(tab)
{
  var dlg = tab.Dlg();

  var regex = dlg.GetString("Enter name regex", "", "512", "OK|Cancel", "Enter regex", tab, null);

  if (regex) {
    tab.vars.Set("regex", regex);

    Script.InitColumns();

    Script.RefreshColumn("DynamicNameRegexColumnv3");
  }
}

function OnInit(initData)
{
  initData.name = "Dynamic Name Regex Column v3";
  initData.desc = "Adds a column that displays names according to a regex.";
  initData.copyright = "(c) 2022 Nisto";
  initData.version = "1.0";
  initData.url = "";
  initData.min_version = "12.0";
  initData.default_enable = true;
}

function OnAddColumns(addColData)
{
  var col = addColData.AddColumn();
  col.name = "DynamicNameRegexColumnv3";
  col.method = "OnDynamicNameRegexColumnv3";
  col.label = "Dynamic Name Regex Column v3";
  col.autogroup = false;
  col.autorefresh = true;
  col.justify = "left";
}

function OnDynamicNameRegexColumnv3(scriptColData)
{
  if (scriptColData.col == "DynamicNameRegexColumnv3") {
    var vars = scriptColData.tab.vars;

    if (!vars.Exists("regex") || !vars.Get("regex")) {
      ConfigureRegex(scriptColData.tab);
    }

    if (vars.Exists("regex") && vars.Get("regex")) {
      var re = new RegExp(scriptColData.tab.vars.Get("regex"));
      scriptColData.value = scriptColData.item.name.replace(re, "$1");
    }
  }
}

It seems to work pretty nicely, but there is a small problem: after I've confirmed the dialogue triggered by the ConfigureRegex() function, the "folder loading" icon in the address bar keeps showing and doesn't disappear until manually refreshing the lister/tab - see top right in this image:

I do realize it's probably rather unorthodox to show dialogues within the OnScriptColumn() method, but this was about the only approach I could seem to find to allow showing a dialogue (in this case for setting a user-defined mandatory regex pattern) when the column first gets added in a lister/tab. If there's a better/simpler way of accomplishing this, I'd love to know!

I've tested both v12.15 and v12.28 - same behavior.

Showing a dialog when a column is added seems bad.

Instead, you could have the script add a command which shows the configuration dialog and adds the column afterwards, and then tell people to use that command to turn on the column. Or just let people configure it the normal way, via the list of scripts, before adding the column.

The columns themselves should not show any UI, and should return as quickly as they can to avoid making other columns/metadata queue up behind them.

Showing a dialog when a column is added seems bad.

Ya, I assumed as much.

Instead, you could have the script add a command which shows the configuration dialog and adds the column afterwards, and then tell people to use that command to turn on the column.

I don't know, it feels a bit.. buggy (for lack of a better word) to not be able to properly use a column only because you don't access it from specific area in the UI. It should be obvious, and just.. work, IMO.

No chance we could have events for "OnColumnAdd" / "OnColumnRemove" or something like that? Basically, an event that you can handle when a column gets added / removed. I was already planning on making a command accessible via a button in my toolbar, but my preference is a button that would only show if the column is already added (which I already have managed to implement with a @hideif btw).

If the column doesn't work until configured, why add it to the list of available columns at all (until it has been configured)? The column isn't really defined yet, so it shouldn't be listed.

Presumably you would also want to be able to have more than one column, if it's dealing in configurable regex? If so, you would want a UI for adding and defining what the columns are. (Similar to the one in WowBagger's script Column - Custom Text and Regexp ).

If the column doesn't work until configured, why add it to the list of available columns at all (until it has been configured)? The column isn't really defined yet, so it shouldn't be listed.

The column doesn't store any persistent configurations, so there isn't really any regex pattern it can use initially. It's quite rare that there's a regex pattern I could actually re-use, so there isn't much of a point in doing it either (storing a persistent config, that is). It's far more often that I'd have to design a new pattern that suits a specific case.

Presumably you would also want to be able to have more than one column, if it's dealing in configurable regex?

Again, no. I haven't ever found myself needing more than one column.

We should have a fix for this in the next update.

1 Like

Thanks so much, Jon.