Revert, revert, revert. Sorry about that, y'all.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7651 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-09-03 17:40:58 +00:00
parent 9498f9758f
commit a52418b360
13 changed files with 547 additions and 1318 deletions

View File

@ -18,8 +18,7 @@
import re
from parser_tools import find_token, find_tokens, find_end_of_inset
from sys import stderr
from string import replace, split, strip
import re
from string import replace, split
def add_end_layout(lines):
i = find_token(lines, '\\layout', 0)
@ -106,77 +105,11 @@ def end_document(lines):
return
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):
add_end_layout(body)
layout2begin_layout(body)
end_document(body)
table_valignment_middle(body)
convert_bibtex(body)
if __name__ == "__main__":
pass

View File

@ -51,16 +51,15 @@
# \converter lyxpreview ${FORMAT} "lyxpreview2bitmap.sh" ""
# where ${FORMAT} is either ppm or png.
# These programs are used by the script.
# These four programs are used by the script.
# Adjust their names to suit your setup.
test -n "$LATEX" || LATEX=latex
DVIPNG=/home/angus/preview-latex/devel/dvipng/dvipng
DVIPS=dvips
GS=gs
PNMCROP=pnmcrop
readonly LATEX DVIPS GS PNMCROP
# Some helper functions.
# Three helper functions.
FIND_IT ()
{
test $# -eq 1 || exit 1
@ -90,118 +89,40 @@ REQUIRED_VERSION ()
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.
if [ $# -ne 3 ]; then
exit 1
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.
DIR=`dirname $1`
BASE=`basename $1 .tex`
SCALEFACTOR=$2
OUTPUTFORMAT=$3
if [ "${OUTPUTFORMAT}" != "ppm" -a "${OUTPUTFORMAT}" != "png" ]; then
if [ "$3" = "ppm" ]; then
GSDEVICE=pnmraw
GSSUFFIX=ppm
elif [ "$3" = "png" ]; then
GSDEVICE=png16m
GSSUFFIX=png
else
BAIL_OUT "Unrecognised output format ${OUTPUTFORMAT}. \
Expected either \"ppm\" or \"png\"."
fi
CHECK_FOR_PROGRAMS ${OUTPUTFORMAT}
# Initialise some variables.
TEXFILE=${BASE}.tex
LOGFILE=${BASE}.log
DVIFILE=${BASE}.dvi
PSFILE=${BASE}.ps
METRICSFILE=${BASE}.metrics
readonly TEXFILE LOGFILE DVIFILE METRICSFILE
readonly TEXFILE LOGFILE DVIFILE PSFILE METRICSFILE
# LaTeX -> DVI.
cd ${DIR}
@ -253,11 +174,58 @@ RESOLUTION=`echo "scale=2; \
${SCALEFACTOR} * (10/${LATEXFONT}) * (1000/${MAGNIFICATION})" \
| bc`
# 4. Generate the bitmap files and clean-up.
if [ "${OUTPUTFORMAT}" = "ppm" ]; then
GENERATE_PPM_FILES ${BASE} ${RESOLUTION}
else
GENERATE_PNG_FILES ${BASE} ${RESOLUTION}
# DVI -> PostScript
${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
${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
echo "Previews generated!"

View File

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

View File

@ -1,7 +1,3 @@
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>
* most files: change to use const buffer refs.

View File

@ -14,12 +14,11 @@
#include "ControlBibtex.h"
#include "Kernel.h"
#include "lyxrc.h"
#include "helper_funcs.h"
#include "tex_helpers.h"
#include "funcrequest.h"
#include "gettext.h"
#include "lyxrc.h"
#include "support/filetools.h"
@ -30,31 +29,10 @@ using std::vector;
ControlBibtex::ControlBibtex(Dialog & d)
: Dialog::Controller(d)
: ControlCommand(d, "bibtex")
{}
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 & title,
string const & pattern)
@ -81,10 +59,6 @@ void ControlBibtex::getBibStyles(vector<string> & data) const
for (; it != end; ++it) {
*it = OnlyFilename(*it);
}
std::sort(data.begin(), end);
// Add an empy string to the list.
data.insert(data.begin(), " ");
}

View File

@ -14,31 +14,17 @@
#define CONTROLBIBTEX_H
#include "Dialog.h"
#include "insets/insetbibtex.h"
#include "ControlCommand.h"
#include <vector>
/** A controller for Bibtex dialogs.
*/
class ControlBibtex : public Dialog::Controller {
class ControlBibtex : public ControlCommand {
public:
///
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
string const Browse(string const &, string const &, string const &);
/// get the list of bst files
@ -48,10 +34,6 @@ public:
/// build filelists of all availabe bib/bst/cls/sty-files. done through
/// kpsewhich and an external script, saved in *Files.lst
void rescanBibStyles() const;
private:
///
InsetBibtexParams params_;
};

View File

@ -62,29 +62,43 @@ void QBibtex::build_dialog()
void QBibtex::update_contents()
{
InsetBibtexParams const & params = controller().params();
dialog_->databaseLB->clear();
vector<FileName>::const_iterator fit = params.databases.begin();
vector<FileName>::const_iterator fend = params.databases.end();
for (; fit != fend; ++fit) {
string const db = fit->outputFilename(kernel().bufferFilepath());
dialog_->databaseLB->insertItem(toqstr(db));
string bibs(controller().params().getContents());
string bib;
while (!bibs.empty()) {
bibs = split(bibs, bib, ',');
bib = trim(bib);
if (!bib.empty())
dialog_->databaseLB->insertItem(toqstr(bib));
}
dialog_->add_->bibLB->clear();
vector<string> bib_str;
controller().getBibFiles(bib_str);
vector<string>::const_iterator sit = bib_str.begin();
vector<string>::const_iterator send = bib_str.end();
for (; sit != send; ++sit) {
string const bibItem = ChangeExtension(*sit, "");
for (vector<string>::const_iterator it = bib_str.begin();
it != bib_str.end(); ++it) {
string bibItem(ChangeExtension(*it, ""));
dialog_->add_->bibLB->insertItem(toqstr(bibItem));
}
dialog_->bibtocCB->setChecked(params.bibtotoc);
string bibtotoc = "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();
@ -92,17 +106,16 @@ void QBibtex::update_contents()
vector<string> str;
controller().getBibStyles(str);
sit = str.begin();
send = str.end();
for (; sit != send; ++sit) {
string const item = ChangeExtension(*sit, "");
if (item == params.style)
item_nr = int(sit - str.begin());
for (vector<string>::const_iterator it = str.begin();
it != str.end(); ++it) {
string item(ChangeExtension(*it, ""));
if (item == bibstyle)
item_nr = int(it - str.begin());
dialog_->styleCB->insertItem(toqstr(item));
}
if (item_nr == -1) {
dialog_->styleCB->insertItem(toqstr(params.style));
dialog_->styleCB->insertItem(toqstr(bibstyle));
item_nr = dialog_->styleCB->count() - 1;
}
@ -112,19 +125,31 @@ void QBibtex::update_contents()
void QBibtex::apply()
{
InsetBibtexParams params;
string dbs(fromqstr(dialog_->databaseLB->text(0)));
for (unsigned int i = 0; i < dialog_->databaseLB->count(); ++i) {
FileName file;
file.set(fromqstr(dialog_->databaseLB->text(i)),
kernel().bufferFilepath());
params.databases.push_back(file);
unsigned int maxCount = dialog_->databaseLB->count();
for (unsigned int i = 1; i < maxCount; i++) {
dbs += ',';
dbs += fromqstr(dialog_->databaseLB->text(i));
}
params.style = fromqstr(dialog_->styleCB->currentText());
params.bibtotoc = dialog_->bibtocCB->isChecked();
controller().params().setContents(dbs);
controller().params() = params;
string const bibstyle(fromqstr(dialog_->styleCB->currentText()));
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,96 +11,26 @@
* 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 "forms/form_bibtex.h"
#include "ControlBibtex.h"
#include "xformsBC.h"
#include "Tooltips.h"
#include "xforms_helpers.h"
#include "lyx_forms.h"
#include "combox.h"
#include "tex_helpers.h"
#include "helper_funcs.h"
#include "gettext.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/filetools.h"
#include "support/lyxalgo.h"
namespace support = lyx::support;
using namespace lyx::support;
using std::vector;
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
using std::sort;
typedef FormController<ControlBibtex, FormView<FD_bibtex> > base_class;
@ -114,394 +44,190 @@ void FormBibtex::build()
{
dialog_.reset(build_bibtex(this));
// Manage the ok and cancel/close buttons
// Manage the ok, apply, restore and cancel/close buttons
bcview().setOK(dialog_->button_ok);
bcview().setApply(dialog_->button_apply);
bcview().setCancel(dialog_->button_close);
bcview().setRestore(dialog_->button_restore);
// 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_->button_add_db);
bcview().addReadOnly(dialog_->combox_style);
bcview().addReadOnly(dialog_->button_browse);
bcview().addReadOnly(dialog_->button_database_browse);
bcview().addReadOnly(dialog_->button_style_browse);
bcview().addReadOnly(dialog_->button_rescan);
bcview().addReadOnly(dialog_->input_style);
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
fl_set_browser_dblclick_callback(dialog_->browser_databases,
fl_set_browser_dblclick_callback(dialog_->browser_styles,
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
string str = _("Selected BibTeX databases. Double click to edit");
tooltips().init(dialog_->browser_databases, str);
string str = _("The database you want to cite from. Insert it "
"without the default extension \".bib\". Use comma "
"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)
// Work-around xforms' bug; enable tooltips for browser widgets.
setPrehandler(dialog_->browser_databases);
setPrehandler(dialog_->browser_styles);
#endif
str = _("Add a BibTeX database file");
tooltips().init(dialog_->button_browse_db, str);
str = _("Remove the selected database");
tooltips().init(dialog_->button_delete_db, 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;
str = _("Updates your TeX system for a new bibstyle list. Only "
"the styles which are in directories where TeX finds them "
"are listed!");
tooltips().init(dialog_->button_rescan, str);
}
ButtonPolicy::SMInput FormBibtex::input(FL_OBJECT * ob, long ob_value)
{
ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
if (ob == dialog_->button_database_browse) {
// 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;
if (ob == dialog_->browser_databases && ob_value == 2) {
activate = browser_double_click();
} else if (ob == dialog_->browser_databases) {
activate = browser_selected();
} else if (ob == dialog_->button_browse_db) {
activate = database_browse();
} else if (ob == dialog_->button_delete_db) {
activate = browser_delete();
} else if (ob == dialog_->radio_absolute_path) {
activate = set_path(ABSOLUTE_PATH);
} 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;
fl_set_input(dialog_->input_database, out_name.c_str());
}
return activate;
} else if (ob == dialog_->button_style_browse) {
string const in_name = getString(dialog_->input_style);
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) {
// double clicked in styles browser
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) {
fl_clear_browser(dialog_->browser_styles);
controller().rescanBibStyles();
vector<string> styles;
controller().getBibStyles(styles);
fl_add_browser_line(dialog_->browser_styles,
getStringFromVector(styles, "\n").c_str());
}
// with an empty database nothing makes sense ...
if (!compare(fl_get_input(dialog_->input_database), "")) {
return ButtonPolicy::SMI_NOOP;
}
return ButtonPolicy::SMI_VALID;
}
ButtonPolicy::SMInput FormBibtex::add_database()
void FormBibtex::update()
{
FL_OBJECT * input = dialog_->input_database;
FL_OBJECT * browser = dialog_->browser_databases;
fl_set_input(dialog_->input_database,
controller().params().getContents().c_str());
string const db = getString(input);
string bibtotoc = "bibtotoc";
string bibstyle = controller().params().getOptions();
bool const activate =
!db.empty() &&
!find_file_in_browser(browser, db, kernel().bufferFilepath(),
bib_files_);
bool const bibtotoc_exists = prefixIs(bibstyle, bibtotoc);
fl_set_button(dialog_->check_bibtotoc, bibtotoc_exists);
if (bibtotoc_exists) {
if (contains(bibstyle, ',')) { // bibstyle exists?
bibstyle = split(bibstyle, bibtotoc, ',');
} else {
bibstyle.erase();
}
}
fl_set_input(dialog_->input_style, bibstyle.c_str());
if (activate)
fl_add_browser_line(browser, db.c_str());
vector<string> styles;
controller().getBibStyles(styles);
fl_set_input(input, "");
setEnabled(dialog_->button_add_db, false);
return activate ? ButtonPolicy::SMI_VALID : ButtonPolicy::SMI_NOOP;
fl_clear_browser(dialog_->browser_styles);
fl_add_browser_line(dialog_->browser_styles,
getStringFromVector(styles, "\n").c_str());
}
namespace {
bool inTeXSearchPath(string const & db, vector<string> const & tex_bib_files)
string const unique_and_no_extensions(string const & str_in)
{
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;
vector<string> dbase = getVectorFromString(str_in);
for (vector<string>::iterator it = dbase.begin();
it != dbase.end(); ++it) {
*it = ChangeExtension(*it, string());
}
lyx::eliminate_duplicates(dbase);
return getStringFromVector(dbase);
}
} // namespace anon
ButtonPolicy::SMInput FormBibtex::browser_selected()
void FormBibtex::apply()
{
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;
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;
}
string const db = getString(dialog_->input_database);
if (db.empty()) {
// no database -> no bibtex-command and no options!
controller().params().setContents("");
controller().params().setOptions("");
return;
}
return ButtonPolicy::SMI_VALID;
}
controller().params().setContents(unique_and_no_extensions(db));
ButtonPolicy::SMInput FormBibtex::database_browse()
{
ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP;
FL_OBJECT * browser = dialog_->browser_databases;
// When browsing, take the first file only
string const in_name = fl_get_browser_maxline(browser) > 0 ?
fl_get_browser_line(browser, 1) : string();
string const out_name =
controller().Browse("", _("Select Database"),
_("*.bib| BibTeX Databases (*.bib)"));
if (!out_name.empty() &&
out_name != in_name &&
!find_file_in_browser(browser, out_name,
kernel().bufferFilepath(),
bib_files_))
activate = browser_add_db(out_name);
return activate;
}
ButtonPolicy::SMInput FormBibtex::style_browse()
{
FL_OBJECT * combox = dialog_->combox_style;
string const in_name = fl_get_combox_text(combox);
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));
// empty is valid!
string bibstyle = getString(dialog_->input_style);
if (!bibstyle.empty()) {
// save the BibTeX style without any ".bst" extension
bibstyle = ChangeExtension(OnlyFilename(bibstyle), "");
}
return ButtonPolicy::SMI_VALID;
}
void FormBibtex::browser_deactivated()
{
setEnabled(dialog_->button_delete_db, false);
input_clear();
storage_.unset();
storage_.setEnabled(false);
}
void FormBibtex::input_clear()
{
fl_set_input(dialog_->input_database, "");
setEnabled(dialog_->button_add_db, false);
}
void FormBibtex::input_database()
{
FL_OBJECT * input = dialog_->input_database;
setEnabled(dialog_->button_add_db, !getString(input).empty());
bool const addtotoc = fl_get_button(dialog_->check_bibtotoc);
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,8 +15,6 @@
#include "FormDialogView.h"
#include "RadioButtonGroup.h"
#include <vector>
class ControlBibtex;
struct FD_bibtex;
@ -28,11 +26,6 @@ class FormBibtex : public FormController<ControlBibtex, FormView<FD_bibtex> > {
public:
///
FormBibtex(Dialog &);
enum PathStyle {ABSOLUTE_PATH = 1,
RELATIVE_PATH,
NAME_ONLY};
private:
/// Set the Params variable for the Controller.
virtual void apply();
@ -42,22 +35,6 @@ private:
virtual void update();
/// Filter the inputs on callback from xforms
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

View File

@ -9,14 +9,14 @@ SnapGrid: 5
=============== FORM ===============
Name: form_bibtex
Width: 340
Height: 370
Number of Objects: 16
Width: 395
Height: 235
Number of Objects: 12
--------------------
class: FL_BOX
type: FLAT_BOX
box: 0 0 340 370
box: 0 0 395 235
boxtype: FL_FLAT_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -31,244 +31,46 @@ name:
callback:
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
type: NORMAL_BUTTON
box: 230 25 100 30
box: 315 25 75 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
label: Update|#U
shortcut:
resize: FL_RESIZE_NONE
resize: FL_RESIZE_X
gravity: FL_North FL_North
name: button_browse_db
name: button_rescan
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 230 60 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: Delete|#e
shortcut:
resize: FL_RESIZE_NONE
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
box: 5 25 225 25
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_LEFT
alignment: FL_ALIGN_TOP_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label:
label: Database:|#D
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
resize: FL_RESIZE_X
gravity: FL_North FL_North
name: input_database
callback: C_FormDialogView_InputCB
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
type: RETURN_BUTTON
box: 120 330 100 30
box: 110 205 90 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -286,7 +88,7 @@ argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 230 330 100 30
box: 300 205 90 25
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -301,5 +103,131 @@ name: button_close
callback: C_FormDialogView_CancelCB
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

View File

@ -4,7 +4,6 @@
* Licence details can be found in the file COPYING.
*
* \author Alejandro Aguilar Sierra
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
@ -19,146 +18,34 @@
#include "funcrequest.h"
#include "gettext.h"
#include "latexrunparams.h"
#include "lyxlex.h"
#include "Lsstream.h"
#include "metricsinfo.h"
#include "support/filetools.h"
#include "support/path.h"
#include "support/os.h"
#include "support/lstrings.h"
#include "support/lyxalgo.h"
#include "support/LAssert.h"
#include "support/tostr.h"
#include <fstream>
#include <cstdlib>
using namespace lyx;
using support::FileName;
using namespace lyx::support;
using std::ostream;
using std::ifstream;
using std::getline;
using std::endl;
using std::vector;
using std::pair;
InsetBibtexParams::InsetBibtexParams()
: 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(InsetCommandParams const & p)
: InsetCommand(p)
{}
InsetBibtex::~InsetBibtex()
{
InsetBibtexMailer(*this).hideDialog();
InsetCommandMailer("bibtex", *this).hideDialog();
}
@ -168,31 +55,40 @@ 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)
{
switch (cmd.action) {
case LFUN_INSET_EDIT:
InsetBibtexMailer(*this).showDialog(cmd.view());
InsetCommandMailer("bibtex", *this).showDialog(cmd.view());
return DISPATCHED;
case LFUN_INSET_MODIFY: {
Buffer const * buffer = cmd.view()->buffer();
InsetBibtexParams p;
InsetBibtexMailer::string2params(cmd.argument, *buffer, p);
InsetCommandParams p;
InsetCommandMailer::string2params(cmd.argument, p);
if (p.getCmdName().empty())
return DISPATCHED;
setParams(p);
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:
return InsetOld::localDispatch(cmd);
return InsetCommand::localDispatch(cmd);
}
}
@ -203,143 +99,102 @@ 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,
LatexRunParams const & runparams) const
{
ostringstream ss;
// changing the sequence of the commands
// 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
if (params().bibtotoc) {
// Assumption: if the textclass name does not contain "art",
// then it's a book.
BufferParams const & bp = buffer.params;
if (!support::contains(bp.getLyXTextClass().name(), "art")) {
if (bp.sides == LyXTextClass::OneSide) {
ss << "\\clearpage";
} else {
ss << "\\cleardoublepage";
// 3. \bibliography{database}
string adb;
string db_in = getContents();
db_in = split(db_in, adb, ',');
// Style-Options
string style = getOptions(); // maybe empty! and with bibtotoc
string bibtotoc;
if (prefixIs(style, "bibtotoc")) {
bibtotoc = "bibtotoc";
if (contains(style, ',')) {
style = split(style, bibtotoc, ',');
}
}
// book class
ss << "\\addcontentsline{toc}{chapter}{\\bibname}\n";
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 {
// twoside
os << "\\cleardoublepage";
}
// bookclass
os << "\\addcontentsline{toc}{chapter}{\\bibname}";
} else {
// article class
ss << "\\addcontentsline{toc}{section}{\\refname}\n";
os << "\\addcontentsline{toc}{section}{\\refname}";
}
}
// 3. \bibliography{database}
// If we generate in a temp dir, we _need_ to use the absolute path,
// else rely on the user.
ss << "\\bibliography{";
vector<FileName>::const_iterator begin = params().databases.begin();
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());
// database
// If we generate in a temp dir, we might need to give an
// absolute path there. This is a bit complicated since we can
// have a comma-separated list of bibliographies
string db_out;
while (!adb.empty()) {
if (!runparams.nice &&
support::IsFileReadable(it->absFilename())+".bib")
db = support::os::external_path(it->absFilename());
ss << db;
IsFileReadable(MakeAbsPath(adb, buffer.filePath())+".bib"))
adb = os::external_path(MakeAbsPath(adb, buffer.filePath()));
db_out += adb;
db_out += ',';
db_in = split(db_in, adb,',');
}
ss << '}';
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;
db_out = rtrim(db_out, ",");
os << "\\bibliography{" << db_out << "}\n";
return 2;
}
vector<string> const InsetBibtex::getFiles(Buffer const & buffer) const
{
support::Path p(buffer.filePath());
Path p(buffer.filePath());
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;
vector<string> vec;
// If we don't find a matching file name just fail silently
if (!file_out.empty())
files.push_back(file_out);
string tmp;
string bibfiles = getContents();
bibfiles = split(bibfiles, tmp, ',');
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 files;
return vec;
}
@ -357,17 +212,17 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
ifstream ifs(it->c_str());
string linebuf0;
while (getline(ifs, linebuf0)) {
string linebuf = support::trim(linebuf0);
string linebuf = trim(linebuf0);
if (linebuf.empty()) continue;
if (support::prefixIs(linebuf, "@")) {
linebuf = support::subst(linebuf, '{', '(');
if (prefixIs(linebuf, "@")) {
linebuf = subst(linebuf, '{', '(');
string tmp;
linebuf = support::split(linebuf, tmp, '(');
tmp = support::ascii_lowercase(tmp);
if (!support::prefixIs(tmp, "@string")
&& !support::prefixIs(tmp, "@preamble")) {
linebuf = support::split(linebuf, tmp, ',');
tmp = support::ltrim(tmp, " \t");
linebuf = split(linebuf, tmp, '(');
tmp = ascii_lowercase(tmp);
if (!prefixIs(tmp, "@string")
&& !prefixIs(tmp, "@preamble")) {
linebuf = split(linebuf, tmp, ',');
tmp = ltrim(tmp, " \t");
if (!tmp.empty()) {
keys.push_back(pair<string,string>(tmp,string()));
}
@ -380,110 +235,33 @@ 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());
if (!support::contains(contents, db)) {
if (!contains(contents, db)) {
if (!contents.empty())
contents += ',';
setContents(contents + db);
return true;
}
#endif
return false;
}
bool InsetBibtex::delDatabase(string const & /* db */)
bool InsetBibtex::delDatabase(string const & db)
{
#ifdef WITH_WARNINGS
#warning delDatabase is currently disabled (no LFUN).
#endif
#if 0
if (support::contains(getContents(), db)) {
if (contains(getContents(), db)) {
string bd = db;
int const n = tokenPos(getContents(), ',', bd);
if (n > 0) {
// Weird code, would someone care to explain this?(Lgb)
string tmp(", ");
tmp += bd;
setContents(support::subst(getContents(), tmp, ", "));
setContents(subst(getContents(), tmp, ", "));
} else if (n == 0)
setContents(support::split(getContents(), bd, ','));
setContents(split(getContents(), bd, ','));
else
return false;
}
#endif
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,36 +13,23 @@
#define INSET_BIBTEX_H
#include "inset.h"
#include "renderers.h"
#include "support/filename.h"
#include "mailinset.h"
#include <vector>
#include "insetcommand.h"
class InsetBibtexParams {
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 {
/** Used to insert BibTeX's information
*/
class InsetBibtex : public InsetCommand {
public:
///
InsetBibtex();
InsetBibtex(InsetBibtexParams const &);
InsetBibtex(InsetCommandParams const &);
///
~InsetBibtex();
///
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
virtual dispatch_result localDispatch(FuncRequest const & cmd);
///
@ -52,19 +39,8 @@ public:
///
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 &,
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,
std::vector<std::pair<string,string> > & keys) const;
@ -72,39 +48,11 @@ public:
std::vector<string> const getFiles(Buffer const &) const;
///
bool addDatabase(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:
///
InsetBibtex & inset_;
///
static string const name_;
};
#endif // INSET_BIBTEX_H

View File

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