Kaynağa Gözat

cdb-view: wip fix formulas

lviguier 1 yıl önce
ebeveyn
işleme
90a74b3b34
2 değiştirilmiş dosya ile 35 ekleme ve 3 silme
  1. 24 2
      hide/comp/cdb/Cell.hx
  2. 11 1
      hide/comp/cdb/Formulas.hx

+ 24 - 2
hide/comp/cdb/Cell.hx

@@ -152,9 +152,31 @@ class Cell {
 				editor.endChanges();
 				refresh();
 			}
-			var forms : Array<hide.comp.ContextMenu.ContextMenuItem>;
+			var forms : Array<hide.comp.ContextMenu.ContextMenuItem> = [];
 			var current = editor.formulas.get(this);
-			forms = [for( f in editor.formulas.getList(table.sheet) ) { label : f.name, click : () -> if( f == current ) setF(null) else setF(f), checked : f == current }];
+
+			var isView = SheetView.isView(table.sheet);
+			var s = isView ? SheetView.getOriginalSheet(table.sheet) : table.sheet;
+			for (f in  editor.formulas.getList(s)) {
+				var el = {
+					label : f.name,
+					click : function() {
+						if( f == current )
+							setF(null)
+						else
+							setF(f);
+
+						if(isView) {
+							SheetView.reloadSheet(table.sheet);
+							editor.refresh();
+						}
+					},
+					checked : f == current,
+				};
+
+				forms.push(el);
+			}
+
 			#if !hl
 			forms.push({ label : "New...", click : () -> editor.formulas.createNew(this, setF) });
 			#end

+ 11 - 1
hide/comp/cdb/Formulas.hx

@@ -215,9 +215,13 @@ class Formulas {
 	}
 
 	public function get( c : Cell ) : Null<Formula> {
-		var tmap = fmap.get(c.table.sheet.name);
+		var isView = SheetView.isView(c.table.sheet);
+		var s = isView ? SheetView.getOriginalSheet(c.table.sheet) : c.table.sheet;
+		var tmap = fmap.get(s.name);
 		if( tmap == null )
 			return null;
+
+		var lineObj = isView ? SheetView.getOriginalObject(c.line) : c.line.obj;
 		var f = Reflect.field(c.line.obj, c.column.name+"__f");
 		if( f == null && c.column.editor != null ) {
 			f = (c.column.editor:Editor.EditorColumnProps).formula;
@@ -227,6 +231,12 @@ class Formulas {
 	}
 
 	public function set( c : Cell, f : Formula ) {
+		// var isView = SheetView.isView(c.table.sheet);
+		// if (isView) {
+		// 	var s = SheetView.getOriginalSheet(c.table.getRealSheet());
+		// 	setForValue(SheetView.getOriginalObject(c.line), s, s.columns[c.columnIndex], f == null ? null : f.name);
+		// }
+
 		setForValue(c.line.obj, c.table.getRealSheet(), c.column, f == null ? null : f.name);
 	}