Browse Source

Project settings: clear code and qol

lviguier 8 months ago
parent
commit
4621dc6047
4 changed files with 36 additions and 14 deletions
  1. 5 0
      bin/style.css
  2. 7 0
      bin/style.less
  3. 9 2
      hide/comp/FileSelect.hx
  4. 15 12
      hide/view/settings/ProjectSettings.hx

+ 5 - 0
bin/style.css

@@ -306,6 +306,9 @@ textarea:hover,
 input.file {
   cursor: pointer;
 }
+input.file.disabled {
+  cursor: default;
+}
 input.file.dragover {
   border-color: white;
   background-color: #141414;
@@ -3567,6 +3570,8 @@ div.gradient-box {
 }
 .project-settings .body .array .rows {
   min-height: 20px;
+  max-height: 750px;
+  overflow-y: scroll;
   width: 100%;
   background: #3f3f3f;
   border-radius: 2px 2px 0px 2px;

+ 7 - 0
bin/style.less

@@ -332,6 +332,11 @@ select, input, textarea, .hide-dropdown >.dropdown-cont {
 
 input.file {
 	cursor : pointer;
+
+	&.disabled {
+		cursor : default;
+	}
+
 	&.dragover {
 		border-color : white;
 		background-color : rgb(20,20,20);
@@ -4168,6 +4173,8 @@ div.gradient-box {
 		.array {
 			.rows {
 				min-height: 20px;
+				max-height: 750px;
+				overflow-y: scroll;
 				width: 100%;
 				background: #3f3f3f;
 				border-radius: 2px 2px 0px 2px;

+ 9 - 2
hide/comp/FileSelect.hx

@@ -4,6 +4,7 @@ class FileSelect extends Component {
 
 	var extensions : Array<String>;
 	public var path(default, set) : String;
+	public var disabled(default, set) = false;
 
 	public function new(extensions,?parent,?root) {
 		if( root == null )
@@ -14,6 +15,7 @@ class FileSelect extends Component {
 		path = null;
 		root.mousedown(function(e) {
 			e.preventDefault();
+			if (disabled) return;
 			if( e.button == 0 ) {
 				if (extensions == null || extensions.length == 0) {
 					ide.chooseDirectory(function(path) {
@@ -34,10 +36,10 @@ class FileSelect extends Component {
 			e.preventDefault();
 			var fpath = getFullPath();
 			ContextMenu.createFromEvent(cast e, [				{ label : "View", enabled : fpath != null, click : function() onView() },
-				{ label : "Clear", enabled : path != null, click : function() { path = null; onChange(); } },
+				{ label : "Clear", enabled : path != null && !disabled, click : function() { path = null; onChange(); } },
 				{ label : "Copy Path", enabled : path != null, click : function() ide.setClipboard(path) },
 				{ label : "Copy Absolute Path", enabled : fpath != null, click : function() { ide.setClipboard(fpath); } },
-				{ label : "Paste Path", click : function() {
+				{ label : "Paste Path", enabled: !disabled, click : function() {
 					path = ide.getClipboard();
 					onChange();
 				}},
@@ -109,6 +111,11 @@ class FileSelect extends Component {
 		return this.path = p;
 	}
 
+	function set_disabled(disabled : Bool) {
+		element.toggleClass("disabled", disabled);
+		return this.disabled = disabled;
+	}
+
 	public dynamic function onChange() {
 	}
 

+ 15 - 12
hide/view/settings/ProjectSettings.hx

@@ -66,6 +66,15 @@ class ProjectSettings extends hide.ui.View<{}> {
 			</div>
 		</div>').appendTo(element.find(".left-panel"));
 
+		function absToRelPath(absPath : String) {
+			if (absPath == null)
+				return "";
+			var relPath = absPath.substr(absPath.indexOf(ide.resourceDir) + ide.resourceDir.length + 1);
+			if (relPath == "")
+				return "[ROOT]";
+			return relPath;
+		}
+
 		function updateOverrides() {
 			var rows = overridesEl.find(".rows");
 			rows.empty();
@@ -91,7 +100,9 @@ class ProjectSettings extends hide.ui.View<{}> {
 				});
 
 				var fileSelect = new hide.comp.FileSelect(null, row, null);
+				fileSelect.disabled = true;
 				fileSelect.path = s.folder;
+				fileSelect.element.val(absToRelPath(haxe.io.Path.normalize(fileSelect.path)));
 			}
 		}
 
@@ -130,22 +141,14 @@ class ProjectSettings extends hide.ui.View<{}> {
 	}
 
 	function inspect(s : LocalSetting) {
-		element.find(".right-panel").empty();
+		var rightPanel = element.find(".right-panel");
+		rightPanel.empty();
 
 		var obj = s.content;
 
 		function onChange(file : String, oldObj : Dynamic, newObj : Dynamic) {
 			sys.io.File.saveContent(file, haxe.Json.stringify(newObj, '\t'));
 			inspect(s);
-
-			undo.change(Custom(function(undo) {
-				// TODO
-				// var o = oldObj;
-				// var n = newObj;
-				// obj = undo ? o : n;
-				// sys.io.File.saveContent(settings[0].file, haxe.Json.stringify(obj, '\t'));
-				// onDisplay();
-			}));
 		}
 
 		// Material library
@@ -159,7 +162,7 @@ class ProjectSettings extends hide.ui.View<{}> {
 					<div class="remove-btn icon ico ico-minus"></div>
 				</div>
 			</div>
-		</div>').appendTo(element.find(".right-panel"));
+		</div>').appendTo(rightPanel);
 
 		if (matLibs != null) {
 			for (ml in matLibs) {
@@ -228,7 +231,7 @@ class ProjectSettings extends hide.ui.View<{}> {
 					<div class="remove-btn icon ico ico-minus"></div>
 				</div>
 			</div>
-		</div>').appendTo(element.find(".right-panel"));
+		</div>').appendTo(rightPanel);
 
 		renderPropsEl.find(".add-btn").click(function(e) {
 			if (renderProps == null) {