Save Button Color After Reopen the Script
Hi,
I'm using app.settings for saving edit text, check boxes and drop down lists and it's working fine.
But I can't figure it out how to use it on colorPicker to save my color button to be the same when I reopen the script.
This is my code:
{
function myScript(thisObj){
function myScript_buildUI(thisObj){
var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", undefined);
//============================================================
function setBG(graphics, rgba){
graphics.backgroundColor = graphics.newBrush(graphics.BrushType.SOLID_COLOR, rgba);
};
function hexToRgb(hex) {
if (typeof hex === 'string') hex = parseInt(hex, 16);
var r = (hex >> 16) & 0xFF;
var g = (hex >> 8 ) & 0xFF;
var b = (hex >> 0 ) & 0xFF;
return [r/255, g/255, b/255];
};
function rgbToHex(rgb){
var r = Math.round(rgb[0]*255);
var g = Math.round(rgb[1]*255);
var b = Math.round(rgb[2]*255);
return b + 256 * (g + 256 * r);
};
var dfltColor1 = [0.98,0.98,0.98];
if (isNaN(newcolor1)){
newcolor1 = dfltColor1;
};
//==========================================================
var myButtonGr = myPanel.add("group{margins: 0}");
setBG(myButtonGr.graphics, newcolor1)
var myButton = myButtonGr.add("button{size: [20,20]}");
var newcolor1;
myButton.onDraw = function(){};
myButton.onClick = function(){
var rgba = this.parent.graphics.backgroundColor.color;
var hex = rgbToHex(rgba);
var newHex = $.colorPicker(hex);
if (isNaN(newHex) || newHex<0) return;
var newRgb = hexToRgb(newHex);
newcolor1 = newRgb.slice(0);
setBG(this.parent.graphics, newcolor1);
};
//============================================================
if (app.settings.haveSetting("Color1", "Check")) {
newcolor1 = app.settings.getSetting("Color1", "Check");
};
myButton.onClick = function () {
app.settings.saveSetting("Color1", "Check", newcolor1.toString());
};
//============================================================
myPanel.layout.layout(true);
myPanel.minimumSize = myPanel.size;
myPanel.layout.resize();
myPanel.onResizing = myPanel.onResize = function(){this.layout.resize()};
return myPanel;
}
var myScriptPal = myScript_buildUI (thisObj);
if((myScriptPal != null) && (myScriptPal instanceof Window)){
myScriptPal.center();
myScriptPal.show();
}
}
myScript(this);
}
