Implement inset-edit in InsetBibtex and add a context menu.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24536 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2008-04-28 15:14:18 +00:00
parent 951dfe70a7
commit a585806b3c
4 changed files with 81 additions and 4 deletions

View File

@ -276,6 +276,13 @@ def checkFormatEntries(dtl_tools):
\Format text3 txt "Plain text (ps2ascii)" "" "" "%%" "document"
\Format text4 txt "Plain text (catdvi)" "" "" "%%" "document"
\Format textparagraph txt "Plain Text, Join Lines" "" "" "%%" "document"''' ])
#
checkViewer('a BibTeX editor', ['sensible-editor', 'pybliographic', 'bibdesk', 'gbib', 'kbib', \
'kbibtex', 'sixpack', 'bibedit', 'tkbibtex' \
'xemacs', 'gvim', 'kedit', 'kwrite', 'kate', \
'nedit', 'gedit', 'notepad'],
rc_entry = [r'''\Format asciichess asc "Plain text (chess output)" "" "" "%%" ""
\Format bibtex bib "BibTeX" "" "" "%%" ""''' ])
#
#checkProg('a Postscript interpreter', ['gs'],
# rc_entry = [ r'\ps_command "%%"' ])

View File

@ -83,10 +83,6 @@ Menuset
Item "Settings...|S" "next-inset-toggle"
End
Menu "edit_reftype"
End
#
# InsetLabel context menu
#
@ -97,6 +93,17 @@ Menuset
Item "Settings...|S" "next-inset-toggle"
End
#
# InsetBibtex context menu
#
Menu "context-bibtex"
Item "Settings...|S" "next-inset-toggle"
Separator
Item "Edit Database(s) externally...|x" "inset-edit"
End
#
# InsetCollapsable context menu
#

View File

@ -17,7 +17,9 @@
#include "BufferParams.h"
#include "DispatchResult.h"
#include "Encoding.h"
#include "Format.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LaTeXFeatures.h"
#include "MetricsInfo.h"
#include "OutputParams.h"
@ -25,6 +27,7 @@
#include "frontends/alert.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/ExceptionMessage.h"
@ -67,6 +70,10 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
case LFUN_INSET_EDIT:
editDatabases();
break;
case LFUN_INSET_MODIFY: {
InsetCommandParams p(BIBTEX_CODE);
try {
@ -96,6 +103,49 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd)
}
bool InsetBibtex::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
switch (cmd.action) {
case LFUN_INSET_EDIT:
flag.enabled(true);
return true;
default:
return InsetCommand::getStatus(cur, cmd, flag);
}
}
void InsetBibtex::editDatabases() const
{
vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
if (bibfilelist.empty())
return;
int nr_databases = bibfilelist.size();
if (nr_databases > 1) {
docstring message = bformat(_("The BibTeX inset includes %1$s databases.\n"
"If you proceed, all of them will be opened."),
convert<docstring>(nr_databases));
int const ret = Alert::prompt(_("Open Databases?"),
message, 0, 1, _("&Cancel"), _("&Proceed"));
if (ret == 0)
return;
}
vector<docstring>::const_iterator it = bibfilelist.begin();
vector<docstring>::const_iterator en = bibfilelist.end();
for (; it != en; ++it) {
FileName bibfile = getBibTeXPath(*it, buffer());
formats.edit(buffer(), bibfile,
formats.getFormatFromFile(bibfile));
}
}
docstring InsetBibtex::screenLabel() const
{
return _("BibTeX Generated Bibliography");
@ -808,4 +858,10 @@ void InsetBibtex::validate(LaTeXFeatures & features) const
}
docstring InsetBibtex::contextMenu(BufferView const &, int, int) const
{
return from_ascii("context-bibtex");
}
} // namespace lyx

View File

@ -59,10 +59,17 @@ public:
/// look up the path to the file using TeX
static support::FileName
getBibTeXPath(docstring const & filename, Buffer const & buf);
///
docstring contextMenu(BufferView const &, int, int) const;
private:
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///
bool getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const;
///
void editDatabases() const;
///
Inset * clone() const { return new InsetBibtex(*this); }
};