Skip to content

Commit

Permalink
Project settings: clear code and qol
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoVgr committed Jan 6, 2025
1 parent 5248853 commit 4621dc6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
5 changes: 5 additions & 0 deletions bin/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ textarea:hover,
input.file {
cursor: pointer;
}
input.file.disabled {
cursor: default;
}
input.file.dragover {
border-color: white;
background-color: #141414;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions bin/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions hide/comp/FileSelect.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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) {
Expand All @@ -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();
}},
Expand Down Expand Up @@ -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() {
}

Expand Down
27 changes: 15 additions & 12 deletions hide/view/settings/ProjectSettings.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)));
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4621dc6

Please sign in to comment.