From 7c98b3bd37f41ad05e9770d66774f999fbd17ff8 Mon Sep 17 00:00:00 2001 From: John Levon Date: Sun, 4 Aug 2002 23:11:50 +0000 Subject: [PATCH] spellchecker cleanup - fscked knows why pspell is broken, I am TOTALLY baffled by that one. Various other cleanups, including a fixed version of lyxlex that doesn't destroy the preamble ... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4854 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 1 + src/BufferView.h | 7 +- src/BufferView2.C | 2 +- src/BufferView_pimpl.C | 12 +- src/ChangeLog | 42 +++ src/LyXAction.C | 5 +- src/Makefile.am | 9 +- src/SpellBase.h | 61 ++++ src/ToolbarDefaults.C | 2 +- src/buffer.C | 2 +- src/buffer.h | 16 +- src/bufferlist.C | 12 +- src/commandtags.h | 3 +- src/frontends/ChangeLog | 4 + src/frontends/LyXView.C | 2 +- src/frontends/controllers/ChangeLog | 7 + .../controllers/ControlSpellchecker.C | 67 ++--- .../controllers/ControlSpellchecker.h | 6 +- .../controllers/ControlTabularCreate.C | 2 +- src/frontends/xforms/FormBase.C | 1 + src/frontends/xforms/FormSpellchecker.C | 6 +- src/frontends/xforms/XFormsView.C | 2 +- src/insets/ChangeLog | 5 + src/insets/inset.h | 2 +- src/insets/insetnote.h | 2 +- src/{sp_spell.C => ispell.C} | 269 ++++-------------- src/ispell.h | 68 +++++ src/lyx_cb.C | 2 +- src/lyx_cb.h | 2 +- src/lyxcursor.C | 14 +- src/lyxcursor.h | 121 ++++---- src/lyxfunc.C | 17 +- src/lyxlex.C | 60 ++-- src/lyxserver.C | 4 +- src/lyxvc.C | 10 +- src/pspell.C | 130 +++++++++ src/pspell.h | 66 +++++ src/sp_base.h | 49 ---- src/sp_ispell.h | 69 ----- src/sp_pspell.h | 58 ---- src/text2.C | 66 +++-- src/vc-backend.C | 6 +- 42 files changed, 668 insertions(+), 623 deletions(-) create mode 100644 src/SpellBase.h rename src/{sp_spell.C => ispell.C} (65%) create mode 100644 src/ispell.h create mode 100644 src/pspell.C create mode 100644 src/pspell.h delete mode 100644 src/sp_base.h delete mode 100644 src/sp_ispell.h delete mode 100644 src/sp_pspell.h diff --git a/src/BufferView.C b/src/BufferView.C index 2548967b6c..0040c41738 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -236,6 +236,7 @@ BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1, (static_cast(uc1) | static_cast(uc2)); } + bool BufferView::dispatch(kb_action action, string const & argument) { return pimpl_->dispatch(action, argument); diff --git a/src/BufferView.h b/src/BufferView.h index 19c299c173..2603dadf1b 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -1,7 +1,8 @@ // -*- C++ -*- -/** \file - * Copyright 2002 the LyX Team - * Read the file COPYING +/** + * \file BufferView.h + * Copyright 2002 the LyX Team + * Read the file COPYING * * \author Lars Gullik Bjønnes */ diff --git a/src/BufferView2.C b/src/BufferView2.C index 031f535d9b..389201ce5f 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -58,7 +58,7 @@ bool BufferView::insertLyXFile(string const & filen) // Copyright CHT Software Service GmbH // Uwe C. Schroeder // - // Insert a Lyxformat - file into current buffer + // Insert a LyXformat - file into current buffer // // Moved from lyx_cb.C (Lgb) { diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 124408dd78..b3e70534bc 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -1571,7 +1571,7 @@ bool BufferView::Pimpl::dispatch(kb_action action, string const & argument) break; case LFUN_GOTONOTE: - gotoInset(Inset::IGNORE_CODE, false); + gotoInset(Inset::NOTE_CODE, false); break; case LFUN_REFERENCE_GOTO: @@ -2814,12 +2814,16 @@ bool BufferView::Pimpl::dispatch(kb_action action, string const & argument) } break; - case LFUN_INSET_TABULAR: + case LFUN_TABULAR_INSERT: { + if (argument.empty()) { + owner_->getDialogs()->showTabularCreate(); + break; + } + int r = 2; int c = 2; - if (!argument.empty()) - ::sscanf(argument.c_str(),"%d%d", &r, &c); + ::sscanf(argument.c_str(),"%d%d", &r, &c); InsetTabular * new_inset = new InsetTabular(*buffer_, r, c); bool const rtl = diff --git a/src/ChangeLog b/src/ChangeLog index f7d53fe384..db13a72283 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,45 @@ +2002-08-04 John Levon + + * BufferView.h: + * BufferView.C: cosmetic change + + * BufferView_pimpl.C: s/IGNORE_CODE/NOTE_CODE/ + + * bufferlist.C: + * buffer.h: + * buffer.C: + * lyxcb.h: + * lyxcb.C: + * lyxserver.C: + * lyxvc.C: + * vc-backend.C: + * BufferView2.C: purge all "Lyx" not "LyX" strings + + * lyxcursor.h: + * lyxcursor.C: attempt to add some documentation + + * lyxfunc.C: + * commandtags.h: + * LyXAction.C: + * ToolbarDefaults.C: + * BufferView_pimpl.C: remove LFUN_DIALOG_TABULAR_INSERT and + merge with LFUN_TABULAR_INSERT + + * Makefile.am: + * SpellBase.h: + * ispell.h: + * ispell.C: + * pspell.h: + * pspell.C: split up i/pspell implementations into separate + files, many cleanups + + * lyxlex.C: unrevert, with a proper fix for prefix.length() == 0 + + * text2.C: some cleanup + + * lyxfunc.C: don't check for isp_command == "none" any more, it + didn't make any sense + 2002-08-02 John Levon * buffer.C: s/lyxconvert/lyx2lyx/ diff --git a/src/LyXAction.C b/src/LyXAction.C index 9c1ac78791..3c5f073ffa 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -365,12 +365,9 @@ void LyXAction::init() { LFUN_SHIFT_TAB, "tab-backward", "", Noop }, { LFUN_TAB, "tab-forward", "", Noop }, { LFUN_TABINSERT, "tab-insert", "", Noop }, - { LFUN_DIALOG_TABULAR_INSERT, "dialog-tabular-insert", - N_("Insert Table"), Noop }, + { LFUN_TABULAR_INSERT, "table-insert", N_("Insert Table"), Noop }, { LFUN_TABULAR_FEATURE, "tabular-feature", N_("Tabular Features"), Noop }, - { LFUN_INSET_TABULAR, "tabular-insert", - N_("Insert a new Tabular Inset"), Noop }, #if 0 { LFUN_INSET_THEOREM, "theorem-insert", "", Noop }, #endif diff --git a/src/Makefile.am b/src/Makefile.am index 1cc4428494..079da02496 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -177,10 +177,11 @@ lyx_SOURCES = \ paragraph.h \ paragraph_pimpl.C \ paragraph_pimpl.h \ - sp_base.h \ - sp_spell.C \ - sp_ispell.h \ - sp_pspell.h \ + SpellBase.h \ + ispell.h \ + ispell.C \ + pspell.h \ + pspell.C \ tabular.C \ tabular.h \ tabular-old.C \ diff --git a/src/SpellBase.h b/src/SpellBase.h new file mode 100644 index 0000000000..0120a0bb07 --- /dev/null +++ b/src/SpellBase.h @@ -0,0 +1,61 @@ +// -*- C++ -*- +/** + * \file SpellBase.h + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author unknown + */ + +#ifndef SPELL_BASE_H +#define SPELL_BASE_H + +#include "LString.h" // can't forward declare... + +class BufferParams; + +/** + * Base class of all spell checker implementations. + */ +class SpellBase { +public: + + /// the result from checking a single word + enum Result { + OK = 1, //< word is correct + ROOT, //< root of given word was found + COMPOUNDWORD, //< word found through compound formation + UNKNOWN, //< word not found + MISSED, //< not found, with suggestions + IGNORE //< number of other ignored "word" + }; + + virtual ~SpellBase() {} + + /// return true if the spellchecker instance still exists + virtual bool alive() = 0; + + /// clean up on messy exit + virtual void cleanUp() = 0; + + /// check the given word and return the result + virtual enum Result check(string const &) = 0; + + /// finish this spellchecker instance + virtual void close() = 0; + + /// insert the given word into the personal dictionary + virtual void insert(string const &) = 0; + + /// accept the given word temporarily + virtual void accept(string const &) = 0; + + /// return the next near miss after a MISSED result + virtual string const nextMiss() = 0; + + /// give an error message on messy exit + virtual string const error() = 0; + +}; + +#endif // SPELL_BASE_H diff --git a/src/ToolbarDefaults.C b/src/ToolbarDefaults.C index 19c025217c..73d9e898b8 100644 --- a/src/ToolbarDefaults.C +++ b/src/ToolbarDefaults.C @@ -91,7 +91,7 @@ void ToolbarDefaults::init() add(SEPARATOR); add(LFUN_INSET_GRAPHICS); - add(LFUN_DIALOG_TABULAR_INSERT); + add(LFUN_TABULAR_INSERT); } diff --git a/src/buffer.C b/src/buffer.C index 49de220f0f..2b3371ab52 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1810,7 +1810,7 @@ bool Buffer::save() const } if (writeFile(fileName())) { - markLyxClean(); + markClean(); removeAutosaveFile(fileName()); } else { // Saving failed, so backup is not backup diff --git a/src/buffer.h b/src/buffer.h index 61338d1bf0..dcb3fd1769 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -35,9 +35,6 @@ class LaTeXFeatures; class Language; class ParIterator; -// When lyx 1.3.x starts we should enable this -// btw. we should also test this with 1.2 so that we -// do not get any surprises. (Lgb) #define NO_COMPABILITY 1 /// @@ -200,15 +197,15 @@ public: Language const * getLanguage() const; /// int runChktex(); - /// - bool isLyxClean() const; + /// return true if the main lyx file does not need saving + bool isClean() const; /// bool isBakClean() const; /// bool isDepClean(string const & name) const; - /// - void markLyxClean() const; + /// mark the main lyx file as not needing saving + void markClean() const; /// void markBakClean(); @@ -394,6 +391,7 @@ public: } return tmp; } + /// Inset * operator*() { return *it; } @@ -463,7 +461,7 @@ Language const * Buffer::getLanguage() const inline -bool Buffer::isLyxClean() const +bool Buffer::isClean() const { return lyx_clean; } @@ -477,7 +475,7 @@ bool Buffer::isBakClean() const inline -void Buffer::markLyxClean() const +void Buffer::markClean() const { if (!lyx_clean) { lyx_clean = true; diff --git a/src/bufferlist.C b/src/bufferlist.C index 5d57c36170..4620d6b1ab 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -141,7 +141,7 @@ bool BufferList::qwriteAll() BufferStorage::iterator it = bstore.begin(); BufferStorage::iterator end = bstore.end(); for (; it != end; ++it) { - if (!(*it)->isLyxClean()) { + if (!(*it)->isClean()) { string fname; if ((*it)->isUnnamed()) fname = OnlyFilename((*it)->fileName()); @@ -181,7 +181,7 @@ bool BufferList::close(Buffer * buf) if (buf->getUser()) buf->getUser()->insetUnlock(); - if (buf->paragraph && !buf->isLyxClean() && !quitting) { + if (buf->paragraph && !buf->isClean() && !quitting) { if (buf->getUser()) buf->getUser()->owner()->prohibitInput(); string fname; @@ -301,7 +301,7 @@ void BufferList::emergencyWrite(Buffer * buf) // No need to save if the buffer has not changed. - if (buf->isLyxClean()) + if (buf->isClean()) return; lyxerr << fmt(_("lyx: Attempting to save document %s as..."), @@ -316,7 +316,7 @@ void BufferList::emergencyWrite(Buffer * buf) s += ".emergency"; lyxerr << " " << s << endl; if (buf->writeFile(s)) { - buf->markLyxClean(); + buf->markClean(); lyxerr << _(" Save seems successful. Phew.") << endl; return; } else { @@ -329,7 +329,7 @@ void BufferList::emergencyWrite(Buffer * buf) s += ".emergency"; lyxerr << " " << s << endl; if (buf->writeFile(s)) { - buf->markLyxClean(); + buf->markClean(); lyxerr << _(" Save seems successful. Phew.") << endl; return; } @@ -343,7 +343,7 @@ void BufferList::emergencyWrite(Buffer * buf) s += ".emergency"; lyxerr << " " << s << endl; if (buf->writeFile(s)) { - buf->markLyxClean(); + buf->markClean(); lyxerr << _(" Save seems successful. Phew.") << endl; return; } diff --git a/src/commandtags.h b/src/commandtags.h index b817dfc968..3f3eaf57fe 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -250,7 +250,7 @@ enum kb_action { LFUN_INSET_GRAPHICS, // Lgb 20000226 LFUN_INSET_FOOTNOTE, // Jug 20000307 LFUN_PARAGRAPH_SPACING, // Lgb 20000411 - LFUN_INSET_TABULAR, // Jug 20000412 + LFUN_TABULAR_INSERT, // Jug 20000412 LFUN_LOFVIEW, // 230 // Dekel 20000519 LFUN_LOTVIEW, // Dekel 20000519 LFUN_LOAVIEW, // Dekel 20000519 @@ -275,7 +275,6 @@ enum kb_action { LFUN_UPDATE, // Dekel 20000805 LFUN_INDEX_INSERT, // Angus 20000803 LFUN_SCREEN_FONT_UPDATE, // ARRae 20000813 - LFUN_DIALOG_TABULAR_INSERT, // 250 // Jug 20000825 (old table-insert) LFUN_GOTO_PARAGRAPH, // Dekel 20000826 LFUN_REFERENCE_GOTO, // Dekel 20010114 LFUN_BOOKMARK_SAVE, // Dekel 20010127 diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 67c08cb8f4..f35b86604b 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,7 @@ +2002-08-04 John Levon + + * LyXView.C: isLyxClean->isClean + 2002-08-02 Edwin Leuven * Dialogs.[Ch] (updateParagraph): converted back to a signal again. diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index db4d1f2c75..2b34be2980 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -184,7 +184,7 @@ void LyXView::updateWindowTitle() string const cur_title = buffer()->fileName(); if (!cur_title.empty()) { title += ": " + MakeDisplayPath(cur_title, 30); - if (!buffer()->isLyxClean()) + if (!buffer()->isClean()) title += _(" (changed)"); if (buffer()->isReadonly()) title += _(" (read only)"); diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 02b36d388d..d7d49d409b 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,10 @@ +2002-08-04 John Levon + + * ControlSpellchecker.h: + * ControlSpellchecker.C: some cleanups + + * ControlTabularCreate.C: s/LFUN_INSET_TABULAR/LFUN_TABULAR_INSERT/ + 2002-08-02 Edwin Leuven * ControlParagraph.[Ch] (changedParagraph): new method invoked when diff --git a/src/frontends/controllers/ControlSpellchecker.C b/src/frontends/controllers/ControlSpellchecker.C index 0465137acb..97db1d0bde 100644 --- a/src/frontends/controllers/ControlSpellchecker.C +++ b/src/frontends/controllers/ControlSpellchecker.C @@ -1,13 +1,8 @@ -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 2001 The LyX Team. - * - * ====================================================== - * +/** * \file ControlSpellchecker.C + * Copyright 2001 the LyX Team + * Read the file COPYING + * * \author Edwin Leuven */ @@ -33,28 +28,15 @@ #include "support/lstrings.h" -# include "sp_ispell.h" +#include "ispell.h" #ifdef USE_PSPELL -# include "sp_pspell.h" -#endif - -#include // needed by at least on freebsd - -#ifdef HAVE_SYS_SELECT_H -# ifdef HAVE_STRINGS_H - // is needed at least on AIX because FD_ZERO uses bzero(). - // BUT we cannot include both string.h and strings.h on Irix 6.5 :( -# ifdef _AIX -# include -# endif -# endif -#include +# include "pspell.h" #endif ControlSpellchecker::ControlSpellchecker(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d), rtl_(false), newval_(0.0), oldval_(0), newvalue_(0), count_(0), - stop_(false), result_(SpellBase::ISP_OK), speller_(0) + stop_(false), speller_(0) {} @@ -87,12 +69,7 @@ void ControlSpellchecker::setParams() rtl_ = lv_.buffer()->params.language->RightToLeft(); } - if (speller_->error() != 0) { -#if 0 - message_ = speller_->error(); - // show error message - view().partialUpdate(2); -#endif + if (!speller_->error().empty()) { clearParams(); return; } @@ -102,7 +79,7 @@ void ControlSpellchecker::setParams() void ControlSpellchecker::check() { - result_ = SpellBase::ISP_OK; + SpellBase::Result res = SpellBase::OK; stop_ = false; // clear any old selection @@ -110,8 +87,7 @@ void ControlSpellchecker::check() lv_.view()->toggleSelection(true); lv_.view()->update(text, BufferView::SELECT); - while ((result_==SpellBase::ISP_OK || result_==SpellBase::ISP_IGNORE) && - !stop_) { + while ((res == SpellBase::OK || res == SpellBase::IGNORE) && !stop_) { word_ = lv_.view()->nextWord(newval_); if (word_.empty()) { @@ -131,14 +107,14 @@ void ControlSpellchecker::check() if (!speller_->alive()) clearParams(); - result_ = speller_->check(word_); + res = speller_->check(word_); } if (!stop_ && !word_.empty()) lv_.view()->selectLastWord(); // set suggestions - if (result_!=SpellBase::ISP_OK && result_!=SpellBase::ISP_IGNORE) { + if (res != SpellBase::OK && res != SpellBase::IGNORE) { view().partialUpdate(1); } } @@ -167,24 +143,20 @@ void ControlSpellchecker::insert() string ControlSpellchecker::getSuggestion() { - // this is needed because string tmp = nextmiss() - // segfaults when nextMiss is 0 - string tmp; - char const * w = speller_->nextMiss(); - - if (w!=0) { - tmp = w; - if (rtl_) std::reverse(tmp.begin(), tmp.end()); - } + string miss(speller_->nextMiss()); - return tmp; + if (rtl_) + std::reverse(miss.begin(), miss.end()); + + return miss; } string ControlSpellchecker::getWord() { string tmp = word_; - if (rtl_) std::reverse(tmp.begin(), tmp.end()); + if (rtl_) + std::reverse(tmp.begin(), tmp.end()); return tmp; } @@ -247,6 +219,5 @@ void ControlSpellchecker::clearParams() count_ = 0; message_.erase(); stop_ = false; - result_ = SpellBase::ISP_OK; speller_ = 0; } diff --git a/src/frontends/controllers/ControlSpellchecker.h b/src/frontends/controllers/ControlSpellchecker.h index c3ed07e9e9..70c205bd4e 100644 --- a/src/frontends/controllers/ControlSpellchecker.h +++ b/src/frontends/controllers/ControlSpellchecker.h @@ -20,8 +20,9 @@ #endif #include "ControlDialog_impl.h" -#include "sp_base.h" +class SpellBase; + /** A controller for Spellchecker dialogs. */ class ControlSpellchecker : public ControlDialogBD { @@ -93,9 +94,6 @@ private: /// set to true to stop checking bool stop_; - /// spellchecker status - enum SpellBase::spellStatus result_; - /// The actual spellchecker object SpellBase * speller_; diff --git a/src/frontends/controllers/ControlTabularCreate.C b/src/frontends/controllers/ControlTabularCreate.C index 9db249361b..0922c54a58 100644 --- a/src/frontends/controllers/ControlTabularCreate.C +++ b/src/frontends/controllers/ControlTabularCreate.C @@ -53,5 +53,5 @@ void ControlTabularCreate::apply() string const val(tostr(params().first) + " " + tostr(params().second)); - lv_.getLyXFunc()->dispatch(LFUN_INSET_TABULAR, val); + lv_.getLyXFunc()->dispatch(LFUN_TABULAR_INSERT, val); } diff --git a/src/frontends/xforms/FormBase.C b/src/frontends/xforms/FormBase.C index 762a09f1e3..317135ea29 100644 --- a/src/frontends/xforms/FormBase.C +++ b/src/frontends/xforms/FormBase.C @@ -60,6 +60,7 @@ void FormBase::redraw() void FormBase::show() { + lyxerr << "show" << endl; if (!form()) { build(); } diff --git a/src/frontends/xforms/FormSpellchecker.C b/src/frontends/xforms/FormSpellchecker.C index 3758be8f5f..b3575dc9e5 100644 --- a/src/frontends/xforms/FormSpellchecker.C +++ b/src/frontends/xforms/FormSpellchecker.C @@ -23,7 +23,8 @@ typedef FormCB > base_class; FormSpellchecker::FormSpellchecker(ControlSpellchecker & c, Dialogs & d) : base_class(c, d, _("LyX: Spellchecker"), false) -{} +{ +} void FormSpellchecker::build() @@ -129,9 +130,8 @@ void FormSpellchecker::partialUpdate(int id) case 2: // show exit message fl_show_messages(controller().getMessage().c_str()); - hide(); + //hide(); } - } diff --git a/src/frontends/xforms/XFormsView.C b/src/frontends/xforms/XFormsView.C index 09d0d63fa0..ea6a8929f9 100644 --- a/src/frontends/xforms/XFormsView.C +++ b/src/frontends/xforms/XFormsView.C @@ -208,7 +208,7 @@ void XFormsView::show_view_state() // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should // run "prohibitInput" on all LyXViews which will run prohibitInput on all // BufferViews. Or is it perhaps just the (input in) BufferViews in the -// current LyxView that should be prohibited (Lgb) (This applies to +// current LyXView that should be prohibited (Lgb) (This applies to // "allowInput" as well.) void XFormsView::prohibitInput() const { diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index ab522377b0..2fb59073e8 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2002-08-04 John Levon + + * inset.h: + * insetnote.h: s/IGNORE_CODE/NOTE_CODE/ + 2002-08-02 Angus Leeming * insetcommandparams.[Ch] (preview): new methods returning and setting diff --git a/src/insets/inset.h b/src/insets/inset.h index f9ece1d87c..fa81f39f00 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -66,7 +66,7 @@ public: /// LABEL_CODE, // 10 /// - IGNORE_CODE, + NOTE_CODE, /// ACCENT_CODE, /// diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index ca75cade01..df864c130e 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -34,7 +34,7 @@ public: /// string const editMessage() const; /// - Inset::Code lyxCode() const { return Inset::IGNORE_CODE; } + Inset::Code lyxCode() const { return Inset::NOTE_CODE; } /// void write(Buffer const *, std::ostream &) const; /// diff --git a/src/sp_spell.C b/src/ispell.C similarity index 65% rename from src/sp_spell.C rename to src/ispell.C index 0963b46c30..95dfcf2eb3 100644 --- a/src/sp_spell.C +++ b/src/ispell.C @@ -1,14 +1,10 @@ -/* This file is part of - * ====================================================== +/** + * \file ispell.C + * Copyright 2002 the LyX Team + * Read the file COPYING * - * LyX, The Document Processor - * - * Copyright 2001 The LyX Team. - * - * ====================================================== - * - * \file sp_pspell.C - * \author Kevin Atkinson + * \author unknown + * \author John Levon */ #include @@ -23,6 +19,7 @@ #include #include +// FIXME: do we need any of this horrible gook ? #if TIME_WITH_SYS_TIME # include # include @@ -51,7 +48,7 @@ #include "language.h" #include "debug.h" #include "encoding.h" -#include "sp_ispell.h" +#include "ispell.h" #ifndef CXX_GLOBAL_CSTD using std::strcpy; @@ -67,169 +64,9 @@ namespace { pid_t isp_pid = -1; } -/// -// ------------------- start special pspell code/class -------------------- -/// -#ifdef USE_PSPELL - -#include "support/LAssert.h" - -#define USE_ORIGINAL_MANAGER_FUNCS 1 -# include - -#include "sp_pspell.h" - - -PSpell::PSpell() - : sc(0), els(0), spell_error_object(0), flag(ISP_UNKNOWN), - alive_(false) -{ -} - - -PSpell::PSpell(BufferParams const & params, string const & lang) - : sc(0), els(0), spell_error_object(0), flag(ISP_UNKNOWN), - alive_(false) -{ - initialize(params, lang); -} - - -PSpell::~PSpell() -{ - cleanUp(); - close(); - if (els) - delete_pspell_string_emulation(els); -} - - -void PSpell::initialize(BufferParams const &, string const & lang) -{ - PspellConfig * config = new_pspell_config(); - config->replace("language-tag", lang.c_str()); - spell_error_object = new_pspell_manager(config); - if (pspell_error_number(spell_error_object) != 0) { - error_ = pspell_error_message(spell_error_object); - } else { - error_ = 0; - sc = to_pspell_manager(spell_error_object); - spell_error_object = 0; - alive_ = true; - } -} - - -void PSpell::cleanUp() -{ - if (spell_error_object) { - delete_pspell_can_have_error(spell_error_object); - spell_error_object = 0; - } -} - - -enum PSpell::spellStatus PSpell::check(string const & word) -{ - if (!sc) - return flag; - - int word_ok = pspell_manager_check(sc, word.c_str()); - lyx::Assert(word_ok != -1); - - if (word_ok) { - flag = ISP_OK; - } else { - PspellWordList const * sugs = - pspell_manager_suggest(sc, word.c_str()); - lyx::Assert(sugs != 0); - els = pspell_word_list_elements(sugs); - if (pspell_word_list_empty(sugs)) - flag = ISP_UNKNOWN; - else - flag = ISP_MISSED; - } - return flag; -} - - -void PSpell::close() -{ - if (sc) - pspell_manager_save_all_word_lists(sc); -} - - -void PSpell::insert(string const & word) -{ - if (sc) - pspell_manager_add_to_personal(sc, word.c_str()); -} - - -void PSpell::accept(string const & word) -{ - if (sc) - pspell_manager_add_to_session(sc, word.c_str()); -} - - -void PSpell::store(string const & mis, string const & cor) -{ - if (sc) - pspell_manager_store_replacement(sc, mis.c_str(), cor.c_str()); -} - - -char const * PSpell::nextMiss() -{ - if (els) - return pspell_string_emulation_next(els); - return ""; -} - - -char const * PSpell::error() -{ - return error_; -} - - -#endif - -/// -// ------------------- start special ispell code/class -------------------- -/// - -ISpell::ISpell() - : str(0), flag(ISP_UNKNOWN) -{} - ISpell::ISpell(BufferParams const & params, string const & lang) - : str(0), flag(ISP_UNKNOWN) -{ - initialize(params, lang); -} - - -ISpell::~ISpell() -{ - delete[] str; -} - - -char const * ISpell::nextMiss() -{ - if (str == 0 || *(e+1) == '\0') return 0; - b = e + 2; - e = strpbrk(b, ",\n"); - *e = '\0'; - return b; -} - - -void ISpell::initialize(BufferParams const & params, string const & lang) + : str(0) { static char o_buf[BUFSIZ]; // jc: it could be smaller int pipein[2]; @@ -363,6 +200,9 @@ void ISpell::initialize(BufferParams const & params, string const & lang) // Hmm...what are we using this id msg for? Nothing? (Lgb) // Actually I used it to tell if it's truly Ispell or if it's // aspell -- (kevinatk@home.com) + // But no code actually used the results for anything useful + // so I removed it again. Perhaps we can remove this code too. + // - jbl char buf[2048]; fd_set infds; struct timeval tv; @@ -386,15 +226,8 @@ void ISpell::initialize(BufferParams const & params, string const & lang) // there is only one fd in infds. fgets(buf, 2048, in); - // determine if the spell checker is really Aspell - if (strstr(buf, "Aspell")) - actual_spell_checker = ASC_ASPELL; - else - actual_spell_checker = ASC_ISPELL; - fputs("!\n", out); // Set terse mode (silently accept correct words) - } else if (retval == 0) { // timeout. Give nice message to user. lyxerr << "Ispell read timed out, what now?" << endl; @@ -426,6 +259,12 @@ void ISpell::initialize(BufferParams const & params, string const & lang) } +ISpell::~ISpell() +{ + delete[] str; +} + + /* FIXME: this is a minimalist solution until the above * code is able to work with forkedcall.h. We only need * to reap the zombies here. @@ -439,6 +278,19 @@ void reapSpellchecker(void) } +string const ISpell::nextMiss() +{ + if (str == 0 || *(e+1) == '\0') + return ""; + char * b = e + 2; + e = strpbrk(b, ",\n"); + *e = '\0'; + if (b) + return b; + return ""; +} + + bool ISpell::alive() { return isp_pid != -1; @@ -451,10 +303,12 @@ void ISpell::cleanUp() } -enum ISpell::spellStatus ISpell::check(string const & word) +enum ISpell::Result ISpell::check(string const & word) { - //Please rewrite to use string. + // FIXME Please rewrite to use string. + Result res; + ::fputs(word.c_str(), out); ::fputc('\n', out); @@ -463,43 +317,46 @@ enum ISpell::spellStatus ISpell::check(string const & word) // I think we have to check if ispell is still alive here because // the signal-handler could have disabled blocking on the fd - if (!alive()) return ISP_UNKNOWN; + if (!alive()) + return UNKNOWN; switch (*buf) { - case '*': // Word found - flag = ISP_OK; + case '*': + res = OK; break; - case '+': // Word found through affix removal - flag = ISP_ROOT; + case '+': + res = ROOT; break; - case '-': // Word found through compound formation - flag = ISP_COMPOUNDWORD; + case '-': + res = COMPOUNDWORD; break; - case '\n': // Number or when in terse mode: no problems - flag = ISP_IGNORE; + case '\n': + res = IGNORE; break; case '#': // Not found, no near misses and guesses - flag = ISP_UNKNOWN; + res = UNKNOWN; break; case '?': // Not found, and no near misses, but guesses (guesses are ignored) case '&': // Not found, but we have near misses { - flag = ISP_MISSED; + res = MISSED; char * p = strpbrk(buf, ":"); str = new char[strlen(p) + 1]; e = str; strcpy(str, p); break; } - default: // This shouldn't happend, but you know Murphy - flag = ISP_UNKNOWN; + default: // This shouldn't happen, but you know Murphy + res = UNKNOWN; } *buf = 0; - if (flag!= ISP_IGNORE) { - while (*buf!= '\n') fgets(buf, 255, in); /* wait for ispell to finish */ + if (res != IGNORE) { + /* wait for ispell to finish */ + while (*buf!= '\n') + fgets(buf, 255, in); } - return flag; + return res; } @@ -533,19 +390,9 @@ void ISpell::accept(string const & word) } -void ISpell::store(string const & mis, string const & cor) +string const ISpell::error() { - if (actual_spell_checker == ASC_ASPELL) { - ::fputs("$$ra ", out); - ::fputs(mis.c_str(), out); - ::fputc(',', out); - ::fputs(cor.c_str(), out); - ::fputc('\n', out); - } -} - - -char const * ISpell::error() -{ - return error_; + if (error_) + return error_; + return ""; } diff --git a/src/ispell.h b/src/ispell.h new file mode 100644 index 0000000000..477cef9ae0 --- /dev/null +++ b/src/ispell.h @@ -0,0 +1,68 @@ +// -*- C++ -*- +/** + * \file sp_ispell.h + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author unknown + */ + +#ifndef SP_ISPELL_H +#define SP_ISPELL_H + +#include + +#include "SpellBase.h" + +class BufferParams; + +/// i/a spell process-based spellchecker +class ISpell : public SpellBase { +public: + ISpell(BufferParams const & params, string const & lang); + + ~ISpell(); + + /// return true if the spellchecker instance still exists + virtual bool alive(); + + /// clean up on messy exit + virtual void cleanUp(); + + /// check the given word and return the result + virtual enum Result check(string const & word); + + /// finish this spellchecker instance + virtual void close(); + + /// insert the given word into the personal dictionary + virtual void insert(string const & word); + + /// accept the given word temporarily + virtual void accept(string const & word); + + /// return the next near miss after a MISSED result + virtual string const nextMiss(); + + /// give an error message on messy exit + virtual string const error(); + +private: + /// instream to communicate with ispell + FILE * in; + /// outstream to communicate with ispell + FILE * out; + /// spell error + char const * error_; + /// the fd of the outgoing pipe + int isp_fd; + + // vileness below ... please FIXME + /// str ??? + char * str; + /// e ??? + char * e; + +}; + +#endif // ISPELL_H diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 27e5fede65..44e2093f1f 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -317,7 +317,7 @@ void AutoSave(BufferView * bv) // create new file with template // SERVERCMD ! // -Buffer * NewLyxFile(string const & filename) +Buffer * NewFile(string const & filename) { // Split argument by : string name; diff --git a/src/lyx_cb.h b/src/lyx_cb.h index 864851af42..5db5524967 100644 --- a/src/lyx_cb.h +++ b/src/lyx_cb.h @@ -27,7 +27,7 @@ void QuitLyX(); /// void AutoSave(BufferView * bv); /// -Buffer * NewLyxFile(string const & filename); +Buffer * NewFile(string const & filename); /// void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph); /// diff --git a/src/lyxcursor.C b/src/lyxcursor.C index a6caad2024..b653075525 100644 --- a/src/lyxcursor.C +++ b/src/lyxcursor.C @@ -1,12 +1,10 @@ -/* This file is part of - * ====================================================== +/** + * \file lyxcursor.C + * Copyright 1995-2001 the LyX Team + * Read the file COPYING * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2001 The LyX Team. - * - * ====================================================== */ + * \author Matthias Ettrich + */ #include diff --git a/src/lyxcursor.h b/src/lyxcursor.h index d33515c44d..7e21d4e2c4 100644 --- a/src/lyxcursor.h +++ b/src/lyxcursor.h @@ -1,13 +1,11 @@ // -*- C++ -*- -/* This file is part of - * ====================================================== +/** + * \file lyxcursor.h + * Copyright 1995-2001 the LyX Team + * Read the file COPYING * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2001 The LyX Team. - * - * ====================================================== */ + * \author Matthias Ettrich + */ #ifndef LYXCURSOR_H #define LYXCURSOR_H @@ -21,79 +19,109 @@ class Paragraph; class Row; -/** All these variables should be explained. Matthias? +/** + * The cursor class describes the position of a cursor within a document. + * Several cursors exist within LyX; for example, when locking an inset, + * the position of the cursor in the containing inset is stored. + * + * FIXME: true ? */ class LyXCursor { public: - /// LyXCursor(); - /// + /// set the paragraph that contains this cursor void par(Paragraph * p); - /// + /// return the paragraph this cursor is in Paragraph * par() const; - /// + /// set the position within the paragraph void pos(lyx::pos_type p); - /// + /// return the position within the paragraph lyx::pos_type pos() const; - /// + /// FIXME void boundary(bool b); - /// + /// FIXME bool boundary() const; - /// + /// set the x position in pixels void x(int i); - /// + /// return the x position in pixels int x() const; - /// + /// set the stored next-line position when at the end of a row void ix(int i); - /// + /** + * Return the x position of the start of the next row, when this + * cursor is at the end of the previous row, for insets that take + * a full row. + * + * FIXME: explain why we need this ? + */ int ix() const; - /// + /// set the cached x position void x_fix(int i); - /// + /** + * Return the cached x position of the cursor. This is used for when + * we have text like : + * + * blah blah blah blah| blah blah blah + * blah blah blah + * blah blah blah blah blah blah + * + * When we move onto row 3, we would like to be vertically aligned + * with where we were in row 1, despite the fact that row 2 is + * shorter than x() + */ int x_fix() const; - /// + /// set the y position in pixels void y(int i); - /// + /// return the y position in pixels int y() const; - /// + /// set the stored next-line y position when at the end of a row void iy(int i); - /// + /** + * Return the y position of the start of the next row, when this + * cursor is at the end of the previous row, for insets that take + * a full row. + * + * FIXME: explain why we need this ? especially for y... + */ int iy() const; - /// + /// set the row of the paragraph the cursor is in void row(Row * r); - /// + /// return the row of the paragraph this cursor is in Row * row() const; - /// + /// set the stored next row void irow(Row * r); - /// + /** + * Return the next row, when this + * cursor is at the end of the previous row, for insets that take + * a full row. + * + * FIXME: explain why we need this ? especially for y... + */ Row * irow() const; private: /// The paragraph the cursor is in. Paragraph * par_; /// The position inside the paragraph lyx::pos_type pos_; - /// + /// FIXME bool boundary_; - /// + /// the pixel x position int x_; - /// the x position of the position before the inset when we put - /// the cursor on the end of the row before, otherwise equal to x. + /// the stored next-row x position int ix_; - /// + /// the cached x position int x_fix_; - /// + /// the pixel y position int y_; - /// the y position of the position before the inset when we put - /// the cursor on the end of the row before, otherwise equal to y. + /// the stored next-row y position int iy_; - /// + /// the containing row Row * row_; - /// the row of the position before the inset when we put - /// the cursor on the end of the row before, otherwise equal to row. + /// the containing row for the next line Row * irow_; }; -/// +/// these three dictate the others inline bool operator==(LyXCursor const & a, LyXCursor const & b) { @@ -102,29 +130,25 @@ bool operator==(LyXCursor const & a, LyXCursor const & b) && a.boundary() == b.boundary(); } -/// inline bool operator!=(LyXCursor const & a, LyXCursor const & b) { return !(a == b); } -/// +/// only compares y() and pos(). Can this be done in another way? inline bool operator<(LyXCursor const & a, LyXCursor const & b) { - // Can this be done in a nother way? return (a.y() < b.y() && a.pos() < b.pos()); } -/// inline bool operator>(LyXCursor const & a, LyXCursor const & b) { return b < a; } -/// inline bool operator>=(LyXCursor const & a, LyXCursor const & b) { @@ -132,11 +156,10 @@ bool operator>=(LyXCursor const & a, LyXCursor const & b) } -/// inline bool operator<=(LyXCursor const & a, LyXCursor const & b) { return !(a > b); } -#endif +#endif // LYXCURSOR_H diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 1d398844ab..356788c3c0 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -345,9 +345,6 @@ FuncStatus LyXFunc::getStatus(kb_action action, case LFUN_REDO: disable = buf->redostack.empty(); break; - case LFUN_SPELLCHECK: - disable = lyxrc.isp_command == "none"; - break; #ifndef HAVE_LIBAIKSAURUS case LFUN_THESAURUS_ENTRY: disable = true; @@ -514,8 +511,7 @@ FuncStatus LyXFunc::getStatus(kb_action action, case LFUN_INSET_FOOTNOTE: code = Inset::FOOT_CODE; break; - case LFUN_DIALOG_TABULAR_INSERT: - case LFUN_INSET_TABULAR: + case LFUN_TABULAR_INSERT: code = Inset::TABULAR_CODE; break; case LFUN_INSET_EXTERNAL: @@ -546,7 +542,7 @@ FuncStatus LyXFunc::getStatus(kb_action action, code = Inset::CAPTION_CODE; break; case LFUN_INSERT_NOTE: - code = Inset::IGNORE_CODE; + code = Inset::NOTE_CODE; break; case LFUN_INSERT_LABEL: code = Inset::LABEL_CODE; @@ -1052,10 +1048,6 @@ void LyXFunc::dispatch(kb_action action, string argument, bool verbose) break; } - case LFUN_DIALOG_TABULAR_INSERT: - owner->getDialogs()->showTabularCreate(); - break; - case LFUN_AUTOSAVE: AutoSave(owner->view().get()); break; @@ -1195,7 +1187,7 @@ void LyXFunc::dispatch(kb_action action, string argument, bool verbose) case LFUN_FILE_NEW: { // servercmd: argument must be :