Skip to content

Commit 9ab0ab0

Browse files
authored
Add message on certain actions when no dictionary is present. (#337)
1 parent 3bb42e4 commit 9ab0ab0

File tree

4 files changed

+65
-89
lines changed

4 files changed

+65
-89
lines changed

src/plugin/DSpellCheck.rc

668 Bytes
Binary file not shown.

src/plugin/Plugin.cpp

Lines changed: 63 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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

114114
int get_context_menu_id_start() { return context_menu_id_start; }
115115

116116
int get_langs_menu_id_start() { return langs_menu_id_start; }
117117

118118
bool 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

122122
std::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

143143
HANDLE 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

168168
NppInterface &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

172184
void show_spell_check_menu_at_cursor() {
173185
auto menu = CreatePopupMenu();
@@ -189,6 +201,8 @@ void show_spell_check_menu_at_cursor() {
189201
}
190202

191203
void 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

207221
void 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

222238
void 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

258276
void 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

270296
void 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-
459495
std::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

481498
std::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);

src/plugin/Plugin.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -61,45 +61,10 @@ class ProgressDialog;
6161
class RemoveDictionariesDialog;
6262
class Settings;
6363

64-
//
65-
// Initialization of your plugin data
66-
// It will be called while plugin loading
67-
//
6864
void set_hmodule(HANDLE h_module_arg);
69-
70-
//
71-
// Cleaning of your plugin
72-
// It will be called while plugin unloading
73-
//
74-
void plugin_clean_up();
75-
76-
//
77-
//Initialization of your plugin commands
78-
//
79-
void command_menu_init();
80-
81-
//
82-
//Clean up your plugin commands allocation (if any)
83-
//
84-
void command_menu_clean_up();
85-
86-
//
87-
// Function which sets your command
88-
//
89-
int set_next_command(const wchar_t *cmd_name, Pfuncplugincmd p_func);
90-
91-
void set_delimiters(const char *str);
9265
std::wstring rc_str(UINT string_id);
9366
std::wstring_view rc_str_view(UINT string_id);
94-
const char *get_delimiters();
95-
void set_encoding_by_id(int enc_id);
96-
void recheck_visible();
97-
void init_classes();
98-
void create_hooks();
9967
LRESULT show_calculated_menu(std::vector<MenuItem> &&menu_list);
100-
void add_icons();
101-
bool get_auto_check_state();
102-
void auto_check_state_received(bool state);
10368
HMENU get_this_plugin_menu();
10469
HMENU get_langs_sub_menu();
10570
HANDLE get_h_module();
@@ -110,18 +75,11 @@ ConnectionSettingsDialog *get_select_proxy();
11075
ProgressDialog *get_progress_dlg();
11176
FuncItem *get_func_item();
11277
std::wstring get_default_hunspell_path();
113-
void set_context_menu_id_start(int id);
114-
void set_langs_menu_id_start(int id);
115-
void set_use_allocated_ids(bool value);
11678
int get_context_menu_id_start();
11779
int get_langs_menu_id_start();
11880
bool get_use_allocated_ids();
119-
const Settings &get_settings();
12081
DWORD get_custom_gui_message_id(CustomGuiMessage message_id);
121-
void register_custom_messages();
12282
std::wstring get_debug_log_path();
123-
void init_npp_interface();
124-
void notify(SCNotification *notify_code);
12583
NppInterface &npp_interface();
12684
void copy_misspellings_to_clipboard();
12785
void delete_log();

src/plugin/resource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@
220220
#define IDS_RESET_SETTINGS_CAPTION 40110
221221
#define IDS_BOOKMARK_LINES_WITH_MISSPELLING 40111
222222
#define IDS_DOWNLOAD_ERRORS_ENCOUNTERED 40112
223+
#define IDC_WARNING_NO_DICTIONARIES_TITLE 40113
224+
#define IDC_WARNING_NO_DICTIONARIES_TEXT 40114
223225

224226
// Next default values for new objects
225227
//

0 commit comments

Comments
 (0)