From 4621dc6047bbbaf4b67b40f267c9f09febfc0e62 Mon Sep 17 00:00:00 2001 From: lviguier Date: Mon, 6 Jan 2025 16:26:33 +0100 Subject: [PATCH] Project settings: clear code and qol --- bin/style.css | 5 +++++ bin/style.less | 7 +++++++ hide/comp/FileSelect.hx | 11 +++++++++-- hide/view/settings/ProjectSettings.hx | 27 +++++++++++++++------------ 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/bin/style.css b/bin/style.css index 68342838c..7eb0675a9 100644 --- a/bin/style.css +++ b/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; diff --git a/bin/style.less b/bin/style.less index 0ceef86eb..e18fbc1ee 100644 --- a/bin/style.less +++ b/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; diff --git a/hide/comp/FileSelect.hx b/hide/comp/FileSelect.hx index 4b60277a3..de7e77400 100644 --- a/hide/comp/FileSelect.hx +++ b/hide/comp/FileSelect.hx @@ -4,6 +4,7 @@ class FileSelect extends Component { var extensions : Array; 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() { } diff --git a/hide/view/settings/ProjectSettings.hx b/hide/view/settings/ProjectSettings.hx index 544fa6431..aca3a2e87 100644 --- a/hide/view/settings/ProjectSettings.hx +++ b/hide/view/settings/ProjectSettings.hx @@ -66,6 +66,15 @@ class ProjectSettings extends hide.ui.View<{}> { ').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<{}> {
- ').appendTo(element.find(".right-panel")); + ').appendTo(rightPanel); if (matLibs != null) { for (ml in matLibs) { @@ -228,7 +231,7 @@ class ProjectSettings extends hide.ui.View<{}> {
- ').appendTo(element.find(".right-panel")); + ').appendTo(rightPanel); renderPropsEl.find(".add-btn").click(function(e) { if (renderProps == null) {