The Movers patch.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9130 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-10-26 18:39:13 +00:00
parent 4f89cf2b1d
commit e5706b107d
29 changed files with 1435 additions and 54 deletions

View File

@ -1,3 +1,11 @@
2004-10-26 Angus Leeming <leeming@lyx.org>
* configure.m4: add an XFig 'copier'.
* scripts/fig_copy.sh: a script to 'copy' an XFig data file. If this
involves a directory change, then any references to picture files are
changed from relative to absolute paths.
2004-10-25 Bennett Helm <bennett.helm@fandm.edu> 2004-10-25 Bennett Helm <bennett.helm@fandm.edu>
* Makefile.am (dist_bind_DATA): add mac.bind * Makefile.am (dist_bind_DATA): add mac.bind
@ -17,9 +25,9 @@
2004-10-19 Jean-Marc Lasgouttes <lasgouttes@lyx.org> 2004-10-19 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* bind/xemacs.bind: * bind/xemacs.bind:
* bind/emacs.bind: * bind/emacs.bind:
* bind/mac.bind: * bind/mac.bind:
* bind/cua.bind: add bindings for buffer-previous/next * bind/cua.bind: add bindings for buffer-previous/next
2004-10-18 Andreas Vox <vox@isp.uni-luebeck.de> 2004-10-18 Andreas Vox <vox@isp.uni-luebeck.de>
@ -84,7 +92,7 @@
be done because LyX is installed in a directory which name be done because LyX is installed in a directory which name
contains spaces. contains spaces.
* chkconfig.ltx: remove use of macro \srcdir * chkconfig.ltx: remove use of macro \srcdir
(\TestDocClass): change to take two arguments (\TestDocClass): change to take two arguments
(\DeclareLaTeXClass, \DeclareLinuxDocClass, \DeclareDocBookClass): (\DeclareLaTeXClass, \DeclareLinuxDocClass, \DeclareDocBookClass):
do not exit after execution do not exit after execution
@ -99,12 +107,12 @@
2004-08-14 Jean-Marc Lasgouttes <lasgouttes@lyx.org> 2004-08-14 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* ui/stdmenus.ui: * ui/stdmenus.ui:
* ui/classic.ui: add LyX menu * ui/classic.ui: add LyX menu
2004-08-14 Bennett Helm <bennett.helm@fandm.edu> 2004-08-14 Bennett Helm <bennett.helm@fandm.edu>
* bind/mac.bind: new file. This is the Mac flavour bind file, based on * bind/mac.bind: new file. This is the Mac flavour bind file, based on
bindings found in the Mac world. bindings found in the Mac world.
2004-08-13 LyX Guy <lasgouttes@lyx.org> 2004-08-13 LyX Guy <lasgouttes@lyx.org>
@ -114,7 +122,7 @@
2004-08-13 José Matos <jamatos@lyx.org> 2004-08-13 José Matos <jamatos@lyx.org>
* layouts/elsart.layout: fixed its permission settings and readded * layouts/elsart.layout: fixed its permission settings and readded
layouts. Added optional itens as already present in 1.3 version. layouts. Added optional itens as already present in 1.3 version.
2004-08-13 José Matos <jamatos@lyx.org> 2004-08-13 José Matos <jamatos@lyx.org>
* layouts/elsart.layout: removed temporarily to correct the * layouts/elsart.layout: removed temporarily to correct the
permission settings of the file. permission settings of the file.
@ -161,12 +169,12 @@
* encodings: * encodings:
* languages: implement iso-8859-13 (latin-7) for Latvian and * languages: implement iso-8859-13 (latin-7) for Latvian and
Lithuanian. Also include Icelandic. Lithuanian. Also include Icelandic.
2004-06-09 Lars Gullik Bjonnes <larsbj@gullik.net> 2004-06-09 Lars Gullik Bjonnes <larsbj@gullik.net>
* Makefile.am (dist_*): Use the dist annotation to clean up the * Makefile.am (dist_*): Use the dist annotation to clean up the
Makefile slightly. Makefile slightly.
2004-06-02 Lars Gullik Bjonnes <larsbj@gullik.net> 2004-06-02 Lars Gullik Bjonnes <larsbj@gullik.net>

View File

@ -479,11 +479,11 @@ EOF
for file in ./layouts/*.layout "${srcdir}"/layouts/*.layout ; do for file in ./layouts/*.layout "${srcdir}"/layouts/*.layout ; do
case $file in case $file in
*/\*.layout) ;; */\*.layout) ;;
*) if test -r "$file" ; then *) if test -r "$file" ; then
class=`echo $file | sed -e 's%^.*layouts/\(.*\)\.layout$%\1%'` class=`echo $file | sed -e 's%^.*layouts/\(.*\)\.layout$%\1%'`
# Generate the proper TestDocClass command for this layout # Generate the proper TestDocClass command for this layout
grep '\\Declare\(LaTeX\|DocBook\|LinuxDoc\)Class' "$file" \ grep '\\Declare\(LaTeX\|DocBook\|LinuxDoc\)Class' "$file" \
| sed -e 's/^\# *\(.*\)$/\\TestDocClass{'${class}'}{\1}/' | sed -e 's/^\# *\(.*\)$/\\TestDocClass{'${class}'}{\1}/'
fi ;; fi ;;
esac esac
done > chklayouts.tex done > chklayouts.tex
@ -587,6 +587,8 @@ cat >$outfile <<EOF
\\converter ps fax "$fax_command" "" \\converter ps fax "$fax_command" ""
\\converter ps pdf "$ps_to_pdf_command" "" \\converter ps pdf "$ps_to_pdf_command" ""
\\converter word latex "$word_to_latex_command" "" \\converter word latex "$word_to_latex_command" ""
\\copier fig "sh \$\$s/fig_copy.sh \$\$i \$\$o"
EOF EOF
### the graphic converter part with the predefined ones ### the graphic converter part with the predefined ones

82
lib/scripts/fig_copy.sh Normal file
View File

@ -0,0 +1,82 @@
#! /bin/sh
# file fig_copy.sh
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.
#
# author Angus Leeming
#
# Full author contact details are available in file CREDITS
# Usage:
# fig_copy.sh <from file> <to file>
# This script will copy an XFIG .fig file "$1" to "$2". In the process,
# it will modify the contents of the .fig file so that the names of any
# picture files that are stored as relative paths are replaced
# with the absolute path.
test $# -eq 2 || {
echo "Usage: fig_copy.sh <from file> <to file>" >&2
exit 1
}
test -r "$1" || {
echo "Unable to read $1" >&2
exit 1
}
# The work is trivial if "to" and "from" are in the same directory.
PRESENT_DIR=$PWD
cd `dirname "$1"` || exit $?
FROM_DIR=$PWD
cd "$PRESENT_DIR" || exit $?
cd `dirname "$2"` || exit $?
TO_DIR=$PWD
cd "$PRESENT_DIR" || exit $?
test "$FROM_DIR" = "$TO_DIR" && {
'cp' -f "$1" "$2"
exit $?
}
# Ok, they're in different directories. The .fig file must be modified.
# WS is a space and a tab character.
WS=' '
TRANSFORMATION="
# We're looking for a line of text that defines an entry of
# type '2' (a polyline), subtype '5' (an external picture file).
# The line has 14 other data fields.
/^[${WS}]*2[${WS}]\{1,\}5\([${WS}]\{1,\}[^${WS}]\{1,\}\)\{14\}/{
:loop
# If we're not on the last line, get the next line.
# It's this that defines the file itself.
$!{
N
# Does the new line contain any data?
# If not, loop
/\n[${WS}]*$/bloop
# Does the new line contain only a comment?
# If so, loop
/\n[${WS}]*#[^\n]*$/bloop
# The contents of the final line containing the file name
# are ' X <file name>', where X = 0 or 1.
# If the file name does not begin with '/', then insert the absolute path.
# Note that this test will work even if the file name contains spaces.
s@\(.*\n[${WS}]*[01][${WS}]\{1,\}\)\([^/]\)@\1${FROM_DIR}/\2@
}
}"
sed "${TRANSFORMATION}" "$1" > "$2"
exit $?

View File

