2024-03-14 15:31:22 +01:00
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let tab_browser_hpath: ui_handle_t = ui_handle_create();
|
|
|
|
|
let tab_browser_hsearch: ui_handle_t = ui_handle_create();
|
2024-03-14 15:31:22 +01:00
|
|
|
let tab_browser_known: bool = false;
|
|
|
|
|
let tab_browser_last_path: string = "";
|
2024-11-08 23:46:39 +01:00
|
|
|
let _tab_browser_draw_file: string;
|
|
|
|
|
let _tab_browser_draw_b: string;
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
function tab_browser_show_directory(directory: string) {
|
|
|
|
|
tab_browser_hpath.text = directory;
|
|
|
|
|
tab_browser_hsearch.text = "";
|
|
|
|
|
ui_base_htabs[tab_area_t.STATUS].position = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
function tab_browser_draw(htab: ui_handle_t) {
|
|
|
|
|
let ui: ui_t = ui_base_ui;
|
2024-03-14 15:31:22 +01:00
|
|
|
let statush: i32 = config_raw.layout[layout_size_t.STATUS_H];
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_tab(htab, tr("Browser")) && statush > ui_status_default_status_h * ui_SCALE(ui)) {
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
if (config_raw.bookmarks == null) {
|
|
|
|
|
config_raw.bookmarks = [];
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let bookmarks_w: i32 = math_floor(100 * ui_SCALE(ui));
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
if (tab_browser_hpath.text == "" && config_raw.bookmarks.length > 0) { // Init to first bookmark
|
|
|
|
|
tab_browser_hpath.text = config_raw.bookmarks[0];
|
2024-09-24 18:26:51 +02:00
|
|
|
///if arm_windows
|
|
|
|
|
tab_browser_hpath.text = string_replace_all(tab_browser_hpath.text, "/", "\\");
|
|
|
|
|
///end
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_begin_sticky();
|
2024-07-20 22:14:26 +02:00
|
|
|
let step: f32 = (1.0 - bookmarks_w / ui._w);
|
2024-03-14 15:31:22 +01:00
|
|
|
if (tab_browser_hsearch.text != "") {
|
2024-11-22 19:45:06 +01:00
|
|
|
let row: f32[] = [bookmarks_w / ui._w, step * 0.07, step * 0.07, step * 0.66, step * 0.17, step * 0.03];
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_row(row);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2024-11-22 19:45:06 +01:00
|
|
|
let row: f32[] = [bookmarks_w / ui._w, step * 0.07, step * 0.07, step * 0.66, step * 0.2];
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_row(row);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-22 19:45:06 +01:00
|
|
|
// Bookmark
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_button("+")) {
|
2024-09-24 18:26:51 +02:00
|
|
|
let bookmark: string = tab_browser_hpath.text;
|
|
|
|
|
///if arm_windows
|
|
|
|
|
bookmark = string_replace_all(bookmark, "\\", "/");
|
|
|
|
|
///end
|
|
|
|
|
array_push(config_raw.bookmarks, bookmark);
|
2024-03-14 15:31:22 +01:00
|
|
|
config_save();
|
|
|
|
|
}
|
2024-03-20 16:13:54 +01:00
|
|
|
if (ui.is_hovered) {
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_tooltip(tr("Add bookmark"));
|
2024-03-20 16:13:54 +01:00
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-11-22 19:45:06 +01:00
|
|
|
// Refresh
|
|
|
|
|
let refresh: bool = false;
|
|
|
|
|
let in_focus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w &&
|
|
|
|
|
ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h;
|
|
|
|
|
if (ui_button(tr("Refresh")) || (in_focus && ui.is_key_pressed && ui.key_code == key_code_t.F5)) {
|
|
|
|
|
refresh = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Previous folder
|
|
|
|
|
let text: string = tab_browser_hpath.text;
|
|
|
|
|
let i1: i32 = string_index_of(text, path_sep);
|
|
|
|
|
let nested: bool = i1 > -1 && text.length - 1 > i1;
|
|
|
|
|
///if arm_windows
|
|
|
|
|
// Server addresses like \\server are not nested
|
|
|
|
|
nested = nested && !(text.length >= 2 && char_at(text, 0) == path_sep && char_at(text, 1) == path_sep && string_last_index_of(text, path_sep) == 1);
|
|
|
|
|
///end
|
|
|
|
|
|
|
|
|
|
ui.enabled = nested;
|
|
|
|
|
if (ui_button("<")) {
|
|
|
|
|
ui_files_go_up(tab_browser_hpath);
|
|
|
|
|
}
|
|
|
|
|
ui.enabled = true;
|
|
|
|
|
if (ui.is_hovered) {
|
|
|
|
|
ui_tooltip(tr("Previous folder"));
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-06 21:11:46 +02:00
|
|
|
///if arm_android
|
2024-03-14 15:31:22 +01:00
|
|
|
let stripped: bool = false;
|
|
|
|
|
let strip: string = "/storage/emulated/0/";
|
2024-03-20 16:13:54 +01:00
|
|
|
if (starts_with(tab_browser_hpath.text, strip)) {
|
|
|
|
|
tab_browser_hpath.text = substring(tab_browser_hpath.text, strip.length - 1, tab_browser_hpath.text.length);
|
2024-03-14 15:31:22 +01:00
|
|
|
stripped = true;
|
|
|
|
|
}
|
|
|
|
|
///end
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
tab_browser_hpath.text = ui_text_input(tab_browser_hpath, tr("Path"));
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-09-06 21:11:46 +02:00
|
|
|
///if arm_android
|
2024-03-14 15:31:22 +01:00
|
|
|
if (stripped) {
|
|
|
|
|
tab_browser_hpath.text = "/storage/emulated/0" + tab_browser_hpath.text;
|
|
|
|
|
}
|
|
|
|
|
///end
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
tab_browser_hsearch.text = ui_text_input(tab_browser_hsearch, tr("Search"), ui_align_t.LEFT, true, true);
|
2024-03-20 16:13:54 +01:00
|
|
|
if (ui.is_hovered) {
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_tooltip(tr("ctrl+f to search") + "\n" + tr("esc to cancel"));
|
2024-03-20 16:13:54 +01:00
|
|
|
}
|
2024-05-03 21:29:39 +02:00
|
|
|
if (ui.is_ctrl_down && ui.is_key_pressed && ui.key_code == key_code_t.F) { // Start searching via ctrl+f
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_start_text_edit(tab_browser_hsearch);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2024-09-03 15:52:05 +02:00
|
|
|
if (tab_browser_hsearch.text != "" && (ui_button(tr("X")) || ui.is_escape_down)) {
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_browser_hsearch.text = "";
|
|
|
|
|
}
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_end_sticky();
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
if (tab_browser_last_path != tab_browser_hpath.text) {
|
|
|
|
|
tab_browser_hsearch.text = "";
|
|
|
|
|
}
|
|
|
|
|
tab_browser_last_path = tab_browser_hpath.text;
|
|
|
|
|
|
|
|
|
|
let _y: f32 = ui._y;
|
|
|
|
|
ui._x = bookmarks_w;
|
|
|
|
|
ui._w -= bookmarks_w;
|
2024-04-07 09:52:45 +02:00
|
|
|
|
2024-09-29 23:48:42 +02:00
|
|
|
ui_files_file_browser(ui, tab_browser_hpath, true, tab_browser_hsearch.text, refresh, function (file: string) {
|
2024-04-07 09:52:45 +02:00
|
|
|
|
2024-03-20 16:13:54 +01:00
|
|
|
let file_name: string = substring(file, string_last_index_of(file, path_sep) + 1, file.length);
|
2024-04-07 09:52:45 +02:00
|
|
|
if (file_name == "..") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_tab_browser_draw_file = file;
|
|
|
|
|
|
|
|
|
|
// Context menu
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_menu_draw(function (ui: ui_t) {
|
2024-04-07 09:52:45 +02:00
|
|
|
let file: string = _tab_browser_draw_file;
|
|
|
|
|
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Import"))) {
|
2024-04-07 09:52:45 +02:00
|
|
|
import_asset_run(file);
|
|
|
|
|
}
|
|
|
|
|
if (path_is_texture(file)) {
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Set as Envmap"))) {
|
2024-04-07 09:52:45 +02:00
|
|
|
|
|
|
|
|
import_asset_run(file, -1.0, -1.0, true, true, function () {
|
2025-03-11 19:49:42 +01:00
|
|
|
sys_notify_on_next_frame(function () {
|
2024-04-07 09:52:45 +02:00
|
|
|
let file: string = _tab_browser_draw_file;
|
|
|
|
|
|
|
|
|
|
let asset_index: i32 = -1;
|
|
|
|
|
for (let i: i32 = 0; i < project_assets.length; ++i) {
|
|
|
|
|
if (project_assets[i].file == file) {
|
|
|
|
|
asset_index = i;
|
|
|
|
|
break;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2024-04-07 09:52:45 +02:00
|
|
|
}
|
|
|
|
|
if (asset_index != -1) {
|
|
|
|
|
import_envmap_run(file, project_get_image(project_assets[asset_index]));
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
});
|
2024-04-07 09:52:45 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///if (is_paint || is_sculpt)
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Set as Mask"))) {
|
2024-04-07 09:52:45 +02:00
|
|
|
import_asset_run(file, -1.0, -1.0, true, true, function () {
|
2025-03-11 19:49:42 +01:00
|
|
|
sys_notify_on_next_frame(function () {
|
2024-04-07 09:52:45 +02:00
|
|
|
let file: string = _tab_browser_draw_file;
|
|
|
|
|
|
|
|
|
|
let asset_index: i32 = -1;
|
|
|
|
|
for (let i: i32 = 0; i < project_assets.length; ++i) {
|
|
|
|
|
if (project_assets[i].file == file) {
|
|
|
|
|
asset_index = i;
|
|
|
|
|
break;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2024-04-07 09:52:45 +02:00
|
|
|
}
|
|
|
|
|
if (asset_index != -1) {
|
2024-11-10 16:53:36 +01:00
|
|
|
layers_create_image_mask(project_assets[asset_index]);
|
2024-04-07 09:52:45 +02:00
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
});
|
2024-04-07 09:52:45 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
///end
|
|
|
|
|
|
|
|
|
|
///if is_paint
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Set as Color ID Map"))) {
|
2024-04-07 09:52:45 +02:00
|
|
|
import_asset_run(file, -1.0, -1.0, true, true, function () {
|
2025-03-11 19:49:42 +01:00
|
|
|
sys_notify_on_next_frame(function () {
|
2024-04-07 09:52:45 +02:00
|
|
|
let file: string = _tab_browser_draw_file;
|
|
|
|
|
|
|
|
|
|
let asset_index: i32 = -1;
|
|
|
|
|
for (let i: i32 = 0; i < project_assets.length; ++i) {
|
|
|
|
|
if (project_assets[i].file == file) {
|
|
|
|
|
asset_index = i;
|
|
|
|
|
break;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2024-04-07 09:52:45 +02:00
|
|
|
}
|
|
|
|
|
if (asset_index != -1) {
|
|
|
|
|
context_raw.colorid_handle.position = asset_index;
|
|
|
|
|
context_raw.colorid_picked = false;
|
|
|
|
|
ui_toolbar_handle.redraws = 1;
|
|
|
|
|
if (context_raw.tool == workspace_tool_t.COLORID) {
|
|
|
|
|
ui_header_handle.redraws = 2;
|
|
|
|
|
context_raw.ddirty = 2;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2024-04-07 09:52:45 +02:00
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
});
|
2024-04-07 09:52:45 +02:00
|
|
|
});
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2024-04-07 09:52:45 +02:00
|
|
|
///end
|
|
|
|
|
}
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Open Externally"))) {
|
2024-04-07 09:52:45 +02:00
|
|
|
file_start(file);
|
|
|
|
|
}
|
2024-09-11 16:32:12 +02:00
|
|
|
});
|
2024-03-14 15:31:22 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (tab_browser_known) {
|
|
|
|
|
let path: string = tab_browser_hpath.text;
|
2025-03-11 19:49:42 +01:00
|
|
|
sys_notify_on_init(function (path: string) {
|
2024-03-14 15:31:22 +01:00
|
|
|
import_asset_run(path);
|
2024-04-07 09:52:45 +02:00
|
|
|
}, path);
|
2024-03-20 16:13:54 +01:00
|
|
|
tab_browser_hpath.text = substring(tab_browser_hpath.text, 0, string_last_index_of(tab_browser_hpath.text, path_sep));
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2024-05-03 21:29:39 +02:00
|
|
|
let hpath_text: string = tab_browser_hpath.text;
|
|
|
|
|
tab_browser_known = string_index_of(substring(tab_browser_hpath.text, string_last_index_of(tab_browser_hpath.text, path_sep), hpath_text.length), ".") > 0;
|
2024-09-06 21:11:46 +02:00
|
|
|
///if arm_android
|
2024-03-20 16:13:54 +01:00
|
|
|
if (ends_with(tab_browser_hpath.text, "." + to_lower_case(manifest_title))) {
|
|
|
|
|
tab_browser_known = false;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
///end
|
|
|
|
|
|
|
|
|
|
let bottom_y: i32 = ui._y;
|
|
|
|
|
ui._x = 0;
|
|
|
|
|
ui._y = _y;
|
|
|
|
|
ui._w = bookmarks_w;
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_button(tr("Cloud"), ui_align_t.LEFT)) {
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_browser_hpath.text = "cloud";
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_button(tr("Disk"), ui_align_t.LEFT)) {
|
2024-09-06 21:11:46 +02:00
|
|
|
///if arm_android
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_menu_draw(function (ui: ui_t) {
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Download"))) {
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_browser_hpath.text = ui_files_default_path;
|
|
|
|
|
}
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Pictures"))) {
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_browser_hpath.text = "/storage/emulated/0/Pictures";
|
|
|
|
|
}
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Camera"))) {
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_browser_hpath.text = "/storage/emulated/0/DCIM/Camera";
|
|
|
|
|
}
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Projects"))) {
|
2025-03-09 17:02:12 +01:00
|
|
|
tab_browser_hpath.text = iron_internal_save_path();
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2024-09-11 16:32:12 +02:00
|
|
|
});
|
2024-03-14 15:31:22 +01:00
|
|
|
///else
|
|
|
|
|
tab_browser_hpath.text = ui_files_default_path;
|
|
|
|
|
///end
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-21 21:06:41 +01:00
|
|
|
for (let i: i32 = 0; i < config_raw.bookmarks.length; ++i) {
|
|
|
|
|
let b: string = config_raw.bookmarks[i];
|
2024-09-24 18:26:51 +02:00
|
|
|
let folder: string = substring(b, string_last_index_of(b, "/") + 1, b.length);
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_button(folder, ui_align_t.LEFT)) {
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_browser_hpath.text = b;
|
2024-09-24 18:26:51 +02:00
|
|
|
///if arm_windows
|
|
|
|
|
tab_browser_hpath.text = string_replace_all(tab_browser_hpath.text, "/", "\\");
|
|
|
|
|
///end
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ui.is_hovered && ui.input_released_r) {
|
2024-04-07 09:52:45 +02:00
|
|
|
_tab_browser_draw_b = b;
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_menu_draw(function (ui: ui_t) {
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Delete"))) {
|
2024-04-07 09:52:45 +02:00
|
|
|
array_remove(config_raw.bookmarks, _tab_browser_draw_b);
|
2024-03-14 15:31:22 +01:00
|
|
|
config_save();
|
|
|
|
|
}
|
2024-09-11 16:32:12 +02:00
|
|
|
});
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 16:13:54 +01:00
|
|
|
if (ui._y < bottom_y) {
|
|
|
|
|
ui._y = bottom_y;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
}
|