spellcheck.cpp revision 066e9d365d60b5516e36e8796ea947f87192c61f
/**
* @file
* Spellcheck dialog.
*/
/* Authors:
* bulia byak <bulia@users.sf.net>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 2009 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "spellcheck.h"
#include "message-stack.h"
#include "macros.h"
#include "inkscape.h"
#include "document.h"
#include "selection.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "tools-switch.h"
#include "ui/tools/text-tool.h"
#include "interface.h"
#include "preferences.h"
#include "sp-text.h"
#include "sp-flowtext.h"
#include "text-editing.h"
#include "sp-tspan.h"
#include "sp-tref.h"
#include "sp-defs.h"
#include "selection-chemistry.h"
#include "display/canvas-bpath.h"
#include "document-undo.h"
#include "sp-root.h"
#include "verbs.h"
#ifdef WIN32
#include <windows.h>
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
namespace Inkscape {
namespace UI {
namespace Dialog {
SpellCheck::SpellCheck (void) :
_stops(0),
_adds(0),
_working(false),
_local_change(false),
_lang("en"),
_lang2(""),
_lang3(""),
accept_button(_("_Accept"), true),
ignoreonce_button(_("_Ignore once"), true),
ignore_button(_("_Ignore"), true),
add_button(_("A_dd"), true),
dictionary_hbox(false, 0),
stop_button(_("_Stop"), true),
start_button(_("_Start"), true),
{
#ifdef HAVE_ASPELL
#endif /* HAVE_ASPELL */
// take languages from prefs
if (_lang == "")
_lang = "en";
{
if (_lang2 != "") {
}
if (_lang3 != "") {
}
}
/*
* Main dialog
*/
/*
* Signal handlers
*/
tree_view.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &SpellCheck::onTreeSelectionChange));
desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &SpellCheck::setTargetDesktop) );
// run it at once
onStart ();
}
SpellCheck::~SpellCheck(void)
{
clearRects();
disconnect();
}
{
}
{
if (_working) {
// Stop and start on the new desktop
finished();
onStart();
}
}
}
void SpellCheck::clearRects()
{
}
}
void SpellCheck::disconnect()
{
if (_release_connection) {
}
if (_modified_connection) {
}
}
{
if (!desktop)
return l; // no desktop to check
if (SP_IS_DEFS(r))
return l; // we're not interested in items in defs
return l; // we're not interested in metadata
}
if ((hidden || !desktop->itemIsHidden(SP_ITEM(child))) && (locked || !SP_ITEM(child)->isLocked())) {
l = g_slist_prepend (l, child);
}
}
}
return l;
}
bool
{
l = allTextItems (root, l, false, true);
g_slist_free (l);
return true;
}
}
g_slist_free (l);
return false;
}
{
return 0;
}
// vector between top left corners
// sort top to bottom, left to right, but:
// if i2 is higher only 0.2 or less times it is righter than i1, put i1 first
return 1;
else
return -1;
return 0;
}
// We regenerate and resort the list every time, because user could have changed it while the
// dialog was waiting
{
l = allTextItems (root, l, false, true);
g_slist_free(l);
return item;
}
}
g_slist_free(l);
return NULL;
}
void
{
disconnect();
if (_text) {
_modified_connection = (SP_OBJECT(_text))->connectModified(sigc::mem_fun(*this, &SpellCheck::onObjModified));
_release_connection = (SP_OBJECT(_text))->connectRelease(sigc::mem_fun(*this, &SpellCheck::onObjReleased));
}
}
bool
{
desktop = d;
tree_view.set_sensitive(false);
accept_button.set_sensitive(false);
ignore_button.set_sensitive(false);
ignoreonce_button.set_sensitive(false);
add_button.set_sensitive(false);
gtk_widget_set_sensitive(dictionary_combo, false);
start_button.set_sensitive(false);
#ifdef WIN32
// on windows, dictionaries are in a lib/aspell-0.60 subdir off inkscape's executable dir;
// this is some black magick to find out the executable path to give it to aspell
if (slashPos)
*slashPos = '\0';
#endif
_stops = 0;
_adds = 0;
clearRects();
#ifdef HAVE_ASPELL
{
#ifdef WIN32
#endif
if (aspell_error(ret) != 0) {
return false;
}
}
if (_lang2 != "") {
#ifdef WIN32
#endif
if (aspell_error(ret) != 0) {
return false;
}
}
if (_lang3 != "") {
#ifdef WIN32
#endif
if (aspell_error(ret) != 0) {
return false;
}
}
#endif /* HAVE_ASPELL */
// empty the list of objects we've checked
// grab first text
nextText();
_working = true;
return true;
}
void
SpellCheck::finished ()
{
#ifdef HAVE_ASPELL
if (_speller2) {
}
if (_speller3) {
}
#endif /* HAVE_ASPELL */
clearRects();
disconnect();
//desktop->clearWaitingCursor();
tree_view.set_sensitive(false);
accept_button.set_sensitive(false);
ignore_button.set_sensitive(false);
ignoreonce_button.set_sensitive(false);
gtk_widget_set_sensitive(dictionary_combo, false);
add_button.set_sensitive(false);
stop_button.set_sensitive(false);
start_button.set_sensitive(true);
{
if (_stops)
else
}
_working = false;
}
bool
{
if (!_working)
return false;
if (!_text) {
finished();
return false;
}
nextText();
return false;
}
}
}
// try to link this word with the next if separated by '
void *rawptr;
if (SP_IS_STRING(char_item)) {
if (SP_IS_STRING(char_item)) {
}
}
}
}
// skip words containing digits
bool digits = false;
if (g_unichar_isdigit(_word[i])) {
digits = true;
break;
}
}
if (digits) {
return false;
}
}
// skip ALL-CAPS words
bool allcaps = true;
if (!g_unichar_isupper(_word[i])) {
allcaps = false;
break;
}
}
if (allcaps) {
return false;
}
}
int have = 0;
#ifdef HAVE_ASPELL
// run it by all active spellers
if (_speller2)
if (_speller3)
#endif /* HAVE_ASPELL */
if (have == 0) { // not found in any!
_stops ++;
//desktop->clearWaitingCursor();
// display it in window
{
if (_lang2 != "")
if (_lang3 != "")
gchar *label = g_strdup_printf(_("Not in dictionary (%s): <b>%s</b>"), langs.c_str(), _word.c_str());
}
tree_view.set_sensitive(true);
ignore_button.set_sensitive(true);
ignoreonce_button.set_sensitive(true);
add_button.set_sensitive(true);
stop_button.set_sensitive(true);
// draw rect
if (points.size() >= 4) { // we may not have a single quad if this is a clipped part of text on path; in that case skip drawing the rect
}
// expand slightly
// create canvas path rectangle, red stroke
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(rect), 0xff0000ff, 3.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
// scroll to make it all visible
double dist = 0;
}
}
}
// select text; if in Text tool, position cursor to the beginning of word
// unless it is already in the word
if (!cursor) // some other text is selected there
}
#ifdef HAVE_ASPELL
// get suggestions
{
{
const char *sugg;
}
}
if (_speller2) {
const char *sugg;
}
}
if (_speller3) {
const char *sugg;
}
}
}
#endif /* HAVE_ASPELL */
return true;
}
return false;
}
void
{
if (_rects) {
}
}
void SpellCheck::doSpellcheck ()
{
//desktop->setWaitingCursor();
while (_working)
if (nextWord())
break;
}
void SpellCheck::onTreeSelectionChange()
{
accept_button.set_sensitive(true);
}
{
if (_local_change) { // this was a change by this dialog, i.e. an Accept, skip it
_local_change = false;
return;
}
// user may have edited the text we're checking; try to do the most sensible thing in this
// situation
// just in case, re-get text's layout
// re-get the word
deleteLastRect ();
doSpellcheck (); // recheck this word and go ahead if it's ok
}
}
}
{
// the text object was deleted
deleteLastRect ();
nextText();
doSpellcheck (); // get next text and continue
}
}
void SpellCheck::onAccept ()
{
// insert chosen suggestion
if (iter) {
//g_print("chosen: %s\n", sugg);
_local_change = true;
// find the end of the word anew
_("Fix spelling"));
}
}
doSpellcheck();
}
void
SpellCheck::onIgnore ()
{
#ifdef HAVE_ASPELL
if (_speller2)
if (_speller3)
#endif /* HAVE_ASPELL */
doSpellcheck();
}
void
{
doSpellcheck();
}
void
SpellCheck::onAdd ()
{
_adds++;
#ifdef HAVE_ASPELL
switch (num) {
case 0:
break;
case 1:
if (_speller2)
break;
case 2:
if (_speller3)
break;
default:
break;
}
#endif /* HAVE_ASPELL */
doSpellcheck();
}
void
SpellCheck::onStop ()
{
finished();
}
void
SpellCheck::onStart ()
{
if (init (SP_ACTIVE_DESKTOP))
doSpellcheck();
}
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :