#include "bufferparams.h"
#include "coordcache.h"
#include "cursor.h"
+#include "CutAndPaste.h"
#include "debug.h"
#include "dispatchresult.h"
#include "factory.h"
void BufferView::Pimpl::MenuInsertLyXFile(string const & filenm)
{
+ BOOST_ASSERT(cursor_.inTexted());
string filename = filenm;
if (filename.empty()) {
string const disp_fn = MakeDisplayPath(filename);
owner_->message(bformat(_("Inserting document %1$s..."), disp_fn));
- cursor_.clearSelection();
- bv_->getLyXText()->breakParagraph(cursor_);
-
- BOOST_ASSERT(cursor_.inTexted());
+ string res;
+ Buffer buf("", false);
+ buf.error.connect(boost::bind(&BufferView::Pimpl::addError, this, _1));
+ if (::loadLyXFile(&buf, MakeAbsPath(filename))) {
+ lyx::cap::pasteParagraphList(cursor_, buf.paragraphs(),
+ buf.params().textclass);
+ res = _("Document %1$s inserted.");
+ } else
+ res = _("Could not insert document %1$s");
- string const fname = MakeAbsPath(filename);
- bool const res = buffer_->readFile(fname, cursor_.pit());
+ owner_->message(bformat(res, disp_fn));
+ bv_->showErrorList(_("Document insertion"));
resizeCurrentBuffer();
-
- string s = res ? _("Document %1$s inserted.")
- : _("Could not insert document %1$s");
- owner_->message(bformat(s, disp_fn));
}
case LFUN_FILE_INSERT:
case LFUN_FILE_INSERT_ASCII_PARA:
case LFUN_FILE_INSERT_ASCII:
+ // FIXME: Actually, these LFUNS should be moved to LyXText
+ flag.enabled(cursor_.inTexted());
+ break;
case LFUN_FONT_STATE:
case LFUN_INSERT_LABEL:
case LFUN_BOOKMARK_SAVE:
+2005-11-29 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
+
+ Fix bug 2096.
+
+ * BufferView_pimpl.C (getStatus): it is only possible to insert a
+ file in a text inset.
+
+ * buffer.C (readDocument): remove pit argument and code releated
+ to it; set the inset owner correctly (unrelated, but useful).
+ (readFile): get rid of pit argument.
+
+ * CutAndPaste.C (pasteSelectionHelper): use a ParagraphList and a
+ textclass instead of a selection index.
+ (pasteParagraphList): new function.
+ (pasteSelection): make it a wrapper around pasteParagraphList.
+
+ * BufferView_pimpl.C (MenuInsertLyXFile): use
+ cap::pasteParagraphList to insert a file.
+
2005-11-29 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* buffer_funcs.C (bufferErrors): prevent endless loop (bug 2121)
2005-11-25 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
- * paragraph.C (asString): use new inset->textString method (fix bug 2089)
+ * paragraph.C (asString): use new inset->textString method (fix
+ bug 2089)
2005-11-24 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
pair<PitPosPair, pit_type>
-pasteSelectionHelper(Buffer const & buffer, ParagraphList & pars,
- pit_type pit, int pos,
- textclass_type tc, size_t cut_index, ErrorList & errorlist)
+pasteSelectionHelper(Buffer const & buffer,
+ ParagraphList & pars, pit_type pit, int pos,
+ ParagraphList const & parlist, textclass_type textclass,
+ ErrorList & errorlist)
{
- if (!checkPastePossible(cut_index))
+ if (parlist.empty())
return make_pair(PitPosPair(pit, pos), pit);
BOOST_ASSERT (pos <= pars[pit].size());
// Make a copy of the CaP paragraphs.
- ParagraphList insertion = theCuts[cut_index].first;
- textclass_type const textclass = theCuts[cut_index].second;
+ ParagraphList insertion = parlist;
+ textclass_type const tc = buffer.params().textclass;
// Now remove all out of the pars which is NOT allowed in the
// new environment and set also another font if that is required.
}
-void pasteSelection(LCursor & cur, size_t sel_index)
+void pasteParagraphList(LCursor & cur, ParagraphList const & parlist,
+ textclass_type textclass)
{
- // this does not make sense, if there is nothing to paste
- lyxerr << "#### pasteSelection " << sel_index << endl;
- if (!checkPastePossible(sel_index))
- return;
-
if (cur.inTexted()) {
LyXText * text = cur.text();
BOOST_ASSERT(text);
pit_type endpit;
PitPosPair ppp;
-
ErrorList el;
boost::tie(ppp, endpit) =
pasteSelectionHelper(cur.buffer(),
text->paragraphs(),
cur.pit(), cur.pos(),
- cur.buffer().params().textclass,
- sel_index, el);
+ parlist, textclass,
+ el);
bufferErrors(cur.buffer(), el);
- cur.bv().showErrorList(_("Paste"));
-
+ updateCounters(cur.buffer());
cur.clearSelection();
text->setCursor(cur, ppp.first, ppp.second);
- cur.setSelection();
- updateCounters(cur.buffer());
}
// mathed is handled in MathNestInset/MathGridInset
}
+void pasteSelection(LCursor & cur, size_t sel_index)
+{
+ // this does not make sense, if there is nothing to paste
+ if (!checkPastePossible(sel_index))
+ return;
+
+ pasteParagraphList(cur, theCuts[sel_index].first,
+ theCuts[sel_index].second);
+ cur.bv().showErrorList(_("Paste"));
+ cur.setSelection();
+}
+
+
void setSelectionRange(LCursor & cur, pos_type length)
{
LyXText * text = cur.text();
///
void pasteSelection(LCursor & cur, size_t sel_index = 0);
+///
+void pasteParagraphList(LCursor & cur, ParagraphList const & parlist,
+ textclass_type textclass);
+
+
/** Needed to switch between different classes. This works
* for a list of paragraphs beginning with the specified par.
* It changes layouts and character styles.
error(ErrorItem(_("Document header error"), s, -1, 0, 0));
}
- if (paragraphs().empty()) {
- readHeader(lex);
- if (!params().getLyXTextClass().load()) {
- string theclass = params().getLyXTextClass().name();
- Alert::error(_("Can't load document class"), bformat(
- "Using the default document class, because the "
- " class %1$s could not be loaded.", theclass));
- params().textclass = 0;
- }
- } else {
- // We don't want to adopt the parameters from the
- // document we insert, so read them into a temporary buffer
- // and then discard it
-
- Buffer tmpbuf("", false);
- tmpbuf.readHeader(lex);
+ // we are reading in a brand new document
+ BOOST_ASSERT(paragraphs().empty());
+
+ readHeader(lex);
+ if (!params().getLyXTextClass().load()) {
+ string theclass = params().getLyXTextClass().name();
+ Alert::error(_("Can't load document class"), bformat(
+ "Using the default document class, because the "
+ " class %1$s could not be loaded.", theclass));
+ params().textclass = 0;
}
- return text().read(*this, lex);
+ bool const res = text().read(*this, lex);
+ for_each(text().paragraphs().begin(),
+ text().paragraphs().end(),
+ bind(&Paragraph::setInsetOwner, _1, &inset()));
+ return res;
}
// remove dummy empty par
paragraphs().clear();
- bool ret = readFile(filename, paragraphs().size());
+ LyXLex lex(0, 0);
+ lex.setFile(filename);
+ bool ret = readFile(lex, filename);
// After we have read a file, we must ensure that the buffer
// language is set and used in the gui.
}
-bool Buffer::readFile(string const & filename, pit_type const pit)
-{
- LyXLex lex(0, 0);
- lex.setFile(filename);
- return readFile(lex, filename, pit);
-}
-
-
bool Buffer::fully_loaded() const
{
return pimpl_->file_fully_loaded;
}
-bool Buffer::readFile(LyXLex & lex, string const & filename, pit_type const pit)
+bool Buffer::readFile(LyXLex & lex, string const & filename)
{
BOOST_ASSERT(!filename.empty());
filename));
return false;
} else {
- bool const ret = readFile(tmpfile, pit);
+ bool const ret = readFile(tmpfile);
// Do stuff with tmpfile name and buffer name here.
return ret;
}
/// load a new file
bool readFile(std::string const & filename);
- bool readFile(std::string const & filename, lyx::pit_type pit);
-
/// read the header, returns number of unknown tokens
int readHeader(LyXLex & lex);
private:
/** Inserts a file into a document
- \param par if != 0 insert the file.
\return \c false if method fails.
*/
- bool readFile(LyXLex &, std::string const & filename,
- lyx::pit_type pit);
+ bool readFile(LyXLex &, std::string const & filename);
bool do_writeFile(std::ostream & ofs) const;