src/support/ChangeLog

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7650 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-09-03 17:28:39 +00:00
parent a4fc784124
commit 9498f9758f
14 changed files with 1327 additions and 555 deletions

View File

@ -18,7 +18,8 @@
import re import re
from parser_tools import find_token, find_tokens, find_end_of_inset from parser_tools import find_token, find_tokens, find_end_of_inset
from sys import stderr from sys import stderr
from string import replace, split from string import replace, split, strip
import re
def add_end_layout(lines): def add_end_layout(lines):
i = find_token(lines, '\\layout', 0) i = find_token(lines, '\\layout', 0)
@ -105,11 +106,77 @@ def end_document(lines):
return return
lines[i] = "\\end_document" lines[i] = "\\end_document"
def convert_bibtex(lines):
bibtex_header = "\\begin_inset LatexCommand \\bibtex"
i = 0
while 1:
i = find_token(lines, bibtex_header, i)
if i == -1:
break
# We've found a bibtex inset.
# I'd like to strip bibtex_header from the front of lines[i]
lines[i] = replace(lines[i], bibtex_header, "")
# Trim any space at extremes
lines[i] = strip(lines[i])
# Does the thing have an opt arg?
optarg_rexp = re.compile(r'^\[([^]]*)\]')
optarg = optarg_rexp.search(lines[i])
optarg_contents = ''
if optarg:
optarg_contents = optarg.group(1)
# strip [<optarg_contents>] from the front of lines[i]
lines[i] = replace (lines[i], '[' + optarg.group(0) + ']', '')
# lines[i] should now contain "{<list of databases>}"
mainarg_rexp = re.compile(r'{([^}]*)}')
mainarg = mainarg_rexp.search(lines[i])
mainarg_contents = ''
if mainarg:
mainarg_contents = mainarg.group(1)
else:
# complain about a mal-formed lyx file.
stderr.write("Mal-formed bibitem\n")
# optarg will contain either
# "bibtotoc,<style>"
# or
# "<style>"
# ie, these are a comma-separated list of arguments.
optarg_list = split(optarg_contents, ',')
if len(optarg_list) == 0:
bibtotoc, style = '',''
elif len(optarg_list) == 1:
bibtotoc, style = '',optarg_list[0]
else:
bibtotoc, style = 'true',optarg_list[1]
# mainarg will contain a comma-separated list of files.
mainarg_list = split( mainarg_contents, ',')
new_syntax = ['\\begin_inset Bibtex']
for file in mainarg_list:
new_syntax.append('\t' + 'filename ' + file)
if style:
new_syntax.append('\t' + 'style ' + style)
if bibtotoc == 'true':
new_syntax.append('\t' + 'bibtotoc ' + bibtotoc)
# Replace old syntax with new
lines[i:i+1] = new_syntax
i = i + len(new_syntax) + 1
def convert(header, body): def convert(header, body):
add_end_layout(body) add_end_layout(body)
layout2begin_layout(body) layout2begin_layout(body)
end_document(body) end_document(body)
table_valignment_middle(body) table_valignment_middle(body)
convert_bibtex(body)
if __name__ == "__main__": if __name__ == "__main__":
pass pass

View File

