#include "debug.h"
#include "gettext.h"
#include "errorlist.h"
+#include "funcrequest.h"
#include "iterators.h"
#include "language.h"
#include "lyxcursor.h"
#include "support/filetools.h"
#include "support/types.h"
#include "support/lyxalgo.h" // lyx_count
+#include "support/LAssert.h"
#include <fstream>
//
// Moved from lyx_cb.C (Lgb)
{
- if (filen.empty())
- return false;
+ Assert(!filen.empty());
string const fname = MakeAbsPath(filen);
- // check if file exist
- FileInfo const fi(fname);
-
- if (!fi.readable()) {
- string const file = MakeDisplayPath(fname, 50);
- string const text =
- bformat(_("The specified document\n%1$s\ncould not be read."), file);
- Alert::error(_("Could not read document"), text);
- return false;
- }
-
beforeChange(text);
- ifstream ifs(fname.c_str());
- if (!ifs) {
- string const file = MakeDisplayPath(fname, 50);
- string const text =
- bformat(_("Could not open the specified document %1$s\n"), file);
- Alert::error(_("Could not open file"), text);
- return false;
- }
-
- int const c = ifs.peek();
-
- LyXLex lex(0, 0);
- lex.setStream(ifs);
-
- bool res = true;
-
text->breakParagraph(buffer()->paragraphs);
- if (c == '#') {
- // FIXME: huh ? No we won't !
- lyxerr[Debug::INFO] << "Will insert file with header" << endl;
- res = buffer()->readFile(lex, fname, ParagraphList::iterator(text->cursor.par()));
- } else {
- lyxerr[Debug::INFO] << "Will insert file without header"
- << endl;
- res = buffer()->readBody(lex, ParagraphList::iterator(text->cursor.par()));
- }
+ bool res = buffer()->readFile(fname, text->cursor.par());
resize();
return res;
tt->setSelectionRange(replacestring.length());
// Go back so that replacement string is also spellchecked
- for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
+ for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
tt->cursorLeft(this);
// FIXME: should be done through LFUN
bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
{
if (theLockingInset() && available()) {
- y += text->cursor.iy() + theLockingInset()->insetInInsetY();
+ y += text->cursor.y() + theLockingInset()->insetInInsetY();
if (screen().fitManualCursor(this, text, x, y, asc, desc)) {
updateScrollbar();
return true;
}
-LyXText * BufferView::getParentText(InsetOld * inset) const
-{
- if (inset->owner()) {
- LyXText * txt = inset->getLyXText(this);
- inset = inset->owner();
- while (inset && inset->getLyXText(this) == txt)
- inset = inset->owner();
- if (inset)
- return inset->getLyXText(this);
- }
- return text;
-}
-
-
Language const * BufferView::getParentLanguage(InsetOld * inset) const
{
- LyXText * text = getParentText(inset);
- return text->cursor.par()->getFontSettings(buffer()->params,
- text->cursor.pos()).language();
+ Paragraph const & par = ownerPar(*buffer(), inset);
+ return par.getFontSettings(buffer()->params,
+ par.getPositionOfInset(inset)).language();
}