• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • part
katespell.cpp
1/* This file is part of the KDE libraries
2 Copyright (C) 2004-2005 Anders Lund <anders@alweb.dk>
3 Copyright (C) 2003 Clarence Dang <dang@kde.org>
4 Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
5 Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
6 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
7 Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License version 2 as published by the Free Software Foundation.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22*/
23
24#include "katespell.h"
25#include "katespell.moc"
26
27#include "kateview.h"
28
29#include <tdeaction.h>
30#include <kstdaction.h>
31#include <tdespell.h>
32#include <ksconfig.h>
33#include <kdebug.h>
34#include <tdemessagebox.h>
35
36KateSpell::KateSpell( KateView* view )
37 : TQObject( view )
38 , m_view (view)
39 , m_tdespell (0)
40{
41}
42
43KateSpell::~KateSpell()
44{
45 // tdespell stuff
46 if( m_tdespell )
47 {
48 m_tdespell->setAutoDelete(true);
49 m_tdespell->cleanUp(); // need a way to wait for this to complete
50 delete m_tdespell;
51 }
52}
53
54void KateSpell::createActions( TDEActionCollection* ac )
55{
56 KStdAction::spelling( this, TQ_SLOT(spellcheck()), ac );
57 TDEAction *a = new TDEAction( i18n("Spelling (from cursor)..."), "tools-check-spelling", 0, this, TQ_SLOT(spellcheckFromCursor()), ac, "tools_spelling_from_cursor" );
58 a->setWhatsThis(i18n("Check the document's spelling from the cursor and forward"));
59
60 m_spellcheckSelection = new TDEAction( i18n("Spellcheck Selection..."), "tools-check-spelling", 0, this, TQ_SLOT(spellcheckSelection()), ac, "tools_spelling_selection" );
61 m_spellcheckSelection->setWhatsThis(i18n("Check spelling of the selected text"));
62}
63
64void KateSpell::updateActions ()
65{
66 m_spellcheckSelection->setEnabled (m_view->hasSelection ());
67}
68
69void KateSpell::spellcheckFromCursor()
70{
71 spellcheck( KateTextCursor(m_view->cursorLine(), m_view->cursorColumnReal()) );
72}
73
74void KateSpell::spellcheckSelection()
75{
76 KateTextCursor from( m_view->selStartLine(), m_view->selStartCol() );
77 KateTextCursor to( m_view->selEndLine(), m_view->selEndCol() );
78 spellcheck( from, to );
79}
80
81void KateSpell::spellcheck()
82{
83 spellcheck( KateTextCursor( 0, 0 ) );
84}
85
86void KateSpell::spellcheck( const KateTextCursor &from, const KateTextCursor &to )
87{
88 m_spellStart = from;
89 m_spellEnd = to;
90
91 if ( to.line() == 0 && to.col() == 0 )
92 {
93 int lln = m_view->doc()->lastLine();
94 m_spellEnd.setLine( lln );
95 m_spellEnd.setCol( m_view->doc()->lineLength( lln ) );
96 }
97
98 m_spellPosCursor = from;
99 m_spellLastPos = 0;
100
101 TQString mt = m_view->doc()->mimeType()/*->name()*/;
102
103 KSpell::SpellerType type = KSpell::Text;
104 if ( mt == "text/x-tex" || mt == "text/x-latex" )
105 type = KSpell::TeX;
106 else if ( mt == "text/html" || mt == "text/xml" || mt == "text/docbook" || mt == "application/x-php")
107 type = KSpell::HTML;
108
109 KSpellConfig *ksc = new KSpellConfig;
110 TQStringList ksEncodings;
111 ksEncodings << "US-ASCII" << "ISO 8859-1" << "ISO 8859-2" << "ISO 8859-3"
112 << "ISO 8859-4" << "ISO 8859-5" << "ISO 8859-7" << "ISO 8859-8"
113 << "ISO 8859-9" << "ISO 8859-13" << "ISO 8859-15" << "UTF-8"
114 << "KOI8-R" << "KOI8-U" << "CP1251" << "CP1255";
115
116 int enc = ksEncodings.findIndex( m_view->doc()->encoding() );
117 if ( enc > -1 )
118 {
119 ksc->setEncoding( enc );
120 kdDebug(13020)<<"KateSpell::spellCheck(): using encoding: "<<enc<<" ("<<ksEncodings[enc]<<") and KSpell::Type "<<type<<" (for '"<<mt<<"')"<<endl;
121 }
122 else
123 kdDebug(13020)<<"KateSpell::spellCheck(): using encoding: "<<enc<<" and KSpell::Type "<<type<<" (for '"<<mt<<"')"<<endl;
124
125 m_tdespell = new KSpell( m_view, i18n("Spellcheck"),
126 this, TQ_SLOT(ready(KSpell *)), ksc, true, true, type );
127
128 connect( m_tdespell, TQ_SIGNAL(death()),
129 this, TQ_SLOT(spellCleanDone()) );
130
131 connect( m_tdespell, TQ_SIGNAL(misspelling(const TQString&, const TQStringList&, unsigned int)),
132 this, TQ_SLOT(misspelling(const TQString&, const TQStringList&, unsigned int)) );
133 connect( m_tdespell, TQ_SIGNAL(corrected(const TQString&, const TQString&, unsigned int)),
134 this, TQ_SLOT(corrected(const TQString&, const TQString&, unsigned int)) );
135 connect( m_tdespell, TQ_SIGNAL(done(const TQString&)),
136 this, TQ_SLOT(spellResult(const TQString&)) );
137}
138
139void KateSpell::ready(KSpell *)
140{
141 m_tdespell->setProgressResolution( 1 );
142
143 m_tdespell->check( m_view->doc()->text( m_spellStart.line(), m_spellStart.col(), m_spellEnd.line(), m_spellEnd.col() ) );
144
145 kdDebug (13020) << "SPELLING READY STATUS: " << m_tdespell->status () << endl;
146}
147
148void KateSpell::locatePosition( uint pos, uint& line, uint& col )
149{
150 uint remains;
151
152 while ( m_spellLastPos < pos )
153 {
154 remains = pos - m_spellLastPos;
155 uint l = m_view->doc()->lineLength( m_spellPosCursor.line() ) - m_spellPosCursor.col();
156 if ( l > remains )
157 {
158 m_spellPosCursor.setCol( m_spellPosCursor.col() + remains );
159 m_spellLastPos = pos;
160 }
161 else
162 {
163 m_spellPosCursor.setLine( m_spellPosCursor.line() + 1 );
164 m_spellPosCursor.setCol(0);
165 m_spellLastPos += l + 1;
166 }
167 }
168
169 line = m_spellPosCursor.line();
170 col = m_spellPosCursor.col();
171}
172
173void KateSpell::misspelling( const TQString& origword, const TQStringList&, unsigned int pos )
174{
175 uint line, col;
176
177 locatePosition( pos, line, col );
178
179 m_view->setCursorPositionInternal (line, col, 1);
180 m_view->setSelection( line, col, line, col + origword.length() );
181}
182
183void KateSpell::corrected( const TQString& originalword, const TQString& newword, unsigned int pos )
184{
185 uint line, col;
186
187 locatePosition( pos, line, col );
188
189 m_view->doc()->removeText( line, col, line, col + originalword.length() );
190 m_view->doc()->insertText( line, col, newword );
191}
192
193void KateSpell::spellResult( const TQString& )
194{
195 m_view->clearSelection();
196 m_tdespell->cleanUp();
197}
198
199void KateSpell::spellCleanDone()
200{
201 KSpell::spellStatus status = m_tdespell->status();
202
203 if( status == KSpell::Error ) {
204 KMessageBox::sorry( 0,
205 i18n("The spelling program could not be started. "
206 "Please make sure you have set the correct spelling program "
207 "and that it is properly configured and in your PATH."));
208 } else if( status == KSpell::Crashed ) {
209 KMessageBox::sorry( 0,
210 i18n("The spelling program seems to have crashed."));
211 }
212
213 delete m_tdespell;
214 m_tdespell = 0;
215
216 kdDebug (13020) << "SPELLING END" << endl;
217}
218//END
KMessageBox::sorry
static void sorry(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
KSpellConfig
KSpell
KSpell::SpellerType
SpellerType
KSpell::spellStatus
spellStatus
KateTextCursor
Simple cursor class with no document pointer.
Definition: katecursor.h:34
TDEActionCollection
TDEAction
TDEAction::setWhatsThis
virtual void setWhatsThis(const TQString &text)
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)
KStdAction::spelling
TDEAction * spelling(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kate

Skip menu "kate"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for kate by doxygen 1.9.4
This website is maintained by Timothy Pearson.