Enable Open Citation menu item iff citation contain locator information or external search script is available.

Per Juergen's request.
This commit is contained in:
Pavel Sanda 2020-08-23 22:19:34 +02:00
parent 9c9a2c1b92
commit 894ad70eba
7 changed files with 70 additions and 11 deletions

View File

@ -49,6 +49,9 @@
* \ct_markup_copied true|false: determines whether change tracking markup should be * \ct_markup_copied true|false: determines whether change tracking markup should be
preserved on copy/paste (default: false). preserved on copy/paste (default: false).
* \citation_search_view lyxpaperview: determines whether external script "lyxpaperview"
should be used for looking up citation source.
!!!The following pref variables were changed in 2.4: !!!The following pref variables were changed in 2.4:

View File

@ -1310,6 +1310,8 @@ def checkOtherEntries():
rc_entry = [ r'\nomencl_command "makeindex -s nomencl.ist"' ]) rc_entry = [ r'\nomencl_command "makeindex -s nomencl.ist"' ])
checkProg('a python-pygments driver command', ['pygmentize'], checkProg('a python-pygments driver command', ['pygmentize'],
rc_entry = [ r'\pygmentize_command "%%"' ]) rc_entry = [ r'\pygmentize_command "%%"' ])
checkProg('external script for searching and showing citation sources',
['lyxpaperview'], rc_entry = [ r'\citation_search_view "%%"' ])
## FIXME: OCTAVE is not used anywhere ## FIXME: OCTAVE is not used anywhere
# path, OCTAVE = checkProg('Octave', ['octave']) # path, OCTAVE = checkProg('Octave', ['octave'])
## FIXME: MAPLE is not used anywhere ## FIXME: MAPLE is not used anywhere
@ -1875,7 +1877,7 @@ if __name__ == '__main__':
lyx_check_config = True lyx_check_config = True
lyx_kpsewhich = True lyx_kpsewhich = True
outfile = 'lyxrc.defaults' outfile = 'lyxrc.defaults'
lyxrc_fileformat = 31 lyxrc_fileformat = 33
rc_entries = '' rc_entries = ''
lyx_keep_temps = False lyx_keep_temps = False
version_suffix = '' version_suffix = ''

View File

@ -129,6 +129,11 @@
# Add ct_markup_copied. # Add ct_markup_copied.
# No convergence necessary. # No convergence necessary.
# Incremented to format 33, by sanda
# Add \citation_search_view.
# No conversion necessary.
# NOTE: The format should also be updated in LYXRC.cpp and # NOTE: The format should also be updated in LYXRC.cpp and
# in configure.py. # in configure.py.
@ -479,5 +484,6 @@ conversions = [
[ 29, [remove_use_pixmap_cache]], [ 29, [remove_use_pixmap_cache]],
[ 30, []], [ 30, []],
[ 31, []], [ 31, []],
[ 32, []] [ 32, []],
[ 33, []]
] ]

View File

