feat: Add /spellcheck list command
To list all available dictionaries. Signed-off-by: Michael Vetter <jubalh@iodoru.org>
This commit is contained in:
@@ -568,6 +568,7 @@ cmd_ac_init(void)
|
|||||||
|
|
||||||
autocomplete_add(spellcheck_ac, "on");
|
autocomplete_add(spellcheck_ac, "on");
|
||||||
autocomplete_add(spellcheck_ac, "off");
|
autocomplete_add(spellcheck_ac, "off");
|
||||||
|
autocomplete_add(spellcheck_ac, "list");
|
||||||
autocomplete_add(spellcheck_ac, "lang");
|
autocomplete_add(spellcheck_ac, "lang");
|
||||||
|
|
||||||
autocomplete_add(disco_ac, "info");
|
autocomplete_add(disco_ac, "info");
|
||||||
|
|||||||
@@ -1458,6 +1458,7 @@ static const struct cmd_t command_defs[] = {
|
|||||||
CMD_TAG_UI)
|
CMD_TAG_UI)
|
||||||
CMD_SYN(
|
CMD_SYN(
|
||||||
"/spellcheck on|off",
|
"/spellcheck on|off",
|
||||||
|
"/spellcheck list",
|
||||||
"/spellcheck lang <locale>")
|
"/spellcheck lang <locale>")
|
||||||
CMD_DESC(
|
CMD_DESC(
|
||||||
"Enable or disable spellchecking, or set the language.")
|
"Enable or disable spellchecking, or set the language.")
|
||||||
|
|||||||
@@ -6571,6 +6571,24 @@ cmd_spellcheck(ProfWin* window, const char* const command, gchar** args)
|
|||||||
} else if (g_strcmp0(args[0], "off") == 0) {
|
} else if (g_strcmp0(args[0], "off") == 0) {
|
||||||
prefs_set_boolean(PREF_SPELLCHECK_ENABLE, FALSE);
|
prefs_set_boolean(PREF_SPELLCHECK_ENABLE, FALSE);
|
||||||
cons_show("Spellcheck disabled.");
|
cons_show("Spellcheck disabled.");
|
||||||
|
} else if (g_strcmp0(args[0], "list") == 0) {
|
||||||
|
GList* langs = spellcheck_get_available_langs();
|
||||||
|
if (langs == NULL) {
|
||||||
|
cons_show("No dictionaries found. Install Enchant-compatible dictionaries (hunspell/aspell).");
|
||||||
|
} else {
|
||||||
|
GString* lang_str = g_string_new("");
|
||||||
|
GList* curr = langs;
|
||||||
|
while (curr) {
|
||||||
|
g_string_append(lang_str, (char*)curr->data);
|
||||||
|
if (curr->next) {
|
||||||
|
g_string_append(lang_str, ", ");
|
||||||
|
}
|
||||||
|
curr = g_list_next(curr);
|
||||||
|
}
|
||||||
|
cons_show("Available spellcheck dictionaries: %s", lang_str->str);
|
||||||
|
g_string_free(lang_str, TRUE);
|
||||||
|
g_list_free_full(langs, g_free);
|
||||||
|
}
|
||||||
} else if (g_strcmp0(args[0], "lang") == 0) {
|
} else if (g_strcmp0(args[0], "lang") == 0) {
|
||||||
if (args[1] == NULL) {
|
if (args[1] == NULL) {
|
||||||
cons_bad_cmd_usage(command);
|
cons_bad_cmd_usage(command);
|
||||||
|
|||||||
@@ -93,6 +93,31 @@ spellcheck_get_lang(void)
|
|||||||
return current_lang;
|
return current_lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_list_dicts_cb(const char* const lang_tag,
|
||||||
|
const char* const provider_name,
|
||||||
|
const char* const provider_desc,
|
||||||
|
const char* const provider_file,
|
||||||
|
void* user_data)
|
||||||
|
{
|
||||||
|
GList** list = (GList**)user_data;
|
||||||
|
if (g_list_find_custom(*list, lang_tag, (GCompareFunc)g_strcmp0) == NULL) {
|
||||||
|
*list = g_list_append(*list, g_strdup(lang_tag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GList*
|
||||||
|
spellcheck_get_available_langs(void)
|
||||||
|
{
|
||||||
|
if (!broker) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GList* list = NULL;
|
||||||
|
enchant_broker_list_dicts(broker, _list_dicts_cb, &list);
|
||||||
|
return g_list_sort(list, (GCompareFunc)g_strcmp0);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
spellcheck_is_misspelled(const char* word)
|
spellcheck_is_misspelled(const char* word)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ void spellcheck_deinit(void);
|
|||||||
gboolean spellcheck_is_misspelled(const char* word);
|
gboolean spellcheck_is_misspelled(const char* word);
|
||||||
gboolean spellcheck_set_lang(const char* lang);
|
gboolean spellcheck_set_lang(const char* lang);
|
||||||
const char* spellcheck_get_lang(void);
|
const char* spellcheck_get_lang(void);
|
||||||
|
GList* spellcheck_get_available_langs(void);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -46,6 +47,11 @@ spellcheck_get_lang(void)
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
static inline GList*
|
||||||
|
spellcheck_get_available_langs(void)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user