#include "TextMetrics.h"
#include "WordLangTuple.h"
+#include "frontends/alert.h"
#include "frontends/Application.h"
#include "frontends/Clipboard.h"
#include "frontends/Selection.h"
#include "support/gettext.h"
#include "support/lassert.h"
#include "support/lstrings.h"
+#include "support/lyxalgo.h"
#include "support/lyxtime.h"
#include "support/os.h"
#include "support/regex.h"
#include "mathed/InsetMathHull.h"
#include "mathed/MathMacroTemplate.h"
-#include <boost/next_prior.hpp>
-
#include <clocale>
#include <sstream>
}
return true;
}
+ else if (cmd.action() == LFUN_ARGUMENT_INSERT) {
+ bool cotextinsert = false;
+ InsetArgument const * const ia = static_cast<InsetArgument const *>(inset);
+ Layout const & lay = cur.paragraph().layout();
+ Layout::LaTeXArgMap args = lay.args();
+ Layout::LaTeXArgMap::const_iterator const lait = args.find(ia->name());
+ if (lait != args.end())
+ cotextinsert = (*lait).second.insertcotext;
+ else {
+ InsetLayout const & il = cur.inset().getLayout();
+ args = il.args();
+ Layout::LaTeXArgMap::const_iterator const ilait = args.find(ia->name());
+ if (ilait != args.end())
+ cotextinsert = (*ilait).second.insertcotext;
+ }
+ // The argument requests to insert a copy of the co-text to the inset
+ if (cotextinsert) {
+ docstring ds;
+ // If we have a selection within a paragraph, use this
+ if (cur.selection() && cur.selBegin().pit() == cur.selEnd().pit())
+ ds = cur.selectionAsString(false);
+ // else use the whole paragraph
+ else
+ ds = cur.paragraph().asString();
+ text->insertInset(cur, inset);
+ if (edit)
+ inset->edit(cur, true);
+ // Now put co-text into inset
+ Font const f(inherit_font, cur.current_font.language());
+ if (!ds.empty()) {
+ cur.text()->insertStringAsLines(cur, ds, f);
+ cur.leaveInset(*inset);
+ }
+ return true;
+ }
+ }
bool gotsel = false;
if (cur.selection()) {
ParagraphList & pars = buf.text().paragraphs();
ParagraphList::iterator const bgn = pars.begin();
// The first paragraph of the area to be copied:
- ParagraphList::iterator start = boost::next(bgn, pit);
+ ParagraphList::iterator start = next(bgn, pit);
// The final paragraph of area to be copied:
ParagraphList::iterator finish = start;
ParagraphList::iterator const end = pars.end();
pit_type const newpit = distance(bgn, dest);
pit_type const len = distance(start, finish);
pit_type const deletepit = pit + len;
- buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
+ buf.undo().recordUndo(cur, newpit, deletepit - 1);
pars.splice(dest, start, finish);
cur.pit() = newpit;
break;
// Nothing to move.
return;
// Go one down from *this* header:
- ParagraphList::iterator dest = boost::next(finish, 1);
+ ParagraphList::iterator dest = next(finish, 1);
// Go further down to find header to insert in front of:
for (; dest != end; ++dest) {
toclevel = buf.text().getTocLevel(distance(bgn, dest));
}
// One such was found:
pit_type newpit = distance(bgn, dest);
- buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
+ buf.undo().recordUndo(cur, pit, newpit - 1);
pit_type const len = distance(start, finish);
pars.splice(dest, start, finish);
cur.pit() = newpit - len;
case OutlineIn:
case OutlineOut: {
pit_type const len = distance(start, finish);
- buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, pit + len - 1);
+ buf.undo().recordUndo(cur, pit, pit + len - 1);
for (; start != finish; ++start) {
toclevel = buf.text().getTocLevel(distance(bgn, start));
if (toclevel == Layout::NOT_IN_TOC)
case LFUN_PARAGRAPH_MOVE_DOWN: {
pit_type const pit = cur.pit();
- recUndo(cur, pit, pit + 1);
+ cur.recordUndo(pit, pit + 1);
cur.finishUndo();
pars_.swap(pit, pit + 1);
needsUpdate = true;
case LFUN_PARAGRAPH_MOVE_UP: {
pit_type const pit = cur.pit();
- recUndo(cur, pit - 1, pit);
+ cur.recordUndo(pit - 1, pit);
cur.finishUndo();
pars_.swap(pit, pit - 1);
--cur.pit();
// FIXME: this don't work for multipart document!
for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
if (pars_[tmp].params().startOfAppendix()) {
- recUndo(cur, tmp);
+ cur.recordUndo(tmp, tmp);
pars_[tmp].params().startOfAppendix(false);
break;
}
break;
case LFUN_CHAR_FORWARD:
- case LFUN_CHAR_FORWARD_SELECT:
+ case LFUN_CHAR_FORWARD_SELECT: {
//LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
needsUpdate |= cur.selHandle(act == LFUN_CHAR_FORWARD_SELECT);
- needsUpdate |= cursorForward(cur);
+ bool const cur_moved = cursorForward(cur);
+ needsUpdate |= cur_moved;
- if (!needsUpdate && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && oldTopSlice == cur.top()
+ && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
}
}
break;
+ }
case LFUN_CHAR_BACKWARD:
- case LFUN_CHAR_BACKWARD_SELECT:
+ case LFUN_CHAR_BACKWARD_SELECT: {
//lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
needsUpdate |= cur.selHandle(act == LFUN_CHAR_BACKWARD_SELECT);
- needsUpdate |= cursorBackward(cur);
+ bool const cur_moved = cursorBackward(cur);
+ needsUpdate |= cur_moved;
- if (!needsUpdate && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && oldTopSlice == cur.top()
+ && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
}
}
break;
+ }
case LFUN_CHAR_LEFT:
case LFUN_CHAR_LEFT_SELECT:
if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(act == LFUN_CHAR_LEFT_SELECT);
- needsUpdate |= cursorVisLeft(cur);
- if (!needsUpdate && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ bool const cur_moved = cursorVisLeft(cur);
+ needsUpdate |= cur_moved;
+ if (!cur_moved && oldTopSlice == cur.top()
+ && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT);
}
case LFUN_CHAR_RIGHT_SELECT:
if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_CHAR_RIGHT_SELECT);
- needsUpdate |= cursorVisRight(cur);
- if (!needsUpdate && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ bool const cur_moved = cursorVisRight(cur);
+ needsUpdate |= cur_moved;
+ if (!cur_moved && oldTopSlice == cur.top()
+ && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
}
ParagraphList & pars = buf.text().paragraphs();
ParagraphList::iterator bgn = pars.begin();
// The first paragraph of the area to be selected:
- ParagraphList::iterator start = boost::next(bgn, pit);
+ ParagraphList::iterator start = next(bgn, pit);
// The final paragraph of area to be selected:
ParagraphList::iterator finish = start;
ParagraphList::iterator end = pars.end();
case LFUN_WORD_RIGHT_SELECT:
if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_RIGHT_SELECT);
- needsUpdate |= cursorVisRightOneWord(cur);
- if (!needsUpdate && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ bool const cur_moved = cursorVisRightOneWord(cur);
+ needsUpdate |= cur_moved;
+ if (!cur_moved && oldTopSlice == cur.top()
+ && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
}
break;
case LFUN_WORD_FORWARD:
- case LFUN_WORD_FORWARD_SELECT:
+ case LFUN_WORD_FORWARD_SELECT: {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_FORWARD_SELECT);
- needsUpdate |= cursorForwardOneWord(cur);
+ bool const cur_moved = cursorForwardOneWord(cur);
+ needsUpdate |= cur_moved;
- if (!needsUpdate && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && oldTopSlice == cur.top()
+ && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_FORWARD);
}
}
break;
+ }
case LFUN_WORD_LEFT:
case LFUN_WORD_LEFT_SELECT:
if (lyxrc.visual_cursor) {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_LEFT_SELECT);
- needsUpdate |= cursorVisLeftOneWord(cur);
- if (!needsUpdate && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ bool const cur_moved = cursorVisLeftOneWord(cur);
+ needsUpdate |= cur_moved;
+ if (!cur_moved && oldTopSlice == cur.top()
+ && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT);
}
break;
case LFUN_WORD_BACKWARD:
- case LFUN_WORD_BACKWARD_SELECT:
+ case LFUN_WORD_BACKWARD_SELECT: {
needsUpdate |= cur.selHandle(cmd.action() == LFUN_WORD_BACKWARD_SELECT);
- needsUpdate |= cursorBackwardOneWord(cur);
+ bool const cur_moved = cursorBackwardOneWord(cur);
+ needsUpdate |= cur_moved;
- if (!needsUpdate && oldTopSlice == cur.top()
- && cur.boundary() == oldBoundary) {
+ if (!cur_moved && oldTopSlice == cur.top()
+ && cur.boundary() == oldBoundary) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
}
}
break;
+ }
case LFUN_WORD_SELECT: {
selectWord(cur, WHOLE_WORD);
needsUpdate |= backspace(cur);
cur.resetAnchor();
}
- // It is possible to make it a lot faster still
- // just comment out the line below...
}
} else {
cutSelection(cur, true, false);
else if (arg == "wmf")
type = Clipboard::WmfGraphicsType;
else
- // We used to assert, but couldn't the argument come from, say, the
- // minibuffer and just be mistyped?
+ // we also check in getStatus()
LYXERR0("Unrecognized graphics type: " << arg);
pasteClipboardGraphics(cur, bv->buffer().errorList("Paste"), type);
bv->buffer().errors("Paste");
cur.clearSelection(); // bug 393
cur.finishUndo();
+ bv->buffer().updatePreviews();
break;
}
arg += " lang=" + from_ascii(cur.getFont().language()->lang());
}
}
+ if (lyxrc.thesaurusdir_path.empty()) {
+ frontend::Alert::warning(_("Path to thesaurus directory not set!"),
+ _("The path to the thesaurus directory has not been specified.\n"
+ "The thesaurus is not functional.\n"
+ "Please refer to sec. 6.15.1 of the User's Guide for setup\n"
+ "instructions."));
+ }
bv->showDialog("thesaurus", to_utf8(arg));
break;
}
word = cur.selectionAsString(false);
}
lang = const_cast<Language *>(cur.getFont().language());
- } else
+ } else if (cmd.getArg(1).empty()) {
+ // optional language argument is missing
+ // use the language at cursor position
+ 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;
word = cur.selectionAsString(false);
}
lang = const_cast<Language *>(cur.getFont().language());
- } else
+ } else if (cmd.getArg(1).empty()) {
+ 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;
word = cur.selectionAsString(false);
}
lang = const_cast<Language *>(cur.getFont().language());
- } else
+ } else if (cmd.getArg(1).empty()) {
+ lang = const_cast<Language *>(cur.getFont().language());
+ } else {
lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
+ }
WordLangTuple wl(word, lang);
theSpellChecker()->remove(wl);
break;
break;
}
- // explicit graphics type?
Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
- if ((arg == "pdf" && (type = Clipboard::PdfGraphicsType))
- || (arg == "png" && (type = Clipboard::PngGraphicsType))
- || (arg == "jpeg" && (type = Clipboard::JpegGraphicsType))
- || (arg == "linkback" && (type = Clipboard::LinkBackGraphicsType))
- || (arg == "emf" && (type = Clipboard::EmfGraphicsType))
- || (arg == "wmf" && (type = Clipboard::WmfGraphicsType))) {
- enable = theClipboard().hasGraphicsContents(type);
+ if (arg == "pdf")
+ type = Clipboard::PdfGraphicsType;
+ else if (arg == "png")
+ type = Clipboard::PngGraphicsType;
+ else if (arg == "jpeg")
+ type = Clipboard::JpegGraphicsType;
+ else if (arg == "linkback")
+ type = Clipboard::LinkBackGraphicsType;
+ else if (arg == "emf")
+ type = Clipboard::EmfGraphicsType;
+ else if (arg == "wmf")
+ type = Clipboard::WmfGraphicsType;
+ else {
+ // unknown argument
+ LYXERR0("Unrecognized graphics type: " << arg);
+ // we don't want to assert if the user just mistyped the LFUN
+ LATTEST(cmd.origin() != FuncRequest::INTERNAL);
+ enable = false;
break;
}
-
- // unknown argument
- enable = false;
+ enable = theClipboard().hasGraphicsContents(type);
break;
- }
+ }
case LFUN_CLIPBOARD_PASTE:
case LFUN_CLIPBOARD_PASTE_SIMPLE:
break;
case LFUN_PARAGRAPH_BREAK:
- enable = cur.inset().getLayout().isMultiPar();
+ enable = inset().allowMultiPar();
break;
case LFUN_SPELLING_ADD:
case LFUN_SPELLING_IGNORE:
case LFUN_SPELLING_REMOVE:
- enable = theSpellChecker();
+ enable = theSpellChecker() != NULL;
+ if (enable && !cmd.getArg(1).empty()) {
+ // validate explicitly given language
+ Language const * const lang = const_cast<Language *>(languages.getLanguage(cmd.getArg(1)));
+ enable &= lang != NULL;
+ }
break;
- case LFUN_LAYOUT:
+ case LFUN_LAYOUT: {
enable = !cur.inset().forcePlainLayout();
+
+ docstring layout = cmd.argument();
+ if (layout.empty()) {
+ DocumentClass const & tclass = cur.buffer()->params().documentClass();
+ layout = tclass.defaultLayoutName();
+ }
+ flag.setOnOff(layout == cur.paragraph().layout().name());
break;
+ }
case LFUN_ENVIRONMENT_SPLIT: {
if (cmd.argument() == "outer") {