feat: refresh button in Files, svg.hpp arc handling

This commit is contained in:
2026-05-18 19:51:23 +02:00
parent 96abe9a5cd
commit 2ceefaf1ca
9 changed files with 198 additions and 39 deletions
@@ -194,9 +194,13 @@ void filemanager_open_ctx_menu(FileManagerState* fm, int local_x, int local_y, i
fm->ctx_open = false;
return;
}
if (fm->clipboard_has_data)
fm->ctx_items[fm->ctx_item_count++] = CTX_PASTE;
fm->ctx_items[fm->ctx_item_count++] = CTX_NEW_FOLDER;
if (filemanager_is_computer_view(fm)) {
fm->ctx_items[fm->ctx_item_count++] = CTX_REFRESH;
} else {
if (fm->clipboard_has_data)
fm->ctx_items[fm->ctx_item_count++] = CTX_PASTE;
fm->ctx_items[fm->ctx_item_count++] = CTX_NEW_FOLDER;
}
}
}
@@ -51,6 +51,7 @@ void filemanager_on_mouse(Window* win, MouseEvent& ev) {
case CTX_DELETE: filemanager_delete_selected(fm); break;
case CTX_NEW_FOLDER: filemanager_new_folder(fm); break;
case CTX_PROPERTIES: filemanager_show_properties(fm, target); break;
case CTX_REFRESH: filemanager_refresh(fm); break;
}
return;
}
@@ -79,21 +80,22 @@ void filemanager_on_mouse(Window* win, MouseEvent& ev) {
// Toolbar button clicks
if (local_y < FM_TOOLBAR_H) {
// Navigation buttons
if (local_x >= 4 && local_x < 28) filemanager_go_back(fm);
if (local_x >= 4 && local_x < 28) filemanager_go_back(fm);
else if (local_x >= 32 && local_x < 56) filemanager_go_forward(fm);
else if (local_x >= 60 && local_x < 84) filemanager_go_up(fm);
else if (local_x >= 88 && local_x < 112) filemanager_go_home(fm);
else if (local_x >= 120 && local_x < 144) {
else if (local_x >= 88 && local_x < 112) filemanager_go_home(fm);
else if (local_x >= 116 && local_x < 140) filemanager_refresh(fm);
else if (local_x >= 148 && local_x < 172) {
fm->grid_view = !fm->grid_view;
fm->scrollbar.scroll_offset = 0;
}
// Action buttons
else if (local_x >= 160 && local_x < 184) filemanager_do_copy(fm);
else if (local_x >= 188 && local_x < 212) filemanager_do_cut(fm);
else if (local_x >= 216 && local_x < 240) filemanager_do_paste(fm);
else if (local_x >= 244 && local_x < 268) filemanager_start_rename(fm);
else if (local_x >= 272 && local_x < 296) filemanager_new_folder(fm);
else if (local_x >= 300 && local_x < 324) filemanager_delete_selected(fm);
else if (local_x >= 188 && local_x < 212) filemanager_do_copy(fm);
else if (local_x >= 216 && local_x < 240) filemanager_do_cut(fm);
else if (local_x >= 244 && local_x < 268) filemanager_do_paste(fm);
else if (local_x >= 272 && local_x < 296) filemanager_start_rename(fm);
else if (local_x >= 300 && local_x < 324) filemanager_new_folder(fm);
else if (local_x >= 328 && local_x < 352) filemanager_delete_selected(fm);
return;
}
@@ -135,6 +135,7 @@ inline constexpr int CTX_RENAME = 4;
inline constexpr int CTX_DELETE = 5;
inline constexpr int CTX_NEW_FOLDER = 6;
inline constexpr int CTX_PROPERTIES = 7;
inline constexpr int CTX_REFRESH = 8;
inline bool filemanager_is_virtual_view(const FileManagerState* fm) {
return fm && fm->virtual_view != FM_VIRTUAL_VIEW_NONE;
@@ -224,6 +225,7 @@ void filemanager_navigate_to_history(FileManagerState* fm);
void filemanager_go_back(FileManagerState* fm);
void filemanager_go_forward(FileManagerState* fm);
void filemanager_go_home(FileManagerState* fm);
void filemanager_refresh(FileManagerState* fm);
void filemanager_start_pathbar(FileManagerState* fm);
void filemanager_cancel_pathbar(FileManagerState* fm);
@@ -25,6 +25,7 @@ const char* ctx_label(int action) {
case CTX_DELETE: return "Delete";
case CTX_NEW_FOLDER: return "New Folder";
case CTX_PROPERTIES: return "Properties";
case CTX_REFRESH: return "Refresh";
default: return "?";
}
}
@@ -137,6 +137,17 @@ void filemanager_go_home(FileManagerState* fm) {
filemanager_push_history(fm);
}
void filemanager_refresh(FileManagerState* fm) {
if (!fm) return;
if (filemanager_is_virtual_view(fm)) {
filemanager_read_virtual_view(fm, fm->virtual_view);
} else if (filemanager_is_computer_view(fm)) {
filemanager_read_drives(fm);
} else {
filemanager_read_dir(fm);
}
}
void filemanager_start_pathbar(FileManagerState* fm) {
fm->pathbar_editing = true;
if (filemanager_is_computer_view(fm) || filemanager_is_virtual_view(fm)) {
@@ -163,16 +163,17 @@ void filemanager_draw_header(Canvas& c, FileManagerState* fm, Color toolbar_colo
// ---- Toolbar (32px) ----
c.fill_rect(0, 0, c.w, FM_TOOLBAR_H, toolbar_color);
// Navigation buttons: Back, Forward, Up, Home
// Navigation buttons: Back, Forward, Up, Home, Refresh
struct ToolBtn { int x; SvgIcon* icon; };
ToolBtn nav_btns[4] = {
{ 4, ds ? &ds->icon_go_back : nullptr },
{ 32, ds ? &ds->icon_go_forward : nullptr },
{ 60, ds ? &ds->icon_go_up : nullptr },
{ 88, ds ? &ds->icon_home : nullptr },
ToolBtn nav_btns[5] = {
{ 4, ds ? &ds->icon_go_back : nullptr },
{ 32, ds ? &ds->icon_go_forward : nullptr },
{ 60, ds ? &ds->icon_go_up : nullptr },
{ 88, ds ? &ds->icon_home : nullptr },
{ 116, ds ? &ds->icon_refresh : nullptr },
};
for (int i = 0; i < 4; i++) {
for (int i = 0; i < 5; i++) {
int bx = nav_btns[i].x;
int by = 4;
c.fill_rect(bx, by, 24, 24, btn_bg);
@@ -185,7 +186,7 @@ void filemanager_draw_header(Canvas& c, FileManagerState* fm, Color toolbar_colo
// View toggle button
{
int bx = 120, by = 4;
int bx = 148, by = 4;
c.fill_rect(bx, by, 24, 24, btn_bg);
if (fm->grid_view) {
for (int r = 0; r < 2; r++)
@@ -198,7 +199,7 @@ void filemanager_draw_header(Canvas& c, FileManagerState* fm, Color toolbar_colo
}
// Separator line between nav group and action group
c.vline(152, 6, 20, colors::BORDER);
c.vline(180, 6, 20, colors::BORDER);
// Action buttons: Copy, Cut, Paste, Rename, New Folder, Delete
bool has_sel = fm->selected >= 0 && fm->selected < fm->entry_count
@@ -211,13 +212,13 @@ void filemanager_draw_header(Canvas& c, FileManagerState* fm, Color toolbar_colo
// Icon toolbar buttons: Copy, Cut, Paste, Rename, New Folder, Delete
struct ActionBtn { int x; SvgIcon* icon; bool enabled; };
ActionBtn action_btns[] = {
{ 160, ds ? &ds->icon_copy : nullptr, has_sel },
{ 188, ds ? &ds->icon_cut : nullptr, has_sel },
{ 216, ds ? &ds->icon_paste : nullptr, has_clip },
{ 244, ds ? &ds->icon_rename : nullptr, has_sel },
{ 272, ds ? &ds->icon_folder_new : nullptr,
{ 188, ds ? &ds->icon_copy : nullptr, has_sel },
{ 216, ds ? &ds->icon_cut : nullptr, has_sel },
{ 244, ds ? &ds->icon_paste : nullptr, has_clip },
{ 272, ds ? &ds->icon_rename : nullptr, has_sel },
{ 300, ds ? &ds->icon_folder_new : nullptr,
!filemanager_is_computer_view(fm) && !filemanager_is_virtual_view(fm) },
{ 300, ds ? &ds->icon_delete : nullptr, has_sel },
{ 328, ds ? &ds->icon_delete : nullptr, has_sel },
};
for (int i = 0; i < 6; i++) {
+1
View File
@@ -197,6 +197,7 @@ void gui::desktop_init(DesktopState* ds) {
ds->icon_go_back = svg_load("0:/icons/go-previous-symbolic.svg", 16, 16, defColor);
ds->icon_go_forward = svg_load("0:/icons/go-next-symbolic.svg", 16, 16, defColor);
ds->icon_home = svg_load("0:/icons/user-home.svg", 16, 16, defColor);
ds->icon_refresh = svg_load("0:/icons/view-refresh-symbolic.svg", 16, 16, defColor);
ds->icon_exec = svg_load("0:/icons/utilities-terminal.svg", 16, 16, defColor);
ds->icon_folder_lg = svg_load("0:/icons/folder.svg", 48, 48, defColor);