@ -61,7 +61,7 @@ namespace {
// The format should also be updated in configure.py, and conversion code // The format should also be updated in configure.py, and conversion code
// should be added to prefs2prefs_prefs.py. // should be added to prefs2prefs_prefs.py.
static unsigned int const LYXRC_FILEFORMAT = 32; // spitz: add \ct_markup_copied static unsigned int const LYXRC_FILEFORMAT = 33; // sanda: add \citation_search_view
// when adding something to this array keep it sorted! // when adding something to this array keep it sorted!
LexerKeyword lyxrcTags[] = { LexerKeyword lyxrcTags[] = {
{ "\\accept_compound", LyXRC::RC_ACCEPT_COMPOUND }, { "\\accept_compound", LyXRC::RC_ACCEPT_COMPOUND },
@ -78,6 +78,7 @@ LexerKeyword lyxrcTags[] = {
{ "\\bind_file", LyXRC::RC_BINDFILE }, { "\\bind_file", LyXRC::RC_BINDFILE },
{ "\\check_lastfiles", LyXRC::RC_CHECKLASTFILES }, { "\\check_lastfiles", LyXRC::RC_CHECKLASTFILES },
{ "\\chktex_command", LyXRC::RC_CHKTEX_COMMAND }, { "\\chktex_command", LyXRC::RC_CHKTEX_COMMAND },
{ "\\citation_search_view", LyXRC::RC_CITATION_SEARCH_VIEW },
{ "\\close_buffer_with_last_view", LyXRC::RC_CLOSE_BUFFER_WITH_LAST_VIEW }, { "\\close_buffer_with_last_view", LyXRC::RC_CLOSE_BUFFER_WITH_LAST_VIEW },
{ "\\completion_cursor_text", LyXRC::RC_COMPLETION_CURSOR_TEXT }, { "\\completion_cursor_text", LyXRC::RC_COMPLETION_CURSOR_TEXT },
{ "\\completion_inline_delay", LyXRC::RC_COMPLETION_INLINE_DELAY }, { "\\completion_inline_delay", LyXRC::RC_COMPLETION_INLINE_DELAY },
@ -679,6 +680,10 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
} }
break; break;
case RC_CITATION_SEARCH_VIEW:
lexrc >> citation_search_view;
break;
case RC_CT_ADDITIONS_UNDERLINED: case RC_CT_ADDITIONS_UNDERLINED:
lexrc >> ct_additions_underlined; lexrc >> ct_additions_underlined;
break; break;
@ -1602,6 +1607,15 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
if (tag != RC_LAST) if (tag != RC_LAST)
break; break;
// fall through // fall through
case RC_CITATION_SEARCH_VIEW:
if (ignore_system_lyxrc ||
citation_search_view != system_lyxrc.citation_search_view) {
os << "\\citaton_search_view "
<< citation_search_view << '\n';
}
if (tag != RC_LAST)
break;
// fall through
case RC_CT_ADDITIONS_UNDERLINED: case RC_CT_ADDITIONS_UNDERLINED:
if (ignore_system_lyxrc || if (ignore_system_lyxrc ||
ct_additions_underlined ct_additions_underlined
@ -2774,6 +2788,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
case LyXRC::RC_BIBTEX_ALTERNATIVES: case LyXRC::RC_BIBTEX_ALTERNATIVES:
case LyXRC::RC_BIBTEX_COMMAND: case LyXRC::RC_BIBTEX_COMMAND:
case LyXRC::RC_BINDFILE: case LyXRC::RC_BINDFILE:
case LyXRC::RC_CITATION_SEARCH_VIEW:
case LyXRC::RC_CHECKLASTFILES: case LyXRC::RC_CHECKLASTFILES:
case LyXRC::RC_COMPLETION_CURSOR_TEXT: case LyXRC::RC_COMPLETION_CURSOR_TEXT:
case LyXRC::RC_COMPLETION_INLINE_DELAY: case LyXRC::RC_COMPLETION_INLINE_DELAY:

View File

@ -53,6 +53,7 @@ public:
RC_BINDFILE, RC_BINDFILE,
RC_CHECKLASTFILES, RC_CHECKLASTFILES,
RC_CHKTEX_COMMAND, RC_CHKTEX_COMMAND,
RC_CITATION_SEARCH_VIEW,
RC_COMPLETION_CURSOR_TEXT, RC_COMPLETION_CURSOR_TEXT,
RC_COMPLETION_INLINE_DELAY, RC_COMPLETION_INLINE_DELAY,
RC_COMPLETION_INLINE_MATH, RC_COMPLETION_INLINE_MATH,
@ -243,6 +244,13 @@ public:
/// default paper size for local xdvi/dvips/ghostview/whatever /// default paper size for local xdvi/dvips/ghostview/whatever
/// command to run chktex incl. options /// command to run chktex incl. options
std::string chktex_command = "chktex -n1 -n3 -n6 -n9 -n22 -n25 -n30 -n38"; std::string chktex_command = "chktex -n1 -n3 -n6 -n9 -n22 -n25 -n30 -n38";
// Name of external script, which searches for file corresponding to a
// given citation. At this moment only script "lyxpaperview" is supported
// (search for pdf based on author+year), but we can generalize if requested.
// Citation context menu item "Open Citation Content" will be always enabled
// if the name of this script in nonempty (last resort when citation entry
// does not contain neccessary info.
std::string citation_search_view;
/// all available commands to run bibtex incl. options /// all available commands to run bibtex incl. options
CommandSet bibtex_alternatives; CommandSet bibtex_alternatives;
/// command to run bibtex incl. options /// command to run bibtex incl. options

View File

@ -24,6 +24,7 @@
#include "FuncStatus.h" #include "FuncStatus.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "LyX.h" #include "LyX.h"
#include "LyXRC.h"
#include "output_xhtml.h" #include "output_xhtml.h"
#include "output_docbook.h" #include "output_docbook.h"
#include "ParIterator.h" #include "ParIterator.h"
@ -168,20 +169,41 @@ void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
} }
} }
bool InsetCitation::openCitationPossible() const
void InsetCitation::openCitation(){ {
Buffer const & buf = *buffer_; Buffer const & buf = *buffer_;
// Only after the buffer is loaded from file... // only after the buffer is loaded from file...
if (!buf.isFullyLoaded()) if (!buf.isFullyLoaded())
return; return false;
BiblioInfo const & bi = buf.masterBibInfo(); BiblioInfo const & bi = buf.masterBibInfo();
if (bi.empty()) if (bi.empty())
return; return false;
docstring const & key = getParam("key"); docstring const & key = getParam("key");
if (key.empty()) if (key.empty())
return; return false;
// does bibtex item contains some locator?
vector<docstring> keys = getVectorFromString(key);
docstring doi, url, file;
for (docstring const & kvar : keys) {
bi.getLocators(kvar, doi, url, file);
if (!file.empty() || !doi.empty() || !url.empty())
return true;
}
// last resort: is external script available?
if (!lyxrc.citation_search_view.empty())
return true;
return false;
}
void InsetCitation::openCitation()
{
Buffer const & buf = *buffer_;
BiblioInfo const & bi = buf.masterBibInfo();
docstring const & key = getParam("key");
vector<docstring> keys = getVectorFromString(key); vector<docstring> keys = getVectorFromString(key);
docstring year, author, doi, url, file; docstring year, author, doi, url, file;
@ -246,7 +268,7 @@ bool InsetCitation::getStatus(Cursor & cur, FuncRequest const & cmd,
} }
return true; return true;
case LFUN_INSET_EDIT: case LFUN_INSET_EDIT:
return true; return openCitationPossible();
default: default:
return InsetCommand::getStatus(cur, cmd, status); return InsetCommand::getStatus(cur, cmd, status);
} }

View File

@ -94,7 +94,10 @@ public:
QualifiedList getQualifiedLists(docstring const & p) const; QualifiedList getQualifiedLists(docstring const & p) const;
/// ///
static bool last_literal; static bool last_literal;
/// /// Check whether citation contains necessary url/file entries
/// or external search script is available
bool openCitationPossible() const;
/// search and open citation source
void openCitation(); void openCitation();
private: private: