Przeglądaj źródła

various cdb usability fixes

ncannasse 7 lat temu
rodzic
commit
01ff60ea51
6 zmienionych plików z 74 dodań i 19 usunięć
  1. 1 1
      bin/cdb.css
  2. 1 1
      bin/cdb.less
  3. 5 1
      hide/comp/ScriptEditor.hx
  4. 15 2
      hide/comp/cdb/Cell.hx
  5. 32 0
      hide/comp/cdb/Editor.hx
  6. 20 14
      hide/comp/cdb/Table.hx

+ 1 - 1
bin/cdb.css

@@ -275,7 +275,7 @@
 }
 .cdb .cdb-sheet div.cdb-script .scripteditor {
   min-width: 500px;
-  min-height: 400px;
+  min-height: 200px;
 }
 .cdb .cdb-sheet div.cdb-script .scriptErrorLine {
   background: #400;

+ 1 - 1
bin/cdb.less

@@ -307,7 +307,7 @@
 		div.cdb-script {
 			.scripteditor {
 				min-width: 500px;
-				min-height: 400px;
+				min-height: 200px;
 			}
 			.scriptErrorLine {
 				background: #400;

+ 5 - 1
hide/comp/ScriptEditor.hx

@@ -277,7 +277,11 @@ class ScriptEditor extends Component {
 				{ range : range, options : { linesDecorationsClassName: "scriptErrorLine", inlineClassName: "scriptErrorContent" } }
 			]);
 			errorMessage.text(hscript.Printer.errorToString(error));
-			errorMessage.show();
+			errorMessage.show(function() {
+				var rect = errorMessage[0].getBoundingClientRect();
+				if( rect.bottom > js.Browser.window.innerHeight )
+					errorMessage[0].scrollIntoView(false);
+			});
 		}
 	}
 

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

@@ -213,6 +213,18 @@ class Cell extends Component {
 		return html;
 	}
 
+	public function isTextInput() {
+		return switch( column.type ) {
+		case TString if( column.kind == Script ):
+			return false;
+		case TString, TInt, TFloat, TId, TCustom(_), TDynamic, TRef(_):
+			return true;
+		default:
+			return false;
+		}
+	}
+
+
 	public function edit() {
 		switch( column.type ) {
 		case TString if( column.kind == Script ):
@@ -223,10 +235,11 @@ class Cell extends Component {
 			var textSpan = element.wrapInner("<span>").find("span");
 			var textHeight = textSpan.height();
 			var textWidth = textSpan.width();
-			var longText = textHeight > 25;
+			var longText = textHeight > 25 || str.indexOf("\n") >= 0;
 			element.empty();
 			element.addClass("edit");
 			var i = new Element(longText ? "<textarea>" : "<input>").appendTo(element);
+			i.keypress(function(e) e.stopPropagation());
 			//if( str != "" && (table.displayMode == Properties || table.displayMode == AllProperties) )
 			//	i.css({ width : Math.ceil(textWidth - 3) + "px" }); -- bug if small text ?
 			if( longText ) {
@@ -276,7 +289,7 @@ class Cell extends Component {
 			i.select();
 			if( longText ) i.scrollTop(0);
 		case TBool:
-			setValue( currentValue == false && column.opt ? null : !currentValue ? true : false );
+			setValue( currentValue == false && column.opt && table.displayMode != Properties ? null : currentValue == null ? true : currentValue ? false : true );
 			refresh();
 		case TProperties, TList:
 			@:privateAccess table.toggleList(this);

+ 32 - 0
hide/comp/cdb/Editor.hx

@@ -26,6 +26,11 @@ class Editor extends Component {
 		this.undo = new hide.ui.UndoHistory();
 		this.sheet = sheet;
 		element.attr("tabindex", 0);
+		element.on("keypress", function(e) {
+			var cell = cursor.getCell();
+			if( cell != null && cell.isTextInput() && !e.ctrlKey )
+				cell.edit();
+		});
 		keys = new hide.ui.Keys(element);
 		keys.addListener(onKey);
 		keys.register("search", function() {
@@ -265,6 +270,33 @@ class Editor extends Component {
 	}
 
 	public function insertLine( table : Table, index = 0 ) {
+		if( table.displayMode == Properties ) {
+			var ins = table.element.find("select.insertField");
+			var options = [for( o in ins.find("option").elements() ) o.val()];
+			ins.attr("size", options.length);
+			options.shift();
+			ins.focus();
+			var index = 0;
+			ins.val(options[0]);
+			ins.off();
+			ins.blur(function(_) table.refresh());
+			ins.keydown(function(e) {
+				switch( e.keyCode ) {
+				case K.ESCAPE:
+					element.focus();
+				case K.UP if( index > 0 ):
+					ins.val(options[--index]);
+				case K.DOWN if( index < options.length - 1 ):
+					ins.val(options[++index]);
+				case K.ENTER:
+					table.insertProperty(ins.val());
+				default:
+				}
+				e.stopPropagation();
+				e.preventDefault();
+			});
+			return;
+		}
 		addChanges([{ ref : cursor.getLine().getChangeRef(), v : DeleteIndex(table.sheet.lines,index+1) }]);
 		table.sheet.newLine(index);
 		table.refresh();

+ 20 - 14
hide/comp/cdb/Table.hx

@@ -210,7 +210,7 @@ class Table extends Component {
 		// add/edit properties
 		var end = new Element("<tr>").appendTo(element);
 		end = new Element("<td>").attr("colspan", "2").appendTo(end);
-		var sel = new Element("<select>").appendTo(end);
+		var sel = new Element("<select class='insertField'>").appendTo(end);
 		new Element("<option>").attr("value", "").text("--- Choose ---").appendTo(sel);
 		for( c in available )
 			J("<option>").attr("value",c.name).text(c.name).appendTo(sel);
@@ -225,22 +225,28 @@ class Table extends Component {
 				editor.newColumn(sheet);
 				return;
 			}
-			for( c in available )
-				if( c.name == v ) {
-					var val = editor.base.getDefault(c, true);
-					Reflect.setField(props, c.name, val);
-					editor.undo.change(Custom(function(undo) {
-						if( undo )
-							Reflect.deleteField(props, c.name);
-						else
-							Reflect.setField(props,c.name, val);
-					}));
-					refresh();
-					return;
-				}
+			insertProperty(v);
 		});
 	}
 
+	public function insertProperty( p : String ) {
+		var props = sheet.lines[0];
+		for( c in sheet.columns )
+			if( c.name == p ) {
+				var val = editor.base.getDefault(c, true);
+				Reflect.setField(props, c.name, val);
+				editor.undo.change(Custom(function(undo) {
+					if( undo )
+						Reflect.deleteField(props, c.name);
+					else
+						Reflect.setField(props,c.name, val);
+				}));
+				refresh();
+				return true;
+			}
+		return false;
+	}
+
 	function toggleList( cell : Cell, ?make : Void -> SubTable ) {
 		var line = cell.line;
 		var cur = line.subTable;