@ -51,15 +51,16 @@
# \converter lyxpreview ${FORMAT} "lyxpreview2bitmap.sh" "" # \converter lyxpreview ${FORMAT} "lyxpreview2bitmap.sh" ""
# where ${FORMAT} is either ppm or png. # where ${FORMAT} is either ppm or png.
# These four programs are used by the script. # These programs are used by the script.
# Adjust their names to suit your setup. # Adjust their names to suit your setup.
test -n "$LATEX" || LATEX=latex test -n "$LATEX" || LATEX=latex
DVIPNG=/home/angus/preview-latex/devel/dvipng/dvipng
DVIPS=dvips DVIPS=dvips
GS=gs GS=gs
PNMCROP=pnmcrop PNMCROP=pnmcrop
readonly LATEX DVIPS GS PNMCROP readonly LATEX DVIPS GS PNMCROP
# Three helper functions. # Some helper functions.
FIND_IT () FIND_IT ()
{ {
test $# -eq 1 || exit 1 test $# -eq 1 || exit 1
@ -89,40 +90,118 @@ REQUIRED_VERSION ()
grep 'Package: preview' $1 grep 'Package: preview' $1
} }
CHECK_FOR_PROGRAMS () {
test $# -eq 1 || exit 1
if [ $1 = "ppm" ]; then
# We use latex, dvips and gs, so check that they're all there.
FIND_IT ${LATEX}
FIND_IT ${DVIPS}
FIND_IT ${GS}
elif [ "$3" = "png" ]; then
# We use latex and dvipng
FIND_IT ${LATEX}
FIND_IT ${DVIPNG}
fi
}
GENERATE_PPM_FILES () {
test $# -eq 2 || exit 1
BASE=$1
RESOLUTION=$2
# DVI -> PostScript
PSFILE=${1}.ps
${DVIPS} -o ${PSFILE} ${DVIFILE} || {
BAIL_OUT "Failed: ${DVIPS} -o ${PSFILE} ${DVIFILE}"
}
# PostScript -> Bitmap files
# Older versions of gs have problems with a large degree of
# anti-aliasing at high resolutions
# test expects integer arguments.
# ${RESOLUTION} may be a float. Truncate it.
INT_RESOLUTION=`echo "${RESOLUTION} / 1" | bc`
ALPHA=4
if [ ${INT_RESOLUTION} -gt 150 ]; then
ALPHA=2
fi
GSDEVICE=pnmraw
GSSUFFIX=ppm
${GS} -q -dNOPAUSE -dBATCH -dSAFER \
-sDEVICE=${GSDEVICE} -sOutputFile=${BASE}%d.${GSSUFFIX} \
-dGraphicsAlphaBit=${ALPHA} -dTextAlphaBits=${ALPHA} \
-r${RESOLUTION} ${PSFILE} ||
{
BAIL_OUT "Failed: ${GS} ${PSFILE}"
}
# All has been successful, so remove everything except the bitmap files
# and the metrics file.
FILES=`ls ${BASE}* | sed -e "/${BASE}.metrics/d" \
-e "/${BASE}\([0-9]*\).${GSSUFFIX}/d"`
# rm -f ${FILES} texput.log
# The bitmap files can have large amounts of whitespace to the left and
# right. This can be cropped if so desired.
CROP=1
type ${PNMCROP} > /dev/null || CROP=0
if [ ${CROP} -eq 1 ]; then
for FILE in ${BASE}*.${GSSUFFIX}
do
if ${PNMCROP} -left ${FILE} 2> /dev/null |\
${PNMCROP} -right 2> /dev/null > ${BASE}.tmp; then
mv ${BASE}.tmp ${FILE}
else
rm -f ${BASE}.tmp
fi
done
rm -f ${BASE}.tmp
fi
}
GENERATE_PNG_FILES () {
test $# -eq 2 || exit 1
BASE=$1
RESOLUTION=$2
${DVIPNG} -D${RESOLUTION} -o${BASE}%d.png ${DVIFILE}
}
echo $*
# Preliminary check. # Preliminary check.
if [ $# -ne 3 ]; then if [ $# -ne 3 ]; then
exit 1 exit 1
fi fi
# We use latex, dvips and gs, so check that they're all there.
FIND_IT ${LATEX}
FIND_IT ${DVIPS}
FIND_IT ${GS}
# Extract the params from the argument list. # Extract the params from the argument list.
DIR=`dirname $1` DIR=`dirname $1`
BASE=`basename $1 .tex` BASE=`basename $1 .tex`
SCALEFACTOR=$2 SCALEFACTOR=$2
OUTPUTFORMAT=$3
if [ "$3" = "ppm" ]; then if [ "${OUTPUTFORMAT}" != "ppm" -a "${OUTPUTFORMAT}" != "png" ]; then
GSDEVICE=pnmraw
GSSUFFIX=ppm
elif [ "$3" = "png" ]; then
GSDEVICE=png16m
GSSUFFIX=png
else
BAIL_OUT "Unrecognised output format ${OUTPUTFORMAT}. \ BAIL_OUT "Unrecognised output format ${OUTPUTFORMAT}. \
Expected either \"ppm\" or \"png\"." Expected either \"ppm\" or \"png\"."
fi fi
CHECK_FOR_PROGRAMS ${OUTPUTFORMAT}
# Initialise some variables. # Initialise some variables.
TEXFILE=${BASE}.tex TEXFILE=${BASE}.tex
LOGFILE=${BASE}.log LOGFILE=${BASE}.log
DVIFILE=${BASE}.dvi DVIFILE=${BASE}.dvi
PSFILE=${BASE}.ps
METRICSFILE=${BASE}.metrics METRICSFILE=${BASE}.metrics
readonly TEXFILE LOGFILE DVIFILE PSFILE METRICSFILE readonly TEXFILE LOGFILE DVIFILE METRICSFILE
# LaTeX -> DVI. # LaTeX -> DVI.
cd ${DIR} cd ${DIR}
@ -174,58 +253,11 @@ RESOLUTION=`echo "scale=2; \
${SCALEFACTOR} * (10/${LATEXFONT}) * (1000/${MAGNIFICATION})" \ ${SCALEFACTOR} * (10/${LATEXFONT}) * (1000/${MAGNIFICATION})" \
| bc` | bc`
# DVI -> PostScript # 4. Generate the bitmap files and clean-up.
${DVIPS} -o ${PSFILE} ${DVIFILE} || if [ "${OUTPUTFORMAT}" = "ppm" ]; then
{ GENERATE_PPM_FILES ${BASE} ${RESOLUTION}
BAIL_OUT "Failed: ${DVIPS} -o ${PSFILE} ${DVIFILE}" else
} GENERATE_PNG_FILES ${BASE} ${RESOLUTION}
# PostScript -> Bitmap files
# Older versions of gs have problems with a large degree of
# anti-aliasing at high resolutions
# test expects integer arguments.
# ${RESOLUTION} may be a float. Truncate it.
INT_RESOLUTION=`echo "${RESOLUTION} / 1" | bc`
ALPHA=4
if [ ${INT_RESOLUTION} -gt 150 ]; then
ALPHA=2
fi
${GS} -q -dNOPAUSE -dBATCH -dSAFER \
-sDEVICE=${GSDEVICE} -sOutputFile=${BASE}%d.${GSSUFFIX} \
-dGraphicsAlphaBit=${ALPHA} -dTextAlphaBits=${ALPHA} \
-r${RESOLUTION} ${PSFILE} ||
{
BAIL_OUT "Failed: ${GS} ${PSFILE}"
}
# All has been successful, so remove everything except the bitmap files
# and the metrics file.
FILES=`ls ${BASE}* | sed -e "/${BASE}.metrics/d" \
-e "/${BASE}\([0-9]*\).${GSSUFFIX}/d"`
rm -f ${FILES} texput.log
# The bitmap files can have large amounts of whitespace to the left and
# right. This can be cropped if so desired.
CROP=1
type ${PNMCROP} > /dev/null || CROP=0
# There's no point cropping the image if using PNG images. If you want to
# crop, use PPM.
# Apparently dvipng will support cropping at some stage in the future...
if [ ${CROP} -eq 1 -a "${GSDEVICE}" = "pnmraw" ]; then
for FILE in ${BASE}*.${GSSUFFIX}
do
if ${PNMCROP} -left ${FILE} 2> /dev/null |\
${PNMCROP} -right 2> /dev/null > ${BASE}.tmp; then
mv ${BASE}.tmp ${FILE}
else
rm -f ${BASE}.tmp
fi
done
rm -f ${BASE}.tmp
fi fi
echo "Previews generated!" echo "Previews generated!"

View File

@ -191,9 +191,11 @@ InsetOld * createInset(FuncRequest const & cmd)
return new InsetBibitem(icp); return new InsetBibitem(icp);
} else if (name == "bibtex") { } else if (name == "bibtex") {
InsetCommandParams icp; Buffer const & buffer = *cmd.view()->buffer();
InsetCommandMailer::string2params(cmd.argument, icp); InsetBibtexParams ibp;
return new InsetBibtex(icp); InsetBibtexMailer::string2params(cmd.argument,
buffer, ibp);
return new InsetBibtex(ibp);
} else if (name == "citation") { } else if (name == "citation") {
InsetCommandParams icp; InsetCommandParams icp;
@ -320,8 +322,6 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf)
} else if (cmdName == "bibitem") { } else if (cmdName == "bibitem") {
lex.printError("Wrong place for bibitem"); lex.printError("Wrong place for bibitem");
inset = new InsetBibitem(inscmd); inset = new InsetBibitem(inscmd);
} else if (cmdName == "bibtex") {
inset = new InsetBibtex(inscmd);
} else if (cmdName == "index") { } else if (cmdName == "index") {
inset = new InsetIndex(inscmd); inset = new InsetIndex(inscmd);
} else if (cmdName == "include") { } else if (cmdName == "include") {
@ -355,6 +355,8 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf)
} else { } else {
if (tmptok == "Quotes") { if (tmptok == "Quotes") {
inset = new InsetQuotes; inset = new InsetQuotes;
} else if (tmptok == "Bibtex") {
inset = new InsetBibtex;
} else if (tmptok == "External") { } else if (tmptok == "External") {
inset = new InsetExternal; inset = new InsetExternal;
} else if (tmptok == "FormulaMacro") { } else if (tmptok == "FormulaMacro") {

View File

@ -1,3 +1,7 @@
2003-07-31 Angus Leeming <leeming@lyx.org>
* ControlBibtex.[Ch]: re-write due to changed InsetBibtex interface.
2003-08-28 Lars Gullik Bjønnes <larsbj@gullik.net> 2003-08-28 Lars Gullik Bjønnes <larsbj@gullik.net>
* most files: change to use const buffer refs. * most files: change to use const buffer refs.

View File

@ -14,11 +14,12 @@
#include "ControlBibtex.h" #include "ControlBibtex.h"
#include "Kernel.h" #include "Kernel.h"
#include "lyxrc.h"
#include "helper_funcs.h" #include "helper_funcs.h"
#include "tex_helpers.h" #include "tex_helpers.h"
#include "funcrequest.h"
#include "gettext.h" #include "gettext.h"
#include "lyxrc.h"
#include "support/filetools.h" #include "support/filetools.h"
@ -29,10 +30,31 @@ using std::vector;
ControlBibtex::ControlBibtex(Dialog & d) ControlBibtex::ControlBibtex(Dialog & d)
: ControlCommand(d, "bibtex") : Dialog::Controller(d)
{} {}
bool ControlBibtex::initialiseParams(string const & data)
{
InsetBibtexMailer::string2params(data, kernel().buffer(), params_);
return true;
}
void ControlBibtex::clearParams()
{
params_.erase();
}
void ControlBibtex::dispatchParams()
{
string const lfun =
InsetBibtexMailer::params2string(params_, kernel().buffer());
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
}
string const ControlBibtex::Browse(string const & in_name, string const ControlBibtex::Browse(string const & in_name,
string const & title, string const & title,
string const & pattern) string const & pattern)
@ -59,6 +81,10 @@ void ControlBibtex::getBibStyles(vector<string> & data) const
for (; it != end; ++it) { for (; it != end; ++it) {
*it = OnlyFilename(*it); *it = OnlyFilename(*it);
} }
std::sort(data.begin(), end);
// Add an empy string to the list.
data.insert(data.begin(), " ");
} }

View File

@ -14,17 +14,31 @@
#define CONTROLBIBTEX_H #define CONTROLBIBTEX_H
#include "ControlCommand.h" #include "Dialog.h"
#include "insets/insetbibtex.h"
#include <vector> #include <vector>
/** A controller for Bibtex dialogs. /** A controller for Bibtex dialogs.
*/ */
class ControlBibtex : public ControlCommand { class ControlBibtex : public Dialog::Controller {
public: public:
/// ///
ControlBibtex(Dialog &); ControlBibtex(Dialog &);
///
InsetBibtexParams & params() { return params_; }
///
InsetBibtexParams const & params() const { return params_; }
///
virtual bool initialiseParams(string const & data);
/// clean-up on hide.
virtual void clearParams();
/// clean-up on hide.
virtual void dispatchParams();
///
virtual bool isBufferDependent() const { return true; }
/// Browse for a file /// Browse for a file
string const Browse(string const &, string const &, string const &); string const Browse(string const &, string const &, string const &);
/// get the list of bst files /// get the list of bst files
@ -34,6 +48,10 @@ public:
/// build filelists of all availabe bib/bst/cls/sty-files. done through /// build filelists of all availabe bib/bst/cls/sty-files. done through
/// kpsewhich and an external script, saved in *Files.lst /// kpsewhich and an external script, saved in *Files.lst
void rescanBibStyles() const; void rescanBibStyles() const;
private:
///
InsetBibtexParams params_;
}; };

View File

@ -62,43 +62,29 @@ void QBibtex::build_dialog()
void QBibtex::update_contents() void QBibtex::update_contents()
{ {
InsetBibtexParams const & params = controller().params();
dialog_->databaseLB->clear(); dialog_->databaseLB->clear();
string bibs(controller().params().getContents()); vector<FileName>::const_iterator fit = params.databases.begin();
string bib; vector<FileName>::const_iterator fend = params.databases.end();
for (; fit != fend; ++fit) {
while (!bibs.empty()) { string const db = fit->outputFilename(kernel().bufferFilepath());
bibs = split(bibs, bib, ','); dialog_->databaseLB->insertItem(toqstr(db));
bib = trim(bib);
if (!bib.empty())
dialog_->databaseLB->insertItem(toqstr(bib));
} }
dialog_->add_->bibLB->clear(); dialog_->add_->bibLB->clear();
vector<string> bib_str; vector<string> bib_str;
controller().getBibFiles(bib_str); controller().getBibFiles(bib_str);
for (vector<string>::const_iterator it = bib_str.begin(); vector<string>::const_iterator sit = bib_str.begin();
it != bib_str.end(); ++it) { vector<string>::const_iterator send = bib_str.end();
string bibItem(ChangeExtension(*it, "")); for (; sit != send; ++sit) {
string const bibItem = ChangeExtension(*sit, "");
dialog_->add_->bibLB->insertItem(toqstr(bibItem)); dialog_->add_->bibLB->insertItem(toqstr(bibItem));
} }
string bibtotoc = "bibtotoc"; dialog_->bibtocCB->setChecked(params.bibtotoc);
string bibstyle(controller().params().getOptions());
// bibtotoc exists?
if (prefixIs(bibstyle, bibtotoc)) {
dialog_->bibtocCB->setChecked(true);
// bibstyle exists?
if (contains(bibstyle,','))
bibstyle = split(bibstyle, bibtotoc, ',');
else
bibstyle.erase();
} else
dialog_->bibtocCB->setChecked(false);
dialog_->styleCB->clear(); dialog_->styleCB->clear();
@ -106,16 +92,17 @@ void QBibtex::update_contents()
vector<string> str; vector<string> str;
controller().getBibStyles(str); controller().getBibStyles(str);
for (vector<string>::const_iterator it = str.begin(); sit = str.begin();
it != str.end(); ++it) { send = str.end();
string item(ChangeExtension(*it, "")); for (; sit != send; ++sit) {
if (item == bibstyle) string const item = ChangeExtension(*sit, "");
item_nr = int(it - str.begin()); if (item == params.style)
item_nr = int(sit - str.begin());
dialog_->styleCB->insertItem(toqstr(item)); dialog_->styleCB->insertItem(toqstr(item));
} }
if (item_nr == -1) { if (item_nr == -1) {
dialog_->styleCB->insertItem(toqstr(bibstyle)); dialog_->styleCB->insertItem(toqstr(params.style));
item_nr = dialog_->styleCB->count() - 1; item_nr = dialog_->styleCB->count() - 1;
} }
@ -125,31 +112,19 @@ void QBibtex::update_contents()
void QBibtex::apply() void QBibtex::apply()
{ {
string dbs(fromqstr(dialog_->databaseLB->text(0))); InsetBibtexParams params;
unsigned int maxCount = dialog_->databaseLB->count(); for (unsigned int i = 0; i < dialog_->databaseLB->count(); ++i) {
for (unsigned int i = 1; i < maxCount; i++) { FileName file;
dbs += ','; file.set(fromqstr(dialog_->databaseLB->text(i)),
dbs += fromqstr(dialog_->databaseLB->text(i)); kernel().bufferFilepath());
} params.databases.push_back(file);
}
controller().params().setContents(dbs); params.style = fromqstr(dialog_->styleCB->currentText());
params.bibtotoc = dialog_->bibtocCB->isChecked();
string const bibstyle(fromqstr(dialog_->styleCB->currentText())); controller().params() = params;
bool const bibtotoc(dialog_->bibtocCB->isChecked());
if (bibtotoc && (!bibstyle.empty())) {
// both bibtotoc and style
controller().params().setOptions("bibtotoc," + bibstyle);
} else if (bibtotoc) {
// bibtotoc and no style
controller().params().setOptions("bibtotoc");
} else {
// only style. An empty one is valid, because some
// documentclasses have an own \bibliographystyle{}
// command!
controller().params().setOptions(bibstyle);
}
} }

View File

@ -11,26 +11,96 @@
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
#include <config.h> #include <config.h>
#include "xformsBC.h"
#include "ControlBibtex.h"
#include "FormBibtex.h" #include "FormBibtex.h"
#include "forms/form_bibtex.h" #include "forms/form_bibtex.h"
#include "ControlBibtex.h"
#include "xformsBC.h"
#include "Tooltips.h" #include "Tooltips.h"
#include "xforms_helpers.h" #include "xforms_helpers.h"
#include "lyx_forms.h" #include "lyx_forms.h"
#include "combox.h"
#include "tex_helpers.h"
#include "helper_funcs.h"
#include "gettext.h" #include "gettext.h"
#include "support/lstrings.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/lyxalgo.h" #include "support/lstrings.h"
using namespace lyx::support; namespace support = lyx::support;
using std::vector; using std::vector;
using std::sort;
namespace {
struct SameName {
SameName(string const & name) : name_(name) {}
bool operator()(string const & abs_name) {
return name_ == support::OnlyFilename(abs_name);
}
private:
string name_;
};
string const get_absolute_filename(string const & file,
string const & buffer_path,
vector<string> const & bibfiles)
{
if (support::AbsolutePath(file))
return file;
string const try1 = support::MakeAbsPath(file, buffer_path);
if (support::IsFileReadable(try1))
return try1;
string const name = support::OnlyFilename(file);
vector<string>::const_iterator it = bibfiles.begin();
vector<string>::const_iterator end = bibfiles.end();
it = std::find_if(it, end, SameName(name));
if (it == end)
return try1;
return *it;
}
bool find_file_in_browser(FL_OBJECT * browser,
string const & name,
string const & buffer_path,
vector<string> const & bibfiles)
{
vector<string> browser_vec = getVector(browser);
vector<string>::iterator begin = browser_vec.begin();
vector<string>::iterator end = browser_vec.end();
vector<string>::iterator it = begin;
for (; it != end; ++it) {
*it = get_absolute_filename(*it, buffer_path, bibfiles);
}
string const abs_name = get_absolute_filename(name, buffer_path, bibfiles);
it = std::find(begin, end, abs_name);
return it != end;
}
int find_style_in_combox(FL_OBJECT * combox, string const & name)
{
int const size = fl_get_combox_maxitems(combox);
for (int i = 1; i <= size; ++i) {
char const * const tmp = fl_get_combox_line(combox, i);
string const str = tmp ? support::trim(tmp) : string();
if (str == name)
return i;
}
return 0;
}
} // namespace anon
typedef FormController<ControlBibtex, FormView<FD_bibtex> > base_class; typedef FormController<ControlBibtex, FormView<FD_bibtex> > base_class;
@ -44,190 +114,394 @@ void FormBibtex::build()
{ {
dialog_.reset(build_bibtex(this)); dialog_.reset(build_bibtex(this));
// Manage the ok, apply, restore and cancel/close buttons // Manage the ok and cancel/close buttons
bcview().setOK(dialog_->button_ok); bcview().setOK(dialog_->button_ok);
bcview().setApply(dialog_->button_apply);
bcview().setCancel(dialog_->button_close); bcview().setCancel(dialog_->button_close);
bcview().setRestore(dialog_->button_restore);
// disable for read-only documents // disable for read-only documents
bcview().addReadOnly(dialog_->browser_databases);
bcview().addReadOnly(dialog_->button_browse_db);
bcview().addReadOnly(dialog_->button_delete_db);
bcview().addReadOnly(dialog_->radio_absolute_path);
bcview().addReadOnly(dialog_->radio_relative_path);
bcview().addReadOnly(dialog_->radio_name_only);
bcview().addReadOnly(dialog_->input_database); bcview().addReadOnly(dialog_->input_database);
bcview().addReadOnly(dialog_->button_database_browse); bcview().addReadOnly(dialog_->button_add_db);
bcview().addReadOnly(dialog_->button_style_browse); bcview().addReadOnly(dialog_->combox_style);
bcview().addReadOnly(dialog_->button_rescan); bcview().addReadOnly(dialog_->button_browse);
bcview().addReadOnly(dialog_->input_style);
bcview().addReadOnly(dialog_->check_bibtotoc); bcview().addReadOnly(dialog_->check_bibtotoc);
// trigger an input event for cut&paste with middle mouse button.
setPrehandler(dialog_->input_database);
setPrehandler(dialog_->input_style);
fl_set_input_return(dialog_->input_database, FL_RETURN_CHANGED);
fl_set_input_return(dialog_->input_style, FL_RETURN_CHANGED);
// callback for double click in browser // callback for double click in browser
fl_set_browser_dblclick_callback(dialog_->browser_styles, fl_set_browser_dblclick_callback(dialog_->browser_databases,
C_FormDialogView_InputCB, 2); C_FormDialogView_InputCB, 2);
fl_set_input_return(dialog_->input_database, FL_RETURN_ALWAYS);
storage_.init(dialog_->radio_absolute_path, ABSOLUTE_PATH);
storage_.init(dialog_->radio_relative_path, RELATIVE_PATH);
storage_.init(dialog_->radio_name_only, NAME_ONLY);
// set up the tooltips // set up the tooltips
string str = _("The database you want to cite from. Insert it " string str = _("Selected BibTeX databases. Double click to edit");
"without the default extension \".bib\". Use comma " tooltips().init(dialog_->browser_databases, str);
"to separate databases.");
tooltips().init(dialog_->button_database_browse, str);
str = _("Browse directory for BibTeX stylefiles");
tooltips().init(dialog_->button_style_browse, str);
str = _("The BibTeX style to use (only one allowed). Insert it without "
"the default extension \".bst\" and without path.");
tooltips().init(dialog_->input_style, str);
str = _("Select if the bibliography should appear in the Table "
"of Contents");
tooltips().init(dialog_->check_bibtotoc, str);
str = _("Double click to choose a BibTeX style from the list.");
tooltips().init(dialog_->browser_styles, str);
#if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0) #if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0)
// Work-around xforms' bug; enable tooltips for browser widgets. // Work-around xforms' bug; enable tooltips for browser widgets.
setPrehandler(dialog_->browser_styles); setPrehandler(dialog_->browser_databases);
#endif #endif
str = _("Add a BibTeX database file");
tooltips().init(dialog_->button_browse_db, str);
str = _("Updates your TeX system for a new bibstyle list. Only " str = _("Remove the selected database");
"the styles which are in directories where TeX finds them " tooltips().init(dialog_->button_delete_db, str);
"are listed!");
tooltips().init(dialog_->button_rescan, str); str = _("Store the absolute path to the file");
tooltips().init(dialog_->radio_absolute_path, str);
str = _("Store the relative path to the file");
tooltips().init(dialog_->radio_relative_path, str);
str = _("Store the file name only. Use TeX magic to find it");
tooltips().init(dialog_->radio_name_only, str);
str = _("Input BibTeX database file");
tooltips().init(dialog_->input_database, str);
str = _("Add the BibTeX database file in the input field");
tooltips().init(dialog_->button_add_db, str);
str = _("The BibTeX style");
tooltips().init(dialog_->combox_style, str);
str = _("Choose a style file");
tooltips().init(dialog_->button_browse, str);
str = _("Add bibliography to the table of contents");
tooltips().init(dialog_->check_bibtotoc, str);
}
void FormBibtex::update()
{
controller().getBibFiles(bib_files_namesonly_);
getTexFileList("bibFiles.lst", bib_files_);
browser_deactivated();
InsetBibtexParams const & params = controller().params();
fl_clear_browser(dialog_->browser_databases);
vector<support::FileName>::const_iterator fit = params.databases.begin();
vector<support::FileName>::const_iterator fend = params.databases.end();
for (; fit != fend; ++fit) {
string const db = fit->outputFilename(kernel().bufferFilepath());
fl_add_browser_line(dialog_->browser_databases, db.c_str());
}
fl_set_button(dialog_->check_bibtotoc, params.bibtotoc);
fl_clear_combox(dialog_->combox_style);
int item_nr = 0;
vector<string> styles;
controller().getBibStyles(styles);
vector<string>::const_iterator sit = styles.begin();
vector<string>::const_iterator send = styles.end();
for (; sit != send; ++sit) {
string const item = support::ChangeExtension(*sit, "");
fl_addto_combox(dialog_->combox_style, item.c_str());
if (item == params.style)
item_nr = fl_get_combox_maxitems(dialog_->combox_style);
}
if (item_nr == 0) {
fl_addto_combox(dialog_->combox_style, params.style.c_str());
item_nr = fl_get_combox_maxitems(dialog_->combox_style);
}
fl_set_combox(dialog_->combox_style, item_nr);
}
void FormBibtex::apply()
{
InsetBibtexParams params;
FL_OBJECT * browser = dialog_->browser_databases;
int const size = fl_get_browser_maxline(browser);
for (int i = 0; i < size; ++i) {
string const text = fl_get_browser_line(browser, i+1);
support::FileName file;
file.set(text, kernel().bufferFilepath());
params.databases.push_back(file);
}
params.style = support::trim(fl_get_combox_text(dialog_->combox_style));
params.bibtotoc = fl_get_button(dialog_->check_bibtotoc);
controller().params() = params;
} }
ButtonPolicy::SMInput FormBibtex::input(FL_OBJECT * ob, long ob_value) ButtonPolicy::SMInput FormBibtex::input(FL_OBJECT * ob, long ob_value)
{ {
if (ob == dialog_->button_database_browse) { ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
// When browsing, take the first file only
string const in_name = getString(dialog_->input_database);
string out_name =
controller().Browse("",
_("Select Database"),
_("*.bib| BibTeX Databases (*.bib)"));
if (!out_name.empty()) {
// add the database to any existing ones
if (!in_name.empty())
out_name = in_name + ',' + out_name;
fl_set_input(dialog_->input_database, out_name.c_str()); if (ob == dialog_->browser_databases && ob_value == 2) {
} activate = browser_double_click();
} else if (ob == dialog_->button_style_browse) { } else if (ob == dialog_->browser_databases) {
string const in_name = getString(dialog_->input_style); activate = browser_selected();
string const style = controller().Browse(in_name,
_("Select BibTeX-Style"),
_("*.bst| BibTeX Styles (*.bst)"));
if (!style.empty()) {
fl_set_input(dialog_->input_style, style.c_str());
}
} else if (ob == dialog_->browser_styles && ob_value == 2) { } else if (ob == dialog_->button_browse_db) {
// double clicked in styles browser activate = database_browse();
string const style = getString(dialog_->browser_styles);
if (style.empty()) {
return ButtonPolicy::SMI_NOOP;
} else {
fl_set_input(dialog_->input_style,
ChangeExtension(style, "").c_str());
}
// reset the browser so that the following
// single-click callback doesn't do anything
fl_deselect_browser(dialog_->browser_styles);
} else if (ob == dialog_->button_rescan) { } else if (ob == dialog_->button_delete_db) {
fl_clear_browser(dialog_->browser_styles); activate = browser_delete();
controller().rescanBibStyles();
vector<string> styles; } else if (ob == dialog_->radio_absolute_path) {
controller().getBibStyles(styles); activate = set_path(ABSOLUTE_PATH);
fl_add_browser_line(dialog_->browser_styles,
getStringFromVector(styles, "\n").c_str()); } else if (ob == dialog_->radio_relative_path) {
activate = set_path(RELATIVE_PATH);
} else if (ob == dialog_->radio_name_only) {
activate = set_path(NAME_ONLY);
} else if (ob == dialog_->input_database) {
input_database();
} else if (ob == dialog_->button_add_db) {
activate = add_database();
} else if (ob == dialog_->button_browse) {
activate = style_browse();
} else if (ob == dialog_->combox_style || ob == dialog_->check_bibtotoc) {
activate = ButtonPolicy::SMI_VALID;
} }
// with an empty database nothing makes sense ... return activate;
if (!compare(fl_get_input(dialog_->input_database), "")) { }
ButtonPolicy::SMInput FormBibtex::add_database()
{
FL_OBJECT * input = dialog_->input_database;
FL_OBJECT * browser = dialog_->browser_databases;
string const db = getString(input);
bool const activate =
!db.empty() &&
!find_file_in_browser(browser, db, kernel().bufferFilepath(),
bib_files_);
if (activate)
fl_add_browser_line(browser, db.c_str());
fl_set_input(input, "");
setEnabled(dialog_->button_add_db, false);
return activate ? ButtonPolicy::SMI_VALID : ButtonPolicy::SMI_NOOP;
}
namespace {
bool inTeXSearchPath(string const & db, vector<string> const & tex_bib_files)
{
vector<string>::const_iterator it = tex_bib_files.begin();
vector<string>::const_iterator end = tex_bib_files.end();
return std::find(it, end, db) != end;
}
FormBibtex::PathStyle storageStyle(string const & db,
vector<string> const & tex_bib_files)
{
if (support::AbsolutePath(db))
return FormBibtex::ABSOLUTE_PATH;
string const name = support::OnlyFilename(db);
if (db == name && inTeXSearchPath(name, tex_bib_files))
return FormBibtex::NAME_ONLY;
return FormBibtex::RELATIVE_PATH;
}
} // namespace anon
ButtonPolicy::SMInput FormBibtex::browser_selected()
{
FL_OBJECT * browser = dialog_->browser_databases;
int const sel = fl_get_browser(browser);
if (sel < 1 || sel > fl_get_browser_maxline(browser))
return ButtonPolicy::SMI_NOOP; return ButtonPolicy::SMI_NOOP;
setEnabled(dialog_->button_delete_db, true);
storage_.setEnabled(true);
fl_set_input(dialog_->input_database, "");
string const db = fl_get_browser_line(browser, sel);
storage_.set(storageStyle(db, bib_files_namesonly_));
return ButtonPolicy::SMI_NOOP;
}
ButtonPolicy::SMInput FormBibtex::browser_double_click()
{
FL_OBJECT * browser = dialog_->browser_databases;
int const sel = fl_get_browser(browser);
if (sel < 1 || sel > fl_get_browser_maxline(browser))
return ButtonPolicy::SMI_NOOP;
string const db = fl_get_browser_line(browser, sel);
fl_set_input(dialog_->input_database, db.c_str());
setEnabled(dialog_->button_add_db, true);
// Reset the browser so that the following single-click
// callback doesn't do anything
fl_deselect_browser(browser);
return ButtonPolicy::SMI_NOOP;
}
ButtonPolicy::SMInput FormBibtex::browser_add_db(string const & name)
{
FL_OBJECT * browser = dialog_->browser_databases;
if (find_file_in_browser(browser, name, kernel().bufferFilepath(),
bib_files_))
return ButtonPolicy::SMI_NOOP;
input_clear();
fl_add_browser_line(browser, name.c_str());
int const line = fl_get_browser_maxline(browser);
fl_select_browser_line(browser, line);
browser_selected();
return ButtonPolicy::SMI_VALID;
}
ButtonPolicy::SMInput FormBibtex::browser_delete()
{
FL_OBJECT * browser = dialog_->browser_databases;
int const sel = fl_get_browser(browser);
if (sel < 1 || sel > fl_get_browser_maxline(browser))
return ButtonPolicy::SMI_NOOP;
fl_delete_browser_line(browser, sel);
browser_deactivated();
return ButtonPolicy::SMI_VALID;
}
ButtonPolicy::SMInput FormBibtex::set_path(PathStyle style)
{
FL_OBJECT * browser = dialog_->browser_databases;
int const sel = fl_get_browser(browser);
if (sel < 1 || sel > fl_get_browser_maxline(browser))
return ButtonPolicy::SMI_NOOP;
string const db = fl_get_browser_line(browser, sel);
string const abs_name =
get_absolute_filename(db, kernel().bufferFilepath(), bib_files_);
switch (style) {
case ABSOLUTE_PATH:
fl_replace_browser_line(browser, sel, abs_name.c_str());
break;
case RELATIVE_PATH:
{
string const rel_name =
support::MakeRelPath(abs_name, kernel().bufferFilepath());
fl_replace_browser_line(browser, sel, rel_name.c_str());
break;
}
case NAME_ONLY:
{
string const name = support::OnlyFilename(abs_name);
fl_replace_browser_line(browser, sel, name.c_str());
break;
}
} }
return ButtonPolicy::SMI_VALID; return ButtonPolicy::SMI_VALID;
} }
void FormBibtex::update() ButtonPolicy::SMInput FormBibtex::database_browse()
{ {
fl_set_input(dialog_->input_database, ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
controller().params().getContents().c_str());
string bibtotoc = "bibtotoc"; FL_OBJECT * browser = dialog_->browser_databases;
string bibstyle = controller().params().getOptions(); // When browsing, take the first file only
string const in_name = fl_get_browser_maxline(browser) > 0 ?
fl_get_browser_line(browser, 1) : string();
bool const bibtotoc_exists = prefixIs(bibstyle, bibtotoc); string const out_name =
fl_set_button(dialog_->check_bibtotoc, bibtotoc_exists); controller().Browse("", _("Select Database"),
if (bibtotoc_exists) { _("*.bib| BibTeX Databases (*.bib)"));
if (contains(bibstyle, ',')) { // bibstyle exists?
bibstyle = split(bibstyle, bibtotoc, ',');
} else {
bibstyle.erase();
}
}
fl_set_input(dialog_->input_style, bibstyle.c_str());
vector<string> styles; if (!out_name.empty() &&
controller().getBibStyles(styles); out_name != in_name &&
!find_file_in_browser(browser, out_name,
fl_clear_browser(dialog_->browser_styles); kernel().bufferFilepath(),
fl_add_browser_line(dialog_->browser_styles, bib_files_))
getStringFromVector(styles, "\n").c_str()); activate = browser_add_db(out_name);
return activate;
} }
namespace {
string const unique_and_no_extensions(string const & str_in) ButtonPolicy::SMInput FormBibtex::style_browse()
{ {
vector<string> dbase = getVectorFromString(str_in); FL_OBJECT * combox = dialog_->combox_style;
for (vector<string>::iterator it = dbase.begin();
it != dbase.end(); ++it) { string const in_name = fl_get_combox_text(combox);
*it = ChangeExtension(*it, string()); string const style =
controller().Browse(in_name, _("Select BibTeX-Style"),
_("*.bst| BibTeX Styles (*.bst)"));
int const sel = find_style_in_combox(combox, style);
if (sel)
fl_set_combox(combox, sel);
else {
fl_addto_combox(combox, style.c_str());
fl_set_combox(combox, fl_get_combox_maxitems(combox));
} }
lyx::eliminate_duplicates(dbase);
return getStringFromVector(dbase); return ButtonPolicy::SMI_VALID;
} }
} // namespace anon
void FormBibtex::browser_deactivated()
void FormBibtex::apply()
{ {
string const db = getString(dialog_->input_database); setEnabled(dialog_->button_delete_db, false);
if (db.empty()) { input_clear();
// no database -> no bibtex-command and no options! storage_.unset();
controller().params().setContents(""); storage_.setEnabled(false);
controller().params().setOptions(""); }
return;
}
void FormBibtex::input_clear()
controller().params().setContents(unique_and_no_extensions(db)); {
fl_set_input(dialog_->input_database, "");
// empty is valid! setEnabled(dialog_->button_add_db, false);
string bibstyle = getString(dialog_->input_style); }
if (!bibstyle.empty()) {
// save the BibTeX style without any ".bst" extension
bibstyle = ChangeExtension(OnlyFilename(bibstyle), ""); void FormBibtex::input_database()
} {
FL_OBJECT * input = dialog_->input_database;
bool const addtotoc = fl_get_button(dialog_->check_bibtotoc); setEnabled(dialog_->button_add_db, !getString(input).empty());
string const bibtotoc = addtotoc ? "bibtotoc" : "";
if (addtotoc && !bibstyle.empty()) {
// Both bibtotoc and style.
controller().params().setOptions(bibtotoc + ',' + bibstyle);
} else {
// At least one of addtotoc and bibstyle is empty. No harm to output both!
controller().params().setOptions(bibtotoc + bibstyle);
}
} }

View File

@ -15,6 +15,8 @@
#include "FormDialogView.h" #include "FormDialogView.h"
#include "RadioButtonGroup.h"
#include <vector>
class ControlBibtex; class ControlBibtex;
struct FD_bibtex; struct FD_bibtex;
@ -26,6 +28,11 @@ class FormBibtex : public FormController<ControlBibtex, FormView<FD_bibtex> > {
public: public:
/// ///
FormBibtex(Dialog &); FormBibtex(Dialog &);
enum PathStyle {ABSOLUTE_PATH = 1,
RELATIVE_PATH,
NAME_ONLY};
private: private:
/// Set the Params variable for the Controller. /// Set the Params variable for the Controller.
virtual void apply(); virtual void apply();
@ -35,6 +42,22 @@ private:
virtual void update(); virtual void update();
/// Filter the inputs on callback from xforms /// Filter the inputs on callback from xforms
virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
ButtonPolicy::SMInput add_database();
ButtonPolicy::SMInput browser_add_db(string const & name);
ButtonPolicy::SMInput browser_selected();
ButtonPolicy::SMInput browser_double_click();
ButtonPolicy::SMInput browser_delete();
ButtonPolicy::SMInput set_path(PathStyle);
ButtonPolicy::SMInput database_browse();
ButtonPolicy::SMInput style_browse();
void browser_deactivated();
void input_clear();
void input_database();
RadioButtonGroup storage_;
std::vector<string> bib_files_;
std::vector<string> bib_files_namesonly_;
}; };
#endif // FORMBIBTEX_H #endif // FORMBIBTEX_H

View File

@ -9,14 +9,14 @@ SnapGrid: 5
=============== FORM =============== =============== FORM ===============
Name: form_bibtex Name: form_bibtex
Width: 395 Width: 340
Height: 235 Height: 370
Number of Objects: 12 Number of Objects: 16
-------------------- --------------------
class: FL_BOX class: FL_BOX
type: FLAT_BOX type: FLAT_BOX
box: 0 0 395 235 box: 0 0 340 370
boxtype: FL_FLAT_BOX boxtype: FL_FLAT_BOX
colors: FL_COL1 FL_COL1 colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER alignment: FL_ALIGN_CENTER
@ -31,46 +31,244 @@ name:
callback: callback:
argument: argument:
--------------------
class: FL_BROWSER
type: HOLD_BROWSER
box: 10 25 210 160
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_TOP_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Databases
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: browser_databases
callback: C_FormDialogView_InputCB
argument: 0
-------------------- --------------------
class: FL_BUTTON class: FL_BUTTON
type: NORMAL_BUTTON type: NORMAL_BUTTON
box: 315 25 75 25 box: 230 25 100 30
boxtype: FL_UP_BOX boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1 colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE size: FL_NORMAL_SIZE
lcol: FL_BLACK lcol: FL_BLACK
label: Update|#U label: Browse...|#r
shortcut: shortcut:
resize: FL_RESIZE_X resize: FL_RESIZE_NONE
gravity: FL_North FL_North gravity: FL_North FL_North
name: button_rescan name: button_browse_db
callback: C_FormDialogView_InputCB callback: C_FormDialogView_InputCB
argument: 0 argument: 0
-------------------- --------------------
class: FL_INPUT class: FL_BUTTON
type: NORMAL_INPUT type: NORMAL_BUTTON
box: 5 25 225 25 box: 230 60 100 30
boxtype: FL_DOWN_BOX boxtype: FL_UP_BOX
colors: FL_COL1 FL_MCOL colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_TOP_LEFT alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE size: FL_NORMAL_SIZE
lcol: FL_BLACK lcol: FL_BLACK
label: Database:|#D label: Delete|#e
shortcut: shortcut:
resize: FL_RESIZE_X resize: FL_RESIZE_NONE
gravity: FL_North FL_North gravity: FL_North FL_North
name: button_delete_db
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BEGIN_GROUP
type: 0
box: 0 10 10 0
boxtype: FL_NO_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_DEFAULT_SIZE
lcol: FL_BLACK
label:
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name:
callback:
argument:
--------------------
class: FL_ROUND3DBUTTON
type: RADIO_BUTTON
box: 230 95 100 30
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Absolute|#s
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: radio_absolute_path
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_ROUND3DBUTTON
type: RADIO_BUTTON
box: 230 125 100 30
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Relative|#l
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: radio_relative_path
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_ROUND3DBUTTON
type: RADIO_BUTTON
box: 230 155 100 30
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Name only|#N
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: radio_name_only
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_END_GROUP
type: 0
box: 0 0 0 0
boxtype: FL_NO_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_DEFAULT_SIZE
lcol: FL_BLACK
label:
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name:
callback:
argument:
--------------------
class: FL_INPUT
type: NORMAL_INPUT
box: 10 190 210 30
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label:
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: input_database name: input_database
callback: C_FormDialogView_InputCB callback: C_FormDialogView_InputCB
argument: 0 argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 230 190 100 30
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Add|#A
shortcut:
resize: FL_RESIZE_NONE
gravity: FL_North FL_North
name: button_add_db
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_CHOICE
type: DROPLIST_CHOICE
box: 10 250 210 30
boxtype: FL_FRAME_BOX
colors: FL_COL1 FL_BLACK
alignment: FL_ALIGN_TOP_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Style|#y
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: combox_style
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 230 250 100 30
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Browse...|#B
shortcut:
resize: FL_RESIZE_NONE
gravity: FL_North FL_North
name: button_browse
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_CHECKBUTTON
type: PUSH_BUTTON
box: 10 290 180 30
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Add bibliography to TOC|#T
shortcut:
resize: FL_RESIZE_NONE
gravity: FL_West FL_West
name: check_bibtotoc
callback: C_FormDialogView_InputCB
argument: 0
-------------------- --------------------
class: FL_BUTTON class: FL_BUTTON
type: RETURN_BUTTON type: RETURN_BUTTON
box: 110 205 90 25 box: 120 330 100 30
boxtype: FL_UP_BOX boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1 colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER alignment: FL_ALIGN_CENTER
@ -88,7 +286,7 @@ argument: 0
-------------------- --------------------
class: FL_BUTTON class: FL_BUTTON
type: NORMAL_BUTTON type: NORMAL_BUTTON
box: 300 205 90 25 box: 230 330 100 30
boxtype: FL_UP_BOX boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1 colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER alignment: FL_ALIGN_CENTER
@ -103,131 +301,5 @@ name: button_close
callback: C_FormDialogView_CancelCB callback: C_FormDialogView_CancelCB
argument: 0 argument: 0
--------------------
class: FL_INPUT
type: NORMAL_INPUT
box: 5 95 225 25
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_TOP_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Style:|#S
shortcut:
resize: FL_RESIZE_X
gravity: FL_North FL_North
name: input_style
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 130 50 100 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Browse...|#B
shortcut:
resize: FL_RESIZE_NONE
gravity: FL_North FL_North
name: button_database_browse
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_CHECKBUTTON
type: PUSH_BUTTON
box: 5 165 180 25
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Add bibliography to TOC|#T
shortcut:
resize: FL_RESIZE_NONE
gravity: FL_West FL_West
name: check_bibtotoc
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BROWSER
type: HOLD_BROWSER
box: 245 50 145 145
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_TOP_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Styles:|#y
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_North FL_South
name: browser_styles
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 130 120 100 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Browse...|#r
shortcut:
resize: FL_RESIZE_NONE
gravity: FL_North FL_North
name: button_style_browse
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 205 205 90 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Apply|#A
shortcut:
resize: FL_RESIZE_NONE
gravity: FL_SouthEast FL_SouthEast
name: button_apply
callback: C_FormDialogView_ApplyCB
argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 5 205 90 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Restore|#R
shortcut:
resize: FL_RESIZE_NONE
gravity: FL_SouthWest FL_SouthWest
name: button_restore
callback: C_FormDialogView_RestoreCB
argument: 0
============================== ==============================
create_the_forms create_the_forms

View File

@ -4,6 +4,7 @@
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author Alejandro Aguilar Sierra * \author Alejandro Aguilar Sierra
* \author Angus Leeming
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -18,34 +19,146 @@
#include "funcrequest.h" #include "funcrequest.h"
#include "gettext.h" #include "gettext.h"
#include "latexrunparams.h" #include "latexrunparams.h"
#include "lyxlex.h"
#include "Lsstream.h"
#include "metricsinfo.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/path.h" #include "support/path.h"
#include "support/os.h" #include "support/os.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/lyxalgo.h"
#include "support/LAssert.h" #include "support/LAssert.h"
#include "support/tostr.h"
#include <fstream> #include <fstream>
#include <cstdlib>
using namespace lyx::support; using namespace lyx;
using support::FileName;
using std::ostream; using std::ostream;
using std::ifstream; using std::ifstream;
using std::getline;
using std::endl; using std::endl;
using std::vector; using std::vector;
using std::pair; using std::pair;
InsetBibtex::InsetBibtex(InsetCommandParams const & p) InsetBibtexParams::InsetBibtexParams()
: InsetCommand(p) : bibtotoc(false)
{}
bool InsetBibtexParams::empty() const
{
return databases.empty();
}
void InsetBibtexParams::erase()
{
databases.clear();
style.erase();
bibtotoc = false;
}
void InsetBibtexParams::write(Buffer const & buffer, std::ostream & os) const
{
os << "Bibtex\n";
vector<FileName>::const_iterator it = databases.begin();
vector<FileName>::const_iterator end = databases.end();
for (; it != end; ++it) {
os << "\tfilename "
<< it->outputFilename(buffer.filePath())
<< '\n';
}
if (!style.empty())
os << "\tstyle " << style << '\n';
if (bibtotoc)
os << "\tbibtotoc " << tostr(bibtotoc) << '\n';
}
void InsetBibtexParams::read(Buffer const & buffer, LyXLex & lex)
{
enum BibtexTags {
BIB_FILENAME = 1,
BIB_STYLE,
BIB_BIBTOTOC,
BIB_END
};
keyword_item bibtex_tags[] = {
{ "\\end_inset", BIB_END },
{ "bibtotoc", BIB_BIBTOTOC },
{ "filename", BIB_FILENAME},
{ "style", BIB_STYLE}
};
pushpophelper pph(lex, bibtex_tags, BIB_END);
bool found_end = false;
bool read_error = false;
while (lex.isOK()) {
switch (lex.lex()) {
case BIB_FILENAME: {
lex.next();
FileName filename;
filename.set(lex.getString(), buffer.filePath());
databases.push_back(filename);
break;
}
case BIB_STYLE: {
lex.next();
style = lex.getString();
break;
}
case BIB_BIBTOTOC: {
lex.next();
bibtotoc = lex.getBool();
break;
}
case BIB_END:
found_end = true;
break;
default:
lex.printError("BibtexInset::read: "
"Wrong tag: $$Token");
read_error = true;
break;
}
if (found_end || read_error)
break;
}
if (!found_end) {
lex.printError("BibtexInset::read: "
"Missing \\end_inset.");
}
}
InsetBibtex::InsetBibtex()
: set_label_(false), center_indent_(0)
{}
InsetBibtex::InsetBibtex(InsetBibtexParams const & p)
: params_(p), set_label_(false), center_indent_(0)
{} {}
InsetBibtex::~InsetBibtex() InsetBibtex::~InsetBibtex()
{ {
InsetCommandMailer("bibtex", *this).hideDialog(); InsetBibtexMailer(*this).hideDialog();
} }
@ -55,40 +168,31 @@ std::auto_ptr<InsetBase> InsetBibtex::clone() const
} }
void InsetBibtex::metrics(MetricsInfo & mi, Dimension & dim) const
{
InsetCommand::metrics(mi, dim);
center_indent_ = (mi.base.textwidth - dim.wid) / 2;
dim.wid = mi.base.textwidth;
dim_ = dim;
}
void InsetBibtex::draw(PainterInfo & pi, int x, int y) const
{
InsetCommand::draw(pi, x + center_indent_, y);
}
dispatch_result InsetBibtex::localDispatch(FuncRequest const & cmd) dispatch_result InsetBibtex::localDispatch(FuncRequest const & cmd)
{ {
switch (cmd.action) { switch (cmd.action) {
case LFUN_INSET_EDIT: case LFUN_INSET_EDIT:
InsetCommandMailer("bibtex", *this).showDialog(cmd.view()); InsetBibtexMailer(*this).showDialog(cmd.view());
return DISPATCHED; return DISPATCHED;
case LFUN_INSET_MODIFY: { case LFUN_INSET_MODIFY: {
InsetCommandParams p; Buffer const * buffer = cmd.view()->buffer();
InsetCommandMailer::string2params(cmd.argument, p); InsetBibtexParams p;
if (p.getCmdName().empty()) InsetBibtexMailer::string2params(cmd.argument, *buffer, p);
return DISPATCHED;
setParams(p); setParams(p);
return DISPATCHED; return DISPATCHED;
} }
case LFUN_INSET_DIALOG_UPDATE:
InsetBibtexMailer(*this).updateDialog(cmd.view());
return DISPATCHED;
case LFUN_MOUSE_RELEASE:
return localDispatch(FuncRequest(cmd.view(), LFUN_INSET_EDIT));
default: default:
return InsetCommand::localDispatch(cmd); return InsetOld::localDispatch(cmd);
} }
} }
@ -99,102 +203,143 @@ string const InsetBibtex::getScreenLabel(Buffer const &) const
} }
void InsetBibtex::metrics(MetricsInfo & mi, Dimension & dim) const
{
if (!set_label_) {
set_label_ = true;
button_.update(getScreenLabel(*mi.base.bv->buffer()),
editable() != NOT_EDITABLE);
}
button_.metrics(mi, dim);
center_indent_ = (mi.base.textwidth - dim.wid) / 2;
dim.wid = mi.base.textwidth;
dim_ = dim;
}
void InsetBibtex::draw(PainterInfo & pi, int x, int y) const
{
button_.draw(pi, x + center_indent_, y);
}
void InsetBibtex::write(Buffer const & buffer, std::ostream & os) const
{
params().write(buffer, os);
}
void InsetBibtex::read(Buffer const & buffer, LyXLex & lex)
{
InsetBibtexParams p;
p.read(buffer, lex);
// Replace the inset's store
setParams(p);
}
int InsetBibtex::latex(Buffer const & buffer, ostream & os, int InsetBibtex::latex(Buffer const & buffer, ostream & os,
LatexRunParams const & runparams) const LatexRunParams const & runparams) const
{ {
// changing the sequence of the commands ostringstream ss;
// 1. \bibliographystyle{style} // 1. \bibliographystyle{style}
if (!params().style.empty()) { // we want no \biblio...{}
string style = params().style;
string const abs_style =
support::MakeAbsPath(style, buffer.filePath());
if (!runparams.nice && support::IsFileReadable(abs_style + ".bst"))
style = abs_style;
ss << "\\bibliographystyle{" << style << "}\n";
}
// 2. \addcontentsline{...} - if option bibtotoc set // 2. \addcontentsline{...} - if option bibtotoc set
// 3. \bibliography{database} if (params().bibtotoc) {
string adb; // Assumption: if the textclass name does not contain "art",
string db_in = getContents(); // then it's a book.
db_in = split(db_in, adb, ','); BufferParams const & bp = buffer.params;
if (!support::contains(bp.getLyXTextClass().name(), "art")) {
// Style-Options if (bp.sides == LyXTextClass::OneSide) {
string style = getOptions(); // maybe empty! and with bibtotoc ss << "\\clearpage";
string bibtotoc;
if (prefixIs(style, "bibtotoc")) {
bibtotoc = "bibtotoc";
if (contains(style, ',')) {
style = split(style, bibtotoc, ',');
}
}
if (!runparams.nice
&& IsFileReadable(MakeAbsPath(style, buffer.filePath()) + ".bst")) {
style = MakeAbsPath(style, buffer.filePath());
}
if (!style.empty()) { // we want no \biblio...{}
os << "\\bibliographystyle{" << style << "}\n";
}
// bibtotoc-Option
if (!bibtotoc.empty()) {
// maybe a problem when a textclass has no "art" as
// part of its name, because it's than book.
// For the "official" lyx-layouts it's no problem to support
// all well
if (!contains(buffer.params.getLyXTextClass().name(),
"art")) {
if (buffer.params.sides == LyXTextClass::OneSide) {
// oneside
os << "\\clearpage";
} else { } else {
// twoside ss << "\\cleardoublepage";
os << "\\cleardoublepage";
} }
// bookclass // book class
os << "\\addcontentsline{toc}{chapter}{\\bibname}"; ss << "\\addcontentsline{toc}{chapter}{\\bibname}\n";
} else { } else {
// article class // article class
os << "\\addcontentsline{toc}{section}{\\refname}"; ss << "\\addcontentsline{toc}{section}{\\refname}\n";
} }
} }
// database // 3. \bibliography{database}
// If we generate in a temp dir, we might need to give an // If we generate in a temp dir, we _need_ to use the absolute path,
// absolute path there. This is a bit complicated since we can // else rely on the user.
// have a comma-separated list of bibliographies ss << "\\bibliography{";
string db_out; vector<FileName>::const_iterator begin = params().databases.begin();
while (!adb.empty()) { vector<FileName>::const_iterator end = params().databases.end();
vector<FileName>::const_iterator it = begin;
for (; it != end; ++it) {
if (it != begin)
ss << ',';
string db = it->outputFilename(buffer.filePath());
if (!runparams.nice && if (!runparams.nice &&
IsFileReadable(MakeAbsPath(adb, buffer.filePath())+".bib")) support::IsFileReadable(it->absFilename())+".bib")
adb = os::external_path(MakeAbsPath(adb, buffer.filePath())); db = support::os::external_path(it->absFilename());
db_out += adb;
db_out += ','; ss << db;
db_in = split(db_in, adb,',');
} }
db_out = rtrim(db_out, ","); ss << '}';
os << "\\bibliography{" << db_out << "}\n";
return 2; string const output = STRCONV(ss.str());
os << output;
return int(lyx::count(output.begin(), output.end(),'\n') + 1);
}
int InsetBibtex::ascii(Buffer const &, std::ostream &, int) const
{
return 0;
}
int InsetBibtex::linuxdoc(Buffer const &, std::ostream &) const
{
return 0;
}
int InsetBibtex::docbook(Buffer const &, std::ostream &, bool) const
{
return 0;
} }
vector<string> const InsetBibtex::getFiles(Buffer const & buffer) const vector<string> const InsetBibtex::getFiles(Buffer const & buffer) const
{ {
Path p(buffer.filePath()); support::Path p(buffer.filePath());
vector<string> vec; vector<string> files;
vector<FileName>::const_iterator it = params().databases.begin();
vector<FileName>::const_iterator end = params().databases.end();
for (; it != end; ++it) {
// I really do need to pass the buffer path here...
// FileName needs extending it would seem.
string file_in = it->relFilename(buffer.filePath());
string file_out = support::findtexfile(
support::ChangeExtension(file_in, "bib"), "bib");
lyxerr[Debug::LATEX] << "Bibfile: " << file_in
<< ' ' << file_out << endl;
string tmp; // If we don't find a matching file name just fail silently
string bibfiles = getContents(); if (!file_out.empty())
bibfiles = split(bibfiles, tmp, ','); files.push_back(file_out);
while (!tmp.empty()) {
string file = findtexfile(ChangeExtension(tmp, "bib"), "bib");
lyxerr[Debug::LATEX] << "Bibfile: " << file << endl;
// If we didn't find a matching file name just fail silently
if (!file.empty())
vec.push_back(file);
// Get next file name
bibfiles = split(bibfiles, tmp, ',');
} }
return vec; return files;
} }
@ -212,17 +357,17 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
ifstream ifs(it->c_str()); ifstream ifs(it->c_str());
string linebuf0; string linebuf0;
while (getline(ifs, linebuf0)) { while (getline(ifs, linebuf0)) {
string linebuf = trim(linebuf0); string linebuf = support::trim(linebuf0);
if (linebuf.empty()) continue; if (linebuf.empty()) continue;
if (prefixIs(linebuf, "@")) { if (support::prefixIs(linebuf, "@")) {
linebuf = subst(linebuf, '{', '('); linebuf = support::subst(linebuf, '{', '(');
string tmp; string tmp;
linebuf = split(linebuf, tmp, '('); linebuf = support::split(linebuf, tmp, '(');
tmp = ascii_lowercase(tmp); tmp = support::ascii_lowercase(tmp);
if (!prefixIs(tmp, "@string") if (!support::prefixIs(tmp, "@string")
&& !prefixIs(tmp, "@preamble")) { && !support::prefixIs(tmp, "@preamble")) {
linebuf = split(linebuf, tmp, ','); linebuf = support::split(linebuf, tmp, ',');
tmp = ltrim(tmp, " \t"); tmp = support::ltrim(tmp, " \t");
if (!tmp.empty()) { if (!tmp.empty()) {
keys.push_back(pair<string,string>(tmp,string())); keys.push_back(pair<string,string>(tmp,string()));
} }
@ -235,33 +380,110 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
} }
bool InsetBibtex::addDatabase(string const & db) bool InsetBibtex::addDatabase(string const & /* db */)
{ {
#ifdef WITH_WARNINGS
#warning addDatabase is currently disabled (no LFUN).
#endif
#if 0
vector<string>
string contents(getContents()); string contents(getContents());
if (!contains(contents, db)) { if (!support::contains(contents, db)) {
if (!contents.empty()) if (!contents.empty())
contents += ','; contents += ',';
setContents(contents + db); setContents(contents + db);
return true; return true;
} }
#endif
return false; return false;
} }
bool InsetBibtex::delDatabase(string const & db) bool InsetBibtex::delDatabase(string const & /* db */)
{ {
if (contains(getContents(), db)) { #ifdef WITH_WARNINGS
#warning delDatabase is currently disabled (no LFUN).
#endif
#if 0
if (support::contains(getContents(), db)) {
string bd = db; string bd = db;
int const n = tokenPos(getContents(), ',', bd); int const n = tokenPos(getContents(), ',', bd);
if (n > 0) { if (n > 0) {
// Weird code, would someone care to explain this?(Lgb) // Weird code, would someone care to explain this?(Lgb)
string tmp(", "); string tmp(", ");
tmp += bd; tmp += bd;
setContents(subst(getContents(), tmp, ", ")); setContents(support::subst(getContents(), tmp, ", "));
} else if (n == 0) } else if (n == 0)
setContents(split(getContents(), bd, ',')); setContents(support::split(getContents(), bd, ','));
else else
return false; return false;
} }
#endif
return true; return true;
} }
void InsetBibtex::setParams(InsetBibtexParams const & params)
{
params_ = params;
}
string const InsetBibtexMailer::name_ = "bibtex";
InsetBibtexMailer::InsetBibtexMailer(InsetBibtex & inset)
: inset_(inset)
{}
string const InsetBibtexMailer::inset2string(Buffer const & buffer) const
{
return params2string(inset_.params(), buffer);
}
void InsetBibtexMailer::string2params(string const & in,
Buffer const & buffer,
InsetBibtexParams & params)
{
params = InsetBibtexParams();
if (in.empty())
return;
istringstream data(STRCONV(in));
LyXLex lex(0,0);
lex.setStream(data);
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != name_)
return;
}
// This is part of the inset proper that is usually swallowed
// by Buffer::readInset
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token != "Bibtex")
return;
}
if (lex.isOK()) {
params.read(buffer, lex);
}
}
string const InsetBibtexMailer::params2string(InsetBibtexParams const & params,
Buffer const & buffer)
{
ostringstream data;
data << name_ << ' ';
params.write(buffer, data);
data << "\\end_inset\n";
return STRCONV(data.str());
}

View File

@ -13,23 +13,36 @@
#define INSET_BIBTEX_H #define INSET_BIBTEX_H
#include "inset.h"
#include "renderers.h"
#include "support/filename.h"
#include "mailinset.h"
#include <vector> #include <vector>
#include "insetcommand.h"
/** Used to insert BibTeX's information
*/ class InsetBibtexParams {
class InsetBibtex : public InsetCommand { public:
InsetBibtexParams();
bool empty() const;
void erase();
void write(Buffer const &, std::ostream &) const;
void read(Buffer const &, LyXLex &);
std::vector<lyx::support::FileName> databases;
string style;
bool bibtotoc;
};
class InsetBibtex : public InsetOld {
public: public:
/// ///
InsetBibtex(InsetCommandParams const &); InsetBibtex();
InsetBibtex(InsetBibtexParams const &);
/// ///
~InsetBibtex(); ~InsetBibtex();
/// ///
std::auto_ptr<InsetBase> clone() const; std::auto_ptr<InsetBase> clone() const;
///
void metrics(MetricsInfo &, Dimension &) const;
///
void draw(PainterInfo & pi, int x, int y) const;
/// small wrapper for the time being /// small wrapper for the time being
virtual dispatch_result localDispatch(FuncRequest const & cmd); virtual dispatch_result localDispatch(FuncRequest const & cmd);
/// ///
@ -39,8 +52,19 @@ public:
/// ///
InsetOld::Code lyxCode() const { return InsetOld::BIBTEX_CODE; } InsetOld::Code lyxCode() const { return InsetOld::BIBTEX_CODE; }
/// ///
virtual void metrics(MetricsInfo &, Dimension &) const;
virtual void draw(PainterInfo & pi, int x, int y) const;
///
virtual void write(Buffer const &, std::ostream & os) const;
virtual void read(Buffer const &, LyXLex & lex);
///
bool display() const { return true; }
///
int latex(Buffer const &, std::ostream &, int latex(Buffer const &, std::ostream &,
LatexRunParams const &) const; LatexRunParams const &) const;
virtual int ascii(Buffer const &, std::ostream &, int linelen) const;
virtual int linuxdoc(Buffer const &, std::ostream &) const;
virtual int docbook(Buffer const &, std::ostream &, bool) const;
/// ///
void fillWithBibKeys(Buffer const & buffer, void fillWithBibKeys(Buffer const & buffer,
std::vector<std::pair<string,string> > & keys) const; std::vector<std::pair<string,string> > & keys) const;
@ -48,11 +72,39 @@ public:
std::vector<string> const getFiles(Buffer const &) const; std::vector<string> const getFiles(Buffer const &) const;
/// ///
bool addDatabase(string const &); bool addDatabase(string const &);
///
bool delDatabase(string const &); bool delDatabase(string const &);
///
InsetBibtexParams const & params() const { return params_; }
void setParams(InsetBibtexParams const &);
private:
InsetBibtexParams params_;
mutable bool set_label_;
mutable unsigned int center_indent_;
mutable ButtonRenderer button_;
};
class InsetBibtexMailer : public MailInset {
public:
///
InsetBibtexMailer(InsetBibtex & inset);
///
virtual InsetBase & inset() const { return inset_; }
///
virtual string const & name() const { return name_; }
///
virtual string const inset2string(Buffer const &) const;
///
static void string2params(string const &, Buffer const &,
InsetBibtexParams &);
///
static string const params2string(InsetBibtexParams const &,
Buffer const &);
private: private:
/// ///
mutable unsigned int center_indent_; InsetBibtex & inset_;
///
static string const name_;
}; };
#endif // INSET_BIBTEX_H #endif // INSET_BIBTEX_H

View File

@ -52,6 +52,7 @@
#include "undo_funcs.h" #include "undo_funcs.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "insets/insetbibtex.h"
#include "insets/insetcommand.h" #include "insets/insetcommand.h"
#include "insets/insetexternal.h" #include "insets/insetexternal.h"
#include "insets/insettabular.h" #include "insets/insettabular.h"
@ -1440,7 +1441,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
string const & name = argument; string const & name = argument;
string data; string data;
if (name == "bibitem" || if (name == "bibitem" ||
name == "bibtex" ||
name == "include" || name == "include" ||
name == "index" || name == "index" ||
name == "ref" || name == "ref" ||
@ -1448,6 +1448,10 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
name == "url") { name == "url") {
InsetCommandParams p(name); InsetCommandParams p(name);
data = InsetCommandMailer::params2string(name, p); data = InsetCommandMailer::params2string(name, p);
} else if (name == "bibtex") {
InsetBibtexParams p;
Buffer const & buffer = *owner->buffer();
data = InsetBibtexMailer::params2string(p, buffer);
} else if (name == "citation") { } else if (name == "citation") {
InsetCommandParams p("cite"); InsetCommandParams p("cite");
data = InsetCommandMailer::params2string(name, p); data = InsetCommandMailer::params2string(name, p);

View File

@ -4,6 +4,7 @@
(mangledFilename): new function, returning a mangled version of the (mangledFilename): new function, returning a mangled version of the
absolute file name, suitable for use in the temp dir when, for example, absolute file name, suitable for use in the temp dir when, for example,
converting an image file to another format. converting an image file to another format.
(isZipped, unzippedFilename): wrappers to global functions.
* filetools.[Ch] (copyFileToDir): removed. * filetools.[Ch] (copyFileToDir): removed.
(compare_timestamps): new function. (compare_timestamps): new function.