@ -1,3 +1,20 @@
2004-10-26 Angus Leeming <leeming@lyx.org>
* Makefile.am: add mover.[Ch].
* converter.C (convert, move): use the new Movers to move external
files to the temp directory.
* lyx_main.C (init): ensure that the global system_movers data
is initialised.
* lyxrc.[Ch]: code to read and write 'copiers' from/to the
preferences file.
* mover.[Ch]: new files, defining a Mover as a utility to move an
external file between directories and, if necessary, manipulate this
file using a helper script.
2004-10-25 José Matos <jamatos@lyx.org> 2004-10-25 José Matos <jamatos@lyx.org>
* output_docbook.C (makeCommand): merge two if's that tested the same condition. * output_docbook.C (makeCommand): merge two if's that tested the same condition.
@ -28,7 +45,7 @@
* output_docbook.C (makeParagraph, makeEnvironment, makeCommand): * output_docbook.C (makeParagraph, makeEnvironment, makeCommand):
use the new functions to fix cleanly the support for descriptions. use the new functions to fix cleanly the support for descriptions.
2004-10-24 José Matos <jamatos@lyx.org> 2004-10-24 José Matos <jamatos@lyx.org>
* buffer.C (makeLinuxDocFile, makeDocBookFile): * buffer.C (makeLinuxDocFile, makeDocBookFile):
@ -73,7 +90,7 @@
* bufferlist.C (previous, next): new methods * bufferlist.C (previous, next): new methods
* lfuns.h: * lfuns.h:
* LyXAction.C (init): add LFUN_NEXTBUFFER and LFUN_PREVIOUSBUFFER * LyXAction.C (init): add LFUN_NEXTBUFFER and LFUN_PREVIOUSBUFFER
2004-10-18 Andreas Vox <vox@isp.uni-luebeck.de> 2004-10-18 Andreas Vox <vox@isp.uni-luebeck.de>
@ -93,13 +110,13 @@
2004-10-13 José Matos <jamatos@lyx.org> 2004-10-13 José Matos <jamatos@lyx.org>
* output_docbook.C (docbookParagraphs): fix closing tags in the * output_docbook.C (docbookParagraphs): fix closing tags in the
end of the document. end of the document.
2004-10-09 José Matos <jamatos@lyx.org> 2004-10-09 José Matos <jamatos@lyx.org>
* buffer.C: format up to 237. * buffer.C: format up to 237.
* bufferparams.C (write): use tostr to convert booleans to strings. * bufferparams.C (write): use tostr to convert booleans to strings.
2004-10-08 Martin Vermeer <martin.vermeer@hut.fi> 2004-10-08 Martin Vermeer <martin.vermeer@hut.fi>
* lyxrc.C: add to tooltip about using xindy to prefs (xforms) * lyxrc.C: add to tooltip about using xindy to prefs (xforms)

View File

@ -226,6 +226,8 @@ lyx_SOURCES = \
messages.h \ messages.h \
metricsinfo.C \ metricsinfo.C \
metricsinfo.h \ metricsinfo.h \
mover.C \
mover.h \
output.C \ output.C \
output.h \ output.h \
outputparams.C \ outputparams.C \

View File

