summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-23 13:01:22 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-23 13:01:22 +0300
commit863adf9118ae98a42bbbbd556087a437aba62329 (patch)
treea371d052e60aee56111667d8ec30d43d26dba9f6 /src
parent12fdf29fffaad285687bef9075214077654ebd74 (diff)
Create bookmarks using a dialog
Diffstat (limited to 'src')
-rw-r--r--src/app.c8
-rw-r--r--src/ui/labelwidget.c4
-rw-r--r--src/ui/labelwidget.h1
-rw-r--r--src/ui/sidebarwidget.c31
-rw-r--r--src/ui/util.c41
-rw-r--r--src/ui/util.h7
6 files changed, 64 insertions, 28 deletions
diff --git a/src/app.c b/src/app.c
index f0249fcf..fe96a1f6 100644
--- a/src/app.c
+++ b/src/app.c
@@ -668,11 +668,9 @@ iBool handleCommand_App(const char *cmd) {
668 } 668 }
669 else if (equal_Command(cmd, "bookmark.add")) { 669 else if (equal_Command(cmd, "bookmark.add")) {
670 iDocumentWidget *doc = document_App(); 670 iDocumentWidget *doc = document_App();
671 add_Bookmarks(d->bookmarks, url_DocumentWidget(doc), 671 makeBookmarkCreation_Widget(url_DocumentWidget(doc),
672 bookmarkTitle_DocumentWidget(doc), 672 bookmarkTitle_DocumentWidget(doc),
673 collectNew_String(), 673 siteIcon_GmDocument(document_DocumentWidget(doc)));
674 siteIcon_GmDocument(document_DocumentWidget(doc)));
675 postCommand_App("bookmarks.changed");
676 return iTrue; 674 return iTrue;
677 } 675 }
678 else if (equal_Command(cmd, "theme.set")) { 676 else if (equal_Command(cmd, "theme.set")) {
diff --git a/src/ui/labelwidget.c b/src/ui/labelwidget.c
index 0e9c592f..d9842a40 100644
--- a/src/ui/labelwidget.c
+++ b/src/ui/labelwidget.c
@@ -333,6 +333,10 @@ void setTextCStr_LabelWidget(iLabelWidget *d, const char *text) {
333 updateSize_LabelWidget(d); 333 updateSize_LabelWidget(d);
334} 334}
335 335
336const iString *label_LabelWidget(const iLabelWidget *d) {
337 return &d->label;
338}
339
336const iString *command_LabelWidget(const iLabelWidget *d) { 340const iString *command_LabelWidget(const iLabelWidget *d) {
337 return &d->command; 341 return &d->command;
338} 342}
diff --git a/src/ui/labelwidget.h b/src/ui/labelwidget.h
index ad1419ef..64f96aed 100644
--- a/src/ui/labelwidget.h
+++ b/src/ui/labelwidget.h
@@ -38,6 +38,7 @@ void updateSize_LabelWidget (iLabelWidget *);
38void updateText_LabelWidget (iLabelWidget *, const iString *text); /* not resized */ 38void updateText_LabelWidget (iLabelWidget *, const iString *text); /* not resized */
39void updateTextCStr_LabelWidget (iLabelWidget *, const char *text); /* not resized */ 39void updateTextCStr_LabelWidget (iLabelWidget *, const char *text); /* not resized */
40 40
41const iString *label_LabelWidget (const iLabelWidget *);
41const iString *command_LabelWidget (const iLabelWidget *); 42const iString *command_LabelWidget (const iLabelWidget *);
42 43
43iLocalDef iLabelWidget *newEmpty_LabelWidget(void) { 44iLocalDef iLabelWidget *newEmpty_LabelWidget(void) {
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 99768b13..a02294dc 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -416,17 +416,12 @@ iBool handleBookmarkEditorCommands_SidebarWidget_(iWidget *editor, const char *c
416 const iString *title = text_InputWidget(findChild_Widget(editor, "bmed.title")); 416 const iString *title = text_InputWidget(findChild_Widget(editor, "bmed.title"));
417 const iString *url = text_InputWidget(findChild_Widget(editor, "bmed.url")); 417 const iString *url = text_InputWidget(findChild_Widget(editor, "bmed.url"));
418 const iString *tags = text_InputWidget(findChild_Widget(editor, "bmed.tags")); 418 const iString *tags = text_InputWidget(findChild_Widget(editor, "bmed.tags"));
419 if (!cmp_String(id_Widget(editor), "bmed.create")) { 419 const iSidebarItem *item = hoverItem_SidebarWidget_(d);
420 add_Bookmarks(bookmarks_App(), url, title, tags, 0x1f310); 420 iAssert(item); /* hover item cannot have been changed */
421 } 421 iBookmark *bm = get_Bookmarks(bookmarks_App(), item->id);
422 else { 422 set_String(&bm->title, title);
423 const iSidebarItem *item = hoverItem_SidebarWidget_(d); 423 set_String(&bm->url, url);
424 iAssert(item); /* hover item cannot have been changed */ 424 set_String(&bm->tags, tags);
425 iBookmark *bm = get_Bookmarks(bookmarks_App(), item->id);
426 set_String(&bm->title, title);
427 set_String(&bm->url, url);
428 set_String(&bm->tags, tags);
429 }
430 postCommand_App("bookmarks.changed"); 425 postCommand_App("bookmarks.changed");
431 } 426 }
432 setFlags_Widget(as_Widget(d), disabled_WidgetFlag, iFalse); 427 setFlags_Widget(as_Widget(d), disabled_WidgetFlag, iFalse);
@@ -556,16 +551,10 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
556 else if (equal_Command(cmd, "history.addbookmark")) { 551 else if (equal_Command(cmd, "history.addbookmark")) {
557 const iSidebarItem *item = hoverItem_SidebarWidget_(d); 552 const iSidebarItem *item = hoverItem_SidebarWidget_(d);
558 if (!isEmpty_String(&item->url)) { 553 if (!isEmpty_String(&item->url)) {
559 iWidget *dlg = makeBookmarkEditor_Widget(); 554 makeBookmarkCreation_Widget(
560 setId_Widget(dlg, "bmed.create"); 555 &item->url,
561 setTextCStr_LabelWidget(findChild_Widget(dlg, "bmed.heading"), 556 collect_String(newRange_String(urlHost_String(&item->url))),
562 uiHeading_ColorEscape "ADD BOOKMARK"); 557 0x1f310 /* globe */);
563 iUrl parts;
564 init_Url(&parts, &item->url);
565 setTextCStr_InputWidget(findChild_Widget(dlg, "bmed.title"),
566 cstr_Rangecc(parts.host));
567 setText_InputWidget(findChild_Widget(dlg, "bmed.url"), &item->url);
568 setCommandHandler_Widget(dlg, handleBookmarkEditorCommands_SidebarWidget_);
569 } 558 }
570 } 559 }
571 else if (equal_Command(cmd, "history.clear")) { 560 else if (equal_Command(cmd, "history.clear")) {
diff --git a/src/ui/util.c b/src/ui/util.c
index d8079383..753fd140 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -23,8 +23,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
23#include "util.h" 23#include "util.h"
24 24
25#include "app.h" 25#include "app.h"
26#include "bookmarks.h"
26#include "color.h" 27#include "color.h"
27#include "command.h" 28#include "command.h"
29#include "gmutil.h"
28#include "labelwidget.h" 30#include "labelwidget.h"
29#include "inputwidget.h" 31#include "inputwidget.h"
30#include "widget.h" 32#include "widget.h"
@@ -791,3 +793,42 @@ iWidget *makeBookmarkEditor_Widget(void) {
791 centerSheet_Widget(dlg); 793 centerSheet_Widget(dlg);
792 return dlg; 794 return dlg;
793} 795}
796
797static iBool handleBookmarkCreationCommands_SidebarWidget_(iWidget *editor, const char *cmd) {
798 if (equal_Command(cmd, "bmed.accept") || equal_Command(cmd, "cancel")) {
799 if (equal_Command(cmd, "bmed.accept")) {
800 const iString *title = text_InputWidget(findChild_Widget(editor, "bmed.title"));
801 const iString *url = text_InputWidget(findChild_Widget(editor, "bmed.url"));
802 const iString *tags = text_InputWidget(findChild_Widget(editor, "bmed.tags"));
803 add_Bookmarks(bookmarks_App(),
804 url,
805 title,
806 tags,
807 first_String(label_LabelWidget(findChild_Widget(editor, "bmed.icon"))));
808 postCommand_App("bookmarks.changed");
809 }
810 destroy_Widget(editor);
811 return iTrue;
812 }
813 return iFalse;
814}
815
816iWidget *makeBookmarkCreation_Widget(const iString *url, const iString *title, iChar icon) {
817 iWidget *dlg = makeBookmarkEditor_Widget();
818 setId_Widget(dlg, "bmed.create");
819 setTextCStr_LabelWidget(findChild_Widget(dlg, "bmed.heading"),
820 uiHeading_ColorEscape "ADD BOOKMARK");
821 iUrl parts;
822 init_Url(&parts, url);
823 setTextCStr_InputWidget(findChild_Widget(dlg, "bmed.title"),
824 title ? cstr_String(title) : cstr_Rangecc(parts.host));
825 setText_InputWidget(findChild_Widget(dlg, "bmed.url"), url);
826 setId_Widget(
827 addChildFlags_Widget(
828 dlg,
829 iClob(new_LabelWidget(cstrCollect_String(newUnicodeN_String(&icon, 1)), 0, 0, NULL)),
830 collapse_WidgetFlag | hidden_WidgetFlag | disabled_WidgetFlag),
831 "bmed.icon");
832 setCommandHandler_Widget(dlg, handleBookmarkCreationCommands_SidebarWidget_);
833 return dlg;
834}
diff --git a/src/ui/util.h b/src/ui/util.h
index 98bb187e..129053e5 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -22,6 +22,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
22 22
23#pragma once 23#pragma once
24 24
25#include <the_Foundation/string.h>
25#include <the_Foundation/rect.h> 26#include <the_Foundation/rect.h>
26#include <the_Foundation/vec2.h> 27#include <the_Foundation/vec2.h>
27#include <SDL_events.h> 28#include <SDL_events.h>
@@ -142,5 +143,7 @@ void updateValueInput_Widget (iWidget *, const char *title, const char *p
142void makeMessage_Widget (const char *title, const char *msg); 143void makeMessage_Widget (const char *title, const char *msg);
143iWidget * makeQuestion_Widget (const char *title, const char *msg, 144iWidget * makeQuestion_Widget (const char *title, const char *msg,
144 const char *labels[], const char *commands[], size_t count); 145 const char *labels[], const char *commands[], size_t count);
145iWidget * makePreferences_Widget (void); 146
146iWidget * makeBookmarkEditor_Widget(void); 147iWidget * makePreferences_Widget (void);
148iWidget * makeBookmarkEditor_Widget (void);
149iWidget * makeBookmarkCreation_Widget (const iString *url, const iString *title, iChar icon);