add handler for the path bar activate events

Tue, 30 Jan 2024 09:10:05 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 30 Jan 2024 09:10:05 +0100
changeset 11
26acbfa75c1f
parent 10
f8dfc5705516
child 12
3eb0cbab53db

add handler for the path bar activate events

application/davcontroller.c file | annotate | diff | comparison | revisions
application/davcontroller.h file | annotate | diff | comparison | revisions
application/window.c file | annotate | diff | comparison | revisions
application/window.h file | annotate | diff | comparison | revisions
--- a/application/davcontroller.c	Tue Jan 30 08:49:35 2024 +0100
+++ b/application/davcontroller.c	Tue Jan 30 09:10:05 2024 +0100
@@ -78,6 +78,7 @@
 // ------------------------------ davbrowser_query_path ------------------------------
 
 typedef struct DavBrowserQueryPath {
+    UiThreadpool *pool;
     DavBrowser *browser;
     char *path;
     DavResource *result;
@@ -97,16 +98,23 @@
     DavBrowserQueryPath *query = data;
     DavBrowser *browser = event->document;
 
-    if (query->result) {
-        davbrowser_set_collection(event->obj, browser, query->result);
+    if (query->pool == browser->dav_queue) {
+        if (query->result) {
+            davbrowser_set_collection(event->obj, browser, query->result);
+        } else {
+            // TODO: error
+        }
+
+        window_progress(event->window, 0);
     } else {
-        // TODO: error
+        // operation aborted
+        if (query->result) {
+            dav_resource_free_all(query->result);
+        }
     }
 
     free(query->path);
     free(query);
-
-    window_progress(event->window, 0);
 }
 
 void davbrowser_query_path(UiObject *ui, DavBrowser *browser, const char *path) {
@@ -125,6 +133,7 @@
     free(full_path);
 
     DavBrowserQueryPath *query = malloc(sizeof(DavBrowserQueryPath));
+    query->pool = browser->dav_queue;
     query->browser = browser;
     query->path = strdup(path);
     query->result = NULL;
@@ -132,3 +141,18 @@
 
     window_progress(ui->window, 1);
 }
+
+void davbrowser_query_url(UiObject *ui, DavBrowser *browser, const char *url) {
+    if (browser->repo_base) {
+        cxstring base = cx_str(browser->repo_base);
+        cxstring newurl = cx_str(url);
+
+        if (cx_strprefix(newurl, base)) {
+            const char *path = url + base.length;
+            davbrowser_query_path(ui, browser, path);
+            return;
+        }
+    }
+
+    // TODO:
+}
--- a/application/davcontroller.h	Tue Jan 30 08:49:35 2024 +0100
+++ b/application/davcontroller.h	Tue Jan 30 09:10:05 2024 +0100
@@ -47,7 +47,7 @@
 
 void davbrowser_query_path(UiObject *ui, DavBrowser *browser, const char *path);
 
-
+void davbrowser_query_url(UiObject *ui, DavBrowser *browser, const char *url);
 
 
 #ifdef	__cplusplus
--- a/application/window.c	Tue Jan 30 08:49:35 2024 +0100
+++ b/application/window.c	Tue Jan 30 09:10:05 2024 +0100
@@ -56,7 +56,7 @@
 		ui_button(obj, .icon = "Back");
 		ui_button(obj, .icon = "Forward");
 
-		ui_path_textfield(obj, .fill = UI_ON, .getpathelm = dav_get_pathelm, .varname = "path");
+		ui_path_textfield(obj, .fill = UI_ON, .getpathelm = dav_get_pathelm, .onactivate = action_path_selected ,.varname = "path");
 
 		ui_progressspinner(obj, .value = wdata->progress);
 	}
@@ -177,3 +177,11 @@
 
 	return elms;
 }
+
+
+
+void action_path_selected(UiEvent *event, void *data) {
+	DavBrowser *browser = event->document;
+	char *path = event->eventdata;
+	davbrowser_query_url(event->obj, browser, path);
+}
--- a/application/window.h	Tue Jan 30 08:49:35 2024 +0100
+++ b/application/window.h	Tue Jan 30 09:10:05 2024 +0100
@@ -54,6 +54,7 @@
 
 void window_progress(MainWindow *win, int on);
 
+void action_path_selected(UiEvent *event, void *data);
 
 #ifdef	__cplusplus
 }

mercurial