From 9ab0ab0df59a4b481bb449eb0300f61e9f5803be Mon Sep 17 00:00:00 2001 From: Sergey Semushin Date: Sat, 16 Mar 2024 22:07:30 +0100 Subject: [PATCH] Add message on certain actions when no dictionary is present. (#337) --- src/plugin/DSpellCheck.rc | Bin 52108 -> 52776 bytes src/plugin/Plugin.cpp | 110 ++++++++++++++++++++++---------------- src/plugin/Plugin.h | 42 --------------- src/plugin/resource.h | 2 + 4 files changed, 65 insertions(+), 89 deletions(-) diff --git a/src/plugin/DSpellCheck.rc b/src/plugin/DSpellCheck.rc index af582908dc1ff9b5c9171815985af6ab9ae9a5e9..6b1c94b46fc5401a95102536e333a01a4229f611 100644 GIT binary patch delta 408 zcmaJ*O-sW-6r7Nf_9j>)hav_Kq6bC)fEfHNNEBJnTT^TNfS8)3q2Bxf3dO!dF1-kX zp0uF9q6dGIvx|qGWZ5@w=grL9r_z2O+2i|(jGUT;j}>!B+f-}S0TK0;px<(&S7wepot8rCm&_*|3# delta 21 dcmZ26hq-4u^M;C3lc&k>P1fR&nrw6S4FF_W2^s(Z diff --git a/src/plugin/Plugin.cpp b/src/plugin/Plugin.cpp index c3dfa61..e1f0f00 100644 --- a/src/plugin/Plugin.cpp +++ b/src/plugin/Plugin.cpp @@ -105,11 +105,11 @@ LRESULT CALLBACK mouse_proc(int n_code, WPARAM w_param, LPARAM l_param) { return CallNextHookEx(h_mouse_hook, n_code, w_param, l_param);; } -void set_context_menu_id_start(int id) { context_menu_id_start = id; } +static void set_context_menu_id_start(int id) { context_menu_id_start = id; } -void set_langs_menu_id_start(int id) { langs_menu_id_start = id; } +static void set_langs_menu_id_start(int id) { langs_menu_id_start = id; } -void set_use_allocated_ids(bool value) { use_allocated_ids = value; } +static void set_use_allocated_ids(bool value) { use_allocated_ids = value; } int get_context_menu_id_start() { return context_menu_id_start; } @@ -117,7 +117,7 @@ int get_langs_menu_id_start() { return langs_menu_id_start; } bool get_use_allocated_ids() { return use_allocated_ids; } -const Settings &get_settings() { return *settings; } +static const Settings &get_settings() { return *settings; } std::wstring get_default_hunspell_path() { std::wstring path = ini_file_path; @@ -142,11 +142,11 @@ DownloadDictionariesDialog *get_download_dics() { return download_dics_dlg.get() HANDLE get_h_module() { return h_module; } -void create_hooks() { +static void create_hooks() { h_mouse_hook = SetWindowsHookEx(WH_MOUSE, mouse_proc, nullptr, GetCurrentThreadId()); } -void plugin_clean_up() { +static void plugin_clean_up() { { auto mut = speller_container->modify(); mut->cleanup(); @@ -155,19 +155,31 @@ void plugin_clean_up() { WinApi::delete_file(get_debug_log_path().c_str()); } -void register_custom_messages() { +static void register_custom_messages() { for (int i = 0; i < static_cast(CustomGuiMessage::max); i++) { custom_gui_message_ids[i] = RegisterWindowMessage(custom_gui_messages_names[i]); } } -void init_npp_interface() { npp = std::make_unique(&npp_data); } +static void init_npp_interface() { npp = std::make_unique(&npp_data); } -void notify(SCNotification *notify_code) { npp->notify(notify_code); } +static void notify(SCNotification *notify_code) { npp->notify(notify_code); } NppInterface &npp_interface() { return *npp; } -void erase_misspellings() { spell_checker->erase_all_misspellings(); } +static bool check_if_any_language_available() { + if (!speller_container->active_speller().get_language_list().empty()) + return true; + + MessageBox(npp->get_editor_hwnd(), rc_str(IDC_WARNING_NO_DICTIONARIES_TEXT).c_str(), rc_str(IDC_WARNING_NO_DICTIONARIES_TITLE).c_str(), + MB_OK | MB_ICONWARNING); + return false; +} + +void erase_misspellings() { + if (!check_if_any_language_available()) + return; + spell_checker->erase_all_misspellings(); } void show_spell_check_menu_at_cursor() { auto menu = CreatePopupMenu(); @@ -189,6 +201,8 @@ void show_spell_check_menu_at_cursor() { } void replace_with_1st_suggestion() { + if (!check_if_any_language_available()) + return; SpellCheckerHelpers::replace_current_word_with_topmost_suggestion(*npp, *spell_checker, *speller_container); } @@ -205,6 +219,8 @@ void ignore_for_current_session() { } void copy_misspellings_to_clipboard() { + if (!check_if_any_language_available()) + return; auto str = spell_checker->get_all_misspellings_as_string(); const size_t len = (str.length() + 1) * 2; HGLOBAL h_mem = GlobalAlloc(GMEM_MOVEABLE, len); @@ -220,6 +236,8 @@ void copy_misspellings_to_clipboard() { } void mark_lines_with_misspelling() { + if (!check_if_any_language_available()) + return; spell_checker->mark_lines_with_misspelling(); } @@ -257,15 +275,23 @@ void start_about_dlg() { about_dlg->do_dialog(); } void start_language_list() { lang_list_instance->do_dialog(); } -void recheck_visible() { +static void recheck_visible() { print_to_log(L"recheck_visible ()", npp->get_editor_hwnd()); ACTIVE_VIEW_BLOCK(npp_interface()); spell_checker->recheck_visible(); } -void find_next_mistake() { spell_checker->find_next_mistake(); } +void find_next_mistake() { + if (!check_if_any_language_available()) + return; + spell_checker->find_next_mistake(); +} -void find_prev_mistake() { spell_checker->find_prev_mistake(); } +void find_prev_mistake() { + if (!check_if_any_language_available()) + return; + spell_checker->find_prev_mistake(); +} void quick_lang_change_context() { POINT pos; @@ -279,10 +305,28 @@ enum_array action_index = []() { return val; }(); -// -// Initialization of your plug-in commands -// You should fill your plug-ins commands here -void command_menu_init() { +static int set_next_command(const wchar_t *cmd_name, Pfuncplugincmd p_func) { + static int counter = 0; + if (counter >= nb_func) { + assert(false); // Less actions specified in nb_func constant than added + return -1; + } + + if (p_func == nullptr) { + counter++; + return counter - 1; + } + + lstrcpy(func_item[counter].item_name, cmd_name); + func_item[counter].p_func = p_func; + func_item[counter].init2_check = false; + func_item[counter].p_sh_key = nullptr; + counter++; + + return counter - 1; +} + +static void command_menu_init() { // // Firstly we get the parameters from your plugin config file (if any) // @@ -340,7 +384,7 @@ void command_menu_init() { // add further set_next_command at the bottom to avoid breaking configured hotkeys } -void add_icons() { +static void add_icons() { static ToolbarIconsWrapper auto_check_icon{static_cast(h_module), MAKEINTRESOURCE(IDI_AUTOCHECK), MAKEINTRESOURCE(IDI_AUTOCHECK_DARK), MAKEINTRESOURCE(IDB_AUTOCHECK_BMP)}; ::SendMessage(npp_data.npp_handle, NPPM_ADDTOOLBARICON_FORDARKMODE, static_cast(func_item[0].cmd_id), reinterpret_cast(auto_check_icon.get())); @@ -401,7 +445,7 @@ void on_settings_changed() { npp->set_menu_item_check(get_func_item()[action_index[Action::toggle_debug_logging]].cmd_id, settings->data.write_debug_log); } -void init_classes() { +static void init_classes() { INITCOMMONCONTROLSEX icc; icc.dwSize = sizeof(icc); @@ -448,35 +492,8 @@ void init_classes() { resources_inited = true; } -void command_menu_clean_up() { -} - -// -// Function that initializes plug-in commands -// -static int counter = 0; - std::vector> shortcut_storage; -int set_next_command(const wchar_t *cmd_name, Pfuncplugincmd p_func) { - if (counter >= nb_func) { - assert(false); // Less actions specified in nb_func constant than added - return -1; - } - - if (p_func == nullptr) { - counter++; - return counter - 1; - } - - lstrcpy(func_item[counter].item_name, cmd_name); - func_item[counter].p_func = p_func; - func_item[counter].init2_check = false; - func_item[counter].p_sh_key = nullptr; - counter++; - - return counter - 1; -} std::wstring get_debug_log_path() { std::vector buf(MAX_PATH); @@ -740,7 +757,6 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification *notify_code) { print_to_log(L"NPPN_SHUTDOWN", npp->get_editor_hwnd()); edit_recheck_timer.reset(); scroll_recheck_timer.reset(); - command_menu_clean_up(); plugin_clean_up(); RemoveWindowSubclass(npp_data.npp_handle, subclass_proc, 0); diff --git a/src/plugin/Plugin.h b/src/plugin/Plugin.h index ce8413b..636cd01 100644 --- a/src/plugin/Plugin.h +++ b/src/plugin/Plugin.h @@ -61,45 +61,10 @@ class ProgressDialog; class RemoveDictionariesDialog; class Settings; -// -// Initialization of your plugin data -// It will be called while plugin loading -// void set_hmodule(HANDLE h_module_arg); - -// -// Cleaning of your plugin -// It will be called while plugin unloading -// -void plugin_clean_up(); - -// -//Initialization of your plugin commands -// -void command_menu_init(); - -// -//Clean up your plugin commands allocation (if any) -// -void command_menu_clean_up(); - -// -// Function which sets your command -// -int set_next_command(const wchar_t *cmd_name, Pfuncplugincmd p_func); - -void set_delimiters(const char *str); std::wstring rc_str(UINT string_id); std::wstring_view rc_str_view(UINT string_id); -const char *get_delimiters(); -void set_encoding_by_id(int enc_id); -void recheck_visible(); -void init_classes(); -void create_hooks(); LRESULT show_calculated_menu(std::vector &&menu_list); -void add_icons(); -bool get_auto_check_state(); -void auto_check_state_received(bool state); HMENU get_this_plugin_menu(); HMENU get_langs_sub_menu(); HANDLE get_h_module(); @@ -110,18 +75,11 @@ ConnectionSettingsDialog *get_select_proxy(); ProgressDialog *get_progress_dlg(); FuncItem *get_func_item(); std::wstring get_default_hunspell_path(); -void set_context_menu_id_start(int id); -void set_langs_menu_id_start(int id); -void set_use_allocated_ids(bool value); int get_context_menu_id_start(); int get_langs_menu_id_start(); bool get_use_allocated_ids(); -const Settings &get_settings(); DWORD get_custom_gui_message_id(CustomGuiMessage message_id); -void register_custom_messages(); std::wstring get_debug_log_path(); -void init_npp_interface(); -void notify(SCNotification *notify_code); NppInterface &npp_interface(); void copy_misspellings_to_clipboard(); void delete_log(); diff --git a/src/plugin/resource.h b/src/plugin/resource.h index e9ca88e..d88d18e 100644 --- a/src/plugin/resource.h +++ b/src/plugin/resource.h @@ -220,6 +220,8 @@ #define IDS_RESET_SETTINGS_CAPTION 40110 #define IDS_BOOKMARK_LINES_WITH_MISSPELLING 40111 #define IDS_DOWNLOAD_ERRORS_ENCOUNTERED 40112 +#define IDC_WARNING_NO_DICTIONARIES_TITLE 40113 +#define IDC_WARNING_NO_DICTIONARIES_TEXT 40114 // Next default values for new objects //