#include "Language.h"
#include "Layout.h"
#include "LyXAction.h"
-#include "LyXFunc.h"
+#include "LyX.h"
#include "Lexer.h"
#include "LyXRC.h"
#include "Paragraph.h"
#include "ParagraphParameters.h"
+#include "SpellChecker.h"
#include "TextClass.h"
#include "TextMetrics.h"
#include "VSpace.h"
+#include "WordLangTuple.h"
#include "frontends/Application.h"
#include "frontends/Clipboard.h"
void regexpDispatch(Cursor & cur, FuncRequest const & cmd)
{
- BOOST_ASSERT(cmd.action == LFUN_REGEXP_MODE);
+ LASSERT(cmd.action == LFUN_REGEXP_MODE, return);
if (cur.inRegexped()) {
- cur.message(_("Already in regexp mode"));
+ cur.message(_("Already in regular expression mode"));
return;
}
cur.recordUndo();
}
-static void dragMove(Cursor & cur, int moveid, int movetoid)
-{
- // Create pointers to buffers
- Buffer & buf_move = *cur.buffer();
- DocIterator dit_move = buf_move.getParFromID(moveid);
- DocIterator dit_dest = buf_move.getParFromID(movetoid);
-
- pit_type & pit_move = dit_move.pit();
- pit_type & pit_dest = dit_dest.pit();
- ParagraphList & pars = dit_move.text()->paragraphs();
-
- // Create references to the paragraphs to be moved
- ParagraphList::iterator const bgn = pars.begin();
- ParagraphList::iterator dest_start = boost::next(bgn, pit_dest);
-
- // The first paragraph of the area to be copied:
- ParagraphList::iterator start = boost::next(bgn, pit_move);
- // The final paragraph of area to be copied:
- ParagraphList::iterator finish = start;
- ParagraphList::iterator const end = pars.end();
-
- // Move out (down) from this section header
- if (finish != end)
- ++finish;
-
- // Seek the one (on same level) below
- int const thistoclevel = start->layout().toclevel;
- for (; finish != end; ++finish) {
- int const toclevel = finish->layout().toclevel;
- if (toclevel != Layout::NOT_IN_TOC
- && toclevel <= thistoclevel)
- break;
- }
-
- if (start == pars.begin() || start == dest_start)
- // Nothing to move
- return;
-
- pars.insert(dest_start, start, finish);
- pars.erase(start, finish);
-
- // FIXME: This only really needs doing for the newly
- // introduced paragraphs. Something like:
- // pit_type const numpars = distance(start, finish);
- // start = boost::next(bgn, pit);
- // finish = boost::next(start, numpars);
- // for (; start != finish; ++start)
- // start->setBuffer(buf);
- // But while this seems to work, it is kind of fragile.
- buf_move.inset().setBuffer(buf_move);
-}
-
-
/// the type of outline operation
enum OutlineOp {
OutlineUp, // Move this header with text down
recUndo(cur, pit, pit + 1);
cur.finishUndo();
pars_.swap(pit, pit + 1);
- cur.buffer()->updateLabels();
+ cur.buffer()->updateBuffer();
needsUpdate = true;
++cur.pit();
break;
recUndo(cur, pit - 1, pit);
cur.finishUndo();
pars_.swap(pit, pit - 1);
- cur.buffer()->updateLabels();
+ cur.buffer()->updateBuffer();
--cur.pit();
needsUpdate = true;
break;
par.params().startOfAppendix(start);
// we can set the refreshing parameters now
- cur.buffer()->updateLabels();
+ cur.buffer()->updateBuffer();
break;
}
case LFUN_MARGINALNOTE_INSERT:
case LFUN_OPTIONAL_INSERT:
case LFUN_INDEX_INSERT:
+ case LFUN_PREVIEW_INSERT:
// Open the inset, and move the current selection
// inside it.
doInsertInset(cur, this, cmd, true, true);
cur.posForward();
// Some insets are numbered, others are shown in the outline pane so
// let's update the labels and the toc backend.
- bv->buffer().updateLabels();
+ bv->buffer().updateBuffer();
break;
case LFUN_TABULAR_INSERT:
// date metrics.
FuncRequest cmd_caption(LFUN_CAPTION_INSERT);
doInsertInset(cur, cur.text(), cmd_caption, true, false);
- bv->buffer().updateLabels();
+ bv->buffer().updateBuffer();
cur.updateFlags(Update::Force);
// FIXME: When leaving the Float (or Wrap) inset we should
// delete any empty paragraph left above or below the
break;
}
+ case LFUN_SPELLING_ADD: {
+ docstring word = from_utf8(cmd.getArg(0));
+ Language * lang;
+ if (word.empty()) {
+ word = cur.selectionAsString(false);
+ // FIXME
+ if (word.size() > 100 || word.empty()) {
+ // Get word or selection
+ selectWordWhenUnderCursor(cur, WHOLE_WORD);
+ word = cur.selectionAsString(false);
+ }
+ lang = const_cast<Language *>(cur.getFont().language());
+ } else
+ lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
+ WordLangTuple wl(word, lang);
+ theSpellChecker()->insert(wl);
+ break;
+ }
+
+ case LFUN_SPELLING_IGNORE: {
+ docstring word = from_utf8(cmd.getArg(0));
+ Language * lang;
+ if (word.empty()) {
+ word = cur.selectionAsString(false);
+ // FIXME
+ if (word.size() > 100 || word.empty()) {
+ // Get word or selection
+ selectWordWhenUnderCursor(cur, WHOLE_WORD);
+ word = cur.selectionAsString(false);
+ }
+ lang = const_cast<Language *>(cur.getFont().language());
+ } else
+ lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
+ WordLangTuple wl(word, lang);
+ theSpellChecker()->accept(wl);
+ break;
+ }
+
case LFUN_PARAGRAPH_PARAMS_APPLY: {
// Given data, an encoding of the ParagraphParameters
// generated in the Paragraph dialog, this function sets
case LFUN_OUTLINE_UP:
outline(OutlineUp, cur);
setCursor(cur, cur.pit(), 0);
- cur.buffer()->updateLabels();
+ cur.buffer()->updateBuffer();
needsUpdate = true;
break;
case LFUN_OUTLINE_DOWN:
outline(OutlineDown, cur);
setCursor(cur, cur.pit(), 0);
- cur.buffer()->updateLabels();
+ cur.buffer()->updateBuffer();
needsUpdate = true;
break;
case LFUN_OUTLINE_IN:
outline(OutlineIn, cur);
- cur.buffer()->updateLabels();
+ cur.buffer()->updateBuffer();
needsUpdate = true;
break;
case LFUN_OUTLINE_OUT:
outline(OutlineOut, cur);
- cur.buffer()->updateLabels();
- needsUpdate = true;
- break;
-
- case LFUN_OUTLINE_DRAGMOVE: {
- int const move_id = convert<int>(cmd.getArg(0));
- int const move_to_id = convert<int>(cmd.getArg(1));
- dragMove(cur, move_id, move_to_id);
- setCursor(cur, cur.pit(), 0);
- cur.buffer()->updateLabels();
+ cur.buffer()->updateBuffer();
needsUpdate = true;
break;
- }
default:
LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text");
// not allowed in description items
enable = !inDescriptionItem(cur);
break;
- case LFUN_FLOAT_LIST_INSERT:
+ case LFUN_FLOAT_LIST_INSERT: {
code = FLOAT_LIST_CODE;
// not allowed in description items
enable = !inDescriptionItem(cur);
+ if (enable) {
+ FloatList const & floats = cur.buffer()->params().documentClass().floats();
+ FloatList::const_iterator cit = floats[to_ascii(cmd.argument())];
+ // make sure we know about such floats
+ if (cit == floats.end() ||
+ // and that we know how to generate a list of them
+ (!cit->second.needsFloatPkg() && cit->second.listCommand().empty())) {
+ flag.unknown(true);
+ // probably not necessary, but...
+ enable = false;
+ }
+ }
break;
+ }
case LFUN_CAPTION_INSERT:
code = CAPTION_CODE;
// not allowed in description items
if (cur.inTexted())
code = SPACE_CODE;
break;
+ case LFUN_PREVIEW_INSERT:
+ code = PREVIEW_CODE;
+ break;
case LFUN_MATH_INSERT:
case LFUN_MATH_AMS_MATRIX:
code = MATH_HULL_CODE;
break;
+ case LFUN_REGEXP_MODE:
+ code = MATH_HULL_CODE;
+ enable = cur.buffer()->isInternal() && !cur.inRegexped();
+ break;
+
case LFUN_INSET_MODIFY:
// We need to disable this, because we may get called for a
// tabular cell via
case LFUN_FONT_EMPH:
flag.setOnOff(fontinfo.emph() == FONT_ON);
+ enable = !cur.inset().getLayout().isPassThru();
break;
case LFUN_FONT_ITAL:
flag.setOnOff(fontinfo.shape() == ITALIC_SHAPE);
+ enable = !cur.inset().getLayout().isPassThru();
break;
case LFUN_FONT_NOUN:
flag.setOnOff(fontinfo.noun() == FONT_ON);
+ enable = !cur.inset().getLayout().isPassThru();
break;
case LFUN_FONT_BOLD:
case LFUN_FONT_BOLDSYMBOL:
flag.setOnOff(fontinfo.series() == BOLD_SERIES);
+ enable = !cur.inset().getLayout().isPassThru();
break;
case LFUN_FONT_SANS:
flag.setOnOff(fontinfo.family() == SANS_FAMILY);
+ enable = !cur.inset().getLayout().isPassThru();
break;
case LFUN_FONT_ROMAN:
flag.setOnOff(fontinfo.family() == ROMAN_FAMILY);
+ enable = !cur.inset().getLayout().isPassThru();
break;
case LFUN_FONT_TYPEWRITER:
flag.setOnOff(fontinfo.family() == TYPEWRITER_FAMILY);
+ enable = !cur.inset().getLayout().isPassThru();
break;
case LFUN_CUT:
case LFUN_OUTLINE_DOWN:
case LFUN_OUTLINE_IN:
case LFUN_OUTLINE_OUT:
- case LFUN_OUTLINE_DRAGMOVE:
// FIXME: LyX is not ready for outlining within inset.
enable = isMainText()
&& cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC;
case LFUN_LANGUAGE:
enable = !cur.inset().getLayout().isPassThru();
+ flag.setOnOff(to_utf8(cmd.argument()) == cur.real_current_font.language()->lang());
break;
case LFUN_BREAK_PARAGRAPH:
enable = cur.inset().getLayout().isMultiPar();
break;
+
+ case LFUN_SPELLING_ADD:
+ case LFUN_SPELLING_IGNORE:
+ enable = theSpellChecker();
+ break;
+
+ case LFUN_LAYOUT:
+ enable = !cur.inset().forcePlainLayout();
+ break;
+
+ case LFUN_LAYOUT_PARAGRAPH:
+ case LFUN_PARAGRAPH_PARAMS:
+ case LFUN_PARAGRAPH_PARAMS_APPLY:
+ case LFUN_PARAGRAPH_UPDATE:
+ enable = cur.inset().allowParagraphCustomization();
+ break;
+
+ // FIXME: why are accent lfuns forbidden with pass_thru layouts?
+ case LFUN_ACCENT_ACUTE:
+ case LFUN_ACCENT_BREVE:
+ case LFUN_ACCENT_CARON:
+ case LFUN_ACCENT_CEDILLA:
+ case LFUN_ACCENT_CIRCLE:
+ case LFUN_ACCENT_CIRCUMFLEX:
+ case LFUN_ACCENT_DOT:
+ case LFUN_ACCENT_GRAVE:
+ case LFUN_ACCENT_HUNGARIAN_UMLAUT:
+ case LFUN_ACCENT_MACRON:
+ case LFUN_ACCENT_OGONEK:
+ case LFUN_ACCENT_TIE:
+ case LFUN_ACCENT_TILDE:
+ case LFUN_ACCENT_UMLAUT:
+ case LFUN_ACCENT_UNDERBAR:
+ case LFUN_ACCENT_UNDERDOT:
+ case LFUN_FONT_DEFAULT:
+ case LFUN_FONT_FRAK:
+ case LFUN_FONT_SIZE:
+ case LFUN_FONT_STATE:
+ case LFUN_FONT_UNDERLINE:
+ case LFUN_FONT_STRIKEOUT:
+ case LFUN_FONT_UULINE:
+ case LFUN_FONT_UWAVE:
+ case LFUN_TEXTSTYLE_APPLY:
+ case LFUN_TEXTSTYLE_UPDATE:
+ enable = !cur.inset().getLayout().isPassThru();
+ break;
case LFUN_WORD_DELETE_FORWARD:
case LFUN_WORD_DELETE_BACKWARD:
case LFUN_WORD_LEFT_SELECT:
case LFUN_WORD_SELECT:
case LFUN_SECTION_SELECT:
+ case LFUN_BUFFER_BEGIN:
+ case LFUN_BUFFER_END:
+ case LFUN_BUFFER_BEGIN_SELECT:
+ case LFUN_BUFFER_END_SELECT:
+ case LFUN_INSET_BEGIN:
+ case LFUN_INSET_END:
+ case LFUN_INSET_BEGIN_SELECT:
+ case LFUN_INSET_END_SELECT:
+ case LFUN_INSET_SELECT_ALL:
case LFUN_PARAGRAPH_UP:
case LFUN_PARAGRAPH_DOWN:
case LFUN_LINE_BEGIN:
case LFUN_SERVER_GET_XY:
case LFUN_SERVER_SET_XY:
case LFUN_SERVER_GET_LAYOUT:
- case LFUN_LAYOUT:
case LFUN_SELF_INSERT:
- case LFUN_FONT_DEFAULT:
- case LFUN_FONT_UNDERLINE:
- case LFUN_FONT_STRIKEOUT:
- case LFUN_FONT_UULINE:
- case LFUN_FONT_UWAVE:
- case LFUN_FONT_SIZE:
- case LFUN_TEXTSTYLE_APPLY:
- case LFUN_TEXTSTYLE_UPDATE:
- case LFUN_LAYOUT_PARAGRAPH:
- case LFUN_PARAGRAPH_UPDATE:
- case LFUN_ACCENT_UMLAUT:
- case LFUN_ACCENT_CIRCUMFLEX:
- case LFUN_ACCENT_GRAVE:
- case LFUN_ACCENT_ACUTE:
- case LFUN_ACCENT_TILDE:
- case LFUN_ACCENT_CEDILLA:
- case LFUN_ACCENT_MACRON:
- case LFUN_ACCENT_DOT:
- case LFUN_ACCENT_UNDERDOT:
- case LFUN_ACCENT_UNDERBAR:
- case LFUN_ACCENT_CARON:
- case LFUN_ACCENT_BREVE:
- case LFUN_ACCENT_TIE:
- case LFUN_ACCENT_HUNGARIAN_UMLAUT:
- case LFUN_ACCENT_CIRCLE:
- case LFUN_ACCENT_OGONEK:
+ case LFUN_UNICODE_INSERT:
case LFUN_THESAURUS_ENTRY:
- case LFUN_PARAGRAPH_PARAMS_APPLY:
- case LFUN_PARAGRAPH_PARAMS:
case LFUN_ESCAPE:
- case LFUN_BUFFER_BEGIN:
- case LFUN_BUFFER_END:
- case LFUN_BUFFER_BEGIN_SELECT:
- case LFUN_BUFFER_END_SELECT:
- case LFUN_INSET_BEGIN:
- case LFUN_INSET_END:
- case LFUN_INSET_BEGIN_SELECT:
- case LFUN_INSET_END_SELECT:
- case LFUN_INSET_SELECT_ALL:
- case LFUN_UNICODE_INSERT:
// these are handled in our dispatch()
enable = true;
break;
|| cur.paragraph().layout().pass_thru))
enable = false;
- switch (cmd.action) {
- case LFUN_ACCENT_ACUTE:
- case LFUN_ACCENT_BREVE:
- case LFUN_ACCENT_CARON:
- case LFUN_ACCENT_CEDILLA:
- case LFUN_ACCENT_CIRCLE:
- case LFUN_ACCENT_CIRCUMFLEX:
- case LFUN_ACCENT_DOT:
- case LFUN_ACCENT_GRAVE:
- case LFUN_ACCENT_HUNGARIAN_UMLAUT:
- case LFUN_ACCENT_MACRON:
- case LFUN_ACCENT_OGONEK:
- case LFUN_ACCENT_TIE:
- case LFUN_ACCENT_TILDE:
- case LFUN_ACCENT_UMLAUT:
- case LFUN_ACCENT_UNDERBAR:
- case LFUN_ACCENT_UNDERDOT:
- case LFUN_FONT_BOLD:
- case LFUN_FONT_BOLDSYMBOL:
- case LFUN_FONT_TYPEWRITER:
- case LFUN_FONT_DEFAULT:
- case LFUN_FONT_EMPH:
- case LFUN_FONT_NOUN:
- case LFUN_FONT_ROMAN:
- case LFUN_FONT_SANS:
- case LFUN_FONT_FRAK:
- case LFUN_FONT_ITAL:
- case LFUN_FONT_SIZE:
- case LFUN_FONT_STATE:
- case LFUN_FONT_UNDERLINE:
- case LFUN_FONT_STRIKEOUT:
- case LFUN_FONT_UULINE:
- case LFUN_FONT_UWAVE:
- case LFUN_TEXTSTYLE_APPLY:
- case LFUN_TEXTSTYLE_UPDATE:
- if (cur.inset().getLayout().isPassThru())
- enable = false;
- break;
- default:
- break;
- }
-
flag.setEnabled(enable);
return true;
}