Commit d743b1fd authored by twanvl's avatar twanvl

apply spelling corrections from the context menu.

parent dfa3debf
...@@ -60,6 +60,8 @@ menu: ...@@ -60,6 +60,8 @@ menu:
symbols: &Symbols Ctrl+M symbols: &Symbols Ctrl+M
reminder text: &Reminder Text Ctrl+R reminder text: &Reminder Text Ctrl+R
insert symbol: I&nsert Symbol insert symbol: I&nsert Symbol
# spelling
no spelling suggestions: (no suggestions)
graph: &Graph graph: &Graph
pie: &Pie 1 pie: &Pie 1
...@@ -168,6 +170,8 @@ help: ...@@ -168,6 +170,8 @@ help:
italic: Makes the selected text italic italic: Makes the selected text italic
symbols: Draws the selected text with symbols symbols: Draws the selected text with symbols
reminder text: Show reminder text for the selected keyword reminder text: Show reminder text for the selected keyword
# spelling
no spelling suggestions: There are no suggestions for correcting this error
graph: graph:
pie: A pie graph, the size of the slice indicates the number of cards pie: A pie graph, the size of the slice indicates the number of cards
...@@ -669,6 +673,7 @@ action: ...@@ -669,6 +673,7 @@ action:
cut: Cut cut: Cut
paste: Paste paste: Paste
auto replace: Auto Replace auto replace: Auto Replace
correct: Spelling Correction
# Choice/color editors # Choice/color editors
change: Change %s change: Change %s
...@@ -704,17 +709,6 @@ action: ...@@ -704,17 +709,6 @@ action:
############################################################## Error messages ############################################################## Error messages
error: error:
# General
internal error:
An internal error occured:
%s
Please save your work (use 'save as' to so you don't overwrite things)
and restart Magic Set Editor.
You should leave a bug report on http://magicseteditor.sourceforge.net/
# File related # File related
file not found: File not found: '%s' in package '%s' file not found: File not found: '%s' in package '%s'
file not found package like: file not found package like:
......
...@@ -91,6 +91,14 @@ void IconMenu::Append(wxMenuItem* item) { ...@@ -91,6 +91,14 @@ void IconMenu::Append(wxMenuItem* item) {
wxMenu::Append(item); wxMenu::Append(item);
} }
void IconMenu::Insert(size_t pos, int id, const String& resource, const String& text, const String& help, int style, wxMenu* submenu) {
// create menu, load icon
wxMenuItem* item = new wxMenuItem(this, id, text, help, style, submenu);
set_menu_item_image(item, resource);
// add to menu
wxMenu::Insert(pos,item);
}
void IconMenu::Insert(size_t pos, int id, const String& text, const String& help) { void IconMenu::Insert(size_t pos, int id, const String& text, const String& help) {
wxMenuItem* item = new wxMenuItem (this, id, text, help); wxMenuItem* item = new wxMenuItem (this, id, text, help);
item->SetBitmap(wxNullBitmap); item->SetBitmap(wxNullBitmap);
......
...@@ -29,6 +29,8 @@ class IconMenu : public wxMenu { ...@@ -29,6 +29,8 @@ class IconMenu : public wxMenu {
void Append(int id, const String& text, const String& help, wxMenu* submenu); void Append(int id, const String& text, const String& help, wxMenu* submenu);
/// Append a menu item, without an image /// Append a menu item, without an image
void Append(wxMenuItem* item); void Append(wxMenuItem* item);
/// Insert a menu item, with an image (loaded from a resource)
void Insert(size_t pos, int id, const String& resource, const String& text, const String& help, int style = wxITEM_NORMAL, wxMenu* submenu = nullptr);
/// Insert a menu item, without an image /// Insert a menu item, without an image
void Insert(size_t pos, int id, const String& text, const String& help); void Insert(size_t pos, int id, const String& text, const String& help);
}; };
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <data/action/value.hpp> #include <data/action/value.hpp>
#include <util/tagged_string.hpp> #include <util/tagged_string.hpp>
#include <util/find_replace.hpp> #include <util/find_replace.hpp>
#include <util/spell_checker.hpp>
#include <util/window_id.hpp> #include <util/window_id.hpp>
#include <wx/clipbrd.h> #include <wx/clipbrd.h>
#include <wx/caret.h> #include <wx/caret.h>
...@@ -508,6 +509,43 @@ bool TextValueEditor::onChar(wxKeyEvent& ev) { ...@@ -508,6 +509,43 @@ bool TextValueEditor::onChar(wxKeyEvent& ev) {
return true; return true;
} }
// ----------------------------------------------------------------------------- : Spellchecking
String spellcheck_word_at(const String& str, size_t start, String& before, String& after) {
size_t end = min(match_close_tag(str,start), str.size());
String word = untag(str.substr(start,end-start));
size_t start_u = 0, end_u = String::npos;
trim_punctuation(word, start_u, end_u);
before = word.substr(0,start_u);
after = word.substr(end_u,String::npos);
word.erase(end_u,String::npos);
word.erase(0,start_u);
return word;
}
void spellcheck_language_at(const String& str, size_t error_pos, SpellChecker** out) {
String tag = tag_at(str,error_pos);
size_t pos = min(tag.find_first_of(_(':')), tag.size()-1);
size_t pos2 = min(tag.find_first_of(_(':'),pos+1), tag.size()-1);
String language = tag.substr(pos+1,pos2-pos-1);
if (language.empty()) return;
out[0] = &SpellChecker::get(language);
String extra = tag.substr(pos2+1);
if (extra.empty()) return;
out[1] = &SpellChecker::get(extra,language);
}
void get_spelling_suggestions(const String& str, size_t error_pos, vector<String>& suggestions_out, String& before, String& after) {
String word = spellcheck_word_at(str, error_pos, before, after);
// find dictionaries
SpellChecker* checkers[3] = {nullptr};
spellcheck_language_at(str, error_pos, checkers);
// suggestions
for (size_t i = 0 ; checkers[i] ; ++i) {
checkers[i]->suggest(word, suggestions_out);
}
}
// ----------------------------------------------------------------------------- : Other events // ----------------------------------------------------------------------------- : Other events
void TextValueEditor::onFocus() { void TextValueEditor::onFocus() {
...@@ -527,12 +565,35 @@ bool TextValueEditor::onContextMenu(IconMenu& m, wxContextMenuEvent& ev) { ...@@ -527,12 +565,35 @@ bool TextValueEditor::onContextMenu(IconMenu& m, wxContextMenuEvent& ev) {
// in a keword? => "reminder text" option // in a keword? => "reminder text" option
size_t kwpos = in_tag(value().value(), _("<kw-"), selection_start_i, selection_start_i); size_t kwpos = in_tag(value().value(), _("<kw-"), selection_start_i, selection_start_i);
if (kwpos != String::npos) { if (kwpos != String::npos) {
m.AppendSeparator(); m.InsertSeparator(0);
m.Append(ID_FORMAT_REMINDER, _("reminder"), _MENU_("reminder text"), _HELP_("reminder text"), wxITEM_CHECK); m.Insert(0,ID_FORMAT_REMINDER, _("reminder"), _MENU_("reminder text"), _HELP_("reminder text"), wxITEM_CHECK);
}
// in a spelling error? => show suggestions and "add to dictionary"
size_t error_pos = in_tag(value().value(), _("<error-spelling"), selection_start_i, selection_start_i);
if (error_pos != String::npos) {
// TODO: "add to dictionary"
//%m.InsertSeparator(0);
//%m.Insert(0,ID_SPELLING_ADD_TO_DICT, _MENU_("add to dictionary"), _HELP_("add to dictionary"));
// suggestions
String before,after;
vector<String> suggestions;
get_spelling_suggestions(value().value(), error_pos, suggestions,before,after);
// add suggestions to menu
m.InsertSeparator(0);
if (suggestions.empty()) {
m.Insert(0,ID_SPELLING_NO_SUGGEST, _MENU_("no spelling suggestions"), _HELP_("no spelling suggestions"));
} else {
int i = 0;
FOR_EACH(s,suggestions) {
m.Insert(i, ID_SPELLING_SUGGEST + i, before+s+after, wxEmptyString);
i++;
}
}
} }
// always show the menu // always show the menu
return true; return true;
} }
bool TextValueEditor::onCommand(int id) { bool TextValueEditor::onCommand(int id) {
if (id >= ID_INSERT_SYMBOL_MENU_MIN && id <= ID_INSERT_SYMBOL_MENU_MAX) { if (id >= ID_INSERT_SYMBOL_MENU_MIN && id <= ID_INSERT_SYMBOL_MENU_MAX) {
// Insert a symbol // Insert a symbol
...@@ -544,9 +605,23 @@ bool TextValueEditor::onCommand(int id) { ...@@ -544,9 +605,23 @@ bool TextValueEditor::onCommand(int id) {
replaceSelection(code, _ACTION_("insert symbol")); replaceSelection(code, _ACTION_("insert symbol"));
return true; return true;
} }
} else if (id == ID_SPELLING_ADD_TO_DICT) {
// TODO
} else if (id >= ID_SPELLING_SUGGEST && id <= ID_SPELLING_SUGGEST_MAX) {
size_t error_pos = in_tag(value().value(), _("<error-spelling"), selection_start_i, selection_start_i);
if (error_pos == String::npos) throw InternalError(_("Unexpected spelling suggestion")); // wrong
String before,after;
vector<String> suggestions;
get_spelling_suggestions(value().value(), error_pos, suggestions,before,after);
selection_start_i = error_pos;
selection_end_i = match_close_tag(value().value(), error_pos);
fixSelection(TYPE_INDEX);
replaceSelection(before + suggestions.at(id - ID_SPELLING_SUGGEST) + after, _ACTION_("correct"));
return true;
} }
return false; return false;
} }
wxMenu* TextValueEditor::getMenu(int type) const { wxMenu* TextValueEditor::getMenu(int type) const {
if (type == ID_INSERT_SYMBOL && (style().always_symbol || style().allow_formating) if (type == ID_INSERT_SYMBOL && (style().always_symbol || style().allow_formating)
&& style().symbol_font.valid()) { && style().symbol_font.valid()) {
......
# This file contains the keys expected to be in MSE locales # This file contains the keys expected to be in MSE locales
# It was automatically generated by tools/locale/locale.pl # It was automatically generated by tools/locale/locale.pl
# Generated on Sun Aug 31 20:53:39 2008 # Generated on Tue Dec 30 20:45:27 2008
action: action:
add control point: 0 add control point: 0
add item: 1 add item: 1
add symmetry: 0 add symmetry: 0
auto replace: 0 auto replace: 0
backspace: 0 backspace: 0
change: 1 change: 1
change combine mode: 0 change combine mode: 0
change shape name: 0 change shape name: 0
change symmetry copies: 0 change symmetry copies: 0
change symmetry type: 0 change symmetry type: 0
convert to curve: 0 convert to curve: 0
convert to line: 0 convert to line: 0
cut: 0 correct: 0
delete: 0 cut: 0
delete point: 0 delete: 0
delete points: 0 delete point: 0
duplicate: 1 delete points: 0
enter: 0 duplicate: 1
group parts: 0 enter: 0
insert symbol: 0 group parts: 0
lock point: 0 insert symbol: 0
move: 1 lock point: 0
move curve: 0 move: 1
move handle: 0 move curve: 0
move symmetry center: 0 move handle: 0
move symmetry handle: 0 move symmetry center: 0
paste: 0 move symmetry handle: 0
remove item: 1 paste: 0
reorder parts: 0 remove item: 1
rotate: 1 reorder parts: 0
scale: 1 rotate: 1
shear: 1 scale: 1
soft line break: 0 shear: 1
typing: 0 soft line break: 0
ungroup parts: 0 typing: 0
button: ungroup parts: 0
add item: 0 button:
always: 0 add item: 0
browse: 0 always: 0
check now: 0 browse: 0
check updates: 0 check now: 0
close: 0 check updates: 0
defaults: 0 close: 0
don't install package: 0 defaults: 0
edit symbol: 0 don't install package: 0
enabled: 0 edit symbol: 0
export custom cards selection: 0 enabled: 0
export entire set: 0 export custom cards selection: 0
export generated packs: 0 export entire set: 0
fixed seed: 0 export generated packs: 0
generate pack: 0 fixed seed: 0
hide: 0 generate pack: 0
high quality: 0 hide: 0
if internet connection exists: 0 high quality: 0
insert parameter: 0 if internet connection exists: 0
install group: optional, 0 insert parameter: 0
install package: 0 install group: optional, 0
keep old: 0 install package: 0
keep package: 0 keep old: 0
last opened set: 0 keep package: 0
move down: 0 last opened set: 0
move up: 0 move down: 0
never: 0 move up: 0
new set: 0 never: 0
number: 0 new set: 0
number overwrite: 0 number: 0
open set: 0 number overwrite: 0
open sets in new window: 0 open set: 0
overwrite: 0 open sets in new window: 0
random seed: 0 overwrite: 0
refer parameter: 0 random seed: 0
reinstall package: 0 refer parameter: 0
remove group: optional, 0 reinstall package: 0
remove item: 0 remove group: optional, 0
remove package: 0 remove item: 0
select: optional, 0 remove package: 0
select all: 0 select: optional, 0
select cards: 0 select all: 0
select none: 0 select cards: 0
show: 0 select none: 0
show editing hints: 0 show: 0
show lines: 0 show editing hints: 0
symbol gallery: optional, 0 show lines: 0
upgrade group: optional, 0 symbol gallery: optional, 0
upgrade package: 0 upgrade group: optional, 0
use auto replace: 0 upgrade package: 0
use custom styling options: 0 use auto replace: 0
use for all cards: 0 use custom styling options: 0
whole word: 0 use for all cards: 0
zoom export: 0 whole word: 0
error: zoom export: 0
aborting parsing: 0 error:
can't convert: 2 aborting parsing: 0
can't convert value: 3 can't convert: 2
can't download installer: 2 can't convert value: 3
cannot create file: 1 can't download installer: 2
change packages successful: 1 cannot create file: 1
checking updates failed: 0 change packages successful: 1
coordinates for blending overlap: 0 checking updates failed: 0
dependency not given: 4 coordinates for blending overlap: 0
dimension not found: 1 dependency not given: 4
downloading updates: 0 dimension not found: 1
expected key: 1 downloading updates: 0
file not found: 2 expected key: 1
file not found package like: 2 file not found: 2
file parse error: 2 file not found package like: 2
has no member: 2 file parse error: 2
has no member value: 2 has no member: 2
images used for blending must have the same size: 0 has no member value: 2
in function: 2 images used for blending must have the same size: 0
in keyword reminder: 2 in function: 2
in parameter: 2 in keyword reminder: 2
install packages successful: 1 in parameter: 2
installing updates: 0 install packages successful: 1
internal error: 1 installing updates: 0
newer version: 2 newer version: 2
no game specified: 1 no game specified: 1
no stylesheet specified for the set: 0 no stylesheet specified for the set: 0
no updates: 0 no updates: 0
pack item not found: 1 pack item not found: 1
package not found: 1 pack type not found: 1
package out of date: 3 package not found: 1
package too new: 4 package out of date: 3
remove packages: 1 package too new: 4
remove packages modified: 2 remove packages: 1
remove packages successful: 1 remove packages modified: 2
stylesheet and set refer to different game: 0 remove packages successful: 1
successful install: optional, 2 stylesheet and set refer to different game: 0
unable to open output file: 0 successful install: optional, 2
unable to store file: 0 unable to open output file: 0
unrecognized value: 1 unable to store file: 0
unsupported field type: 1 unrecognized value: 1
unsupported fill type: 1 unsupported field type: 1
unsupported format: 1 unsupported fill type: 1
word list type not found: 1 unsupported format: 1
help: word list type not found: 1
about: 0 help:
add card: 0 about: 0
add cards: 0 add card: 0
add keyword: 0 add cards: 0
add symmetry: 0 add keyword: 0
app language: 0 add symmetry: 0
auto replace: 0 add to dictionary: optional, 0
bar: 0 app language: 0
basic shapes: 0 auto replace: 0
bold: 0 bar: 0
border: 0 basic shapes: 0
card list columns: 0 bold: 0
cards tab: 0 border: 0
check updates: 0 card list columns: 0
click to select shape: 0 cards tab: 0
close symbol editor: 0 check updates: 0
collapse notes: 0 click to select shape: 0
copies: 0 close symbol editor: 0
copy: 0 collapse notes: 0
copy card: 0 copies: 0
copy keyword: 0 copy: 0
curve segment: 0 copy card: 0
cut: 0 copy keyword: 0
cut card: 0 curve segment: 0
cut keyword: 0 cut: 0
difference: 0 cut card: 0
drag to draw shape: 0 cut keyword: 0
drag to move curve: 0 difference: 0
drag to move line: 0 drag to draw shape: 0
drag to move point: 0 drag to move curve: 0
drag to resize: 1 drag to move line: 0
drag to rotate: 1 drag to move point: 0
drag to shear: 1 drag to resize: 1
draw ellipse: 0 drag to rotate: 1
draw polygon: 0 drag to shear: 1
draw rectangle: 0 draw ellipse: 0
draw star: 0 draw polygon: 0
duplicate: 0 draw rectangle: 0
ellipse: 0 draw star: 0
exit: 0 duplicate: 0
expand notes: 0 ellipse: 0
export: 0 exit: 0
export apprentice: 0 expand notes: 0
export html: 0 export: 0
export image: 0 export apprentice: 0
export images: 0 export html: 0
export mws: 0 export image: 0
filename format: 0 export images: 0
find: 0 export mws: 0
find next: 0 filename format: 0
fixed seed: 0 find: 0
free point: 0 find next: 0
grid: 0 fixed seed: 0
group: 0 free point: 0
index: 0 grid: 0
intersect: 0 group: 0
italic: 0 index: 0
keywords tab: 0 intersect: 0
last opened set: 1 italic: 0
line segment: 0 keywords tab: 0
merge: 0 last opened set: 1
new set: 0 line segment: 0
new symbol: 0 merge: 0
new window: 0 new set: 0
next card: 0 new symbol: 0
next keyword: 0 new window: 0
open set: 0 next card: 0
open symbol: 0 next keyword: 0
orientation: 0 no spelling suggestions: 0
overlap: 0 open set: 0
paint: 0 open symbol: 0
paste: 0 orientation: 0
paste card: 0 overlap: 0
paste keyword: 0 paint: 0
pie: 0 paste: 0
points: 0 paste card: 0
polygon: 0 paste keyword: 0
preferences: 0 pie: 0
previous card: 0 points: 0
previous keyword: 0 polygon: 0
print: 0 preferences: 0
print preview: 0 previous card: 0
random pack tab: 0 previous keyword: 0
random seed: 0 print: 0
rectangle: 0 print preview: 0
redo: 0 random pack tab: 0
reflection: 0 random seed: 0
reload data: 0 rectangle: 0
reminder text: 0 redo: 0
remove card: 0 reflection: 0
remove keyword: 0 reload data: 0
remove symmetry: 0 reminder text: 0
replace: 0 remove card: 0
rotate: 0 remove keyword: 0
rotate 0: 0 remove symmetry: 0
rotate 180: 0 replace: 0
rotate 270: 0 rotate: 0
rotate 90: 0 rotate 0: 0
rotate card: 0 rotate 180: 0
rotation: 0 rotate 270: 0
save set: 0 rotate 90: 0
save set as: 0 rotate card: 0
save symbol: 0 rotation: 0
save symbol as: 0 save set: 0
scatter: 0 save set as: 0
scatter pie: 0 save symbol: 0
seed: 0 save symbol as: 0
select: 0 scatter: 0
set code: 0 scatter pie: 0
set info tab: 0 seed: 0
sides: 0 select: 0
smooth point: 0 set code: 0
snap: 0 set info tab: 0
stack: 0 sides: 0
star: 0 smooth point: 0
stats tab: 0 snap: 0
store symbol: 0 stack: 0
style tab: 0 star: 0
subtract: 0 stats tab: 0
symbols: 0 store symbol: 0
symmetric point: 0 style tab: 0
symmetry: 0 subtract: 0
undo: 0 symbols: 0
ungroup: 0 symmetric point: 0
website: 0 symmetry: 0
welcome: 0 undo: 0
zoom export: 0 ungroup: 0
label: website: 0
app language: 0 welcome: 0
apprentice: 0 zoom export: 0
apprentice exe: 0 label:
apprentice export cancelled: 0 app language: 0
auto match: 0 apprentice: 0
auto replace: 0 apprentice exe: 0
card display: 0 apprentice export cancelled: 0
card notes: 0 auto match: 0
check at startup: 0 auto replace: 0
checking requires internet: 0 card display: 0
columns: 0 card notes: 0
custom size: 0 check at startup: 0
export filenames: 0 checking requires internet: 0
external programs: 0 columns: 0
filename conflicts: 0 custom size: 0
filename format: 0 export filenames: 0
filename is ignored: 0 external programs: 0
filter: 0 filename conflicts: 0
fix aspect ratio: 0 filename format: 0
force to fit: 0 filename is ignored: 0
game type: 0 filter: 0
html export options: 0 fix aspect ratio: 0
html template: 0 force to fit: 0
install package: 0 game type: 0
installable version: 0 html export options: 0
installed version: 0 html template: 0
installer size: optional, 0 install package: 0
installer status: optional, 0 installable version: 0
keyword: 0 installed version: 0
language: 0 installer size: optional, 0
magic set editor package: optional, 0 installer status: optional, 0
match: 0 keyword: 0
mode: 0 language: 0
no version: 0 magic set editor package: optional, 0
original: 0 match: 0
original size: 0 mode: 0
pack selection: 0 no version: 0
pack totals: 0 original: 0
package action: 0 original size: 0
package conflicts: 0 pack selection: 0
package installable: 0 pack totals: 0
package installed: 0 package action: 0
package modified: 0 package conflicts: 0
package name: 0 package installable: 0
package status: 0 package installed: 0
package updates: 0 package modified: 0
percent of normal: 0 package name: 0
reinstall package: 0 package status: 0
reminder: 0 package updates: 0
remove package: 0 percent of normal: 0
result: 0 reinstall package: 0
rules: 0 reminder: 0
save changes: 1 remove package: 0
seed: 0 result: 0
select cards: 0 rules: 0
select cards print: optional, 0 save changes: 1
select columns: 0 seed: 0
selected card count: 1 select cards: 0
selection: 0 select cards print: optional, 0
selection height: 0 select columns: 0
selection left: 0 selected card count: 1
selection top: 0 selection: 0
selection width: 0 selection height: 0
set code: 0 selection left: 0
sharpen filter: 0 selection top: 0
sides: optional, 0 selection width: 0
size: 0 set code: 0
size to fit: 0 sharpen filter: 0
standard keyword: 1 sides: optional, 0
style type: 0 size: 0
stylesheet not found: 1 size to fit: 0
styling options: 0 standard keyword: 1
total cards: 0 style type: 0
upgrade package: 0 stylesheet not found: 1
uses: 0 styling options: 0
windows: 0 total cards: 0
zoom: 0 upgrade package: 0
zoom %: 0 uses: 0
zoom amount: 0 windows: 0
zoom amount x: 0 zoom: 0
zoom amount y: 0 zoom %: 0
menu: zoom amount: 0
about: 0 zoom amount x: 0
add card: 0 zoom amount y: 0
add cards: 0 menu:
add keyword: 0 about: 0
auto replace: 0 add card: 0
bar: 0 add cards: 0
basic shapes: 0 add keyword: 0
bold: 0 add to dictionary: optional, 0
card list columns: 0 auto replace: 0
cards: 0 bar: 0
cards tab: 0 basic shapes: 0
check updates: 0 bold: 0
close symbol editor: 0 card list columns: 0
copy: 0 cards: 0
cut: 0 cards tab: 0
duplicate: 0 check updates: 0
edit: 0 close symbol editor: 0
exit: 0 copy: 0
export: 0 cut: 0
export apprentice: 0 duplicate: 0
export html: 0 edit: 0
export image: 0 exit: 0
export images: 0 export: 0
export mws: 0 export apprentice: 0
file: 0 export html: 0
find: 0 export image: 0
find next: 0 export images: 0
format: 0 export mws: 0
graph: 0 file: 0
group: 0 find: 0
help: 0 find next: 0
index: 0 format: 0
insert symbol: 0 graph: 0
italic: 0 group: 0
keywords: 0 help: 0
keywords tab: 0 index: 0
new set: 0 insert symbol: 0
new symbol: 0 italic: 0
new window: 0 keywords: 0
next card: 0 keywords tab: 0
next keyword: 0 new set: 0
open set: 0 new symbol: 0
open symbol: 0 new window: 0
orientation: 0 next card: 0
paint: 0 next keyword: 0
paste: 0 no spelling suggestions: 0
pie: 0 open set: 0
points: 0 open symbol: 0
preferences: 0 orientation: 0
previous card: 0 paint: 0
previous keyword: 0 paste: 0
print: 0 pie: 0
print preview: 0 points: 0
random pack tab: 0 preferences: 0
redo: 1 previous card: 0
reload data: 0 previous keyword: 0
reminder text: 0 print: 0
remove card: 0 print preview: 0
remove keyword: 0 random pack tab: 0
replace: 0 redo: 1
rotate: 0 reload data: 0
rotate 0: 0 reminder text: 0
rotate 180: 0 remove card: 0
rotate 270: 0 remove keyword: 0
rotate 90: 0 replace: 0
save set: 0 rotate: 0
save set as: 0 rotate 0: 0
save symbol: 0 rotate 180: 0
save symbol as: 0 rotate 270: 0
scatter: 0 rotate 90: 0
scatter pie: 0 save set: 0
select: 0 save set as: 0
set info tab: 0 save symbol: 0
stack: 0 save symbol as: 0
stats tab: 0 scatter: 0
store symbol: 0 scatter pie: 0
style tab: 0 select: 0
symbols: 0 set info tab: 0
symmetry: 0 stack: 0
tool: 0 stats tab: 0
undo: 1 store symbol: 0
ungroup: 0 style tab: 0
website: 0 symbols: 0
window: 0 symmetry: 0
title: tool: 0
%s - magic set editor: 1 undo: 1
about: 0 ungroup: 0
auto replaces: 0 website: 0
cannot create file: 0 window: 0
directories: 0 title:
display: 0 %s - magic set editor: 1
export cancelled: 0 about: 0
export html: 0 auto replaces: 0
export images: 0 cannot create file: 0
global: 0 directories: 0
installing updates: 0 display: 0
locate apprentice: 0 export cancelled: 0
magic set editor: 0 export html: 0
new set: 0 export images: 0
open set: 0 global: 0
packages window: 0 installing updates: 0
preferences: 0 locate apprentice: 0
print preview: 0 magic set editor: 0
save changes: 0 new set: 0
save html: 0 open set: 0
save image: 0 packages window: 0
save set: 0 preferences: 0
select cards: 0 print preview: 0
select cards export: 0 save changes: 0
select columns: 0 save html: 0
select stylesheet: 0 save image: 0
slice image: 0 save set: 0
symbol editor: 0 select cards: 0
untitled: 0 select cards export: 0
update check: 0 select columns: 0
updates: 0 select stylesheet: 0
updates available: 0 slice image: 0
tool: symbol editor: 0
add symmetry: 0 untitled: 0
basic shapes: 0 update check: 0
border: 0 updates: 0
cards tab: 0 updates available: 0
curve segment: 0 tool:
difference: 0 add symmetry: 0
ellipse: 0 basic shapes: 0
free point: 0 border: 0
grid: 0 cards tab: 0
intersect: 0 curve segment: 0
keywords tab: 0 difference: 0
line segment: 0 ellipse: 0
merge: 0 free point: 0
overlap: 0 grid: 0
paint: optional, 0 intersect: 0
points: 0 keywords tab: 0
polygon: 0 line segment: 0
random pack tab: 0 merge: 0
rectangle: 0 overlap: 0
redo: 0 paint: optional, 0
reflection: 0 points: 0
remove symmetry: 0 polygon: 0
rotate: 0 random pack tab: 0
rotation: 0 rectangle: 0
select: 0 redo: 0
set info tab: 0 reflection: 0
smooth point: 0 remove symmetry: 0
snap: 0 rotate: 0
star: 0 rotation: 0
stats tab: 0 select: 0
store symbol: 0 set info tab: 0
style tab: 0 smooth point: 0
subtract: 0 snap: 0
symmetric point: 0 star: 0
symmetry: 0 stats tab: 0
undo: 0 store symbol: 0
tooltip: style tab: 0
add card: 0 subtract: 0
add keyword: 0 symmetric point: 0
add symmetry: 0 symmetry: 0
bar: 0 undo: 0
basic shapes: 0 tooltip:
bold: 0 add card: 0
border: 0 add keyword: 0
cards tab: 0 add symmetry: 0
copy: 0 bar: 0
curve segment: 0 basic shapes: 0
cut: 0 bold: 0
difference: 0 border: 0
ellipse: 0 cards tab: 0
export: 0 copy: 0
free point: 0 curve segment: 0
grid: 0 cut: 0
intersect: 0 difference: 0
italic: 0 ellipse: 0
keywords tab: 0 export: 0
line segment: 0 free point: 0
merge: 0 grid: 0
new set: 0 intersect: 0
open set: 0 italic: 0
overlap: 0 keywords tab: 0
paint: optional, 0 line segment: 0
paste: 0 merge: 0
pie: 0 new set: 0
points: 0 open set: 0
polygon: 0 overlap: 0
random pack tab: 0 paint: optional, 0
rectangle: 0 paste: 0
redo: 1 pie: 0
reflection: 0 points: 0
reminder text: 0 polygon: 0
remove card: 0 random pack tab: 0
remove keyword: 0 rectangle: 0
remove symmetry: 0 redo: 1
rotate: 0 reflection: 0
rotate card: 0 reminder text: 0
rotation: 0 remove card: 0
save set: 0 remove keyword: 0
scatter: 0 remove symmetry: 0
scatter pie: 0 rotate: 0
select: 0 rotate card: 0
set info tab: 0 rotation: 0
smooth point: 0 save set: 0
snap: 0 scatter: 0
stack: 0 scatter pie: 0
star: 0 select: 0
stats tab: 0 set info tab: 0
store symbol: 0 smooth point: 0
style tab: 0 snap: 0
subtract: 0 stack: 0
symbols: 0 star: 0
symmetric point: 0 stats tab: 0
symmetry: 0 store symbol: 0
undo: 1 style tab: 0
type: subtract: 0
boolean: 0 symbols: 0
card: 0 symmetric point: 0
cards: 0 symmetry: 0
circle: 0 undo: 1
collection: 0 type:
collection of: 1 boolean: 0
color: 0 card: 0
double: 0 cards: 0
ellipse: 0 circle: 0
export template: 0 collection: 0
field: 0 collection of: 1
function: 0 color: 0
game: 0 double: 0
group: 0 ellipse: 0
hexagon: 0 export template: 0
image: 0 field: 0
integer: 0 function: 0
keyword: 0 game: 0
keywords: 0 group: 0
locale: optional, 0 hexagon: 0
nil: 0 image: 0
object: 0 integer: 0
package: optional, 0 keyword: 0
pentagon: 0 keywords: 0
point: 0 locale: optional, 0
points: 0 nil: 0
polygon: 0 object: 0
rectangle: 0 package: optional, 0
reflection: 0 pentagon: 0
rhombus: 0 point: 0
rotation: 0 points: 0
set: 0 polygon: 0
shape: 0 rectangle: 0
shapes: 0 reflection: 0
square: 0 rhombus: 0
star: 0 rotation: 0
string: 0 set: 0
style: 0 shape: 0
stylesheet: 0 shapes: 0
symbol: 0 square: 0
triangle: 0 star: 0
value: 0 string: 0
style: 0
stylesheet: 0
symbol: 0
triangle: 0
value: 0
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
// ----------------------------------------------------------------------------- : Functions // ----------------------------------------------------------------------------- : Functions
inline bool spelled_correctly(const String& input, size_t start, size_t end, SpellChecker** checkers, const ScriptValueP& extra_test, Context& ctx) { inline size_t spelled_correctly(const String& input, size_t start, size_t end, SpellChecker** checkers, const ScriptValueP& extra_test, Context& ctx) {
// untag // untag
String word = untag(input.substr(start,end-start)); String word = untag(input.substr(start,end-start));
if (word.empty()) return true; if (word.empty()) return true;
...@@ -36,8 +36,8 @@ inline bool spelled_correctly(const String& input, size_t start, size_t end, Spe ...@@ -36,8 +36,8 @@ inline bool spelled_correctly(const String& input, size_t start, size_t end, Spe
// run through spellchecker(s) // run through spellchecker(s)
word.erase(end_u,String::npos); word.erase(end_u,String::npos);
word.erase(0,start_u); word.erase(0,start_u);
for (SpellChecker** c = checkers ; *c ; ++c) { for (size_t i = 0 ; checkers[i] ; ++i) {
if ((*c)->spell(word)) { if (checkers[i]->spell(word)) {
return true; return true;
} }
} }
...@@ -51,12 +51,12 @@ inline bool spelled_correctly(const String& input, size_t start, size_t end, Spe ...@@ -51,12 +51,12 @@ inline bool spelled_correctly(const String& input, size_t start, size_t end, Spe
return false; return false;
} }
void check_word(const String& input, String& out, size_t start, size_t end, SpellChecker** checkers, const ScriptValueP& extra_test, Context& ctx) { void check_word(const String& tag, const String& input, String& out, size_t start, size_t end, SpellChecker** checkers, const ScriptValueP& extra_test, Context& ctx) {
if (start >= end) return; if (start >= end) return;
bool good = spelled_correctly(input, start, end, checkers, extra_test, ctx); bool good = spelled_correctly(input, start, end, checkers, extra_test, ctx);
if (!good) out += _("<error-spelling>"); if (!good) out += _("<") + tag;
out.append(input, start, end-start); out.append(input, start, end-start);
if (!good) out += _("</error-spelling>"); if (!good) out += _("</") + tag;
} }
SCRIPT_FUNCTION(check_spelling) { SCRIPT_FUNCTION(check_spelling) {
...@@ -75,6 +75,13 @@ SCRIPT_FUNCTION(check_spelling) { ...@@ -75,6 +75,13 @@ SCRIPT_FUNCTION(check_spelling) {
if (!extra_dictionary.empty()) { if (!extra_dictionary.empty()) {
checkers[1] = &SpellChecker::get(extra_dictionary,language); checkers[1] = &SpellChecker::get(extra_dictionary,language);
} }
// what will the missspelling tag be?
String tag = _("error-spelling:");
tag += language;
if (!extra_dictionary.empty()) {
tag += _(":") + extra_dictionary;
}
tag += _(">");
// now walk over the words in the input, and mark misspellings // now walk over the words in the input, and mark misspellings
String result; String result;
size_t word_start = 0, word_end = 0, pos = 0; size_t word_start = 0, word_end = 0, pos = 0;
...@@ -91,7 +98,7 @@ SCRIPT_FUNCTION(check_spelling) { ...@@ -91,7 +98,7 @@ SCRIPT_FUNCTION(check_spelling) {
} }
} else if (isSpace(c) || c == EM_DASH || c == EN_DASH) { } else if (isSpace(c) || c == EM_DASH || c == EN_DASH) {
// word boundary -> check word // word boundary -> check word
check_word(input, result, word_start, word_end, checkers, extra_match, ctx); check_word(tag, input, result, word_start, word_end, checkers, extra_match, ctx);
// non-word characters // non-word characters
result.append(input, word_end, pos - word_end + 1); result.append(input, word_end, pos - word_end + 1);
// next // next
...@@ -101,7 +108,7 @@ SCRIPT_FUNCTION(check_spelling) { ...@@ -101,7 +108,7 @@ SCRIPT_FUNCTION(check_spelling) {
} }
} }
// last word // last word
check_word(input, result, word_start, word_end, checkers, extra_match, ctx); check_word(tag, input, result, word_start, word_end, checkers, extra_match, ctx);
result.append(input, word_end, String::npos); result.append(input, word_end, String::npos);
// done // done
SCRIPT_RETURN(result); SCRIPT_RETURN(result);
......
...@@ -71,8 +71,7 @@ void SpellChecker::destroyAll() { ...@@ -71,8 +71,7 @@ void SpellChecker::destroyAll() {
// ----------------------------------------------------------------------------- : Spell checker : use // ----------------------------------------------------------------------------- : Spell checker : use
bool SpellChecker::spell(const String& word) { bool SpellChecker::convert_encoding(const String& word, CharBuffer& out) {
if (word.empty()) return true; // empty word is okay
// fix curly quotes, especially apstrophes // fix curly quotes, especially apstrophes
String fixed; String fixed;
FOR_EACH_CONST(c,word) { FOR_EACH_CONST(c,word) {
...@@ -96,16 +95,20 @@ bool SpellChecker::spell(const String& word) { ...@@ -96,16 +95,20 @@ bool SpellChecker::spell(const String& word) {
} }
} }
// convert encoding // convert encoding
#ifdef UNICODE out = fixed.mb_str(encoding);
wxCharBuffer str = fixed.mb_str(encoding); if (*out == '\0') {
#else
wxCharBuffer str = fixed.mb_str(encoding);
#endif
if (*str == '\0') {
// If encoding fails we get an empty string, since the word was not empty this can never happen // If encoding fails we get an empty string, since the word was not empty this can never happen
// words that can't be encoded are not in the dictionary, so they are wrong. // words that can't be encoded are not in the dictionary, so they are wrong.
return false; return false;
} else {
return true;
} }
}
bool SpellChecker::spell(const String& word) {
if (word.empty()) return true; // empty word is okay
CharBuffer str;
if (!convert_encoding(word,str)) return false;
return Hunspell::spell(str); return Hunspell::spell(str);
} }
...@@ -115,3 +118,16 @@ bool SpellChecker::spell_with_punctuation(const String& word) { ...@@ -115,3 +118,16 @@ bool SpellChecker::spell_with_punctuation(const String& word) {
if (start >= end) return true; // just punctuation is wrong if (start >= end) return true; // just punctuation is wrong
return spell(word.substr(start,end-start)); return spell(word.substr(start,end-start));
} }
void SpellChecker::suggest(const String& word, vector<String>& suggestions_out) {
CharBuffer str;
if (!convert_encoding(word,str)) return;
// call Hunspell
char** suggestions;
int num_suggestions = Hunspell::suggest(&suggestions, str);
// copy sugestions
for (int i = 0 ; i < num_suggestions ; ++i) {
suggestions_out.push_back(String(suggestions[i],encoding));
}
free(suggestions);
}
...@@ -14,6 +14,12 @@ ...@@ -14,6 +14,12 @@
DECLARE_POINTER_TYPE(SpellChecker); DECLARE_POINTER_TYPE(SpellChecker);
#ifdef UNICODE
typedef wxCharBuffer CharBuffer;
#else
typedef char* CharBuffer;
#endif
// ----------------------------------------------------------------------------- : Spell checker // ----------------------------------------------------------------------------- : Spell checker
/// A spelling checker for a particular language /// A spelling checker for a particular language
...@@ -33,9 +39,13 @@ class SpellChecker : public Hunspell, public IntrusivePtrBase<SpellChecker> { ...@@ -33,9 +39,13 @@ class SpellChecker : public Hunspell, public IntrusivePtrBase<SpellChecker> {
/// Check the spelling of a single word, ignore punctuation /// Check the spelling of a single word, ignore punctuation
bool spell_with_punctuation(const String& word); bool spell_with_punctuation(const String& word);
/// Give spelling suggestions
void suggest(const String& word, vector<String>& suggestions_out);
private: private:
/// Convert between String and dictionary encoding /// Convert between String and dictionary encoding
wxCSConv encoding; wxCSConv encoding;
bool convert_encoding(const String& word, CharBuffer& out);
SpellChecker(const char* aff_path, const char* dic_path); SpellChecker(const char* aff_path, const char* dic_path);
static map<String,SpellCheckerP> spellers; //< Cached checkers for each language static map<String,SpellCheckerP> spellers; //< Cached checkers for each language
......
...@@ -120,8 +120,14 @@ enum ChildMenuID { ...@@ -120,8 +120,14 @@ enum ChildMenuID {
, ID_FORMAT_REMINDER , ID_FORMAT_REMINDER
, ID_INSERT_SYMBOL , ID_INSERT_SYMBOL
// Spelling errors
, ID_SPELLING_ADD_TO_DICT = 6301
, ID_SPELLING_NO_SUGGEST
, ID_SPELLING_SUGGEST
, ID_SPELLING_SUGGEST_MAX = 6399
// Graph menu // Graph menu
, ID_GRAPH_PIE = 6301 // corresponds to GraphType , ID_GRAPH_PIE = 6401 // corresponds to GraphType
, ID_GRAPH_BAR , ID_GRAPH_BAR
, ID_GRAPH_STACK , ID_GRAPH_STACK
, ID_GRAPH_SCATTER , ID_GRAPH_SCATTER
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment