summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/sidebarwidget.c24
-rw-r--r--src/ui/util.c46
-rw-r--r--src/ui/util.h1
3 files changed, 60 insertions, 11 deletions
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 7729ccca..7d0e8b42 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -76,8 +76,12 @@ static void clearItems_SidebarWidget_(iSidebarWidget *d) {
76 76
77static iRect contentBounds_SidebarWidget_(const iSidebarWidget *d) { 77static iRect contentBounds_SidebarWidget_(const iSidebarWidget *d) {
78 iRect bounds = bounds_Widget(constAs_Widget(d)); 78 iRect bounds = bounds_Widget(constAs_Widget(d));
79 adjustEdges_Rect(&bounds, as_Widget(d->modeButtons[0])->rect.size.y + gap_UI, 79 const iWidget *scroll = constAs_Widget(d->scroll);
80 -constAs_Widget(d->scroll)->rect.size.x, -gap_UI, 0); 80 adjustEdges_Rect(&bounds,
81 as_Widget(d->modeButtons[0])->rect.size.y + gap_UI,
82 isVisible_Widget(scroll) ? -scroll->rect.size.x : 0,
83 -gap_UI,
84 0);
81 return bounds; 85 return bounds;
82} 86}
83 87
@@ -318,6 +322,15 @@ void setWidth_SidebarWidget(iSidebarWidget *d, int width) {
318iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *cmd) { 322iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *cmd) {
319 iSidebarWidget *d = findWidget_App("sidebar"); 323 iSidebarWidget *d = findWidget_App("sidebar");
320 if (equal_Command(cmd, "bmed.accept") || equal_Command(cmd, "cancel")) { 324 if (equal_Command(cmd, "bmed.accept") || equal_Command(cmd, "cancel")) {
325 if (equal_Command(cmd, "bmed.accept")) {
326 const iSidebarItem *item = hoverItem_SidebarWidget_(d);
327 iAssert(item); /* hover item cannot have been changed */
328 iBookmark *bm = get_Bookmarks(bookmarks_App(), item->id);
329 set_String(&bm->title, text_InputWidget(findChild_Widget(editor, "bmed.title")));
330 set_String(&bm->url, text_InputWidget(findChild_Widget(editor, "bmed.url")));
331 set_String(&bm->tags, text_InputWidget(findChild_Widget(editor, "bmed.tags")));
332 postCommand_App("bookmarks.changed");
333 }
321 setFlags_Widget(as_Widget(d), disabled_WidgetFlag, iFalse); 334 setFlags_Widget(as_Widget(d), disabled_WidgetFlag, iFalse);
322 destroy_Widget(editor); 335 destroy_Widget(editor);
323 return iTrue; 336 return iTrue;
@@ -402,9 +415,10 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
402 if (d->mode == bookmarks_SidebarMode && item) { 415 if (d->mode == bookmarks_SidebarMode && item) {
403 setFlags_Widget(w, disabled_WidgetFlag, iTrue); 416 setFlags_Widget(w, disabled_WidgetFlag, iTrue);
404 iWidget *dlg = makeBookmarkEditor_Widget(); 417 iWidget *dlg = makeBookmarkEditor_Widget();
405 setText_InputWidget(findChild_Widget(dlg, "bmed.title"), &item->label); 418 iBookmark *bm = get_Bookmarks(bookmarks_App(), item->id);
406 setText_InputWidget(findChild_Widget(dlg, "bmed.url"), &item->url); 419 setText_InputWidget(findChild_Widget(dlg, "bmed.title"), &bm->title);
407 //setText_InputWidget(findChild_Widget(dlg, "bmed.tags"), &item->) 420 setText_InputWidget(findChild_Widget(dlg, "bmed.url"), &bm->url);
421 setText_InputWidget(findChild_Widget(dlg, "bmed.tags"), &bm->tags);
408 setCommandHandler_Widget(dlg, handleBookmarkEditorCommands_SidebarWidget_); 422 setCommandHandler_Widget(dlg, handleBookmarkEditorCommands_SidebarWidget_);
409 } 423 }
410 return iTrue; 424 return iTrue;
diff --git a/src/ui/util.c b/src/ui/util.c
index 185d37f3..05b3c930 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -168,8 +168,9 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) {
168 setFrameColor_Widget(menu, black_ColorId); 168 setFrameColor_Widget(menu, black_ColorId);
169 setBackgroundColor_Widget(menu, gray25_ColorId); 169 setBackgroundColor_Widget(menu, gray25_ColorId);
170 setFlags_Widget(menu, 170 setFlags_Widget(menu,
171 keepOnTop_WidgetFlag | hidden_WidgetFlag | arrangeVertical_WidgetFlag | 171 keepOnTop_WidgetFlag | collapse_WidgetFlag | hidden_WidgetFlag |
172 arrangeSize_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, 172 arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag |
173 resizeChildrenToWidestChild_WidgetFlag,
173 iTrue); 174 iTrue);
174 for (size_t i = 0; i < n; ++i) { 175 for (size_t i = 0; i < n; ++i) {
175 const iMenuItem *item = &items[i]; 176 const iMenuItem *item = &items[i];
@@ -659,10 +660,8 @@ iWidget *makeQuestion_Widget(const char *title,
659 660
660void setToggle_Widget(iWidget *d, iBool active) { 661void setToggle_Widget(iWidget *d, iBool active) {
661 setFlags_Widget(d, selected_WidgetFlag, active); 662 setFlags_Widget(d, selected_WidgetFlag, active);
662 updateText_LabelWidget( 663 updateText_LabelWidget((iLabelWidget *) d,
663 (iLabelWidget *) d, 664 collectNewFormat_String("%s", isSelected_Widget(d) ? "YES" : "NO"));
664 collectNewFormat_String(
665 "%s", isSelected_Widget(d) ? "YES" : "NO"));
666} 665}
667 666
668static iBool toggleHandler_(iWidget *d, const char *cmd) { 667static iBool toggleHandler_(iWidget *d, const char *cmd) {
@@ -709,3 +708,38 @@ iWidget *makePreferences_Widget(void) {
709 centerSheet_Widget(dlg); 708 centerSheet_Widget(dlg);
710 return dlg; 709 return dlg;
711} 710}
711
712iWidget *makeBookmarkEditor_Widget(void) {
713 iWidget *dlg = makeSheet_Widget("bmed");
714 addChild_Widget(dlg, iClob(new_LabelWidget(cyan_ColorEscape "EDIT BOOKMARK", 0, 0, NULL)));
715 iWidget *page = new_Widget();
716 addChild_Widget(dlg, iClob(page));
717 setFlags_Widget(page, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
718 iWidget *headings = addChildFlags_Widget(
719 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
720 iWidget *values = addChildFlags_Widget(
721 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
722 iInputWidget *inputs[4];
723 addChild_Widget(headings, iClob(makeHeading_Widget("Title:")));
724 setId_Widget(addChild_Widget(values, iClob(inputs[0] = new_InputWidget(0))), "bmed.title");
725 addChild_Widget(headings, iClob(makeHeading_Widget("URL:")));
726 setId_Widget(addChild_Widget(values, iClob(inputs[1] = new_InputWidget(0))), "bmed.url");
727 addChild_Widget(headings, iClob(makeHeading_Widget("Tags:")));
728 setId_Widget(addChild_Widget(values, iClob(inputs[2] = new_InputWidget(0))), "bmed.tags");
729 arrange_Widget(dlg);
730 for (int i = 0; i < 3; ++i) {
731 as_Widget(inputs[i])->rect.size.x = dlg->rect.size.x - headings->rect.size.x - 3 * gap_UI;
732 }
733 iWidget *div = new_Widget(); {
734 setFlags_Widget(div, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
735 addChild_Widget(div, iClob(new_LabelWidget("Cancel", SDLK_ESCAPE, 0, "cancel")));
736 addChild_Widget(
737 div,
738 iClob(new_LabelWidget(
739 orange_ColorEscape "Save", SDLK_RETURN, KMOD_PRIMARY, "bmed.accept")));
740 }
741 addChild_Widget(dlg, iClob(div));
742 addChild_Widget(get_Window()->root, iClob(dlg));
743 centerSheet_Widget(dlg);
744 return dlg;
745}
diff --git a/src/ui/util.h b/src/ui/util.h
index b67f0a87..6595b94c 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -121,3 +121,4 @@ void makeMessage_Widget (const char *title, const char *msg);
121iWidget * makeQuestion_Widget (const char *title, const char *msg, 121iWidget * makeQuestion_Widget (const char *title, const char *msg,
122 const char *labels[], const char *commands[], size_t count); 122 const char *labels[], const char *commands[], size_t count);
123iWidget * makePreferences_Widget (void); 123iWidget * makePreferences_Widget (void);
124iWidget * makeBookmarkEditor_Widget(void);