>>>>> "Georg" == Georg Baum <[EMAIL PROTECTED]> writes:
Georg> I could only find one: The error list is not shown if the file
Georg> is corrupt. This could probably be fixed by handing the temp
Georg> buffer to InsertLyXFile:
Is it really necessary to disconnect, or is it done when the buffer is
deleted?
Here is my new update patch, where I removed the code in
buffer_funcs.*, since it was so short.
Is it OK?
JMarc
Index: src/BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.599
diff -u -p -r1.599 BufferView_pimpl.C
--- src/BufferView_pimpl.C 7 Nov 2005 15:06:41 -0000 1.599
+++ src/BufferView_pimpl.C 29 Nov 2005 11:20:49 -0000
@@ -25,6 +25,7 @@
#include "bufferparams.h"
#include "coordcache.h"
#include "cursor.h"
+#include "CutAndPaste.h"
#include "debug.h"
#include "dispatchresult.h"
#include "factory.h"
@@ -831,6 +832,7 @@ void BufferView::Pimpl::stuffClipboard(s
void BufferView::Pimpl::MenuInsertLyXFile(string const & filenm)
{
+ BOOST_ASSERT(cursor_.inTexted());
string filename = filenm;
if (filename.empty()) {
@@ -875,18 +877,19 @@ void BufferView::Pimpl::MenuInsertLyXFil
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));
}
@@ -1022,6 +1025,9 @@ FuncStatus BufferView::Pimpl::getStatus(
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:
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.2330
diff -u -p -r1.2330 ChangeLog
--- src/ChangeLog 28 Nov 2005 18:58:15 -0000 1.2330
+++ src/ChangeLog 29 Nov 2005 11:20:50 -0000
@@ -1,3 +1,22 @@
+2005-11-29 Jean-Marc Lasgouttes <[EMAIL PROTECTED]>
+
+ 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-17 Michael Gerz <[EMAIL PROTECTED]>
* exporter.C: fix typo in text message
@@ -12,7 +31,8 @@
2005-11-25 Jürgen Spitzmüller <[EMAIL PROTECTED]>
- * 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 <[EMAIL PROTECTED]>
Index: src/CutAndPaste.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/CutAndPaste.C,v
retrieving revision 1.159
diff -u -p -r1.159 CutAndPaste.C
--- src/CutAndPaste.C 25 Nov 2005 09:27:08 -0000 1.159
+++ src/CutAndPaste.C 29 Nov 2005 11:20:50 -0000
@@ -105,18 +105,19 @@ bool checkPastePossible(int index)
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.
@@ -608,13 +609,9 @@ std::string getSelection(Buffer const &
}
-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);
@@ -623,26 +620,36 @@ void pasteSelection(LCursor & cur, size_
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
BOOST_ASSERT(!cur.inMathed());
+}
+
+
+void pasteSelection(LCursor & cur, size_t sel_index)
+{
+ // this does not make sense, if there is nothing to paste
+ lyxerr[Debug::DEBUG] << "#### pasteSelection " << sel_index << endl;
+ if (!checkPastePossible(sel_index))
+ return;
+
+ pasteParagraphList(cur, theCuts[sel_index].first,
+ theCuts[sel_index].second);
+ cur.bv().showErrorList(_("Paste"));
+ cur.setSelection();
}
Index: src/CutAndPaste.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/CutAndPaste.h,v
retrieving revision 1.42
diff -u -p -r1.42 CutAndPaste.h
--- src/CutAndPaste.h 25 Nov 2005 09:27:08 -0000 1.42
+++ src/CutAndPaste.h 29 Nov 2005 11:20:50 -0000
@@ -56,6 +56,11 @@ void copySelection(LCursor & cur);
///
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.
Index: src/buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.629
diff -u -p -r1.629 buffer.C
--- src/buffer.C 13 Oct 2005 10:59:37 -0000 1.629
+++ src/buffer.C 29 Nov 2005 11:20:50 -0000
@@ -470,25 +470,23 @@ bool Buffer::readDocument(LyXLex & lex)
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());
- return text().read(*this, lex);
+ 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;
+ }
+
+ bool const res = text().read(*this, lex);
+ for_each(text().paragraphs().begin(),
+ text().paragraphs().end(),
+ bind(&Paragraph::setInsetOwner, _1, &inset()));
+ return res;
}
@@ -556,7 +554,9 @@ bool Buffer::readFile(string const & fil
// 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.
@@ -567,14 +567,6 @@ bool Buffer::readFile(string const & fil
}
-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;
@@ -587,7 +579,7 @@ void Buffer::fully_loaded(bool const val
}
-bool Buffer::readFile(LyXLex & lex, string const & filename, pit_type const pit)
+bool Buffer::readFile(LyXLex & lex, string const & filename)
{
BOOST_ASSERT(!filename.empty());
@@ -668,7 +660,7 @@ bool Buffer::readFile(LyXLex & lex, stri
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;
}
Index: src/buffer.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.h,v
retrieving revision 1.193
diff -u -p -r1.193 buffer.h
--- src/buffer.h 17 Jul 2005 23:02:58 -0000 1.193
+++ src/buffer.h 29 Nov 2005 11:20:50 -0000
@@ -93,8 +93,6 @@ public:
/// 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);
@@ -338,11 +336,9 @@ public:
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;
Index: src/frontends/controllers/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ChangeLog,v
retrieving revision 1.501
diff -u -p -r1.501 ChangeLog
--- src/frontends/controllers/ChangeLog 2 Nov 2005 20:11:35 -0000 1.501
+++ src/frontends/controllers/ChangeLog 29 Nov 2005 11:20:50 -0000
@@ -1,3 +1,8 @@
+2005-11-28 Jean-Marc Lasgouttes <[EMAIL PROTECTED]>
+
+ * ControlErrorList.C (goTo): give a better error message when pid
+ is not found.
+
2005-11-02 Angus Leeming <[EMAIL PROTECTED]>
* helper_funcs.C: trivial fix to a MSVS warning.
Index: src/frontends/controllers/ControlErrorList.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlErrorList.C,v
retrieving revision 1.27
diff -u -p -r1.27 ControlErrorList.C
--- src/frontends/controllers/ControlErrorList.C 3 Jun 2005 08:48:04 -0000 1.27
+++ src/frontends/controllers/ControlErrorList.C 29 Nov 2005 11:20:50 -0000
@@ -64,7 +64,7 @@ void ControlErrorList::goTo(int item)
ParIterator pit = buf.getParFromID(err.par_id);
if (pit == buf.par_iterator_end()) {
- lyxerr << "par id not found" << endl;
+ lyxerr << "par id " << err.par_id << " not found" << endl;
return;
}