X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer_funcs.cpp;h=fd0a4c32e0aa357d775e81920a0d518e30b41f11;hb=ca339eb1991efcab02a5f1b7f33387b35df2a416;hp=7a8618cc1564d3ebf30557a68dfcabacd507ba5f;hpb=9092bffc32c3a9206818f82265ff9a6db4bc7fbe;p=lyx.git diff --git a/src/buffer_funcs.cpp b/src/buffer_funcs.cpp index 7a8618cc15..fd0a4c32e0 100644 --- a/src/buffer_funcs.cpp +++ b/src/buffer_funcs.cpp @@ -180,6 +180,47 @@ bool loadLyXFile(Buffer * b, FileName const & s) return false; } + +Buffer * checkAndLoadLyXFile(FileName const & filename) +{ + // File already open? + if (theBufferList().exists(filename.absFilename())) { + docstring const file = makeDisplayPath(filename.absFilename(), 20); + docstring text = bformat(_("The document %1$s is already " + "loaded.\n\nDo you want to revert " + "to the saved version?"), file); + if (Alert::prompt(_("Revert to saved document?"), + text, 0, 1, _("&Revert"), _("&Switch to document"))) + return theBufferList().getBuffer(filename.absFilename()); + + // FIXME: should be LFUN_REVERT + if (theBufferList().close(theBufferList().getBuffer(filename.absFilename()), false)) + // Load it again. + return checkAndLoadLyXFile(filename); + else + // The file could not be closed. + return 0; + } + + if (isFileReadable(filename)) { + Buffer * b = theBufferList().newBuffer(filename.absFilename()); + if (!lyx::loadLyXFile(b, filename)) { + theBufferList().release(b); + return 0; + } + return b; + } + + docstring text = bformat(_("The document %1$s does not yet " + "exist.\n\nDo you want to create a new document?"), + from_utf8(filename.absFilename())); + if (!Alert::prompt(_("Create new document?"), + text, 0, 1, _("&Create"), _("Cancel"))) + return newFile(filename.absFilename(), string(), true); + + return 0; +} + // FIXME newFile() should probably be a member method of Application... Buffer * newFile(string const & filename, string const & templatename, bool const isNamed) @@ -377,7 +418,7 @@ void setCaptionLabels(Inset & inset, string const & type, setCaptionLabels(icap, type, label, counters); if (icap.lyxCode() == Inset::CAPTION_CODE) { // We found a caption! - counters.step(counter); + counters.step(counter); int number = counters.value(counter); InsetCaption & ic = static_cast(icap); ic.setType(type); @@ -400,7 +441,7 @@ void setCaptions(Paragraph & par, TextClass const & textclass) InsetList::iterator end = par.insetlist.end(); for (; it != end; ++it) { Inset & inset = *it->inset; - if (inset.lyxCode() == Inset::FLOAT_CODE + if (inset.lyxCode() == Inset::FLOAT_CODE || inset.lyxCode() == Inset::WRAP_CODE) { docstring const name = inset.name(); if (name.empty()) @@ -419,6 +460,10 @@ void setCaptions(Paragraph & par, TextClass const & textclass) } else if (inset.lyxCode() == Inset::LISTINGS_CODE) setCaptionLabels(inset, "listing", from_ascii("Listing"), counters); + else if (inset.lyxCode() == Inset::INCLUDE_CODE) + // if this include inset contains lstinputlisting, and has a caption + // it will increase the 'listing' counter by one + static_cast(inset).updateCounter(counters); } } @@ -705,8 +750,7 @@ void updateLabels(Buffer const & buf, bool childonly) void checkBufferStructure(Buffer & buffer, ParIterator const & par_it) { - if (par_it->layout()->labeltype == LABEL_COUNTER - && par_it->layout()->toclevel != Layout::NOT_IN_TOC) { + if (par_it->layout()->toclevel != Layout::NOT_IN_TOC) { Buffer * master = buffer.getMasterBuffer(); master->tocBackend().updateItem(par_it); master->structureChanged();