X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetCitation.cpp;h=a9597ca872b8d8939d52a2e2355aaa257d9730be;hb=c3a8b3a566e9e90f9ade72acbc723232d721d0b1;hp=69367f6afb175d530348613ae0ffd90e3e70ec99;hpb=07b6198f4c3aa6dfe3245394b660966fd3e85c99;p=lyx.git diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 69367f6afb..a9597ca872 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -15,44 +15,29 @@ #include "Buffer.h" #include "BufferParams.h" -#include "debug.h" +#include "support/debug.h" #include "DispatchResult.h" +#include "support/gettext.h" +#include "EmbeddedFiles.h" #include "FuncRequest.h" #include "LaTeXFeatures.h" -#include "support/fs_extras.h" #include "support/lstrings.h" +#include "support/docstream.h" #include -#include -#include - +using namespace std; +using namespace lyx::support; namespace lyx { -using support::FileName; -using support::getStringFromVector; -using support::getVectorFromString; -using support::ltrim; -using support::prefixIs; -using support::rtrim; -using support::split; -using support::tokenPos; - -using std::endl; -using std::string; -using std::vector; - -namespace fs = boost::filesystem; - - namespace { vector const init_possible_cite_commands() { char const * const possible[] = { - "cite", "citet", "citep", "citealt", "citealp", + "cite", "nocite", "citet", "citep", "citealt", "citealp", "citeauthor", "citeyear", "citeyearpar", "citet*", "citep*", "citealt*", "citealp*", "citeauthor*", "Citet", "Citep", "Citealt", "Citealp", "Citeauthor", @@ -107,7 +92,7 @@ string const string output; switch (engine) { case biblio::ENGINE_BASIC: - output = default_str; + output = input; break; case biblio::ENGINE_NATBIB_AUTHORYEAR: @@ -141,7 +126,7 @@ string const } -docstring const getNatbibLabel(Buffer const & buffer, +docstring const getComplexLabel(Buffer const & buffer, string const & citeType, docstring const & keyList, docstring const & before, docstring const & after, biblio::CiteEngine engine) @@ -151,33 +136,24 @@ docstring const getNatbibLabel(Buffer const & buffer, return docstring(); // Cache the labels - typedef std::map CachedMap; + typedef map CachedMap; static CachedMap cached_keys; // and cache the timestamp of the bibliography files. - static std::map bibfileStatus; + static map bibfileStatus; BiblioInfo biblist; - vector const & bibfilesCache = buffer.getBibfilesCache(); + EmbeddedFileList const & bibfilesCache = buffer.getBibfilesCache(); // compare the cached timestamps with the actual ones. bool changed = false; - for (vector::const_iterator it = bibfilesCache.begin(); + for (EmbeddedFileList::const_iterator it = bibfilesCache.begin(); it != bibfilesCache.end(); ++ it) { FileName const f = *it; - try { - std::time_t lastw = f.lastModified(); - if (lastw != bibfileStatus[f]) { - changed = true; - bibfileStatus[f] = lastw; - } - } - catch (fs::filesystem_error & fserr) { + time_t lastw = f.lastModified(); + if (lastw != bibfileStatus[f]) { changed = true; - lyxerr << "Couldn't find or read bibtex file " - << f << endl; - LYXERR(Debug::DEBUG) << "Fs error: " - << fserr.what() << endl; + bibfileStatus[f] = lastw; } } @@ -234,16 +210,25 @@ docstring const getNatbibLabel(Buffer const & buffer, } docstring after_str; - if (!after.empty()) { - // The "after" key is appended only to the end of the whole. + // The "after" key is appended only to the end of the whole. + if (cite_type == "nocite") + after_str = " (" + _("not cited") + ')'; + else if (!after.empty()) { after_str = ", " + after; } // One day, these might be tunable (as they are in BibTeX). - char const op = '('; // opening parenthesis. - char const cp = ')'; // closing parenthesis. - // puctuation mark separating citation entries. - char const * const sep = ";"; + char op, cp; // opening and closing parenthesis. + char * sep; // punctuation mark separating citation entries. + if (engine == biblio::ENGINE_BASIC) { + op = '['; + cp = ']'; + sep = ","; + } else { + op = '('; + cp = ')'; + sep = ";"; + } docstring const op_str = ' ' + docstring(1, op); docstring const cp_str = docstring(1, cp) + ' '; @@ -264,11 +249,19 @@ docstring const getNatbibLabel(Buffer const & buffer, // authors1/; ... ; // authors_last, - if (cite_type == "cite" && engine == biblio::ENGINE_JURABIB) { - if (it == keys.begin()) - label += author + before_str + sep_str; - else - label += author + sep_str; + if (cite_type == "cite") { + if (engine == biblio::ENGINE_BASIC) { + label += *it + sep_str; + } else if (engine == biblio::ENGINE_JURABIB) { + if (it == keys.begin()) + label += author + before_str + sep_str; + else + label += author + sep_str; + } + + // nocite + } else if (cite_type == "nocite") { + label += *it + sep_str; // (authors1 ( year); ... ; // authors_last ( year, ) @@ -349,7 +342,8 @@ docstring const getNatbibLabel(Buffer const & buffer, label = before_str + label; } - if (cite_type == "citep" || cite_type == "citeyearpar") + if (cite_type == "citep" || cite_type == "citeyearpar" || + (cite_type == "cite" && engine == biblio::ENGINE_BASIC) ) label = op + label + cp; return label; @@ -358,8 +352,6 @@ docstring const getNatbibLabel(Buffer const & buffer, docstring const getBasicLabel(docstring const & keyList, docstring const & after) { - using support::contains; - docstring keys = keyList; docstring label; @@ -388,7 +380,7 @@ InsetCitation::InsetCitation(InsetCommandParams const & p) {} -CommandInfo const * InsetCitation::findInfo(std::string const & /* cmdName */) +CommandInfo const * InsetCitation::findInfo(string const & /* cmdName */) { // standard cite does only take one argument if jurabib is // not used, but jurabib extends this to two arguments, so @@ -402,11 +394,11 @@ CommandInfo const * InsetCitation::findInfo(std::string const & /* cmdName */) } -bool InsetCitation::isCompatibleCommand(std::string const & cmd) +bool InsetCitation::isCompatibleCommand(string const & cmd) { vector const & possibles = possible_cite_commands(); vector::const_iterator const end = possibles.end(); - return std::find(possibles.begin(), end, cmd) != end; + return find(possibles.begin(), end, cmd) != end; } @@ -417,15 +409,12 @@ docstring const InsetCitation::generateLabel(Buffer const & buffer) const docstring label; biblio::CiteEngine const engine = buffer.params().getEngine(); - if (engine != biblio::ENGINE_BASIC) { - label = getNatbibLabel(buffer, getCmdName(), getParam("key"), - before, after, engine); - } + label = getComplexLabel(buffer, getCmdName(), getParam("key"), + before, after, engine); // Fallback to fail-safe - if (label.empty()) { + if (label.empty()) label = getBasicLabel(getParam("key"), after); - } return label; } @@ -494,17 +483,16 @@ static docstring const cleanupWhitespace(docstring const & citelist) int InsetCitation::docbook(Buffer const &, odocstream & os, OutputParams const &) const { - os << "" + os << from_ascii("") << cleanupWhitespace(getParam("key")) - << ""; + << from_ascii(""); return 0; } -int InsetCitation::textString(Buffer const & buf, odocstream & os, - OutputParams const & op) const +void InsetCitation::textString(Buffer const & buf, odocstream & os) const { - return plaintext(buf, os, op); + plaintext(buf, os, OutputParams(0)); }