summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-05-20 21:07:03 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-05-20 21:07:03 +0300
commit5eef316269435522111db7d1b51c8a82a6ecda0d (patch)
tree84f14851675b1a64e90d29a8dea2ca77e387b21d /src/ui
parent046869954cceb49f106e3a5051517050a5515b31 (diff)
SidebarWidget: Identities list click behavior
Avoid accidental activations by never (de)activating identities based on a single click. Now both left and right mouse clicks will open the context menu.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/listwidget.c7
-rw-r--r--src/ui/listwidget.h1
-rw-r--r--src/ui/sidebarwidget.c26
3 files changed, 21 insertions, 13 deletions
diff --git a/src/ui/listwidget.c b/src/ui/listwidget.c
index a3406d48..a43b11ee 100644
--- a/src/ui/listwidget.c
+++ b/src/ui/listwidget.c
@@ -369,6 +369,13 @@ static iBool processEvent_ListWidget_(iListWidget *d, const SDL_Event *ev) {
369 return processEvent_Widget(w, ev); 369 return processEvent_Widget(w, ev);
370} 370}
371 371
372iRect itemRect_ListWidget(const iListWidget *d, size_t index) {
373 const iRect bounds = innerBounds_Widget(constAs_Widget(d));
374 const int scrollY = pos_SmoothScroll(&d->scrollY);
375 return (iRect){ addY_I2(topLeft_Rect(bounds), d->itemHeight * (int) index - scrollY),
376 init_I2(width_Rect(bounds), d->itemHeight) };
377}
378
372static void draw_ListWidget_(const iListWidget *d) { 379static void draw_ListWidget_(const iListWidget *d) {
373 const iWidget *w = constAs_Widget(d); 380 const iWidget *w = constAs_Widget(d);
374 const iRect bounds = innerBounds_Widget(w); 381 const iRect bounds = innerBounds_Widget(w);
diff --git a/src/ui/listwidget.h b/src/ui/listwidget.h
index 16adf664..314c183a 100644
--- a/src/ui/listwidget.h
+++ b/src/ui/listwidget.h
@@ -73,6 +73,7 @@ iAnyObject * hoverItem_ListWidget (iListWidget *);
73size_t numItems_ListWidget (const iListWidget *); 73size_t numItems_ListWidget (const iListWidget *);
74int visCount_ListWidget (const iListWidget *); 74int visCount_ListWidget (const iListWidget *);
75size_t itemIndex_ListWidget (const iListWidget *, iInt2 pos); 75size_t itemIndex_ListWidget (const iListWidget *, iInt2 pos);
76iRect itemRect_ListWidget (const iListWidget *, size_t index);
76const iAnyObject * constItem_ListWidget (const iListWidget *, size_t index); 77const iAnyObject * constItem_ListWidget (const iListWidget *, size_t index);
77const iAnyObject * constHoverItem_ListWidget (const iListWidget *); 78const iAnyObject * constHoverItem_ListWidget (const iListWidget *);
78size_t hoverItemIndex_ListWidget (const iListWidget *); 79size_t hoverItemIndex_ListWidget (const iListWidget *);
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index aa58eb45..556ae951 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -766,7 +766,7 @@ static iGmIdentity *hoverIdentity_SidebarWidget_(const iSidebarWidget *d) {
766 return iConstCast(iGmIdentity *, constHoverIdentity_SidebarWidget_(d)); 766 return iConstCast(iGmIdentity *, constHoverIdentity_SidebarWidget_(d));
767} 767}
768 768
769static void itemClicked_SidebarWidget_(iSidebarWidget *d, const iSidebarItem *item) { 769static void itemClicked_SidebarWidget_(iSidebarWidget *d, iSidebarItem *item, size_t itemIndex) {
770 setFocus_Widget(NULL); 770 setFocus_Widget(NULL);
771 switch (d->mode) { 771 switch (d->mode) {
772 case documentOutline_SidebarMode: { 772 case documentOutline_SidebarMode: {
@@ -791,17 +791,16 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, const iSidebarItem *it
791 break; 791 break;
792 } 792 }
793 case identities_SidebarMode: { 793 case identities_SidebarMode: {
794 iGmIdentity *ident = hoverIdentity_SidebarWidget_(d); 794 d->contextItem = item;
795 if (ident) { 795 d->contextIndex = itemIndex;
796 const iString *tabUrl = url_DocumentWidget(document_App()); 796 if (itemIndex < numItems_ListWidget(d->list)) {
797 if (isUsedOn_GmIdentity(ident, tabUrl)) { 797 updateContextMenu_SidebarWidget_(d);
798 signOut_GmCerts(certs_App(), tabUrl); 798 arrange_Widget(d->menu);
799 } 799 openMenu_Widget(d->menu,
800 else { 800 d->side == left_SideBarSide
801 signIn_GmCerts(certs_App(), ident, tabUrl); 801 ? topRight_Rect(itemRect_ListWidget(d->list, itemIndex))
802 } 802 : addX_I2(topLeft_Rect(itemRect_ListWidget(d->list, itemIndex)),
803 updateItems_SidebarWidget_(d); 803 -width_Widget(d->menu)));
804 updateMouseHover_ListWidget(d->list);
805 } 804 }
806 break; 805 break;
807 } 806 }
@@ -1065,7 +1064,8 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1065 return iTrue; 1064 return iTrue;
1066 } 1065 }
1067 else if (isCommand_Widget(w, ev, "list.clicked")) { 1066 else if (isCommand_Widget(w, ev, "list.clicked")) {
1068 itemClicked_SidebarWidget_(d, pointerLabel_Command(cmd, "item")); 1067 itemClicked_SidebarWidget_(
1068 d, pointerLabel_Command(cmd, "item"), argU32Label_Command(cmd, "arg"));
1069 return iTrue; 1069 return iTrue;
1070 } 1070 }
1071 else if (isCommand_Widget(w, ev, "menu.closed")) { 1071 else if (isCommand_Widget(w, ev, "menu.closed")) {