feat: system settings stored as applets in virtual folder
This commit is contained in:
@@ -8,14 +8,54 @@
|
||||
|
||||
namespace filemanager {
|
||||
|
||||
void filemanager_push_history(FileManagerState* fm) {
|
||||
// Don't push if same as current position
|
||||
if (fm->history_count > 0 && fm->history_pos >= 0) {
|
||||
if (montauk::streq(fm->history[fm->history_pos], fm->current_path)) return;
|
||||
static void filemanager_store_location(FileManagerLocation* location,
|
||||
const char* path,
|
||||
FileManagerVirtualViewKind virtual_view) {
|
||||
if (!location) return;
|
||||
montauk::strncpy(location->path, path ? path : "", sizeof(location->path));
|
||||
location->virtual_view = virtual_view;
|
||||
}
|
||||
|
||||
static bool filemanager_location_matches_current(const FileManagerState* fm,
|
||||
const FileManagerLocation& location) {
|
||||
return fm
|
||||
&& location.virtual_view == fm->virtual_view
|
||||
&& montauk::streq(location.path, fm->current_path);
|
||||
}
|
||||
|
||||
static void filemanager_restore_location(FileManagerState* fm, const FileManagerLocation& location) {
|
||||
montauk::strncpy(fm->current_path, location.path, sizeof(fm->current_path));
|
||||
|
||||
if (location.virtual_view != FM_VIRTUAL_VIEW_NONE) {
|
||||
filemanager_read_virtual_view(fm, location.virtual_view);
|
||||
} else if (location.path[0] == '\0') {
|
||||
filemanager_read_drives(fm);
|
||||
} else {
|
||||
filemanager_read_dir(fm);
|
||||
}
|
||||
}
|
||||
|
||||
void filemanager_push_history(FileManagerState* fm) {
|
||||
if (!fm) return;
|
||||
|
||||
if (fm->history_count > 0 && fm->history_pos >= 0) {
|
||||
if (filemanager_location_matches_current(fm, fm->history[fm->history_pos])) return;
|
||||
}
|
||||
|
||||
if (fm->history_pos < fm->history_count - 1) {
|
||||
fm->history_count = fm->history_pos + 1;
|
||||
}
|
||||
|
||||
if (fm->history_count >= 16) {
|
||||
for (int i = 1; i < 16; i++) {
|
||||
fm->history[i - 1] = fm->history[i];
|
||||
}
|
||||
fm->history_count = 15;
|
||||
fm->history_pos = 14;
|
||||
}
|
||||
|
||||
fm->history_pos++;
|
||||
if (fm->history_pos >= 16) fm->history_pos = 15;
|
||||
montauk::strcpy(fm->history[fm->history_pos], fm->current_path);
|
||||
filemanager_store_location(&fm->history[fm->history_pos], fm->current_path, fm->virtual_view);
|
||||
fm->history_count = fm->history_pos + 1;
|
||||
}
|
||||
|
||||
@@ -25,17 +65,14 @@ void filemanager_navigate(FileManagerState* fm, const char* name) {
|
||||
str_append(fm->current_path, "/", 256);
|
||||
}
|
||||
str_append(fm->current_path, name, 256);
|
||||
filemanager_push_history(fm);
|
||||
filemanager_read_dir(fm);
|
||||
filemanager_push_history(fm);
|
||||
}
|
||||
|
||||
void filemanager_go_up(FileManagerState* fm) {
|
||||
if (fm->at_drives_root) return;
|
||||
if (filemanager_is_computer_view(fm)) return;
|
||||
|
||||
// From apps view, go back to Computer
|
||||
if (fm->at_apps_view) {
|
||||
fm->at_apps_view = false;
|
||||
filemanager_free_app_icons(fm);
|
||||
if (filemanager_is_virtual_view(fm)) {
|
||||
filemanager_read_drives(fm);
|
||||
filemanager_push_history(fm);
|
||||
return;
|
||||
@@ -46,7 +83,6 @@ void filemanager_go_up(FileManagerState* fm) {
|
||||
// At drive root (e.g. "0:/" or "10:/") -- go to drives view
|
||||
bool is_drive_root = false;
|
||||
if (len >= 3 && fm->current_path[len - 1] == '/') {
|
||||
// Check if path is just "N:/" or "NN:/"
|
||||
int colon = -1;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (fm->current_path[i] == ':') { colon = i; break; }
|
||||
@@ -69,24 +105,19 @@ void filemanager_go_up(FileManagerState* fm) {
|
||||
if (fm->current_path[i] == '/') { last_slash = i; break; }
|
||||
}
|
||||
if (last_slash >= 0) {
|
||||
// Keep the slash only if it's the root slash (right after "N:")
|
||||
if (last_slash > 0 && fm->current_path[last_slash - 1] == ':') {
|
||||
fm->current_path[last_slash + 1] = '\0';
|
||||
} else {
|
||||
fm->current_path[last_slash] = '\0';
|
||||
}
|
||||
}
|
||||
filemanager_push_history(fm);
|
||||
filemanager_read_dir(fm);
|
||||
filemanager_push_history(fm);
|
||||
}
|
||||
|
||||
void filemanager_navigate_to_history(FileManagerState* fm) {
|
||||
montauk::strcpy(fm->current_path, fm->history[fm->history_pos]);
|
||||
if (fm->current_path[0] == '\0') {
|
||||
filemanager_read_drives(fm);
|
||||
} else {
|
||||
filemanager_read_dir(fm);
|
||||
}
|
||||
if (!fm || fm->history_pos < 0 || fm->history_pos >= fm->history_count) return;
|
||||
filemanager_restore_location(fm, fm->history[fm->history_pos]);
|
||||
}
|
||||
|
||||
void filemanager_go_back(FileManagerState* fm) {
|
||||
@@ -102,17 +133,13 @@ void filemanager_go_forward(FileManagerState* fm) {
|
||||
}
|
||||
|
||||
void filemanager_go_home(FileManagerState* fm) {
|
||||
if (fm->at_apps_view) {
|
||||
fm->at_apps_view = false;
|
||||
filemanager_free_app_icons(fm);
|
||||
}
|
||||
filemanager_read_drives(fm);
|
||||
filemanager_push_history(fm);
|
||||
}
|
||||
|
||||
void filemanager_start_pathbar(FileManagerState* fm) {
|
||||
fm->pathbar_editing = true;
|
||||
if (fm->at_drives_root) {
|
||||
if (filemanager_is_computer_view(fm) || filemanager_is_virtual_view(fm)) {
|
||||
fm->pathbar_buf[0] = '\0';
|
||||
fm->pathbar_len = 0;
|
||||
} else {
|
||||
@@ -134,15 +161,14 @@ void filemanager_commit_pathbar(FileManagerState* fm) {
|
||||
return;
|
||||
}
|
||||
montauk::strcpy(fm->current_path, fm->pathbar_buf);
|
||||
filemanager_push_history(fm);
|
||||
filemanager_read_dir(fm);
|
||||
filemanager_push_history(fm);
|
||||
}
|
||||
|
||||
void filemanager_open_entry(FileManagerState* fm, int idx) {
|
||||
if (idx < 0 || idx >= fm->entry_count) return;
|
||||
|
||||
// Special user folder in Computer view
|
||||
if (fm->at_drives_root && fm->entry_types[idx] == 7) {
|
||||
if (filemanager_is_computer_view(fm) && fm->entry_types[idx] == FM_ENTRY_SPECIAL_DIR) {
|
||||
DesktopState* ds = fm->desktop;
|
||||
if (ds && ds->home_dir[0] != '\0') {
|
||||
montauk::strcpy(fm->current_path, ds->home_dir);
|
||||
@@ -150,23 +176,33 @@ void filemanager_open_entry(FileManagerState* fm, int idx) {
|
||||
if (plen > 0 && fm->current_path[plen - 1] != '/')
|
||||
str_append(fm->current_path, "/", 256);
|
||||
str_append(fm->current_path, fm->entry_names[idx], 256);
|
||||
filemanager_push_history(fm);
|
||||
filemanager_read_dir(fm);
|
||||
filemanager_push_history(fm);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Apps shortcut in Computer view
|
||||
if (fm->at_drives_root && fm->entry_types[idx] == 5) {
|
||||
filemanager_read_apps(fm);
|
||||
if (filemanager_is_computer_view(fm) && fm->entry_types[idx] == FM_ENTRY_APPS_ROOT) {
|
||||
filemanager_read_virtual_view(fm, FM_VIRTUAL_VIEW_APPS);
|
||||
filemanager_push_history(fm);
|
||||
return;
|
||||
}
|
||||
|
||||
// App entry in apps view - launch it
|
||||
if (fm->at_apps_view && fm->entry_types[idx] == 6) {
|
||||
if (filemanager_is_computer_view(fm) && fm->entry_types[idx] == FM_ENTRY_SYSTEM_TOOLS_ROOT) {
|
||||
filemanager_read_virtual_view(fm, FM_VIRTUAL_VIEW_SYSTEM_TOOLS);
|
||||
filemanager_push_history(fm);
|
||||
return;
|
||||
}
|
||||
|
||||
if (filemanager_is_virtual_view(fm) && fm->entry_types[idx] == FM_ENTRY_VIRTUAL_APP) {
|
||||
DesktopState* ds = fm->desktop;
|
||||
if (ds && fm->app_map[idx] >= 0 && fm->app_map[idx] < ds->external_app_count) {
|
||||
const ExternalApp& app = ds->external_apps[fm->app_map[idx]];
|
||||
const FileManagerVirtualEntry& entry = fm->virtual_entries[idx];
|
||||
if (ds && entry.builtin_id != DESKTOP_BUILTIN_NONE) {
|
||||
desktop_launch_builtin(ds, entry.builtin_id);
|
||||
return;
|
||||
}
|
||||
if (ds && entry.external_app_index >= 0 && entry.external_app_index < ds->external_app_count) {
|
||||
const ExternalApp& app = ds->external_apps[entry.external_app_index];
|
||||
if (app.launch_with_home) {
|
||||
montauk::spawn(app.binary_path, ds->home_dir);
|
||||
} else {
|
||||
@@ -176,18 +212,17 @@ void filemanager_open_entry(FileManagerState* fm, int idx) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fm->at_drives_root && fm->entry_types[idx] == 4) {
|
||||
// Home folder
|
||||
if (filemanager_is_computer_view(fm) && fm->entry_types[idx] == FM_ENTRY_HOME) {
|
||||
DesktopState* ds = fm->desktop;
|
||||
if (ds && ds->home_dir[0] != '\0') {
|
||||
montauk::strcpy(fm->current_path, ds->home_dir);
|
||||
filemanager_push_history(fm);
|
||||
filemanager_read_dir(fm);
|
||||
filemanager_push_history(fm);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fm->at_drives_root && fm->entry_types[idx] == 3) {
|
||||
if (filemanager_is_computer_view(fm) && fm->entry_types[idx] == FM_ENTRY_DRIVE) {
|
||||
int d = fm->drive_indices[idx];
|
||||
char dpath[8];
|
||||
if (d < 10) {
|
||||
@@ -196,8 +231,8 @@ void filemanager_open_entry(FileManagerState* fm, int idx) {
|
||||
dpath[0] = '1'; dpath[1] = '0' + (d - 10); dpath[2] = ':'; dpath[3] = '/'; dpath[4] = '\0';
|
||||
}
|
||||
montauk::strcpy(fm->current_path, dpath);
|
||||
filemanager_push_history(fm);
|
||||
filemanager_read_dir(fm);
|
||||
filemanager_push_history(fm);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user