Hi Ernest,
I did some experiments and the following code worked for me. I added a saveLocation method to globals as follows:
- Code: Select all
function saveLocation(_cFormName){
var _oForm = forms[_cFormName];
var _oElement;
var _cSaveFile = "";
var _nLocationX = 0;
var _nLocationY = 0;
var _lSuccess = false;
for (var i=0; i < _oForm.elements.length; i++)
{
_oElement = _oForm.elements[i];
_nLocationX = _oElement.getLocationX();
_nLocationY = _oElement.getLocationY();
_cSaveFile = _cSaveFile + _oElement.getName() + "|" + _nLocationX + "," + _nLocationY + "\n";
}
_cSaveFile = _cSaveFile + " \n "; // avoid infinite loop on the last line
_lSuccess = plugins.file.writeTXTFile(_cFormName+"_loc.mem", _cSaveFile);
}
and a restoreLocation like this:
- Code: Select all
function restoreLocation(_cFormName){
var _oForm = forms[_cFormName];
var _oFile = plugins.file.convertToJSFile(_cFormName+"_loc.mem");
try {
if (_oFile.exists()){
var _cSaveFile = plugins.file.readTXTFile(_cFormName+"_loc.mem");
var _nPos1, _nPos2, _nPos3, _nLocX, _nLocY;
var _cElementName;
while ( _cSaveFile.indexOf("|") > -1) {
_nPos1 = _cSaveFile.indexOf("|")
_nPos2 = _cSaveFile.indexOf(",")
_nPos3 = _cSaveFile.indexOf("\n")
_cElementName = _cSaveFile.substr(0,_nPos1);
_nLocX = utils.stringToNumber(_cSaveFile.substr(_nPos1+1, _nPos2-1));
_nLocY = utils.stringToNumber(_cSaveFile.substr(_nPos2+1, _nPos3-1));
_cSaveFile = _cSaveFile.substr(_nPos3+1);
_oForm.elements[_cElementName].setLocation(_nLocX, _nLocY);
}
}
}
catch(_oException) {
application.output(_oException.message);
_oFile.deleteFile();
}
}
to trigger the saving you could add a call in the onHide event:
- Code: Select all
function onHide(event) {
globals.saveLocation(controller.getName());
return true
}
and to trigger restoring on startup add a call to the onShow:
- Code: Select all
function onShow(firstShow, event) {
if (firstShow){
globals.restoreLocation(controller.getName());
}
}
This works for any ListView form. You may want to add some more validation code.
To save and restore sorting info use JSFoundset.getCurrentSort() and JSFoundset.Sort().