Find Views Containing Bad Filters

The following is a cunning way to look for bad filters in views.
I am afraid that the bad views cannot be fixed without loading the view, but this will tell you where to look.

This script relies on the following assumptions:

  • When a module is opened, the default view is loaded. This is true even when the module is not visible.
  • When a view with a bad filter is loaded then the filtering property is set to true, but the filter itself is null.
// Check module for bad filters in views

/*
Tony Goodman.
*/

Skip viewNames = createString

/*************************
checkModuleForBadFilters
*************************/
string checkModuleForBadFilters(string modName)
{
Module m = null
Filter f = null
string vn = ""
string defViewUser    = ""

m = read(modName, false)

if (null m) return("Error opening module")

// get the user's default view - we need to restore this later
defViewUser = getDefaultViewForUser(m)

// get list of views
for vn in views(m) do
{
put(viewNames, vn, vn)
}

// set each view as default in turn and re-open the module
for vn in viewNames do
{
print("Checking view \"" vn "\"\n")

setDefaultViewForUser(m, vn)

close(m)

m = read(modName, false)

// if filtering is ON, but the filter is null, then we have found a bad filter
if (filtering(m))
{
f = current

if (null f)
{
print("**** View \"" vn "\" contains a bad filter\n")
}
}
}

// reset the user's default view (if there was one)
if (!null defViewUser)
{
setDefaultViewForUser(m, defViewUser)
}

return("")
}

string res = checkModuleForBadFilters("")
print(res)