Does "namerefresh" work correctly?

Here's a question I've been meaning to ask for some months.
On my scripts, namerefresh seems to behave erratically. When the file name changes, sometimes namerefresh kicks in, sometimes it doesn't.

On this screen shot, at the top, I finished editing the file name name, but the min column hasn't been updated.
At the bottom, after pressing F5, the column has updated.


As you can see on this excerpt from OnInit(), namerefresh is enabled (near the bottom). Am I using it incorrectly?
The full code can be inspected on the Movie Filename Database thread.

for(var key in columns) { if (columns.hasOwnProperty(key)) { var column = columns[key]; var cmd = initData.AddColumn(); cmd.autorefresh = true; cmd.defsort = (typeof column.sort === 'undefined') || (column.sort != "DESC") ? 1 : -1; cmd.defwidth = (typeof column.width === 'undefined') ? 5 : column.width; cmd.header = key; cmd.infotiponly = (typeof column.infotiponly === 'undefined') ? false : column.infotiponly; cmd.justify = (typeof column.justify === 'undefined') ? "left" : column.justify; cmd.label = ColumnPrefix + key; cmd.method = "OnRegexColumn"; cmd.name = key; cmd.namerefresh = true; cmd.type = (typeof column.type === 'undefined') ? null : column.type; } }

Thanks in advance for any insights!

Have you got a minimal script that reproduces the problem?

Hi Leo,

Just made one by shrinking the previous script to its bones.

Here is the procedure to reproduce.

  1. Install the script
  • in a test folder, right-click column names and add the three columns under Script / Test NameRefresh
  1. Create a text file named Fight Club [y=1901].txt
    At that stage, for me, the year column only displays after I hit F5

  2. Add a field by inline-renaming the file: insert min=150_ in the square brackets so the full file name becomes Fight Club [min=150_y=1901].txt
    The min field only appears after I press F5.

Attaching the script, pasting the code for convenience.

[code]// Opus calls OnInit to initialize the script add-in
function OnInit(initData) {
initData.name = "Test Name Refresh";
initData.desc = "Adds columns defined by regex search against filenames.";
initData.copyright = "playful & contributors 2015";
initData.min_version = "11.5.1"
initData.version = "0.9.2";
initData.default_enable = true;
var ColumnPrefix = "REFRESH.";

// Add all columns (create ScriptColumn objects via AddColumn()
for(var key in columns) {
if (columns.hasOwnProperty(key)) {
var column = columns[key];
var cmd = initData.AddColumn();
cmd.autorefresh = true;
cmd.namerefresh = true;
cmd.defsort = 1 ;
cmd.defwidth = (typeof column.width === 'undefined') ? 5 : column.width;
cmd.header = key;
cmd.label = ColumnPrefix + key;
cmd.method = "OnRegexColumn";
cmd.name = key;
cmd.type = null;
}
}
} // End OnInit

// Define Three Columns

var columns = {
'Title' : {
// The title (stripping [the keys=values] )
pattern: /^(?:[^ ]| (?![))*/,
width: 30
},

'Min' : {
// Duration, e.g. 120
// acceptable aliases for key: min, dur, duration
pattern: /[(?:[^]]+)?(?:min|dur(?:ation)?)=([^]]+)/i,
group: 1,
width: 3,
},
'Year' : {
// What year was it released?
// acceptable aliases for key: y, yr, year
pattern: /[(?:[^]]+)?y(?:(?:ea)?r)?=([^]]+)/i,
group: 1,
width: 4,
}

};

function OnRegexColumn(ColumnData) {
// OnRegexColumn is an OnScriptColumn method
// See http://www.gpsoft.com.au/help/opus11/index.html#!Documents/Scripting/OnScriptColumn.htm
// ColumnData is a ScriptColumnData object
// See http://www.gpsoft.com.au/help/opus11/index.html#!Documents/Scripting/ScriptColumnData.htm
var colName = ColumnData.col;
if(!columns[colName]) return;

var regexMatch;
var subject = ColumnData.item["name_stem"];;

regexMatch = columns[colName].pattern.exec(subject);

if (regexMatch != null) {
// display the value for the correct capture group
var capturegroup = (typeof columns[colName].group === 'undefined') ? 0 : columns[colName].group;
ColumnData.value = regexMatch[capturegroup];
} // regexmatch
} // OnRegexColumn

[/code]
TestNameRefresh.js.txt (4.68 KB)

@Leo
Trying this in DO12 Beta 4, still behaving as in the very last post (simplified script).
Is that script thin enough for you to replicate the issue and see what's happening?
In advance, thanks for your thoughts.

If you make it set ColumnData.value = ""; when the regex doesn't match, instead of returning without setting a value, it should then work consistently.

This looks like a bug, though, so we'll also make it so what you were doing originally will work. (Maybe there's merit in having a way for the script to say "don't call me again for this file", but if so it should probably be explicit instead of the way it is right now, which I think is accidental.)