Tue, 29 Oct 2024 10:27:16 +0100
add main menu
--- a/application/application.c Mon Oct 28 17:02:12 2024 +0100 +++ b/application/application.c Tue Oct 29 10:27:16 2024 +0100 @@ -82,33 +82,61 @@ void application_create_menu(void) { // menu - + ui_menu("File") { + ui_menuitem(.label = "New Window", .onclick = action_window_new); + ui_menuseparator(); + ui_menuitem(.label = "New Folder", .onclick = action_mkcol, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_menuitem(.label = "New File", .onclick = action_newfile, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_menuitem(.label = "Delete", .onclick = action_delete, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_menuseparator(); + ui_menuitem(.label = "Upload File", .onclick = action_upload_file, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_menuitem(.label = "Upload Folder", .onclick = action_upload_dir, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_menuitem(.label = "Download", .onclick = action_download, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); + ui_menuitem("Open Properties", .onclick = action_open_properties, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); + ui_menuitem("Open as Text File", .onclick = action_open_properties, .onclickdata = "text/plain", .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); + ui_menuseparator(); + ui_menuitem(.label = "Close", .onclick = action_window_close); + } + + ui_menu("Edit") { + ui_menuitem(.label = "Preferences", .onclick = action_open_settings); + } + + ui_menu("Go") { + ui_menuitem(.label = "Parent", .onclick = action_go_parent, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_menuitem(.label = "Back", .onclick = action_go_back, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_menuitem(.label = "Forward", .onclick = action_go_forward, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_menuseparator(); + ui_menu("Repositories") { + ui_menu_itemlist(.varname = "repolist", .getvalue = davrepo_getname, .onselect = action_repo_selected); + } + } // toolbar ui_toolbar_item("Home", .icon = UI_ICON_HOME); ui_toolbar_item("NewWindow", .icon = UI_ICON_NEW_WINDOW, .onclick = action_window_new); - ui_toolbar_item("Refresh", .icon = UI_ICON_REFRESH, .onclick = action_refresh); + ui_toolbar_item("Refresh", .icon = UI_ICON_REFRESH, .onclick = action_refresh, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); ui_toolbar_menu("Repo", .label = "Repository") { ui_menu_itemlist(.varname = "repolist", .getvalue = davrepo_getname, .onselect = action_repo_selected); } - ui_toolbar_item("NewFolder", .icon = UI_ICON_NEW_FOLDER, .onclick = action_mkcol); - ui_toolbar_item("NewFile", .icon = UI_ICON_ADD, .onclick = action_newfile); - ui_toolbar_item("Upload", .label = "Upload", .icon = UI_ICON_UPLOAD, .onclick = action_upload_file); - ui_toolbar_item("Download", .icon = UI_ICON_SAVE_LOCAL, .onclick = action_download); - ui_toolbar_item("Remove", .icon = UI_ICON_DELETE, .onclick = action_delete ); + ui_toolbar_item("NewFolder", .icon = UI_ICON_NEW_FOLDER, .onclick = action_mkcol, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_toolbar_item("NewFile", .icon = UI_ICON_ADD, .onclick = action_newfile, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_toolbar_item("Upload", .label = "Upload", .icon = UI_ICON_UPLOAD, .onclick = action_upload_file, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_toolbar_item("Download", .icon = UI_ICON_SAVE_LOCAL, .onclick = action_download, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); + ui_toolbar_item("Remove", .icon = UI_ICON_DELETE, .onclick = action_delete, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); ui_toolbar_toggleitem("LocalBrowser", .icon = UI_ICON_DOCK_LEFT, .label = "Local Browser"); ui_toolbar_toggleitem("PreviewPane", .icon = UI_ICON_DOCK_RIGHT); ui_toolbar_appmenu() { ui_menuitem("New Window", .onclick = action_window_new); ui_menuseparator(); - ui_menuitem("Download", .onclick = action_download); - ui_menuitem("Upload Files", .onclick = action_upload_file); - ui_menuitem("Upload Directory", .onclick = action_upload_dir); - ui_menuitem("Open Properties", .onclick = action_open_properties); - ui_menuitem("Open as Text File", .onclick = action_open_properties, .onclickdata = "text/plain"); + ui_menuitem("Download", .onclick = action_download, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); + ui_menuitem("Upload Files", .onclick = action_upload_file, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_menuitem("Upload Directory", .onclick = action_upload_dir, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); + ui_menuitem("Open Properties", .onclick = action_open_properties, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); + ui_menuitem("Open as Text File", .onclick = action_open_properties, .onclickdata = "text/plain", .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); ui_menuseparator(); - ui_menuitem("Settings", .onclick = action_open_settings); + ui_menuitem("Preferences", .onclick = action_open_settings); } //ui_toolbar_add_default("Home", UI_TOOLBAR_LEFT); @@ -166,6 +194,10 @@ ui_show(win); } +void action_window_close(UiEvent *event, void *data) { + ui_close(event->obj); +} + void action_refresh(UiEvent *event, void *data) { DavBrowser *browser = event->document; if (browser->current) { @@ -251,10 +283,18 @@ } void action_upload_file(UiEvent *event, void *data) { + DavBrowser *browser = event->document; + if(!browser->sn) { + return; + } ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_MULTI, file_selected, NULL); } void action_upload_dir(UiEvent *event, void *data) { + DavBrowser *browser = event->document; + if(!browser->sn) { + return; + } ui_openfiledialog(event->obj, UI_FILEDIALOG_SELECT_FOLDER|UI_FILEDIALOG_SELECT_MULTI, file_selected, NULL); }
--- a/application/application.h Mon Oct 28 17:02:12 2024 +0100 +++ b/application/application.h Tue Oct 29 10:27:16 2024 +0100 @@ -44,7 +44,9 @@ extern "C" { #endif - +#define APP_STATE_BROWSER_SESSION 100 +#define APP_STATE_BROWSER_SELECTION 110 + typedef struct DavApp { DavConfig *dav_config; UiList *repos; @@ -168,6 +170,8 @@ void action_window_new(UiEvent *event, void *data); +void action_window_close(UiEvent *event, void *data); + void action_repo_selected(UiEvent *event, void *data); void action_download(UiEvent *event, void *data);
--- a/application/davcontroller.c Mon Oct 28 17:02:12 2024 +0100 +++ b/application/davcontroller.c Tue Oct 29 10:27:16 2024 +0100 @@ -72,6 +72,8 @@ } browser->resources->update(browser->resources, 0); + + ui_set_group(ui->ctx, APP_STATE_BROWSER_SESSION); } // ------------------------------ davbrowser_connect2repo ------------------------------ @@ -315,6 +317,16 @@ } } +void davbrowser_navigation_parent(UiObject *ui, DavBrowser *browser) { + if(browser->current) { + char *parent = util_parent_path(browser->current->path); + if(strlen(parent) > 0) { + davbrowser_query_path(ui, browser, parent); + } + free(parent); + } +} + void davbrowser_navigation_back(UiObject *ui, DavBrowser *browser) { if (browser->navstack_pos+1 < cxListSize(browser->navigation_stack)) { browser->navstack_pos++;
--- a/application/davcontroller.h Mon Oct 28 17:02:12 2024 +0100 +++ b/application/davcontroller.h Tue Oct 29 10:27:16 2024 +0100 @@ -60,6 +60,7 @@ void davbrowser_add2navstack(DavBrowser *browser, const char *base, const char *path); +void davbrowser_navigation_parent(UiObject *ui, DavBrowser *browser); void davbrowser_navigation_back(UiObject *ui, DavBrowser *browser); void davbrowser_navigation_forward(UiObject *ui, DavBrowser *browser);
--- a/application/settings.c Mon Oct 28 17:02:12 2024 +0100 +++ b/application/settings.c Tue Oct 29 10:27:16 2024 +0100 @@ -356,10 +356,10 @@ ui_tab(obj, "Repositories") { - ui_tabview(obj, .value = wdata->repo_tabview, .margin = 10, .tabview = UI_TABVIEW_INVISIBLE) { + ui_tabview(obj, .value = wdata->repo_tabview, .tabview = UI_TABVIEW_INVISIBLE) { ui_tab(obj, "list") { - ui_grid(obj, .margin = 10, .columnspacing = 10, .rowspacing = 10) { - ui_hbox(obj, .spacing = 10) { + ui_grid(obj, .margin = 16, .columnspacing = 10, .rowspacing = 10) { + ui_hbox(obj, .spacing = 4) { ui_button(obj, .label = "Add", .onclick = repolist_add); ui_button(obj, .label = "Edit", .onclick = repolist_edit, .groups = UI_GROUPS(SETTINGS_STATE_REPOLIST_SELECTED)); ui_button(obj, .label = "Remove", .onclick = repolist_remove, .groups = UI_GROUPS(SETTINGS_STATE_REPOLIST_SELECTED)); @@ -379,7 +379,7 @@ } ui_tab(obj, "repo") { - ui_vbox(obj, .margin = 10, .spacing = 10) { + ui_vbox(obj, .margin = 16, .spacing = 10) { ui_hbox(obj, .fill = UI_OFF, .spacing = 4) { ui_button(obj, .icon = UI_ICON_GO_BACK, .onclick = editrepo_go_back); ui_label(obj, .label = "Repository List"); @@ -461,7 +461,7 @@ } ui_tab(obj, "Credentials") { - ui_hbox(obj, .margin = 10, .spacing = 10) { + ui_hbox(obj, .margin = 16, .spacing = 10) { ui_vbox(obj, .fill = UI_OFF) { ui_listview(obj, .list = wdata->credentials_users, .fill = UI_ON, .onselection = credentials_onselect); ui_hbox(obj, .fill = UI_OFF, .spacing = 4) {
--- a/application/window.c Mon Oct 28 17:02:12 2024 +0100 +++ b/application/window.c Tue Oct 29 10:27:16 2024 +0100 @@ -73,7 +73,7 @@ // main content UiModel* model = ui_model(obj->ctx, UI_ICON_TEXT, "Name", UI_STRING, "Type", UI_STRING_FREE, "Last Modified", UI_STRING_FREE, "Size", -1); model->getvalue = (ui_getvaluefunc) window_resource_table_getvalue; - ui_table(obj, .fill = UI_ON, .model = model, .onactivate = action_list_activate, .ondrop = action_dnd_drop, .varname = "reslist", .multiselection = TRUE); + ui_table(obj, .fill = UI_ON, .model = model, .onselection = action_list_selection, .onactivate = action_list_activate, .ondrop = action_dnd_drop, .varname = "reslist", .multiselection = TRUE); // status bar @@ -344,6 +344,11 @@ return elms; } +void action_go_parent(UiEvent *event, void *data) { + DavBrowser *browser = event->document; + davbrowser_navigation_parent(event->obj, browser); +} + void action_go_back(UiEvent *event, void *data) { DavBrowser *browser = event->document; davbrowser_navigation_back(event->obj, browser); @@ -362,6 +367,15 @@ } } +void action_list_selection(UiEvent *event, void *data) { + UiListSelection *selection = event->eventdata; + if (selection->count > 0) { + ui_set_group(event->obj->ctx, APP_STATE_BROWSER_SELECTION); + } else { + ui_unset_group(event->obj->ctx, APP_STATE_BROWSER_SELECTION); + } +} + void action_list_activate(UiEvent *event, void *data) { UiListSelection *selection = event->eventdata; DavBrowser *browser = event->document;
--- a/application/window.h Mon Oct 28 17:02:12 2024 +0100 +++ b/application/window.h Tue Oct 29 10:27:16 2024 +0100 @@ -62,11 +62,13 @@ void auth_dialog(SessionAuthData *auth); +void action_go_parent(UiEvent *event, void *data); void action_go_back(UiEvent *event, void *data); void action_go_forward(UiEvent *event, void *data); void action_path_selected(UiEvent *event, void *data); +void action_list_selection(UiEvent *event, void *data); void action_list_activate(UiEvent *event, void *data); void action_dnd_drop(UiEvent *event, void *data);
--- a/ui/common/menu.c Mon Oct 28 17:02:12 2024 +0100 +++ b/ui/common/menu.c Tue Oct 29 10:27:16 2024 +0100 @@ -78,7 +78,7 @@ if (ngroups > 0) { int* newarray = calloc(n, sizeof(int)); - memcpy(newarray, groups, n); + memcpy(newarray, groups, n * sizeof(int)); *ngroups = n; return newarray; }
--- a/ui/ui/toolbar.h Mon Oct 28 17:02:12 2024 +0100 +++ b/ui/ui/toolbar.h Tue Oct 29 10:27:16 2024 +0100 @@ -43,6 +43,8 @@ ui_callback onclick; void* onclickdata; + + const int *groups; } UiToolbarItemArgs; typedef struct UiToolbarToggleItemArgs { @@ -53,6 +55,8 @@ const char* varname; ui_callback onchange; void* onchangedata; + + const int *groups; } UiToolbarToggleItemArgs; typedef struct UiToolbarMenuArgs {