| 50 folder_icon = ui_foldericon(16); |
50 folder_icon = ui_foldericon(16); |
| 51 file_icon = ui_fileicon(16); |
51 file_icon = ui_fileicon(16); |
| 52 |
52 |
| 53 // initialize the browser context menu |
53 // initialize the browser context menu |
| 54 ui_contextmenu(&contextmenu) { |
54 ui_contextmenu(&contextmenu) { |
| 55 ui_menuitem(.label = "New Folder", .onclick = action_mkcol, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); |
55 ui_menuitem(.label = "New Folder", .onclick = action_mkcol, .states = UI_GROUPS(APP_STATE_BROWSER_SESSION)); |
| 56 ui_menuitem(.label = "New File", .onclick = action_newfile, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); |
56 ui_menuitem(.label = "New File", .onclick = action_newfile, .states = UI_GROUPS(APP_STATE_BROWSER_SESSION)); |
| 57 ui_menuseparator(); |
57 ui_menuseparator(); |
| 58 //ui_menuitem(.label = "Cut", .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
58 //ui_menuitem(.label = "Cut", .states = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
| 59 //ui_menuitem(.label = "Copy", .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
59 //ui_menuitem(.label = "Copy", .states = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
| 60 //ui_menuitem(.label = "Paste", .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
60 //ui_menuitem(.label = "Paste", .states = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
| 61 ui_menuitem(.label = "Download", .onclick = action_download, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
61 ui_menuitem(.label = "Download", .onclick = action_download, .states = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
| 62 ui_menuitem(.label = "Delete", .onclick = action_delete, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); |
62 ui_menuitem(.label = "Delete", .onclick = action_delete, .states = UI_GROUPS(APP_STATE_BROWSER_SESSION)); |
| 63 ui_menuitem(.label = "Select All", .onclick = action_selectall, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION)); |
63 ui_menuitem(.label = "Select All", .onclick = action_selectall, .states = UI_GROUPS(APP_STATE_BROWSER_SESSION)); |
| 64 ui_menuseparator(); |
64 ui_menuseparator(); |
| 65 ui_menuitem(.label = "Rename", .onclick = action_rename, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
65 ui_menuitem(.label = "Rename", .onclick = action_rename, .states = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
| 66 ui_menuseparator(); |
66 ui_menuseparator(); |
| 67 ui_menuitem("Open Properties", .onclick = action_open_properties, .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
67 ui_menuitem("Open Properties", .onclick = action_open_properties, .states = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
| 68 ui_menuitem("Open as Text File", .onclick = action_open_properties, .onclickdata = "text/plain", .groups = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
68 ui_menuitem("Open as Text File", .onclick = action_open_properties, .onclickdata = "text/plain", .states = UI_GROUPS(APP_STATE_BROWSER_SESSION, APP_STATE_BROWSER_SELECTION)); |
| 69 } |
69 } |
| 70 } |
70 } |
| 71 |
71 |
| 72 UiObject* window_create(void) { |
72 UiObject* window_create(void) { |
| 73 UiObject* obj = ui_window("iDAV", NULL); |
73 UiObject* obj = ui_window("iDAV"); |
| 74 ui_window_size(obj, 900, 700); |
74 ui_window_size(obj, 900, 700); |
| 75 |
75 |
| 76 MainWindow* wdata = ui_malloc(obj->ctx, sizeof (MainWindow)); |
76 MainWindow* wdata = ui_malloc(obj->ctx, sizeof (MainWindow)); |
| 77 memset(wdata, 0, sizeof (MainWindow)); |
77 memset(wdata, 0, sizeof (MainWindow)); |
| 78 obj->window = wdata; |
78 obj->window = wdata; |
| 184 } |
184 } |
| 185 } |
185 } |
| 186 |
186 |
| 187 void resourceviewer_new(DavBrowser *browser, const char *path, DavResourceViewType type) { |
187 void resourceviewer_new(DavBrowser *browser, const char *path, DavResourceViewType type) { |
| 188 const char *name = util_resource_name(path); |
188 const char *name = util_resource_name(path); |
| 189 UiObject *win = ui_simple_window(name, NULL); |
189 UiObject *win = ui_simple_window(name); |
| 190 ui_window_size(win, 600, 600); |
190 ui_window_size(win, 600, 600); |
| 191 |
191 |
| 192 ui_headerbar(win, .showtitle = TRUE) { |
192 ui_headerbar(win, .showtitle = TRUE) { |
| 193 ui_headerbar_start(win) { |
193 ui_headerbar_start(win) { |
| 194 ui_button(win, .label = "Save", .onclick = action_resourceviewer_save, .groups = UI_GROUPS(RESOURCEVIEWER_STATE_MODIFIED)); |
194 ui_button(win, .label = "Save", .onclick = action_resourceviewer_save, .states = UI_GROUPS(RESOURCEVIEWER_STATE_MODIFIED)); |
| 195 } |
195 } |
| 196 } |
196 } |
| 197 |
197 |
| 198 DavResourceViewer *doc = dav_resourceviewer_create(win, browser->sn, path, type); |
198 DavResourceViewer *doc = dav_resourceviewer_create(win, browser->sn, path, type); |
| 199 ui_attach_document(win->ctx, doc); |
199 ui_attach_document(win->ctx, doc); |
| 262 .varname = "properties", |
262 .varname = "properties", |
| 263 .onselection = action_resourceviewer_property_select, |
263 .onselection = action_resourceviewer_property_select, |
| 264 .onactivate = action_resourceviewer_property_activate); |
264 .onactivate = action_resourceviewer_property_activate); |
| 265 ui_hbox(win, .margin = 4, .spacing = 4) { |
265 ui_hbox(win, .margin = 4, .spacing = 4) { |
| 266 ui_button(win, .label = "Add", .onclick = action_resourceviewer_property_add); |
266 ui_button(win, .label = "Add", .onclick = action_resourceviewer_property_add); |
| 267 ui_button(win, .label = "Edit", .onclick = action_resourceviewer_property_edit, .groups = UI_GROUPS(RESOURCEVIEWER_STATE_PROP_SELECTED)); |
267 ui_button(win, .label = "Edit", .onclick = action_resourceviewer_property_edit, .states = UI_GROUPS(RESOURCEVIEWER_STATE_PROP_SELECTED)); |
| 268 ui_button(win, .label = "Remove", .onclick = action_resourceviewer_property_remove, .groups = UI_GROUPS(RESOURCEVIEWER_STATE_PROP_SELECTED)); |
268 ui_button(win, .label = "Remove", .onclick = action_resourceviewer_property_remove, .states = UI_GROUPS(RESOURCEVIEWER_STATE_PROP_SELECTED)); |
| 269 } |
269 } |
| 270 } |
270 } |
| 271 } |
271 } |
| 272 } |
272 } |
| 273 } |
273 } |
| 483 } |
483 } |
| 484 |
484 |
| 485 void action_list_selection(UiEvent *event, void *data) { |
485 void action_list_selection(UiEvent *event, void *data) { |
| 486 UiListSelection *selection = event->eventdata; |
486 UiListSelection *selection = event->eventdata; |
| 487 if (selection->count > 0) { |
487 if (selection->count > 0) { |
| 488 ui_set_group(event->obj->ctx, APP_STATE_BROWSER_SELECTION); |
488 ui_set_state(event->obj->ctx, APP_STATE_BROWSER_SELECTION); |
| 489 } else { |
489 } else { |
| 490 ui_unset_group(event->obj->ctx, APP_STATE_BROWSER_SELECTION); |
490 ui_unset_state(event->obj->ctx, APP_STATE_BROWSER_SELECTION); |
| 491 } |
491 } |
| 492 } |
492 } |
| 493 |
493 |
| 494 void action_list_activate(UiEvent *event, void *data) { |
494 void action_list_activate(UiEvent *event, void *data) { |
| 495 UiListSelection *selection = event->eventdata; |
495 UiListSelection *selection = event->eventdata; |
| 559 |
559 |
| 560 void action_resourceviewer_property_select(UiEvent *event, void *data) { |
560 void action_resourceviewer_property_select(UiEvent *event, void *data) { |
| 561 DavResourceViewer *doc = event->document; |
561 DavResourceViewer *doc = event->document; |
| 562 UiListSelection *selection = event->eventdata; |
562 UiListSelection *selection = event->eventdata; |
| 563 if(selection->count == 1) { |
563 if(selection->count == 1) { |
| 564 ui_set_group(event->obj->ctx, RESOURCEVIEWER_STATE_PROP_SELECTED); |
564 ui_set_state(event->obj->ctx, RESOURCEVIEWER_STATE_PROP_SELECTED); |
| 565 doc->selected_property = ui_list_get(doc->properties, selection->rows[0]); |
565 doc->selected_property = ui_list_get(doc->properties, selection->rows[0]); |
| 566 } else { |
566 } else { |
| 567 ui_unset_group(event->obj->ctx, RESOURCEVIEWER_STATE_PROP_SELECTED); |
567 ui_unset_state(event->obj->ctx, RESOURCEVIEWER_STATE_PROP_SELECTED); |
| 568 doc->selected_property = NULL; |
568 doc->selected_property = NULL; |
| 569 } |
569 } |
| 570 } |
570 } |
| 571 |
571 |
| 572 void action_resourceviewer_property_activate(UiEvent *event, void *data) { |
572 void action_resourceviewer_property_activate(UiEvent *event, void *data) { |
| 639 |
639 |
| 640 static void prop_type_changed(UiEvent *event, void *data) { |
640 static void prop_type_changed(UiEvent *event, void *data) { |
| 641 DavResourceViewer *res = data; |
641 DavResourceViewer *res = data; |
| 642 switch(ui_get(res->property_type)) { |
642 switch(ui_get(res->property_type)) { |
| 643 case 0: { |
643 case 0: { |
| 644 ui_unset_group(event->obj->ctx, RESOURCEVIEWER_STATE_PROP_XML); |
644 ui_unset_state(event->obj->ctx, RESOURCEVIEWER_STATE_PROP_XML); |
| 645 break; |
645 break; |
| 646 } |
646 } |
| 647 case 1: { |
647 case 1: { |
| 648 ui_set_group(event->obj->ctx, RESOURCEVIEWER_STATE_PROP_XML); |
648 ui_set_state(event->obj->ctx, RESOURCEVIEWER_STATE_PROP_XML); |
| 649 char *ns = ui_get(res->property_ns); |
649 char *ns = ui_get(res->property_ns); |
| 650 char *nsdef = ui_get(res->property_nsdef); |
650 char *nsdef = ui_get(res->property_nsdef); |
| 651 if(strlen(nsdef) == 0) { |
651 if(strlen(nsdef) == 0) { |
| 652 cxmutstr def = cx_asprintf("xmlns:x0=\"%s\"", ns); |
652 cxmutstr def = cx_asprintf("xmlns:x0=\"%s\"", ns); |
| 653 ui_set(res->property_nsdef, def.ptr); |
653 ui_set(res->property_nsdef, def.ptr); |
| 688 ui_radiobutton(obj, .label = "XML", .value = res->property_type, .onchange = prop_type_changed, .onchangedata = res); |
688 ui_radiobutton(obj, .label = "XML", .value = res->property_type, .onchange = prop_type_changed, .onchangedata = res); |
| 689 } |
689 } |
| 690 ui_newline(obj); |
690 ui_newline(obj); |
| 691 |
691 |
| 692 ui_llabel(obj, .label = "Namespace Declarations"); |
692 ui_llabel(obj, .label = "Namespace Declarations"); |
| 693 ui_textfield(obj, .hexpand = TRUE, .value = res->property_nsdef, .groups = UI_GROUPS(RESOURCEVIEWER_STATE_PROP_XML)); |
693 ui_textfield(obj, .hexpand = TRUE, .value = res->property_nsdef, .states = UI_GROUPS(RESOURCEVIEWER_STATE_PROP_XML)); |
| 694 ui_newline(obj); |
694 ui_newline(obj); |
| 695 |
695 |
| 696 ui_textarea(obj, .value = res->property_value, .hexpand = TRUE, .vexpand = TRUE, .colspan = 2); |
696 ui_textarea(obj, .value = res->property_value, .hexpand = TRUE, .vexpand = TRUE, .colspan = 2); |
| 697 ui_newline(obj); |
697 ui_newline(obj); |
| 698 |
698 |
| 704 ui_set(res->property_name, prop->name); |
704 ui_set(res->property_name, prop->name); |
| 705 if(prop->value_full) { |
705 if(prop->value_full) { |
| 706 ui_set(res->property_type, 0); |
706 ui_set(res->property_type, 0); |
| 707 ui_set(res->property_nsdef, ""); |
707 ui_set(res->property_nsdef, ""); |
| 708 ui_set(res->property_value, prop->value_full); |
708 ui_set(res->property_value, prop->value_full); |
| 709 ui_unset_group(obj->ctx, RESOURCEVIEWER_STATE_PROP_XML); |
709 ui_unset_state(obj->ctx, RESOURCEVIEWER_STATE_PROP_XML); |
| 710 } else if(prop->xml) { |
710 } else if(prop->xml) { |
| 711 ui_set(res->property_type, 1); |
711 ui_set(res->property_type, 1); |
| 712 cxmutstr xml; |
712 cxmutstr xml; |
| 713 cxmutstr nsdef; |
713 cxmutstr nsdef; |
| 714 property_xml2str(prop->xml, prop->ns, &xml, &nsdef); |
714 property_xml2str(prop->xml, prop->ns, &xml, &nsdef); |
| 715 ui_set(res->property_nsdef, nsdef.ptr); |
715 ui_set(res->property_nsdef, nsdef.ptr); |
| 716 ui_set(res->property_value, xml.ptr); |
716 ui_set(res->property_value, xml.ptr); |
| 717 free(xml.ptr); |
717 free(xml.ptr); |
| 718 free(nsdef.ptr); |
718 free(nsdef.ptr); |
| 719 ui_set_group(obj->ctx, RESOURCEVIEWER_STATE_PROP_XML); |
719 ui_set_state(obj->ctx, RESOURCEVIEWER_STATE_PROP_XML); |
| 720 } |
720 } |
| 721 } else { |
721 } else { |
| 722 ui_set(res->property_ns, ""); |
722 ui_set(res->property_ns, ""); |
| 723 ui_set(res->property_name, ""); |
723 ui_set(res->property_name, ""); |
| 724 ui_set(res->property_nsdef, ""); |
724 ui_set(res->property_nsdef, ""); |