Merge pull request #1520 from MathemanFlo/BrowserContextMenu

Add context menu to browser
This commit is contained in:
Lubos Lenco
2023-02-16 12:50:25 +01:00
committed by GitHub
2 changed files with 74 additions and 2 deletions
+69 -1
View File
@@ -3,6 +3,7 @@ package arm.ui;
import kha.input.KeyCode;
import zui.Zui;
import zui.Id;
import arm.sys.File;
import arm.sys.Path;
import arm.io.ImportAsset;
import arm.Enums;
@@ -92,7 +93,74 @@ class TabBrowser {
var _y = ui._y;
ui._x = bookmarksW;
ui._w -= bookmarksW;
UIFiles.fileBrowser(ui, hpath, false, true, hsearch.text, refresh);
UIFiles.fileBrowser(ui, hpath, false, true, hsearch.text, refresh, function(file) {
var fileName = file.substr(file.lastIndexOf(Path.sep)+1);
if (fileName != "..") {
UIMenu.draw(function(ui: Zui) {
ui.text(fileName, Right, ui.t.HIGHLIGHT_COL);
if (ui.button(tr("Import"), Left)) {
ImportAsset.run(file);
}
if (Path.isTexture(file)) {
if (ui.button(tr("Set as Envmap"), Left)) {
ImportAsset.run(file, -1.0, -1.0, true, true, function() {
App.notifyOnNextFrame(function() {
var assetIndex = -1;
for (i in 0...Project.assets.length) {
if (Project.assets[i].file == file) {
assetIndex = i;
break;
}
}
if (assetIndex != -1)
arm.io.ImportEnvmap.run(file, Project.getImage(Project.assets[assetIndex]));
});
});
}
if (ui.button(tr("Set as Mask"), Left)) {
ImportAsset.run(file, -1.0, -1.0, true, true, function() {
App.notifyOnNextFrame(function() {
var assetIndex = -1;
for (i in 0...Project.assets.length) {
if (Project.assets[i].file == file) {
assetIndex = i;
break;
}
}
if (assetIndex != -1)
Layers.createImageMask(Project.assets[assetIndex]);
});
});
}
if (ui.button(tr("Set as Color ID Map"), Left)) {
ImportAsset.run(file, -1.0, -1.0, true, true, function() {
App.notifyOnNextFrame(function() {
var assetIndex = -1;
for (i in 0...Project.assets.length) {
if (Project.assets[i].file == file) {
assetIndex = i;
break;
}
}
if (assetIndex != -1) {
Context.colorIdHandle.position = assetIndex;
Context.colorIdPicked = false;
UIToolbar.inst.toolbarHandle.redraws = 1;
if (Context.tool == ToolColorId) {
UIHeader.inst.headerHandle.redraws = 2;
Context.ddirty = 2;
}
}
});
});
}
}
if (ui.button(tr("Open externally"), Left)) {
File.start(file);
}
}, Path.isTexture(file) ? 6 : 3);
}
});
if (known) {
var path = hpath.text;
+5 -1
View File
@@ -82,7 +82,7 @@ class UIFiles {
@:access(zui.Zui)
@:access(arm.sys.File)
public static function fileBrowser(ui: Zui, handle: Handle, foldersOnly = false, dragFiles = false, search = "", refresh = false): String {
public static function fileBrowser(ui: Zui, handle: Handle, foldersOnly = false, dragFiles = false, search = "", refresh = false, contextMenu : String -> Void = null): String {
var icons = Res.get("icons.k");
var folder = Res.tile50(icons, 2, 1);
@@ -257,6 +257,10 @@ class UIFiles {
state = ui.image(icons, col, 50 * ui.SCALE(), rect.x, rect.y, rect.w, rect.h);
}
if (ui.isHovered && ui.inputReleasedR && contextMenu != null) {
contextMenu(handle.text + Path.sep + f);
}
if (state == Started) {
if (f != ".." && dragFiles) {
var mouse = Input.getMouse();