From bbe22712fe551e8ee79726002725cfc211086024 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Wed, 2 Sep 2020 16:28:35 +0200 Subject: Enable switching among more than 10 dictionaries Ctrl + PageUp/PageDown/Left/Right now change the active tab. --- src/sdtui.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sdtui.c b/src/sdtui.c index be6a43c..9818d4b 100644 --- a/src/sdtui.c +++ b/src/sdtui.c @@ -1,7 +1,7 @@ /* * StarDict terminal UI * - * Copyright (c) 2013 - 2018, Přemysl Eric Janouch + * Copyright (c) 2013 - 2020, Přemysl Eric Janouch * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted. @@ -1296,6 +1296,22 @@ app_goto_dictionary (Application *self, guint n) return TRUE; } +/// Switch to a different dictionary by delta. +static gboolean +app_goto_dictionary_delta (Application *self, gint n) +{ + GArray *dicts = self->dictionaries; + if (dicts->len <= 1) + return FALSE; + + guint i = 0; + while (i < dicts->len && + g_array_index (dicts, Dictionary, i).dict != self->dict) + i++; + + return app_goto_dictionary (self, (i + dicts->len + n) % dicts->len); +} + /// The terminal has been resized, make appropriate changes. static gboolean app_process_resize (Application *self) @@ -1337,6 +1353,8 @@ enum user_action USER_ACTION_GOTO_DEFINITION_NEXT, USER_ACTION_GOTO_PAGE_PREVIOUS, USER_ACTION_GOTO_PAGE_NEXT, + USER_ACTION_GOTO_DICTIONARY_PREVIOUS, + USER_ACTION_GOTO_DICTIONARY_NEXT, USER_ACTION_INPUT_CONFIRM, USER_ACTION_INPUT_HOME, @@ -1429,6 +1447,15 @@ app_process_user_action (Application *self, UserAction action) RESTORE_CURSOR return TRUE; + case USER_ACTION_GOTO_DICTIONARY_PREVIOUS: + if (!app_goto_dictionary_delta (self, -1)) + beep (); + return TRUE; + case USER_ACTION_GOTO_DICTIONARY_NEXT: + if (!app_goto_dictionary_delta (self, +1)) + beep (); + return TRUE; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - case USER_ACTION_INPUT_HOME: @@ -1593,6 +1620,10 @@ app_process_keysym (Application *self, termo_key_t *event) { [TERMO_SYM_UP] = USER_ACTION_GOTO_ENTRY_PREVIOUS, [TERMO_SYM_DOWN] = USER_ACTION_GOTO_ENTRY_NEXT, + [TERMO_SYM_LEFT] = USER_ACTION_GOTO_DICTIONARY_PREVIOUS, + [TERMO_SYM_RIGHT] = USER_ACTION_GOTO_DICTIONARY_NEXT, + [TERMO_SYM_PAGEUP] = USER_ACTION_GOTO_DICTIONARY_PREVIOUS, + [TERMO_SYM_PAGEDOWN] = USER_ACTION_GOTO_DICTIONARY_NEXT, }; if (!event->modifiers) -- cgit v1.2.3-70-g09d2