@ -20,6 +20,7 @@
#include "gettext.h" #include "gettext.h"
#include "language.h" #include "language.h"
#include "LaTeX.h" #include "LaTeX.h"
#include "mover.h"
#include "frontends/Alert.h" #include "frontends/Alert.h"
@ -42,7 +43,6 @@ using lyx::support::OnlyPath;
using lyx::support::Path; using lyx::support::Path;
using lyx::support::prefixIs; using lyx::support::prefixIs;
using lyx::support::QuoteName; using lyx::support::QuoteName;
using lyx::support::rename;
using lyx::support::split; using lyx::support::split;
using lyx::support::subst; using lyx::support::subst;
using lyx::support::Systemcall; using lyx::support::Systemcall;
@ -283,7 +283,7 @@ bool Converters::convert(Buffer const * buffer,
formats.extension(to_format)); formats.extension(to_format));
if (from_format == to_format) if (from_format == to_format)
return move(from_file, to_file, false); return move(from_format, from_file, to_file, false);
Graph::EdgePath edgepath = getPath(from_format, to_format); Graph::EdgePath edgepath = getPath(from_format, to_format);
if (edgepath.empty()) { if (edgepath.empty()) {
@ -374,7 +374,8 @@ bool Converters::convert(Buffer const * buffer,
res = one.startscript(type, command); res = one.startscript(type, command);
if (!real_outfile.empty()) { if (!real_outfile.empty()) {
if (!rename(outfile, real_outfile)) Mover const & mover = movers(conv.to);
if (!mover.rename(outfile, real_outfile))
res = -1; res = -1;
else else
lyxerr[Debug::FILES] lyxerr[Debug::FILES]
@ -414,7 +415,6 @@ bool Converters::convert(Buffer const * buffer,
if (conv.To->dummy()) if (conv.To->dummy())
return true; return true;
if (!conv.result_dir.empty()) { if (!conv.result_dir.empty()) {
to_file = AddName(subst(conv.result_dir, token_base, to_base), to_file = AddName(subst(conv.result_dir, token_base, to_base),
subst(conv.result_file, subst(conv.result_file,
@ -424,7 +424,8 @@ bool Converters::convert(Buffer const * buffer,
token_base, from_base); token_base, from_base);
string to = subst(conv.result_dir, string to = subst(conv.result_dir,
token_base, to_base); token_base, to_base);
if (!rename(from, to)) { Mover const & mover = movers(conv.from);
if (!mover.rename(from, to)) {
Alert::error(_("Cannot convert file"), Alert::error(_("Cannot convert file"),
bformat(_("Could not move a temporary file from %1$s to %2$s."), bformat(_("Could not move a temporary file from %1$s to %2$s."),
from, to)); from, to));
@ -433,13 +434,14 @@ bool Converters::convert(Buffer const * buffer,
} }
return true; return true;
} else } else
return move(outfile, to_file, conv.latex); return move(conv.to, outfile, to_file, conv.latex);
} }
// If from = /path/file.ext and to = /path2/file2.ext2 then this method // If from = /path/file.ext and to = /path2/file2.ext2 then this method
// moves each /path/file*.ext file to /path2/file2*.ext2' // moves each /path/file*.ext file to /path2/file2*.ext2'
bool Converters::move(string const & from, string const & to, bool copy) bool Converters::move(string const & fmt,
string const & from, string const & to, bool copy)
{ {
if (from == to) if (from == to)
return true; return true;
@ -459,9 +461,11 @@ bool Converters::move(string const & from, string const & to, bool copy)
to2 = ChangeExtension(to2, to_extension); to2 = ChangeExtension(to2, to_extension);
lyxerr[Debug::FILES] << "moving " << from2 lyxerr[Debug::FILES] << "moving " << from2
<< " to " << to2 << endl; << " to " << to2 << endl;
bool const moved = (copy)
? lyx::support::copy(from2, to2) Mover const & mover = movers(fmt);
: rename(from2, to2); bool const moved = copy
? mover.copy(from2, to2)
: mover.rename(from2, to2);
if (!moved && no_errors) { if (!moved && no_errors) {
Alert::error(_("Cannot convert file"), Alert::error(_("Cannot convert file"),
bformat(_("Could not move a temporary file from %1$s to %2$s."), bformat(_("Could not move a temporary file from %1$s to %2$s."),
@ -531,7 +535,7 @@ bool Converters::runLaTeX(Buffer const & buffer, string const & command,
{ {
buffer.busy(true); buffer.busy(true);
buffer.message(_("Running LaTeX...")); buffer.message(_("Running LaTeX..."));
runparams.document_language = buffer.params().language->babel(); runparams.document_language = buffer.params().language->babel();
// do the LaTeX run(s) // do the LaTeX run(s)

View File

@ -142,7 +142,9 @@ private:
/// ///
std::string latex_command_; std::string latex_command_;
/// ///
bool move(std::string const & from, std::string const & to, bool copy); bool move(std::string const & fmt,
std::string const & from, std::string const & to,
bool copy);
/// ///
Graph G_; Graph G_;
}; };

View File

@ -1,3 +1,7 @@
2004-10-26 Angus Leeming <leeming@lyx.org>
* ControlPrefs.[Ch]: add code to interface with the Movers.
2004-09-14 Jean-Marc Lasgouttes <lasgouttes@lyx.org> 2004-09-14 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* ControlSpellchecker.C (check): do not set the selection * ControlSpellchecker.C (check): do not set the selection

View File

@ -52,6 +52,7 @@ bool ControlPrefs::initialiseParams(std::string const &)
formats_ = ::formats; formats_ = ::formats;
converters_ = ::converters; converters_ = ::converters;
converters_.update(formats_); converters_.update(formats_);
movers_ = ::movers;
colors_.clear(); colors_.clear();
redraw_gui_ = false; redraw_gui_ = false;
update_screen_font_ = false; update_screen_font_ = false;
@ -75,6 +76,8 @@ void ControlPrefs::dispatchParams()
::converters.update(::formats); ::converters.update(::formats);
::converters.buildGraph(); ::converters.buildGraph();
::movers = movers_;
vector<string>::const_iterator it = colors_.begin(); vector<string>::const_iterator it = colors_.begin();
vector<string>::const_iterator const end = colors_.end(); vector<string>::const_iterator const end = colors_.end();
for (; it != end; ++it) for (; it != end; ++it)

View File

@ -16,6 +16,7 @@
#include "converter.h" #include "converter.h"
#include "format.h" #include "format.h"
#include "lyxrc.h" #include "lyxrc.h"
#include "mover.h"
#include <string> #include <string>
#include <vector> #include <vector>
@ -46,6 +47,9 @@ public:
Formats & formats() { return formats_; } Formats & formats() { return formats_; }
Formats const & formats() const { return formats_; } Formats const & formats() const { return formats_; }
Movers & movers() { return movers_; }
Movers const & movers() const { return movers_; }
/// various file pickers /// various file pickers
std::string const browsebind(std::string const & file) const; std::string const browsebind(std::string const & file) const;
std::string const browseUI(std::string const & file) const; std::string const browseUI(std::string const & file) const;
@ -79,6 +83,9 @@ private:
/// temporary formats /// temporary formats
Formats formats_; Formats formats_;
/// temporary movers
Movers movers_;
/// A list of colors to be dispatched /// A list of colors to be dispatched
std::vector<std::string> colors_; std::vector<std::string> colors_;

View File

@ -1,3 +1,11 @@
2004-10-26 Angus Leeming <leeming@lyx.org>
* Makefile.dialogs:
* QPrefs.[Ch]:
* QPrefsDialog.[Ch]:
* ui/QPrefCopierModule.ui: enable the Movers to be modified from the
preferences dialog.
2004-10-18 Georg Baum <Georg.Baum@post.rwth-aachen.de> 2004-10-18 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* ui/QPrefConvertersModule.ui: Add translation context to "To:" * ui/QPrefConvertersModule.ui: Add translation context to "To:"
@ -6,7 +14,7 @@
2004-10-11 Andreas Vox <vox@isp.uni-luebeck.de> 2004-10-11 Andreas Vox <vox@isp.uni-luebeck.de>
* qfont_loader.C (initFontPath, addToFontPath): two new static * qfont_loader.C (initFontPath, addToFontPath): two new static
member functions that replace addFontPath member functions that replace addFontPath
(available): remove special MacOSX code; use addToFontPath (available): remove special MacOSX code; use addToFontPath
* lyx_gui.C (parse_init): add call to qfont_loader::initFontPath() * lyx_gui.C (parse_init): add call to qfont_loader::initFontPath()

View File

@ -40,6 +40,7 @@ UIFILES = \
QPrefAsciiModule.ui \ QPrefAsciiModule.ui \
QPrefColorsModule.ui \ QPrefColorsModule.ui \
QPrefConvertersModule.ui \ QPrefConvertersModule.ui \
QPrefCopiersModule.ui \
QPrefDateModule.ui \ QPrefDateModule.ui \
QPrefDisplayModule.ui \ QPrefDisplayModule.ui \
QPrefFileformatsModule.ui \ QPrefFileformatsModule.ui \

View File

@ -93,6 +93,12 @@ Formats & QPrefs::formats()
} }
Movers & QPrefs::movers()
{
return controller().movers();
}
void QPrefs::build_dialog() void QPrefs::build_dialog()
{ {
dialog_.reset(new QPrefsDialog(this)); dialog_.reset(new QPrefsDialog(this));
@ -626,8 +632,8 @@ void QPrefs::update_contents()
fontmod->screenHugerED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_HUGER]))); fontmod->screenHugerED->setText(toqstr(tostr(rc.font_sizes[LyXFont::SIZE_HUGER])));
dialog_->updateFormats(); dialog_->updateFormats();
dialog_->updateConverters(); dialog_->updateConverters();
dialog_->updateCopiers();
} }
} // namespace frontend } // namespace frontend

View File

@ -17,6 +17,7 @@
class Converters; class Converters;
class Formats; class Formats;
class Movers;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
@ -45,6 +46,7 @@ private:
Converters & converters(); Converters & converters();
Formats & formats(); Formats & formats();
Movers & movers();
/// languages /// languages
std::vector<std::string> lang_; std::vector<std::string> lang_;

View File

@ -9,6 +9,7 @@
*/ */
#include <config.h> #include <config.h>
#include "debug.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "QPrefsDialog.h" #include "QPrefsDialog.h"
@ -28,6 +29,7 @@
#include "ui/QPrefPathsModule.h" #include "ui/QPrefPathsModule.h"
#include "ui/QPrefSpellcheckerModule.h" #include "ui/QPrefSpellcheckerModule.h"
#include "ui/QPrefConvertersModule.h" #include "ui/QPrefConvertersModule.h"
#include "ui/QPrefCopiersModule.h"
#include "ui/QPrefFileformatsModule.h" #include "ui/QPrefFileformatsModule.h"
#include "ui/QPrefLanguageModule.h" #include "ui/QPrefLanguageModule.h"
#include "ui/QPrefPrinterModule.h" #include "ui/QPrefPrinterModule.h"
@ -74,6 +76,7 @@ QPrefsDialog::QPrefsDialog(QPrefs * form)
pathsModule = new QPrefPathsModule(this); pathsModule = new QPrefPathsModule(this);
spellcheckerModule = new QPrefSpellcheckerModule(this); spellcheckerModule = new QPrefSpellcheckerModule(this);
convertersModule = new QPrefConvertersModule(this); convertersModule = new QPrefConvertersModule(this);
copiersModule = new QPrefCopiersModule(this);
fileformatsModule = new QPrefFileformatsModule(this); fileformatsModule = new QPrefFileformatsModule(this);
languageModule = new QPrefLanguageModule(this); languageModule = new QPrefLanguageModule(this);
printerModule = new QPrefPrinterModule(this); printerModule = new QPrefPrinterModule(this);
@ -104,6 +107,7 @@ QPrefsDialog::QPrefsDialog(QPrefs * form)
prefsPS->addPanel(pathsModule, _("Paths")); prefsPS->addPanel(pathsModule, _("Paths"));
prefsPS->addPanel(fileformatsModule, _("File formats")); prefsPS->addPanel(fileformatsModule, _("File formats"));
prefsPS->addPanel(convertersModule, _("Converters")); prefsPS->addPanel(convertersModule, _("Converters"));
prefsPS->addPanel(copiersModule, _("Copiers"));
prefsPS->setCurrentPanel(_("User interface")); prefsPS->setCurrentPanel(_("User interface"));
@ -176,6 +180,16 @@ QPrefsDialog::QPrefsDialog(QPrefs * form)
connect(convertersModule->converterNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(convertersModule->converterNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(convertersModule->converterModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(convertersModule->converterModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(copiersModule->copierNewPB, SIGNAL(clicked()), this, SLOT(new_copier()));
connect(copiersModule->copierRemovePB, SIGNAL(clicked()), this, SLOT(remove_copier()));
connect(copiersModule->copierModifyPB, SIGNAL(clicked()), this, SLOT(modify_copier()));
connect(copiersModule->AllCopiersLB, SIGNAL(highlighted(int)), this, SLOT(switch_copierLB(int)));
connect(copiersModule->copierFormatCO, SIGNAL(activated(int)), this, SLOT(switch_copierCO(int)));
connect(copiersModule->copierNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(copiersModule->copierRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(copiersModule->copierModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(fileformatsModule->formatNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(fileformatsModule->formatNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(fileformatsModule->formatRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(fileformatsModule->formatRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(fileformatsModule->formatModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor())); connect(fileformatsModule->formatModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
@ -359,6 +373,185 @@ void QPrefsDialog::remove_converter()
} }
void QPrefsDialog::updateCopiers()
{
// The choice widget
copiersModule->copierFormatCO->clear();
for (Formats::const_iterator it = form_->formats().begin(),
end = form_->formats().end();
it != end; ++it) {
copiersModule->copierFormatCO->insertItem(toqstr(it->prettyname()));
}
// The browser widget
copiersModule->AllCopiersLB->clear();
for (Movers::iterator it = form_->movers().begin(),
end = form_->movers().end();
it != end; ++it) {
std::string const & command = it->second.command();
if (command.empty())
continue;
std::string const & fmt = it->first;
std::string const & pretty = form_->formats().prettyName(fmt);
copiersModule->AllCopiersLB->insertItem(toqstr(pretty));
}
if (copiersModule->AllCopiersLB->currentItem() == -1)
copiersModule->AllCopiersLB->setCurrentItem(0);
}
namespace {
struct SamePrettyName {
SamePrettyName(string const & n) : pretty_name_(n) {}
bool operator()(::Format const & fmt) const {
return fmt.prettyname() == pretty_name_;
}
private:
string const pretty_name_;
};
Format const * getFormat(std::string const & prettyname)
{
Formats::const_iterator it = ::formats.begin();
Formats::const_iterator const end = ::formats.end();
it = std::find_if(it, end, SamePrettyName(prettyname));
return it == end ? 0 : &*it;
}
} // namespace anon
void QPrefsDialog::switch_copierLB(int nr)
{
std::string const browser_text =
fromqstr(copiersModule->AllCopiersLB->currentText());
lyxerr << "switch_copierLB(" << nr << ")\n"
<< "browser_text " << browser_text << std::endl;
Format const * fmt = getFormat(browser_text);
if (fmt == 0)
return;
string const & fmt_name = fmt->name();
string const & gui_name = fmt->prettyname();
string const & command = form_->movers().command(fmt_name);
lyxerr << "switch_copierLB(" << nr << ")\n"
<< "fmt_name " << fmt_name << '\n'
<< "gui_name " << gui_name << '\n'
<< "command " << command << std::endl;
copiersModule->copierED->clear();
int const combo_size = copiersModule->copierFormatCO->count();
for (int i = 0; i < combo_size; ++i) {
QString const qtext = copiersModule->copierFormatCO->text(i);
std::string const text = fromqstr(qtext);
if (text == gui_name) {
copiersModule->copierFormatCO->setCurrentItem(i);
copiersModule->copierED->setText(toqstr(command));
lyxerr << "found combo item " << i << std::endl;
break;
}
}
}
void QPrefsDialog::switch_copierCO(int nr)
{
std::string const combo_text =
fromqstr(copiersModule->copierFormatCO->currentText());
lyxerr << "switch_copierCO(" << nr << ")\n"
<< "combo_text " << combo_text << std::endl;
Format const * fmt = getFormat(combo_text);
if (fmt == 0)
return;
string const & fmt_name = fmt->name();
string const & gui_name = fmt->prettyname();
string const & command = form_->movers().command(fmt_name);
lyxerr << "switch_copierCO(" << nr << ")\n"
<< "fmt_name " << fmt_name << '\n'
<< "gui_name " << gui_name << '\n'
<< "command " << command << std::endl;
copiersModule->copierED->setText(toqstr(command));
int const index = copiersModule->AllCopiersLB->currentItem();
if (index >= 0)
copiersModule->AllCopiersLB->setSelected(index, false);
int const browser_size = copiersModule->AllCopiersLB->count();
for (int i = 0; i < browser_size; ++i) {
QString const qtext = copiersModule->AllCopiersLB->text(i);
std::string const text = fromqstr(qtext);
if (text == gui_name) {
copiersModule->AllCopiersLB->setSelected(i, true);
int top = std::max(i - 5, 0);
copiersModule->AllCopiersLB->setTopItem(top);
break;
}
}
}
void QPrefsDialog::new_copier()
{
std::string const combo_text =
fromqstr(copiersModule->copierFormatCO->currentText());
Format const * fmt = getFormat(combo_text);
if (fmt == 0)
return;
string const command = fromqstr(copiersModule->copierED->text());
if (command.empty())
return;
form_->movers().set(fmt->name(), command);
updateCopiers();
int const last = copiersModule->AllCopiersLB->count() - 1;
copiersModule->AllCopiersLB->setCurrentItem(last);
}
void QPrefsDialog::modify_copier()
{
std::string const combo_text =
fromqstr(copiersModule->copierFormatCO->currentText());
Format const * fmt = getFormat(combo_text);
if (fmt == 0)
return;
string const command = fromqstr(copiersModule->copierED->text());
form_->movers().set(fmt->name(), command);
updateCopiers();
}
void QPrefsDialog::remove_copier()
{
std::string const combo_text =
fromqstr(copiersModule->copierFormatCO->currentText());
Format const * fmt = getFormat(combo_text);
if (fmt == 0)
return;
string const & fmt_name = fmt->name();
form_->movers().set(fmt_name, string());
updateCopiers();
}
void QPrefsDialog::updateFormats() void QPrefsDialog::updateFormats()
{ {
QPrefFileformatsModule * formatmod(fileformatsModule); QPrefFileformatsModule * formatmod(fileformatsModule);

View File

@ -27,6 +27,7 @@ class QPrefDisplayModule;
class QPrefPathsModule; class QPrefPathsModule;
class QPrefSpellcheckerModule; class QPrefSpellcheckerModule;
class QPrefConvertersModule; class QPrefConvertersModule;
class QPrefCopiersModule;
class QPrefFileformatsModule; class QPrefFileformatsModule;
class QPrefLanguageModule; class QPrefLanguageModule;
class QPrefPrinterModule; class QPrefPrinterModule;
@ -48,7 +49,7 @@ public:
~QPrefsDialog(); ~QPrefsDialog();
void updateConverters(); void updateConverters();
void updateCopiers();
void updateFormats(); void updateFormats();
public slots: public slots:
@ -64,6 +65,12 @@ public slots:
void modify_converter(); void modify_converter();
void remove_converter(); void remove_converter();
void switch_copierLB(int nr);
void switch_copierCO(int nr);
void new_copier();
void modify_copier();
void remove_copier();
void change_color(); void change_color();
void select_ui(); void select_ui();
@ -98,6 +105,7 @@ private:
QPrefPathsModule * pathsModule; QPrefPathsModule * pathsModule;
QPrefSpellcheckerModule * spellcheckerModule; QPrefSpellcheckerModule * spellcheckerModule;
QPrefConvertersModule * convertersModule; QPrefConvertersModule * convertersModule;
QPrefCopiersModule * copiersModule;
QPrefFileformatsModule * fileformatsModule; QPrefFileformatsModule * fileformatsModule;
QPrefLanguageModule * languageModule; QPrefLanguageModule * languageModule;
QPrefPrinterModule * printerModule; QPrefPrinterModule * printerModule;

View File

@ -0,0 +1,296 @@
<!DOCTYPE UI><UI>
<class>QPrefCopiersModule</class>
<include location="global">config.h</include>
<include location="local">qt_helpers.h</include>
<widget>
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>QPrefCopiersModule</cstring>
</property>
<property stdset="1">
<name>geometry</name>
<rect>
<x>0</x>
<y>0</y>
<width>547</width>
<height>261</height>
</rect>
</property>
<property stdset="1">
<name>caption</name>
<string>File Conversion</string>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>11</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout4</cstring>
</property>
<vbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>AllCopiersLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>C&amp;opiers</string>
</property>
<property>
<name>buddy</name>
<cstring>AllCopiersLB</cstring>
</property>
</widget>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout1</cstring>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget row="0" column="0" rowspan="1" colspan="2" >
<class>QListBox</class>
<item>
<property>
<name>text</name>
<string>New Item</string>
</property>
</item>
<property stdset="1">
<name>name</name>
<cstring>AllCopiersLB</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>7</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>vScrollBarMode</name>
<enum>AlwaysOn</enum>
</property>
<property stdset="1">
<name>hScrollBarMode</name>
<enum>AlwaysOff</enum>
</property>
</widget>
<widget row="1" column="0" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>copierNewPB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;New</string>
</property>
</widget>
<widget row="1" column="1" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>copierRemovePB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Remove</string>
</property>
</widget>
</grid>
</widget>
</vbox>
</widget>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout6</cstring>
</property>
<vbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout2</cstring>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget row="0" column="1" >
<class>QComboBox</class>
<property stdset="1">
<name>name</name>
<cstring>copierFormatCO</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
</widget>
<widget row="2" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>copierLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Copier:</string>
</property>
<property>
<name>buddy</name>
<cstring>copierED</cstring>
</property>
</widget>
<widget row="0" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>copierFormatLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Format:</string>
</property>
<property>
<name>buddy</name>
<cstring>copierFormatCO</cstring>
</property>
</widget>
<widget row="2" column="1" >
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>copierED</cstring>
</property>
</widget>
</grid>
</widget>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout5</cstring>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>copierModifyPB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Modify</string>
</property>
</widget>
<spacer>
<property>
<name>name</name>
<cstring>Spacer2</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Horizontal</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>Expanding</enum>
</property>
<property>
<name>sizeHint</name>
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</hbox>
</widget>
<spacer>
<property>
<name>name</name>
<cstring>Spacer28</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Vertical</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>Expanding</enum>
</property>
<property>
<name>sizeHint</name>
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</vbox>
</widget>
</hbox>
</widget>
<tabstops>
<tabstop>AllCopiersLB</tabstop>
<tabstop>copierFormatCO</tabstop>
<tabstop>copierED</tabstop>
<tabstop>copierNewPB</tabstop>
<tabstop>copierRemovePB</tabstop>
</tabstops>
</UI>

View File

@ -1,3 +1,9 @@
2004-10-26 Angus Leeming <leeming@lyx.org>
* FormPreferences.[Ch]:
* forms/form_preferences.fd: enable the Movers to be modified from the
preferences dialog.
2004-10-18 Georg Baum <Georg.Baum@post.rwth-aachen.de> 2004-10-18 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* forms/form_preferences.fd: Add translation context to "To:" * forms/form_preferences.fd: Add translation context to "To:"

View File

@ -93,13 +93,12 @@ typedef FormController<ControlPrefs, FormView<FD_preferences> > base_class;
FormPreferences::FormPreferences(Dialog & parent) FormPreferences::FormPreferences(Dialog & parent)
: base_class(parent, _("Preferences"), scalableTabfolders), : base_class(parent, _("Preferences"), scalableTabfolders),
colors_(*this), converters_(*this), inputs_misc_(*this), colors_(*this), converters_(*this), copiers_(*this),
formats_(*this), interface_(*this), language_(*this), formats_(*this), identity_(*this), inputs_misc_(*this),
lnf_misc_(*this), identity_(*this), outputs_misc_(*this), interface_(*this), language_(*this), lnf_misc_(*this),
paths_(*this), printer_(*this), screen_fonts_(*this), outputs_misc_(*this), paths_(*this), printer_(*this),
spelloptions_(*this) screen_fonts_(*this), spelloptions_(*this)
{ {}
}
void FormPreferences::redraw() void FormPreferences::redraw()
@ -169,6 +168,7 @@ void FormPreferences::build()
// these will become nested tabfolders // these will become nested tabfolders
colors_.build(); colors_.build();
converters_.build(); converters_.build();
copiers_.build();
formats_.build(); formats_.build();
inputs_misc_.build(); inputs_misc_.build();
interface_.build(); interface_.build();
@ -245,6 +245,9 @@ void FormPreferences::build()
fl_addto_tabfolder(converters_tab_->tabfolder_inner, fl_addto_tabfolder(converters_tab_->tabfolder_inner,
_("Converters").c_str(), _("Converters").c_str(),
converters_.dialog()->form); converters_.dialog()->form);
fl_addto_tabfolder(converters_tab_->tabfolder_inner,
_("Copiers").c_str(),
copiers_.dialog()->form);
// then build inputs // then build inputs
// Paths should probably go in a few inner_tab called Files // Paths should probably go in a few inner_tab called Files
@ -317,6 +320,8 @@ string const FormPreferences::getFeedback(FL_OBJECT * ob)
return colors_.feedback(ob); return colors_.feedback(ob);
if (ob->form->fdui == converters_.dialog()) if (ob->form->fdui == converters_.dialog())
return converters_.feedback(ob); return converters_.feedback(ob);
if (ob->form->fdui == copiers_.dialog())
return copiers_.feedback(ob);
if (ob->form->fdui == formats_.dialog()) if (ob->form->fdui == formats_.dialog())
return formats_.feedback(ob); return formats_.feedback(ob);
if (ob->form->fdui == inputs_misc_.dialog()) if (ob->form->fdui == inputs_misc_.dialog())
@ -356,6 +361,8 @@ ButtonPolicy::SMInput FormPreferences::input(FL_OBJECT * ob, long)
colors_.input(ob); colors_.input(ob);
} else if (ob->form->fdui == converters_.dialog()) { } else if (ob->form->fdui == converters_.dialog()) {
valid = converters_.input(ob); valid = converters_.input(ob);
} else if (ob->form->fdui == copiers_.dialog()) {
valid = copiers_.input(ob);
} else if (ob->form->fdui == formats_.dialog()) { } else if (ob->form->fdui == formats_.dialog()) {
valid = formats_.input(ob); valid = formats_.input(ob);
} else if (ob->form->fdui == interface_.dialog()) { } else if (ob->form->fdui == interface_.dialog()) {
@ -384,6 +391,7 @@ void FormPreferences::update()
colors_.update(); colors_.update();
formats_.update(); // Must be before converters_.update() formats_.update(); // Must be before converters_.update()
converters_.update(); converters_.update();
copiers_.update();
inputs_misc_.update(rc); inputs_misc_.update(rc);
interface_.update(rc); interface_.update(rc);
language_.update(rc); language_.update(rc);
@ -971,6 +979,292 @@ void FormPreferences::Converters::UpdateChoices()
} }
FormPreferences::Copiers::Copiers(FormPreferences & p)
: parent_(p)
{}
FD_preferences_copiers const * FormPreferences::Copiers::dialog()
{
return dialog_.get();
}
::Movers & FormPreferences::Copiers::movers()
{
return parent_.controller().movers();
}
void FormPreferences::Copiers::build()
{
dialog_.reset(build_preferences_copiers(&parent_));
fl_set_input_return(dialog_->input_copier, FL_RETURN_CHANGED);
// set up the feedback mechanism
setPrehandler(dialog_->browser_all);
setPrehandler(dialog_->button_delete);
setPrehandler(dialog_->button_add);
setPrehandler(dialog_->choice_format);
setPrehandler(dialog_->input_copier);
}
string const
FormPreferences::Copiers::feedback(FL_OBJECT const * const ob) const
{
if (ob == dialog_->browser_all)
return _("All explicitly defined copiers for LyX");
if (ob == dialog_->choice_format)
return _("Copier for this format");
if (ob == dialog_->input_copier)
return _("The command used to copy the file. "
"$$i is the \"from\" file name and "
"$$o is the \"to\" file name.\n"
"$$s can be used as path to "
"LyX's own collection of scripts.");
if (ob == dialog_->button_delete)
return _("Remove the current copier from the list of available "
"copiers. Note: you must then \"Apply\" the change.");
if (ob == dialog_->button_add) {
if (string(ob->label) == _("Add"))
return _("Add the current copier to the list of available "
"copiers. Note: you must then \"Apply\" the change.");
else
return _("Modify the contents of the current copier. "
"Note: you must then \"Apply\" the change.");
}
return string();
}
bool FormPreferences::Copiers::input(FL_OBJECT const * const ob)
{
if (ob == dialog_->browser_all)
return Browser();
if (ob == dialog_->choice_format
|| ob == dialog_->input_copier)
return Input();
if (ob == dialog_->button_add)
return Add();
if (ob == dialog_->button_delete)
return Erase();
return true;
}
void FormPreferences::Copiers::update()
{
// Build data for the browser widget
Movers::iterator const begin = movers().begin();
Movers::iterator const end = movers().end();
vector<string> fmts;
fmts.reserve(std::distance(begin, end));
for (Movers::iterator it = begin; it != end; ++it) {
std::string const & command = it->second.command();
if (command.empty())
continue;
std::string const & fmt = it->first;
fmts.push_back(::formats.prettyName(fmt));
}
std::sort(fmts.begin(), fmts.end());
// Build data for the choice widget
string choice;
for (::Formats::const_iterator it = ::formats.begin();
it != ::formats.end(); ++it) {
if (!choice.empty())
choice += " | ";
else
choice += ' ';
choice += it->prettyname();
}
choice += ' ';
// The input widget
fl_freeze_form(dialog_->form);
fl_set_input(dialog_->input_copier, "");
// The browser widget
fl_clear_browser(dialog_->browser_all);
vector<string>::const_iterator it = fmts.begin();
vector<string>::const_iterator const fmts_end = fmts.end();
for (; it != fmts_end; ++it)
fl_addto_browser(dialog_->browser_all, it->c_str());
// The choice widget
fl_clear_choice(dialog_->choice_format);
fl_addto_choice(dialog_->choice_format, choice.c_str());
fl_set_choice(dialog_->choice_format, 1);
Input();
fl_unfreeze_form(dialog_->form);
}
namespace {
struct SamePrettyName {
SamePrettyName(string const & n) : pretty_name_(n) {}
bool operator()(::Format const & fmt) const {
return fmt.prettyname() == pretty_name_;
}
private:
string const pretty_name_;
};
::Format const * getFormat(std::string const & prettyname)
{
::Formats::const_iterator it = ::formats.begin();
::Formats::const_iterator const end = ::formats.end();
it = std::find_if(it, end, SamePrettyName(prettyname));
return it == end ? 0 : &*it;
}
} // namespace anon
bool FormPreferences::Copiers::Add()
{
::Format const * fmt = getFormat(getString(dialog_->choice_format));
if (fmt == 0)
return false;
string const command = getString(dialog_->input_copier);
if (command.empty())
return false;
fl_freeze_form(dialog_->form);
movers().set(fmt->name(), command);
update();
setEnabled(dialog_->button_add, false);
fl_unfreeze_form(dialog_->form);
return true;
}
bool FormPreferences::Copiers::Browser()
{
int const i = fl_get_browser(dialog_->browser_all);
if (i <= 0) return false;
::Format const * fmt = getFormat(getString(dialog_->browser_all, i));
if (fmt == 0)
return false;
string const & fmt_name = fmt->name();
string const & gui_name = fmt->prettyname();
string const & command = movers().command(fmt_name);
fl_freeze_form(dialog_->form);
int const choice_size = fl_get_choice_maxitems(dialog_->choice_format);
for (int i = 1; i <= choice_size; ++i) {
char const * const c_str =
fl_get_choice_item_text(dialog_->choice_format, i);
string const line = c_str ? trim(c_str) : string();
if (line == gui_name) {
fl_set_choice(dialog_->choice_format, i);
break;
}
}
fl_set_input(dialog_->input_copier, command.c_str());
fl_set_object_label(dialog_->button_add, idex(_("Modify|#M")).c_str());
fl_set_button_shortcut(dialog_->button_add,
scex(_("Modify|#M")).c_str(), 1);
setEnabled(dialog_->button_add, false);
setEnabled(dialog_->button_delete, true);
fl_unfreeze_form(dialog_->form);
return false;
}
bool FormPreferences::Copiers::Erase()
{
::Format const * fmt = getFormat(getString(dialog_->choice_format));
if (fmt == 0)
return false;
string const & fmt_name = fmt->name();
movers().set(fmt_name, string());
update();
return true;
}
bool FormPreferences::Copiers::Input()
{
::Format const * fmt = getFormat(getString(dialog_->choice_format));
if (fmt == 0)
return false;
string const & gui_name = fmt->prettyname();
string const command = getString(dialog_->input_copier);
fl_freeze_form(dialog_->form);
fl_deselect_browser(dialog_->browser_all);
bool found_line = false;
int const browser_size = fl_get_browser_maxline(dialog_->browser_all);
for (int i = 1; i <= browser_size; ++i) {
char const * const c_str =
fl_get_browser_line(dialog_->browser_all, i);
string const line = c_str ? trim(c_str) : string();
if (line == gui_name) {
fl_select_browser_line(dialog_->browser_all, i);
int top = max(i-5, 1);
fl_set_browser_topline(dialog_->browser_all, top);
found_line = true;
break;
}
}
if (!found_line) {
fl_set_object_label(dialog_->button_add,
idex(_("Add|#A")).c_str());
fl_set_button_shortcut(dialog_->button_add,
scex(_("Add|#A")).c_str(), 1);
setEnabled(dialog_->button_delete, false);
} else {
fl_set_object_label(dialog_->button_add,
idex(_("Modify|#M")).c_str());
fl_set_button_shortcut(dialog_->button_add,
scex(_("Modify|#M")).c_str(), 1);
setEnabled(dialog_->button_delete, true);
}
setEnabled(dialog_->button_add, !command.empty());
fl_unfreeze_form(dialog_->form);
return false;
}
FormPreferences::Formats::Formats(FormPreferences & p) FormPreferences::Formats::Formats(FormPreferences & p)
: parent_(p) : parent_(p)
{} {}

View File

@ -21,6 +21,7 @@
class Converters; class Converters;
class Formats; class Formats;
class Movers;
class Dialogs; class Dialogs;
class LyXRC; class LyXRC;
@ -33,6 +34,7 @@ class ControlPrefs;
struct FD_preferences; struct FD_preferences;
struct FD_preferences_colors; struct FD_preferences_colors;
struct FD_preferences_converters; struct FD_preferences_converters;
struct FD_preferences_copiers;
struct FD_preferences_formats; struct FD_preferences_formats;
struct FD_preferences_inputs_misc; struct FD_preferences_inputs_misc;
struct FD_preferences_interface; struct FD_preferences_interface;
@ -185,6 +187,42 @@ private:
/// ///
friend class Converters; friend class Converters;
///
class Copiers {
public:
///
Copiers(FormPreferences & p);
///
FD_preferences_copiers const * dialog();
///
void build();
///
std::string const feedback(FL_OBJECT const * const) const;
///
bool input(FL_OBJECT const * const);
///
void update();
private:
///
bool Add();
///
bool Browser();
///
bool Erase();
///
bool Input();
///
::Movers & movers();
///
FormPreferences & parent_;
///
boost::scoped_ptr<FD_preferences_copiers> dialog_;
};
///
friend class Copiers;
/// ///
class Formats { class Formats {
public: public:
@ -492,18 +530,20 @@ private:
/// ///
Converters converters_; Converters converters_;
/// ///
InputsMisc inputs_misc_; Copiers copiers_;
/// ///
Formats formats_; Formats formats_;
/// ///
Identity identity_;
///
InputsMisc inputs_misc_;
///
Interface interface_; Interface interface_;
/// ///
Language language_; Language language_;
/// ///
LnFmisc lnf_misc_; LnFmisc lnf_misc_;
/// ///
Identity identity_;
///
OutputsMisc outputs_misc_; OutputsMisc outputs_misc_;
/// ///
Paths paths_; Paths paths_;

View File

@ -3,7 +3,7 @@ Magic: 13000
Internal Form Definition File Internal Form Definition File
(do not change) (do not change)
Number of forms: 15 Number of forms: 16
Unit of measure: FL_COORD_PIXEL Unit of measure: FL_COORD_PIXEL
SnapGrid: 5 SnapGrid: 5
@ -1937,7 +1937,7 @@ boxtype: FL_FRAME_BOX
colors: FL_COL1 FL_BLACK colors: FL_COL1 FL_BLACK
alignment: FL_ALIGN_LEFT alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE style: FL_NORMAL_STYLE
size: FL_DEFAULT_SIZE size: FL_NORMAL_SIZE
lcol: FL_BLACK lcol: FL_BLACK
label: From:|#F label: From:|#F
shortcut: shortcut:
@ -1955,7 +1955,7 @@ boxtype: FL_FRAME_BOX
colors: FL_COL1 FL_BLACK colors: FL_COL1 FL_BLACK
alignment: FL_ALIGN_LEFT alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE style: FL_NORMAL_STYLE
size: FL_DEFAULT_SIZE size: FL_NORMAL_SIZE
lcol: FL_BLACK lcol: FL_BLACK
label: To:|#T[[as in 'From format x to format y']] label: To:|#T[[as in 'From format x to format y']]
shortcut: shortcut:
@ -2037,6 +2037,120 @@ name: button_delete
callback: C_FormDialogView_InputCB callback: C_FormDialogView_InputCB
argument: 0 argument: 0
=============== FORM ===============
Name: form_preferences_copiers
Width: 450
Height: 360
Number of Objects: 6
--------------------
class: FL_BOX
type: FLAT_BOX
box: 0 0 450 360
boxtype: FL_FLAT_BOX
colors: FL_COL1 FL_COL1
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_BROWSER
type: HOLD_BROWSER
box: 30 30 160 270
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_TOP
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: All copiers:|#l
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: browser_all
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_CHOICE
type: NORMAL_CHOICE
box: 280 30 150 30
boxtype: FL_FRAME_BOX
colors: FL_COL1 FL_BLACK
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Format:|#F
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: choice_format
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_INPUT
type: NORMAL_INPUT
box: 280 70 150 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: Copier:|#C
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: input_copier
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 240 270 90 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_ALL
gravity: FL_NoGravity FL_NoGravity
name: button_add
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 340 270 90 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|#D
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: button_delete
callback: C_FormDialogView_InputCB
argument: 0
=============== FORM =============== =============== FORM ===============
Name: form_preferences_paths Name: form_preferences_paths
Width: 450 Width: 450

View File

@ -1,7 +1,13 @@
2004-10-26 Angus Leeming <leeming@lyx.org>
* ExternalSupport.C (updateExternal):
* insetgraphics.C (copyFileIfNeeded): use the new Movers to move external
files to the temp directory.
2004-10-25 Jürgen Spitzmüller <j.spitzmueller@gmx.de> 2004-10-25 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* insetfoot.C (latex): use \thanks instead of \footnote on titlepage * insetfoot.C (latex): use \thanks instead of \footnote on titlepage
layouts. This fixes problems with the memoir class (which does not layouts. This fixes problems with the memoir class (which does not
allow \footnote) [bug 1677] allow \footnote) [bug 1677]
2004-10-24 Andreas Vox <vox@isp.uni-luebeck.de> 2004-10-24 Andreas Vox <vox@isp.uni-luebeck.de>
@ -44,16 +50,16 @@
2004-09-29 Andreas Vox <vox@isp.uni-luebeck.de> 2004-09-29 Andreas Vox <vox@isp.uni-luebeck.de>
* insetgraphics.C (createDocBookAttribute, docbook) : * insetgraphics.C (createDocBookAttribute, docbook) :
convert scale, width, height and keepaspectratio to Docbook standards) convert scale, width, height and keepaspectratio to Docbook standards)
* insetgraphics.[hC] (toDocbookLength): new method to convert TeX units * insetgraphics.[hC] (toDocbookLength): new method to convert TeX units
to Docbook units where possible. to Docbook units where possible.
2004-09-29 Andreas Vox <vox@isp.uni-luebeck.de> 2004-09-29 Andreas Vox <vox@isp.uni-luebeck.de>
* insetgraphics.C (docbook): create inlinegraphic instead of graphic. * insetgraphics.C (docbook): create inlinegraphic instead of graphic.
* insetgraphics.[hC] (createDocBookAttributes): Export parameters * insetgraphics.[hC] (createDocBookAttributes): Export parameters
as attributes with new method for docbook. as attributes with new method for docbook.

View File

@ -21,6 +21,7 @@
#include "debug.h" #include "debug.h"
#include "exporter.h" #include "exporter.h"
#include "format.h" #include "format.h"
#include "mover.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/forkedcall.h" #include "support/forkedcall.h"
@ -204,7 +205,8 @@ void updateExternal(InsetExternalParams const & params,
unsigned long const temp_checksum = support::sum(temp_file); unsigned long const temp_checksum = support::sum(temp_file);
if (from_checksum != temp_checksum) { if (from_checksum != temp_checksum) {
if (!support::copy(abs_from_file, temp_file)) { Mover const & mover = movers(from_format);
if (!mover.copy(abs_from_file, temp_file)) {
lyxerr[Debug::EXTERNAL] lyxerr[Debug::EXTERNAL]
<< "external::updateExternal. " << "external::updateExternal. "
<< "Unable to copy " << "Unable to copy "

View File

@ -67,6 +67,7 @@ TODO
#include "lyxlength.h" #include "lyxlength.h"
#include "lyxlex.h" #include "lyxlex.h"
#include "metricsinfo.h" #include "metricsinfo.h"
#include "mover.h"
#include "outputparams.h" #include "outputparams.h"
#include "frontends/Alert.h" #include "frontends/Alert.h"
@ -454,7 +455,8 @@ copyFileIfNeeded(string const & file_in, string const & file_out)
// Nothing to do... // Nothing to do...
return std::make_pair(IDENTICAL_CONTENTS, file_out); return std::make_pair(IDENTICAL_CONTENTS, file_out);
bool const success = support::copy(file_in, file_out); Mover const & mover = movers(getExtFromContents(file_in));
bool const success = mover.copy(file_in, file_out);
if (!success) { if (!success) {
lyxerr[Debug::GRAPHICS] lyxerr[Debug::GRAPHICS]
<< support::bformat(_("Could not copy the file\n%1$s\n" << support::bformat(_("Could not copy the file\n%1$s\n"
@ -796,7 +798,7 @@ int writeImageObject(char * format, ostream& os, OutputParams const & runparams,
if (runparams.flavor != OutputParams::XML) { if (runparams.flavor != OutputParams::XML) {
os << "<![ %output.print." << format << "; [" << std::endl; os << "<![ %output.print." << format << "; [" << std::endl;
} }
os <<"<imageobject><imagedata fileref=\"&" os <<"<imageobject><imagedata fileref=\"&"
<< graphic_label << ";." << format << "\" " << attributes ; << graphic_label << ";." << format << "\" " << attributes ;
if (runparams.flavor == OutputParams::XML) { if (runparams.flavor == OutputParams::XML) {
os << " role=\"" << format << "\"/>" ; os << " role=\"" << format << "\"/>" ;
@ -831,14 +833,14 @@ int InsetGraphics::docbook(Buffer const &, ostream & os,
params().filename.absFilename()); params().filename.absFilename());
} }
os << "<inlinemediaobject>"; os << "<inlinemediaobject>";
int r = 0; int r = 0;
string attributes = createDocBookAttributes(); string attributes = createDocBookAttributes();
r += writeImageObject("png", os, runparams, graphic_label, attributes); r += writeImageObject("png", os, runparams, graphic_label, attributes);
r += writeImageObject("pdf", os, runparams, graphic_label, attributes); r += writeImageObject("pdf", os, runparams, graphic_label, attributes);
r += writeImageObject("eps", os, runparams, graphic_label, attributes); r += writeImageObject("eps", os, runparams, graphic_label, attributes);
r += writeImageObject("bmp", os, runparams, graphic_label, attributes); r += writeImageObject("bmp", os, runparams, graphic_label, attributes);
os << "</inlinemediaobject>"; os << "</inlinemediaobject>";
return r; return r;
} }

View File

@ -36,6 +36,7 @@
#include "lyxtextclasslist.h" #include "lyxtextclasslist.h"
#include "lyxserver.h" #include "lyxserver.h"
#include "MenuBackend.h" #include "MenuBackend.h"
#include "mover.h"
#include "ToolbarBackend.h" #include "ToolbarBackend.h"
#include "mathed/math_inset.h" #include "mathed/math_inset.h"
@ -373,6 +374,7 @@ void LyX::init(bool gui)
system_lyxrc = lyxrc; system_lyxrc = lyxrc;
system_formats = formats; system_formats = formats;
system_converters = converters; system_converters = converters;
system_movers = movers;
system_lcolor = lcolor; system_lcolor = lcolor;
string prefsfile = "preferences"; string prefsfile = "preferences";

View File

@ -29,6 +29,7 @@
#include "LColor.h" #include "LColor.h"
#include "lyxlex.h" #include "lyxlex.h"
#include "lyxfont.h" #include "lyxfont.h"
#include "mover.h"
#include "graphics/GraphicsTypes.h" #include "graphics/GraphicsTypes.h"
@ -71,6 +72,7 @@ keyword_item lyxrcTags[] = {
{ "\\check_lastfiles", LyXRC::RC_CHECKLASTFILES }, { "\\check_lastfiles", LyXRC::RC_CHECKLASTFILES },
{ "\\chktex_command", LyXRC::RC_CHKTEX_COMMAND }, { "\\chktex_command", LyXRC::RC_CHKTEX_COMMAND },
{ "\\converter", LyXRC::RC_CONVERTER }, { "\\converter", LyXRC::RC_CONVERTER },
{ "\\copier", LyXRC::RC_COPIER },
{ "\\cursor_follows_scrollbar", LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR }, { "\\cursor_follows_scrollbar", LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR },
{ "\\custom_export_command", LyXRC::RC_CUSTOM_EXPORT_COMMAND }, { "\\custom_export_command", LyXRC::RC_CUSTOM_EXPORT_COMMAND },
{ "\\custom_export_format", LyXRC::RC_CUSTOM_EXPORT_FORMAT }, { "\\custom_export_format", LyXRC::RC_CUSTOM_EXPORT_FORMAT },
@ -964,6 +966,18 @@ int LyXRC::read(LyXLex & lexrc)
} }
break; break;
case RC_COPIER: {
string fmt, command;
if (lexrc.next()) {
fmt = lexrc.getString();
}
if (lexrc.next()) {
command = lexrc.getString();
}
movers.set(fmt, command);
break;
}
case RC_CONVERTER: { case RC_CONVERTER: {
string from, to, command, flags; string from, to, command, flags;
if (lexrc.next()) { if (lexrc.next()) {
@ -1136,6 +1150,23 @@ void LyXRC::print() const
} }
struct SameMover {
typedef std::pair<std::string, SpecialisedMover> Data;
SameMover(Data const & comparison)
: comparison_(comparison) {}
bool operator()(Data const & data) const
{
return data.first == comparison_.first &&
data.second.command() == comparison_.second.command();
}
private:
Data comparison_;
};
void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
{ {
os << "### This file is part of\n" os << "### This file is part of\n"
@ -1915,7 +1946,34 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc) const
os << "\\converter \"" << cit->from os << "\\converter \"" << cit->from
<< "\" \"" << cit->to << "\" \"\" \"\"\n"; << "\" \"" << cit->to << "\" \"\" \"\"\n";
case RC_COPIER:
os << "\n#\n"
<< "# COPIERS SECTION ##########################\n"
<< "#\n\n";
// Look for new movers
Movers::iterator const sysbegin = system_movers.begin();
Movers::iterator const sysend = system_movers.end();
for (Movers::iterator it = movers.begin(), end = movers.end();
it != end; ++it) {
Movers::iterator const sysit =
std::find_if(sysbegin, sysend, SameMover(*it));
if (sysit == sysend) {
std::string const & fmt = it->first;
std::string const & command =
it->second.command();
os << "\\copier " << fmt
<< " \"" << command << "\"\n";
}
}
// We don't actually delete SpecialisedMover(s) from the
// map, just clear their 'command', so there's no need
// to test for anything else.
} }
os.flush(); os.flush();
} }

View File

@ -120,6 +120,7 @@ enum LyXRCTags {
RC_SHOW_BANNER, RC_SHOW_BANNER,
RC_WHEEL_JUMP, RC_WHEEL_JUMP,
RC_CONVERTER, RC_CONVERTER,
RC_COPIER,
RC_VIEWER, RC_VIEWER,
RC_FORMAT, RC_FORMAT,
RC_DEFAULT_LANGUAGE, RC_DEFAULT_LANGUAGE,

83
src/mover.C Normal file
View File

@ -0,0 +1,83 @@
/**
* \file mover.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
#include "mover.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/systemcall.h"
#include <sstream>
using std::ostringstream;
using std::string;
namespace support = lyx::support;
Movers movers;
Movers system_movers;
bool Mover::do_copy(string const & from, string const & to) const
{
return support::copy(from, to);
}
bool Mover::do_rename(string const & from, string const & to) const
{
return support::rename(from, to);
}
bool SpecialisedMover::do_copy(string const & from, string const & to) const
{
if (command_.empty())
return Mover::do_copy(from, to);
string command = support::LibScriptSearch(command_);
command = support::subst(command, "$$i", from);
command = support::subst(command, "$$o", to);
support::Systemcall one;
return one.startscript(support::Systemcall::Wait, command) == 0;
}
bool SpecialisedMover::do_rename(string const & from, string const & to) const
{
if (command_.empty())
return Mover::do_rename(from, to);
if (!do_copy(from, to))
return false;
return support::unlink(from) == 0;
}
void Movers::set(string const & fmt, string const & command)
{
specials_[fmt] = SpecialisedMover(command);
}
Mover const & Movers::operator()(string const & fmt) const
{
SpecialsMap::const_iterator const it = specials_.find(fmt);
return (it == specials_.end()) ? default_ : it->second;
}
string const Movers::command(string const & fmt) const
{
SpecialsMap::const_iterator const it = specials_.find(fmt);
return (it == specials_.end()) ? string() : it->second.command();
}

128
src/mover.h Normal file
View File

@ -0,0 +1,128 @@
// -*- C++ -*-
/**
* \file mover.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS.
*/
#ifndef MOVER_H
#define MOVER_H
#include <map>
#include <string>
/**
* Utility to copy a file of a specified format from one place to another.
* This base class simply invokes the command support::copy().
*/
class Mover
{
public:
virtual ~Mover() {}
/** Copy file @c from to @c to.
* \returns true if successful.
*/
bool
copy(std::string const & from, std::string const & to) const
{
return do_copy(from, to);
}
/** Rename file @c from as @c to.
* \returns true if successful.
*/
bool
rename(std::string const & from, std::string const & to) const
{
return do_rename(from, to);
}
protected:
virtual bool
do_copy(std::string const & from, std::string const & to) const;
virtual bool
do_rename(std::string const & from, std::string const & to) const;
};
/**
* Specialisation of the Mover concept that uses an external command
* to copy a file.
*
* For example, an XFig .fig file can contain references to external
* picture files. If such a reference has a relative path, then the
* copied .fig file will require a transformation of the picture file
* reference if it is to be found by XFig.
*/
struct SpecialisedMover : public Mover
{
SpecialisedMover() {}
/** @c command should be of the form
* <code>
* sh $$s/copy_fig.sh $$i $$o
* </code>
* where $$s is a placeholder for the lyx script directory,
* $$i is a placeholder for the name of the file to be moved,
* $$o is a placeholder for the name of the file after moving.
*/
SpecialisedMover(std::string const & command)
: command_(command) {}
/// The template used to launch the external command.
std::string const & command() const { return command_; }
private:
virtual bool
do_copy(std::string const & from, std::string const & to) const;
virtual bool
do_rename(std::string const & from, std::string const & to) const;
std::string command_;
};
/**
* Manage the store of (Mover)s.
*/
class Movers
{
public:
/** Register a specialised @c command to be used to copy a file
* of format @c fmt.
*/
void set(std::string const & fmt, std::string const & command);
/// @c returns the Mover registered for format @c fmt.
Mover const & operator()(std::string const & fmt) const;
/** @returns the command template if @c fmt 'finds' a
* SpecialisedMover. Otherwise, returns an empty string.
*/
std::string const command(std::string const & fmt) const;
private:
typedef std::map<std::string, SpecialisedMover> SpecialsMap;
public:
typedef SpecialsMap::const_iterator iterator;
iterator begin() const { return specials_.begin(); }
iterator end() const { return specials_.end(); }
private:
Mover default_;
SpecialsMap specials_;
};
extern Movers movers;
extern Movers system_movers;
#endif // MOVER_H