From fa65ced22f1c74a095394a0e3362b9939321c800 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Mon, 16 Nov 2020 16:01:38 +0200 Subject: Closing the sidebar with Escape --- src/ui/sidebarwidget.c | 12 ++++++++++++ src/ui/window.c | 12 +++++------- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src/ui') diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 88ffffba..f17f82a1 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -771,6 +771,18 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) } } } + if (ev->type == SDL_KEYDOWN) { + const int key = ev->key.keysym.sym; + const int kmods = keyMods_Sym(ev->key.keysym.mod); + /* Hide the sidebar when Escape is pressed. */ + if (kmods == 0 && key == SDLK_ESCAPE && isVisible_Widget(d)) { + setFlags_Widget(w, hidden_WidgetFlag, iTrue); + arrange_Widget(w->parent); + updateSize_DocumentWidget(document_App()); + refresh_Widget(w->parent); + return iTrue; + } + } if (hoverItem_ListWidget(d->list) || isVisible_Widget(d->menu)) { processContextMenuEvent_Widget(d->menu, ev, {}); } diff --git a/src/ui/window.c b/src/ui/window.c index ba6ee869..63f19e3f 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -326,7 +326,7 @@ static iBool handleSearchBarCommands_(iWidget *searchBar, const char *cmd) { else if (equal_Command(cmd, "focus.gained")) { if (pointer_Command(cmd) == findChild_Widget(searchBar, "find.input")) { if (!isVisible_Widget(searchBar)) { - setFlags_Widget(searchBar, hidden_WidgetFlag, iFalse); + setFlags_Widget(searchBar, hidden_WidgetFlag | disabled_WidgetFlag, iFalse); arrange_Widget(get_Window()->root); refresh_App(); } @@ -334,16 +334,13 @@ static iBool handleSearchBarCommands_(iWidget *searchBar, const char *cmd) { } else if (equal_Command(cmd, "find.close")) { if (isVisible_Widget(searchBar)) { - setFlags_Widget(searchBar, hidden_WidgetFlag, iTrue); + setFlags_Widget(searchBar, hidden_WidgetFlag | disabled_WidgetFlag, iTrue); arrange_Widget(searchBar->parent); if (isFocused_Widget(findChild_Widget(searchBar, "find.input"))) { setFocus_Widget(NULL); } refresh_Widget(searchBar->parent); } - else if (isVisible_Widget(findWidget_App("sidebar"))) { - postCommand_App("sidebar.toggle"); - } return iTrue; } return iFalse; @@ -446,8 +443,9 @@ static void setupUserInterface_Window(iWindow *d) { iWidget *searchBar = new_Widget(); setId_Widget(searchBar, "search"); setFlags_Widget(searchBar, - hidden_WidgetFlag | collapse_WidgetFlag | arrangeHeight_WidgetFlag | - resizeChildren_WidgetFlag | arrangeHorizontal_WidgetFlag, + hidden_WidgetFlag | disabled_WidgetFlag | collapse_WidgetFlag | + arrangeHeight_WidgetFlag | resizeChildren_WidgetFlag | + arrangeHorizontal_WidgetFlag, iTrue); addChild_Widget(div, iClob(searchBar)); setBackgroundColor_Widget(searchBar, uiBackground_ColorId); -- cgit v1.2.3