@@ -105,19 +105,19 @@ LRESULT CALLBACK mouse_proc(int n_code, WPARAM w_param, LPARAM l_param) {
105105 return CallNextHookEx (h_mouse_hook, n_code, w_param, l_param);;
106106}
107107
108- void set_context_menu_id_start (int id) { context_menu_id_start = id; }
108+ static void set_context_menu_id_start (int id) { context_menu_id_start = id; }
109109
110- void set_langs_menu_id_start (int id) { langs_menu_id_start = id; }
110+ static void set_langs_menu_id_start (int id) { langs_menu_id_start = id; }
111111
112- void set_use_allocated_ids (bool value) { use_allocated_ids = value; }
112+ static void set_use_allocated_ids (bool value) { use_allocated_ids = value; }
113113
114114int get_context_menu_id_start () { return context_menu_id_start; }
115115
116116int get_langs_menu_id_start () { return langs_menu_id_start; }
117117
118118bool get_use_allocated_ids () { return use_allocated_ids; }
119119
120- const Settings &get_settings () { return *settings; }
120+ static const Settings &get_settings () { return *settings; }
121121
122122std::wstring get_default_hunspell_path () {
123123 std::wstring path = ini_file_path;
@@ -142,11 +142,11 @@ DownloadDictionariesDialog *get_download_dics() { return download_dics_dlg.get()
142142
143143HANDLE get_h_module () { return h_module; }
144144
145- void create_hooks () {
145+ static void create_hooks () {
146146 h_mouse_hook = SetWindowsHookEx (WH_MOUSE, mouse_proc, nullptr , GetCurrentThreadId ());
147147}
148148
149- void plugin_clean_up () {
149+ static void plugin_clean_up () {
150150 {
151151 auto mut = speller_container->modify ();
152152 mut->cleanup ();
@@ -155,19 +155,31 @@ void plugin_clean_up() {
155155 WinApi::delete_file (get_debug_log_path ().c_str ());
156156}
157157
158- void register_custom_messages () {
158+ static void register_custom_messages () {
159159 for (int i = 0 ; i < static_cast <int >(CustomGuiMessage::max); i++) {
160160 custom_gui_message_ids[i] = RegisterWindowMessage (custom_gui_messages_names[i]);
161161 }
162162}
163163
164- void init_npp_interface () { npp = std::make_unique<NppInterface>(&npp_data); }
164+ static void init_npp_interface () { npp = std::make_unique<NppInterface>(&npp_data); }
165165
166- void notify (SCNotification *notify_code) { npp->notify (notify_code); }
166+ static void notify (SCNotification *notify_code) { npp->notify (notify_code); }
167167
168168NppInterface &npp_interface () { return *npp; }
169169
170- void erase_misspellings () { spell_checker->erase_all_misspellings (); }
170+ static bool check_if_any_language_available () {
171+ if (!speller_container->active_speller ().get_language_list ().empty ())
172+ return true ;
173+
174+ MessageBox (npp->get_editor_hwnd (), rc_str (IDC_WARNING_NO_DICTIONARIES_TEXT).c_str (), rc_str (IDC_WARNING_NO_DICTIONARIES_TITLE).c_str (),
175+ MB_OK | MB_ICONWARNING);
176+ return false ;
177+ }
178+
179+ void erase_misspellings () {
180+ if (!check_if_any_language_available ())
181+ return ;
182+ spell_checker->erase_all_misspellings (); }
171183
172184void show_spell_check_menu_at_cursor () {
173185 auto menu = CreatePopupMenu ();
@@ -189,6 +201,8 @@ void show_spell_check_menu_at_cursor() {
189201}
190202
191203void replace_with_1st_suggestion () {
204+ if (!check_if_any_language_available ())
205+ return ;
192206 SpellCheckerHelpers::replace_current_word_with_topmost_suggestion (*npp, *spell_checker, *speller_container);
193207}
194208
@@ -205,6 +219,8 @@ void ignore_for_current_session() {
205219}
206220
207221void copy_misspellings_to_clipboard () {
222+ if (!check_if_any_language_available ())
223+ return ;
208224 auto str = spell_checker->get_all_misspellings_as_string ();
209225 const size_t len = (str.length () + 1 ) * 2 ;
210226 HGLOBAL h_mem = GlobalAlloc (GMEM_MOVEABLE, len);
@@ -220,6 +236,8 @@ void copy_misspellings_to_clipboard() {
220236}
221237
222238void mark_lines_with_misspelling () {
239+ if (!check_if_any_language_available ())
240+ return ;
223241 spell_checker->mark_lines_with_misspelling ();
224242}
225243
@@ -257,15 +275,23 @@ void start_about_dlg() { about_dlg->do_dialog(); }
257275
258276void start_language_list () { lang_list_instance->do_dialog (); }
259277
260- void recheck_visible () {
278+ static void recheck_visible () {
261279 print_to_log (L" recheck_visible ()" , npp->get_editor_hwnd ());
262280 ACTIVE_VIEW_BLOCK (npp_interface ());
263281 spell_checker->recheck_visible ();
264282}
265283
266- void find_next_mistake () { spell_checker->find_next_mistake (); }
284+ void find_next_mistake () {
285+ if (!check_if_any_language_available ())
286+ return ;
287+ spell_checker->find_next_mistake ();
288+ }
267289
268- void find_prev_mistake () { spell_checker->find_prev_mistake (); }
290+ void find_prev_mistake () {
291+ if (!check_if_any_language_available ())
292+ return ;
293+ spell_checker->find_prev_mistake ();
294+ }
269295
270296void quick_lang_change_context () {
271297 POINT pos;
@@ -279,10 +305,28 @@ enum_array<Action, int> action_index = []() {
279305 return val;
280306}();
281307
282- //
283- // Initialization of your plug-in commands
284- // You should fill your plug-ins commands here
285- void command_menu_init () {
308+ static int set_next_command (const wchar_t *cmd_name, Pfuncplugincmd p_func) {
309+ static int counter = 0 ;
310+ if (counter >= nb_func) {
311+ assert (false ); // Less actions specified in nb_func constant than added
312+ return -1 ;
313+ }
314+
315+ if (p_func == nullptr ) {
316+ counter++;
317+ return counter - 1 ;
318+ }
319+
320+ lstrcpy (func_item[counter].item_name , cmd_name);
321+ func_item[counter].p_func = p_func;
322+ func_item[counter].init2_check = false ;
323+ func_item[counter].p_sh_key = nullptr ;
324+ counter++;
325+
326+ return counter - 1 ;
327+ }
328+
329+ static void command_menu_init () {
286330 //
287331 // Firstly we get the parameters from your plugin config file (if any)
288332 //
@@ -340,7 +384,7 @@ void command_menu_init() {
340384 // add further set_next_command at the bottom to avoid breaking configured hotkeys
341385}
342386
343- void add_icons () {
387+ static void add_icons () {
344388 static ToolbarIconsWrapper auto_check_icon{static_cast <HINSTANCE>(h_module), MAKEINTRESOURCE (IDI_AUTOCHECK), MAKEINTRESOURCE (IDI_AUTOCHECK_DARK),
345389 MAKEINTRESOURCE (IDB_AUTOCHECK_BMP)};
346390 ::SendMessage (npp_data.npp_handle, NPPM_ADDTOOLBARICON_FORDARKMODE, static_cast <WPARAM>(func_item[0 ].cmd_id), reinterpret_cast<LPARAM>(auto_check_icon.get()));
@@ -401,7 +445,7 @@ void on_settings_changed() {
401445 npp->set_menu_item_check (get_func_item ()[action_index[Action::toggle_debug_logging]].cmd_id , settings->data .write_debug_log );
402446}
403447
404- void init_classes () {
448+ static void init_classes () {
405449 INITCOMMONCONTROLSEX icc;
406450
407451 icc.dwSize = sizeof (icc);
@@ -448,35 +492,8 @@ void init_classes() {
448492 resources_inited = true ;
449493}
450494
451- void command_menu_clean_up () {
452- }
453-
454- //
455- // Function that initializes plug-in commands
456- //
457- static int counter = 0 ;
458-
459495std::vector<std::unique_ptr<ShortcutKey>> shortcut_storage;
460496
461- int set_next_command (const wchar_t *cmd_name, Pfuncplugincmd p_func) {
462- if (counter >= nb_func) {
463- assert (false ); // Less actions specified in nb_func constant than added
464- return -1 ;
465- }
466-
467- if (p_func == nullptr ) {
468- counter++;
469- return counter - 1 ;
470- }
471-
472- lstrcpy (func_item[counter].item_name , cmd_name);
473- func_item[counter].p_func = p_func;
474- func_item[counter].init2_check = false ;
475- func_item[counter].p_sh_key = nullptr ;
476- counter++;
477-
478- return counter - 1 ;
479- }
480497
481498std::wstring get_debug_log_path () {
482499 std::vector<wchar_t > buf (MAX_PATH);
@@ -740,7 +757,6 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification *notify_code) {
740757 print_to_log (L" NPPN_SHUTDOWN" , npp->get_editor_hwnd ());
741758 edit_recheck_timer.reset ();
742759 scroll_recheck_timer.reset ();
743- command_menu_clean_up ();
744760
745761 plugin_clean_up ();
746762 RemoveWindowSubclass (npp_data.npp_handle , subclass_proc, 0 );
0 commit comments