18#include <glibmm/i18n.h>
19#include <gtkmm/dropdown.h>
20#include <gtkmm/columnview.h>
21#include <gtkmm/singleselection.h>
22#include <gtkmm/stringlist.h>
49void show_spellcheck_preferences_dialog()
52 SP_ACTIVE_DESKTOP->getContainer()->new_dialog(
"Preferences");
60 if (!bbox1 || !bbox2) {
65 auto diff = bbox1->min() - bbox2->min();
67 return diff.y() == 0 ? diff.x() < 0 : diff.y() < 0;
77#define BUILD(name) name{UI::get_widget<std::remove_reference_t<decltype(name)>>(builder, #name)}
80 :
DialogBase(
"/dialogs/spellcheck/",
"Spellcheck")
84 , BUILD(accept_button)
85 , BUILD(ignoreonce_button)
86 , BUILD(ignore_button)
89 , BUILD(dictionary_combo)
95 _provider = spelling_provider_get_default();
97 [&](
auto name,
auto code) {
_langs.push_back({.name =
name, .code = code}); });
100 banner_label.set_markup(Glib::ustring::compose(
"<i>%1</i>", _(
"No dictionaries installed")));
108 auto list = Gtk::StringList::create();
109 for (
auto const &pair :
_langs) {
110 list->append(pair.name);
114 auto lookup_lang_code = [
this] (Glib::ustring
const &code) -> std::optional<int> {
116 return pair.code == code.raw();
121 return std::distance(begin(
_langs), it);
139 pref_button.signal_clicked().connect(sigc::ptr_fun(show_spellcheck_preferences_dialog));
177 if (!std::strcmp(r->
getRepr()->
name(),
"svg:metadata")) {
186 if (is<SPText>(
item) || is<SPFlowtext>(
item)) {
199 std::vector<SPItem *> l;
201 return std::find(l.begin(), l.end(), text) != l.end();
208 std::vector<SPItem *> l;
210 std::sort(l.begin(), l.end(), compare_bboxes);
212 for (
auto item : l) {
243 if (i != GTK_INVALID_LIST_POSITION) {
293 ? Glib::ustring::compose(_(
"<b>Finished</b>, <b>%1</b> words added to dictionary"),
_adds)
294 : _(
"<b>Finished</b>, nothing suspicious found")
316 while (
_word.size() == 0) {
335 Glib::ustring::iterator text_iter;
337 if (is<SPString>(char_item)) {
338 int this_char = *text_iter;
339 if (this_char ==
'\'' || this_char == 0x2019) {
343 if (is<SPString>(char_item)) {
344 int this_char = *text_iter;
345 if (g_ascii_isalpha(this_char)) {
356 for (
unsigned int i :
_word) {
357 if (g_unichar_isdigit(i)) {
370 for (
unsigned int i :
_word) {
371 if (!g_unichar_isupper(i)) {
391 banner_label.set_markup(Glib::ustring::compose(_(
"Not in dictionary: <b>%1</b>"),
_word));
403 if (points.size() >= 4) {
406 double mindim = std::min(area.width(), area.height());
407 area.expandBy(std::max(0.05 * mindim, 1.0));
411 rect->set_stroke(0xff0000ff);
412 rect->set_visible(
true);
413 _rects.emplace_back(rect);
417 area.expandBy(0.5 * mindim);
420 for (
unsigned corner = 0; corner < 4; corner ++) {
421 if (
Geom::L2(area.corner(corner) - center) > dist) {
422 dist =
Geom::L2(area.corner(corner) - center);
423 scrollto = area.corner(corner);
436 auto cursor = get_cursor_position(*text_tool,
_text);
439 }
else if (*cursor <= _begin_w || *cursor >=
_end_w) {
449 if (!new_corrections.empty()) {
505 if (word_new !=
_word) {
528 if (
index != GTK_INVALID_LIST_POSITION) {
581 if (
index == GTK_INVALID_LIST_POSITION) {
static CRect from_range(InputIterator start, InputIterator end)
Create a rectangle from a range of points.
Two-dimensional point that doubles as a vector.
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
bool isLayer(SPObject *object) const
True if object is a layer.
SPItem * singleItem()
Returns a single selected item.
Preference storage class.
Glib::ustring getString(Glib::ustring const &pref_path, Glib::ustring const &def="")
Retrieve an UTF-8 string.
static Preferences * get()
Access the singleton Preferences object.
int getInt(Glib::ustring const &pref_path, int def=0)
Retrieve an integer.
void setString(Glib::ustring const &pref_path, Glib::ustring const &value)
Set an UTF-8 string value.
void setInt(Glib::ustring const &pref_path, int value)
Set an integer value.
void set(XML::Node *repr)
Set the selection to an XML node's SPObject.
std::vector< Geom::Point > createSelectionShape(iterator const &it_start, iterator const &it_end, Geom::Affine const &transform) const
Basically uses characterBoundingBox() on all the characters from start to end and returns the union o...
void validateIterator(iterator *it) const
Checks the validity of the given iterator over the current layout.
iterator end() const
Returns an iterator pointing just past the end of the last glyph, which is also just past the end of ...
void getSourceOfCharacter(iterator const &it, SPObject **source, Glib::ustring::iterator *text_iterator=nullptr) const
Discovers where the character pointed to by it came from, by retrieving the object that was passed to...
bool isStartOfWord(iterator const &it) const
Returns true if it points to a character which is a the start of a word, as defined by Pango.
iterator begin() const
Returns an iterator pointing at the first glyph of the flowed output.
DialogBase is the base class for the dialog system.
SPDocument * getDocument() const
Glib::ustring const _prefs_path
SPDesktop * getDesktop() const
A dialog widget to checking spelling of text elements in the document Uses gspell and one of the lang...
void onIgnore()
Ignore button clicked.
sigc::scoped_connection _release_connection
void onAccept()
Accept button clicked.
SPItem * getText(SPObject *root)
Compare the visual bounds of 2 SPItems referred to by a and b.
void onStop()
Stop button clicked.
Glib::ustring _word
the word we're checking
Gtk::Button & accept_button
Glib::RefPtr< Gtk::StringList > corrections
std::vector< LanguagePair > _langs
void onStart()
Start button clicked.
void disconnect()
Release handlers to the selected item.
int _stops
counters for the number of stops and dictionary adds
void onLanguageChanged()
Language selection changed.
Text::Layout::iterator _begin_w
iterators for the start and end of the current word
Util::GObjectPtr< SpellingChecker > _checker
void onIgnoreOnce()
Ignore once button clicked.
void finished()
Cleanup after spellcheck is finished.
SpellingProvider * _provider
bool textIsValid(SPObject *root, SPItem *text)
Is text inside the SPOject's tree.
void documentReplaced() override
Gtk::Button & stop_button
bool _working
true if we are in the middle of a check
void onTreeSelectionChange()
Selection in suggestions text view changed.
void onAdd()
Add button clicked.
Gtk::Button & ignore_button
Gtk::Button & ignoreonce_button
bool nextWord()
Find the next word to spell check.
Gtk::Button & start_button
Gtk::DropDown & dictionary_combo
Gtk::Button & pref_button
void clearRects()
Remove the highlight rectangle form the canvas.
std::vector< CanvasItemPtr< CanvasItemRect > > _rects
list of canvasitems (currently just rects) that mark misspelled things on canvas
SPItem * _text
the object currently being checked
sigc::scoped_connection _modified_connection
connect to the object being checked in case it is modified or deleted by user
bool _local_change
true if the spell checker dialog has changed text, to suppress modified callback
void onObjModified()
Selected object modified on canvas.
Text::Layout const * _layout
current objects layout
void onObjReleased()
Selected object removed from canvas.
Gtk::ColumnView & column_view
void allTextItems(SPObject *r, std::vector< SPItem * > &l, bool hidden, bool locked)
Returns a list of all the text items in the SPObject.
Glib::RefPtr< Gtk::SingleSelection > selection_model
Text::Layout::iterator _end_w
Gtk::Label & banner_label
std::set< SPItem * > _seen_objects
list of text objects we have already checked in this session
bool updateSpeller()
Update speller from language combobox.
virtual char const * name() const =0
Get the name of the element node.
Geom::Point current_center() const
bool itemIsHidden(SPItem const *item) const
Inkscape::CanvasItemGroup * getCanvasSketch() const
Inkscape::Selection * getSelection() const
Inkscape::UI::Tools::ToolBase * getTool() const
bool scroll_to_point(Geom::Point const &s_dt, double autoscrollspeed=0)
Scroll screen so as to keep point 'p' visible in window.
Inkscape::LayerManager & layerManager()
SPRoot * getRoot()
Returns our SPRoot.
Base class for visual SVG elements.
Geom::Affine i2dt_affine() const
Returns the transformation from item to desktop coords.
Geom::OptRect documentVisualBounds() const
Get item's visual bbox in document coordinate system.
SPObject is an abstract base class of all of the document nodes at the SVG document level.
sigc::connection connectRelease(sigc::slot< void(SPObject *)> slot)
Connects to the release request signal.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
sigc::connection connectModified(sigc::slot< void(SPObject *, unsigned int)> slot)
Connects to the modification notification signal.
Editable view implementation.
A widget that manages DialogNotebook's and other widgets inside a horizontal DialogMultipaned.
TODO: insert short description here.
Macro for icon names used in Inkscape.
Inkscape Preferences dialog.
C++ wrapping for libspelling C API.
SBasis L2(D2< SBasis > const &a, unsigned k)
auto list_corrections(SpellingChecker *checker, char const *word)
Glib::RefPtr< Gtk::Builder > create_builder(const char *filename)
void list_language_names_and_codes(SpellingProvider *provider, F &&cb)
static void append(std::vector< T > &target, std::vector< T > &&source)
TODO: insert short description here.
SPRoot: SVG <svg> implementation.
TODO: insert short description here.
Glib::ustring sp_te_get_string_multiline(SPItem const *text)
Gets a text-only representation of the given text or flowroot object, replacing line break elements w...
Inkscape::Text::Layout const * te_get_layout(SPItem const *item)
Inkscape::Text::Layout::iterator sp_te_replace(SPItem *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, gchar const *utf8)
Glib::RefPtr< Gtk::Builder > builder