Play.
function OnClick(clickData)
{
var cmd = clickData.func.command;
var filepath = "%appdata%\\GPSoftware\\Directory Opus\\Scripts\\INI\\CustomFilters.txt"; //File path
if(DOpus.FSUtil.Exists(filepath)) { //Read file
var FSU = DOpus.FSUtil;
var ST = DOpus.Create.StringTools();
var text = FSU.OpenFile(filepath).Read();
var text = ST.Decode(text, "utf-8 bom");
} else {var text = "New Filter\r\n-";}
var myArray = text.split("\r\n");
var opt1 = DOpus.NewVector();
for(i = 0; myArray[i]; i++) {
opt1(i) = myArray[i];
}
var opt2 = DOpus.NewVector(opt1.length);
var dlg = clickData.func.dlg;
//Show menu
dlg.choices = opt1;
dlg.menu = opt2;
var r = dlg.Show();
//If clicking
if (r > 0)
{
//Get Clicked item
var c = opt1(r - 1);
if(c == "New Filter") {
var dlg = clickData.func.Dlg;
dlg.title = "New Filter";
dlg.message = "Enter a new filter";
dlg.buttons = "OK|Cancel";
dlg.max = 256;
dlg.defvalue = "";
dlg.select = true;
dlg.Show();
var input = dlg.input;
if (dlg.result == 0 || input == "")
return;
}
var newFilter = "";
var filecontent = "";
if(c != "New Filter") {
cmd.Runcommand('Set QUICKFILTER="' + c + '"'); //Run an internal command
} else {
if(input != "") {
cmd.Runcommand('Set QUICKFILTER="' + input + '"'); //Run an internal command
for(i = 0; myArray[i]; i++) {
if(input == myArray[i]) {var equal = 1};
//DOpus.Output(newFilter)
}
if(equal != 1) {newFilter = input};
if(newFilter != "" && text != "") {
filecontent = text + "\r\n" + newFilter;
} else {
if(newFilter != "" && text == "") {
var filecontent = "New Filter\r\n-" + "\r\n" + newFilter;
}
}
if(!DOpus.FSUtil.Exists("%appdata%\\GPSoftware\\Directory Opus\\Scripts\\INI\\")) { //Create the path if does not exist
cmd.Runcommand('CreateFolder "%appdata%\\GPSoftware\\Directory Opus\\Scripts\\INI\\"');
}
//DOpus.Output(filecontent);
if(filecontent != "") {
var FSU2 = DOpus.FSUtil;
var ST2 = DOpus.Create.StringTools();
var oFileWrite = FSU2.OpenFile(filepath, "wa"); //Save filters
var utf8bom = ST2.Encode(filecontent, "utf-8 bom");
if(oFileWrite.error == 0)
{
oFileWrite.Write(utf8bom)
}
oFileWrite.Close()
}
}
}
}
}