Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
d743b1fd
Commit
d743b1fd
authored
Dec 30, 2008
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apply spelling corrections from the context menu.
parent
dfa3debf
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
759 additions
and
636 deletions
+759
-636
data/en.mse-locale/locale
data/en.mse-locale/locale
+5
-11
src/gui/icon_menu.cpp
src/gui/icon_menu.cpp
+8
-0
src/gui/icon_menu.hpp
src/gui/icon_menu.hpp
+2
-0
src/gui/value/text.cpp
src/gui/value/text.cpp
+77
-2
src/resource/common/expected_locale_keys
src/resource/common/expected_locale_keys
+611
-606
src/script/functions/spelling.cpp
src/script/functions/spelling.cpp
+15
-8
src/util/spell_checker.cpp
src/util/spell_checker.cpp
+24
-8
src/util/spell_checker.hpp
src/util/spell_checker.hpp
+10
-0
src/util/window_id.hpp
src/util/window_id.hpp
+7
-1
No files found.
data/en.mse-locale/locale
View file @
d743b1fd
...
...
@@ -60,6 +60,8 @@ menu:
symbols
:
&
Symbols
Ctrl
+
M
reminder
text
:
&
Reminder
Text
Ctrl
+
R
insert
symbol
:
I
&
nsert
Symbol
#
spelling
no
spelling
suggestions
:
(
no
suggestions
)
graph
:
&
Graph
pie
:
&
Pie
1
...
...
@@ -168,6 +170,8 @@ help:
italic
:
Makes
the
selected
text
italic
symbols
:
Draws
the
selected
text
with
symbols
reminder
text
:
Show
reminder
text
for
the
selected
keyword
#
spelling
no
spelling
suggestions
:
There
are
no
suggestions
for
correcting
this
error
graph
:
pie
:
A
pie
graph
,
the
size
of
the
slice
indicates
the
number
of
cards
...
...
@@ -669,6 +673,7 @@ action:
cut: Cut
paste: Paste
auto replace: Auto Replace
correct: Spelling Correction
# Choice/color editors
change: Change %s
...
...
@@ -704,17 +709,6 @@ action:
############################################################## Error messages
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 not found: File not found: '
%
s
' in package '
%
s
'
file not found package like:
...
...
src/gui/icon_menu.cpp
View file @
d743b1fd
...
...
@@ -91,6 +91,14 @@ void IconMenu::Append(wxMenuItem* 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
)
{
wxMenuItem
*
item
=
new
wxMenuItem
(
this
,
id
,
text
,
help
);
item
->
SetBitmap
(
wxNullBitmap
);
...
...
src/gui/icon_menu.hpp
View file @
d743b1fd
...
...
@@ -29,6 +29,8 @@ class IconMenu : public wxMenu {
void
Append
(
int
id
,
const
String
&
text
,
const
String
&
help
,
wxMenu
*
submenu
);
/// Append a menu item, without an image
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
void
Insert
(
size_t
pos
,
int
id
,
const
String
&
text
,
const
String
&
help
);
};
...
...
src/gui/value/text.cpp
View file @
d743b1fd
...
...
@@ -17,6 +17,7 @@
#include <data/action/value.hpp>
#include <util/tagged_string.hpp>
#include <util/find_replace.hpp>
#include <util/spell_checker.hpp>
#include <util/window_id.hpp>
#include <wx/clipbrd.h>
#include <wx/caret.h>
...
...
@@ -508,6 +509,43 @@ bool TextValueEditor::onChar(wxKeyEvent& ev) {
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
void
TextValueEditor
::
onFocus
()
{
...
...
@@ -527,12 +565,35 @@ bool TextValueEditor::onContextMenu(IconMenu& m, wxContextMenuEvent& ev) {
// in a keword? => "reminder text" option
size_t
kwpos
=
in_tag
(
value
().
value
(),
_
(
"<kw-"
),
selection_start_i
,
selection_start_i
);
if
(
kwpos
!=
String
::
npos
)
{
m
.
AppendSeparator
();
m
.
Append
(
ID_FORMAT_REMINDER
,
_
(
"reminder"
),
_MENU_
(
"reminder text"
),
_HELP_
(
"reminder text"
),
wxITEM_CHECK
);
m
.
InsertSeparator
(
0
);
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
return
true
;
}
bool
TextValueEditor
::
onCommand
(
int
id
)
{
if
(
id
>=
ID_INSERT_SYMBOL_MENU_MIN
&&
id
<=
ID_INSERT_SYMBOL_MENU_MAX
)
{
// Insert a symbol
...
...
@@ -544,9 +605,23 @@ bool TextValueEditor::onCommand(int id) {
replaceSelection
(
code
,
_ACTION_
(
"insert symbol"
));
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
;
}
wxMenu
*
TextValueEditor
::
getMenu
(
int
type
)
const
{
if
(
type
==
ID_INSERT_SYMBOL
&&
(
style
().
always_symbol
||
style
().
allow_formating
)
&&
style
().
symbol_font
.
valid
())
{
...
...
src/resource/common/expected_locale_keys
View file @
d743b1fd
This diff is collapsed.
Click to expand it.
src/script/functions/spelling.cpp
View file @
d743b1fd
...
...
@@ -15,7 +15,7 @@
// ----------------------------------------------------------------------------- : 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
String
word
=
untag
(
input
.
substr
(
start
,
end
-
start
));
if
(
word
.
empty
())
return
true
;
...
...
@@ -36,8 +36,8 @@ inline bool spelled_correctly(const String& input, size_t start, size_t end, Spe
// run through spellchecker(s)
word
.
erase
(
end_u
,
String
::
npos
);
word
.
erase
(
0
,
start_u
);
for
(
SpellChecker
**
c
=
checkers
;
*
c
;
++
c
)
{
if
(
(
*
c
)
->
spell
(
word
))
{
for
(
size_t
i
=
0
;
checkers
[
i
]
;
++
i
)
{
if
(
checkers
[
i
]
->
spell
(
word
))
{
return
true
;
}
}
...
...
@@ -51,12 +51,12 @@ inline bool spelled_correctly(const String& input, size_t start, size_t end, Spe
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
;
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
);
if
(
!
good
)
out
+=
_
(
"</
error-spelling>"
)
;
if
(
!
good
)
out
+=
_
(
"</
"
)
+
tag
;
}
SCRIPT_FUNCTION
(
check_spelling
)
{
...
...
@@ -75,6 +75,13 @@ SCRIPT_FUNCTION(check_spelling) {
if
(
!
extra_dictionary
.
empty
())
{
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
String
result
;
size_t
word_start
=
0
,
word_end
=
0
,
pos
=
0
;
...
...
@@ -91,7 +98,7 @@ SCRIPT_FUNCTION(check_spelling) {
}
}
else
if
(
isSpace
(
c
)
||
c
==
EM_DASH
||
c
==
EN_DASH
)
{
// 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
result
.
append
(
input
,
word_end
,
pos
-
word_end
+
1
);
// next
...
...
@@ -101,7 +108,7 @@ SCRIPT_FUNCTION(check_spelling) {
}
}
// 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
);
// done
SCRIPT_RETURN
(
result
);
...
...
src/util/spell_checker.cpp
View file @
d743b1fd
...
...
@@ -71,8 +71,7 @@ void SpellChecker::destroyAll() {
// ----------------------------------------------------------------------------- : Spell checker : use
bool
SpellChecker
::
spell
(
const
String
&
word
)
{
if
(
word
.
empty
())
return
true
;
// empty word is okay
bool
SpellChecker
::
convert_encoding
(
const
String
&
word
,
CharBuffer
&
out
)
{
// fix curly quotes, especially apstrophes
String
fixed
;
FOR_EACH_CONST
(
c
,
word
)
{
...
...
@@ -96,16 +95,20 @@ bool SpellChecker::spell(const String& word) {
}
}
// convert encoding
#ifdef UNICODE
wxCharBuffer
str
=
fixed
.
mb_str
(
encoding
);
#else
wxCharBuffer
str
=
fixed
.
mb_str
(
encoding
);
#endif
if
(
*
str
==
'\0'
)
{
out
=
fixed
.
mb_str
(
encoding
);
if
(
*
out
==
'\0'
)
{
// 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.
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
);
}
...
...
@@ -115,3 +118,16 @@ bool SpellChecker::spell_with_punctuation(const String& word) {
if
(
start
>=
end
)
return
true
;
// just punctuation is wrong
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
);
}
src/util/spell_checker.hpp
View file @
d743b1fd
...
...
@@ -14,6 +14,12 @@
DECLARE_POINTER_TYPE
(
SpellChecker
);
#ifdef UNICODE
typedef
wxCharBuffer
CharBuffer
;
#else
typedef
char
*
CharBuffer
;
#endif
// ----------------------------------------------------------------------------- : Spell checker
/// A spelling checker for a particular language
...
...
@@ -33,9 +39,13 @@ class SpellChecker : public Hunspell, public IntrusivePtrBase<SpellChecker> {
/// Check the spelling of a single word, ignore punctuation
bool
spell_with_punctuation
(
const
String
&
word
);
/// Give spelling suggestions
void
suggest
(
const
String
&
word
,
vector
<
String
>&
suggestions_out
);
private:
/// Convert between String and dictionary encoding
wxCSConv
encoding
;
bool
convert_encoding
(
const
String
&
word
,
CharBuffer
&
out
);
SpellChecker
(
const
char
*
aff_path
,
const
char
*
dic_path
);
static
map
<
String
,
SpellCheckerP
>
spellers
;
//< Cached checkers for each language
...
...
src/util/window_id.hpp
View file @
d743b1fd
...
...
@@ -120,8 +120,14 @@ enum ChildMenuID {
,
ID_FORMAT_REMINDER
,
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
,
ID_GRAPH_PIE
=
6
3
01
// corresponds to GraphType
,
ID_GRAPH_PIE
=
6
4
01
// corresponds to GraphType
,
ID_GRAPH_BAR
,
ID_GRAPH_STACK
,
ID_GRAPH_SCATTER
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment