Enable switching among more than 10 dictionaries

Ctrl + PageUp/PageDown/Left/Right now change the active tab.
This commit is contained in:
Přemysl Eric Janouch 2020-09-02 16:28:35 +02:00
parent 37bf8ee648
commit bbe22712fe
Signed by: p
GPG Key ID: A0420B94F92B9493
2 changed files with 33 additions and 2 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2013 - 2018, Přemysl Eric Janouch <p@janouch.name> Copyright (c) 2013 - 2020, Přemysl Eric Janouch <p@janouch.name>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted. purpose with or without fee is hereby granted.

View File

@ -1,7 +1,7 @@
/* /*
* StarDict terminal UI * StarDict terminal UI
* *
* Copyright (c) 2013 - 2018, Přemysl Eric Janouch <p@janouch.name> * Copyright (c) 2013 - 2020, Přemysl Eric Janouch <p@janouch.name>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted. * purpose with or without fee is hereby granted.
@ -1296,6 +1296,22 @@ app_goto_dictionary (Application *self, guint n)
return TRUE; 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. /// The terminal has been resized, make appropriate changes.
static gboolean static gboolean
app_process_resize (Application *self) app_process_resize (Application *self)
@ -1337,6 +1353,8 @@ enum user_action
USER_ACTION_GOTO_DEFINITION_NEXT, USER_ACTION_GOTO_DEFINITION_NEXT,
USER_ACTION_GOTO_PAGE_PREVIOUS, USER_ACTION_GOTO_PAGE_PREVIOUS,
USER_ACTION_GOTO_PAGE_NEXT, USER_ACTION_GOTO_PAGE_NEXT,
USER_ACTION_GOTO_DICTIONARY_PREVIOUS,
USER_ACTION_GOTO_DICTIONARY_NEXT,
USER_ACTION_INPUT_CONFIRM, USER_ACTION_INPUT_CONFIRM,
USER_ACTION_INPUT_HOME, USER_ACTION_INPUT_HOME,
@ -1429,6 +1447,15 @@ app_process_user_action (Application *self, UserAction action)
RESTORE_CURSOR RESTORE_CURSOR
return TRUE; 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: 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_UP] = USER_ACTION_GOTO_ENTRY_PREVIOUS,
[TERMO_SYM_DOWN] = USER_ACTION_GOTO_ENTRY_NEXT, [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) if (!event->modifiers)