").addClass("hide-modal").appendTo(element);
element.append(div);
modal.click(function(e) {
setValue(val);
refresh();
});
case TTilePos:
var modal = new hide.comp.Modal(element);
modal.element.click(function(_) closeEdit());
var t : cdb.Types.TilePos = currentValue;
var file = t == null ? null : t.file;
var size = t == null ? 16 : t.size;
var pos = t == null ? { x : 0, y : 0, width : 1, height : 1 } : { x : t.x, y : t.y, width : t.width == null ? 1 : t.width, height : t.height == null ? 1 : t.height };
if( file == null ) {
var y = line.index - 1;
while( y >= 0 ) {
var o = line.table.lines[y--];
var v2 = Reflect.field(o.obj, column.name);
if( v2 != null ) {
file = v2.file;
size = v2.size;
break;
}
}
}
function setVal() {
var v : Dynamic = { file : file, size : size, x : pos.x, y : pos.y };
if( pos.width != 1 ) v.width = pos.width;
if( pos.height != 1 ) v.height = pos.height;
setRawValue(v);
}
if( file == null ) {
ide.chooseFile(["png","jpeg","jpg","gif"],function(path) {
file = path;
setVal();
closeEdit();
edit();
});
return;
}
var ts = new hide.comp.TileSelector(file,size,modal.content);
ts.allowRectSelect = true;
ts.allowSizeSelect = true;
ts.allowFileChange = true;
ts.value = pos;
ts.onChange = function(cancel) {
if( !cancel ) {
file = ts.file;
size = ts.size;
pos = ts.value;
setVal();
}
refresh();
focus();
};
case TLayer(_), TTileLayer:
// no edit
case TImage:
// deprecated
}
}
public function open( ?immediate : Bool ) {
if( column.type == TString && column.kind == Script ) {
if( immediate ) return;
var str = value == null ? "" : editor.base.valToString(column.type, value);
@:privateAccess table.toggleList(this, function() return new ScriptTable(editor, this));
} else
@:privateAccess table.toggleList(this, immediate);
}
public function setErrorMessage( msg : String ) {
element.find("div.error").remove();
if( msg == null ) return;
new Element("
").addClass("error").html(msg).appendTo(element);
}
function setRawValue( str : Dynamic ) {
var newValue : Dynamic;
if( Std.is(str,String) ) {
newValue = try editor.base.parseValue(column.type, str, false) catch( e : Dynamic ) return;
} else
newValue = str;
if( newValue == null || newValue == currentValue )
return;
switch( column.type ) {
case TId:
var obj = line.obj;
var prevValue = value;
// most likely our obj, unless there was a #DUP
var prevObj = value != null ? table.sheet.index.get(value) : null;
// have we already an obj mapped to the same id ?
var prevTarget = table.sheet.index.get(newValue);
editor.beginChanges();
if( prevObj == null || prevObj.obj == obj ) {
// remap
var m = new Map();
m.set(value, newValue);
editor.base.updateRefs(table.sheet, m);
}
setValue(newValue);
editor.endChanges();
editor.refreshAll();
focus();
/*
// creates or remove a #DUP : need to refresh the whole table
if( prevTarget != null || (prevObj != null && (prevObj.obj != obj || table.sheet.index.get(prevValue) != null)) )
table.refresh();
*/
case TString if( column.kind == Script ):
setValue(StringTools.trim(newValue));
case TTilePos:
// if we change a file that has moved, change it for all instances having the same file
editor.beginChanges();
var obj = line.obj;
var change = false;
var oldV : cdb.Types.TilePos = currentValue;
var newV : cdb.Types.TilePos = newValue;
if( newV != null && oldV != null && oldV.file != newV.file && !sys.FileSystem.exists(ide.getPath(oldV.file)) && sys.FileSystem.exists(ide.getPath(newV.file)) ) {
for( l in table.lines) {
if( l == line ) continue;
var t : Dynamic = Reflect.field(l.obj, column.name);
if( t != null && t.file == oldV.file ) {
t.file = newV.file;
change = true;
}
}
}
setValue(newValue);
editor.endChanges();
if( change )
editor.refresh();
default:
setValue(newValue);
}
}
public function setValue( value : Dynamic ) {
currentValue = value;
editor.changeObject(line,column,value);
}
public function closeEdit() {
var str = element.find("input,textarea").val();
if( str != null ) setRawValue(str);
refresh();
focus();
}
}