Import patch from Dekel.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1199 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2000-11-06 11:20:22 +00:00
parent adaef99e60
commit 29f7055e95
23 changed files with 524 additions and 185 deletions

View File

@ -1,3 +1,43 @@
2000-11-06 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* lib/configure.m4: == is not a valid operator for command test.
* src/lyxrc.C: add using directive.
* src/converter.h: add std:: qualifier.
2000-11-03 Dekel Tsur <dekelts@tau.ac.il>
* src/converter.[Ch] and other files: Change the Format class to a
real class, and create two instances: formats and system_format.
* src/lyxrc.C (output): Output the difference between formats and
system_formats.
* src/frontends/xforms/FormPreferences.C (input): Simplify.
(buildFormats): Insert formats into browser.
(inputFormats): Made the browser and add button functional.
(applyFormats): Update formats from format_vec.
* src/converter.C: Changed all (*it). to it->
(Format::dummy): New method.
(Format::importer): New format flag.
(Formats::GetAllFormats): New method.
(Formats::Add): Delete format from the map if prettyname is empty.
(Converter::Convert): Print an error message if moving the file fails.
(Converter::GetReachableTo): New method
* src/MenuBackend.[Ch]: Add support for importformats tag.
* src/support/rename.C (rename): Call to lyx::copy if ::rename fails.
* lib/configure.m4: Add word->tex and ps->fax converters.
* lib/ui/default.ui: Use ImportFormats on file->import menu.
Return fax to file menu.
* NEWS: Updated.
2000-11-04 Lars Gullik Bjønnes <larsbj@lyx.org> 2000-11-04 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/frontends/xforms/FormPreferences.h (operator=): move out of RGB * src/frontends/xforms/FormPreferences.h (operator=): move out of RGB

16
NEWS
View File

@ -52,11 +52,12 @@ Other major changes in 1.1.6 include:
rendering when you do Ascii export if you have gifscii installed. rendering when you do Ascii export if you have gifscii installed.
- The code which converts from LyX format to anything else (for - The code which converts from LyX format to anything else (for
viewing or exporting purposes) has been rewritten. In particular, the viewing or exporting purposes) and from anything else to LyX has been
PDF format is now supported. In fact it's now possible to add rewritten. In particular, it is now possible to export to PDF, and to
new export formats without recompiling LyX by specifying external import from HTML/MSWord. In fact it's now possible to add new import/export
programs or scripts in lyxrc settings (note that the old export lyxrc formats without recompiling LyX by specifying external programs or scripts
settings no longer work). in lyxrc settings
(note that the old import/export lyxrc settings no longer work).
- LyX can do command line exports without opening any GUI components. - LyX can do command line exports without opening any GUI components.
@ -67,11 +68,14 @@ Other major changes in 1.1.6 include:
have differently encoded languages in the same paragraph. have differently encoded languages in the same paragraph.
The languages and the encodings are defined in text files. The languages and the encodings are defined in text files.
- Improved support for Hebrew and Arabic (already present in 1.1.5fix2). - Improved support for Hebrew and Arabic (also present in 1.1.5fix2).
- included files work now with docbook and linuxdoc; new layout - included files work now with docbook and linuxdoc; new layout
docbook-book. docbook-book.
- PSpell library and Aspell spell checker support now included thanks
largely to Kevin Atkinson (PSpell and Aspell maintainer).
And finally, there have been a lot of smaller changes, which are And finally, there have been a lot of smaller changes, which are
mentioned here for your information mentioned here for your information

90
lib/configure vendored
View File

@ -333,6 +333,43 @@ fi
test $html_to_latex_command = "html2latex" && html_to_latex_command="html2latex \$\$FName" test $html_to_latex_command = "html2latex" && html_to_latex_command="html2latex \$\$FName"
echo $ac_n "checking for a MSWord -> Latex converter""... $ac_c"
echo "$ac_t""(wvCleanLatex word2x)"
word_to_latex_command=
for ac_prog in wvCleanLatex word2x
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog ; ac_word=$2
if test -n "$ac_word"; then
echo $ac_n "+checking for \"$ac_word\"""... $ac_c"
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
for ac_dir in $PATH; do
test -z "$ac_dir" && ac_dir=.
if test -x $ac_dir/$ac_word; then
word_to_latex_command="$ac_prog"
break
fi
done
IFS="$ac_save_ifs"
if test -n "$word_to_latex_command"; then
ac_result=yes
else
ac_result=no
fi
echo "$ac_t""$ac_result"
test -n "$word_to_latex_command" && break
fi
done
if test -z "$word_to_latex_command" ; then
word_to_latex_command=none
fi
test $word_to_latex_command = "wvCleanLatex" && word_to_latex_command="wvCleanLatex \$\$FName \$\$OutName"
test $word_to_latex_command = "word2x" && word_to_latex_command="word2x -f latex \$\$FName"
echo $ac_n "checking for Image converter""... $ac_c" echo $ac_n "checking for Image converter""... $ac_c"
echo "$ac_t""(convert)" echo "$ac_t""(convert)"
image_command= image_command=
@ -737,6 +774,43 @@ fi
# Search a GUI Fax program
echo $ac_n "checking for a fax program""... $ac_c"
echo "$ac_t""(ksendfax)"
fax_command=
for ac_prog in ksendfax
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog ; ac_word=$2
if test -n "$ac_word"; then
echo $ac_n "+checking for \"$ac_word\"""... $ac_c"
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
for ac_dir in $PATH; do
test -z "$ac_dir" && ac_dir=.
if test -x $ac_dir/$ac_word; then
fax_command="$ac_prog"
break
fi
done
IFS="$ac_save_ifs"
if test -n "$fax_command"; then
ac_result=yes
else
ac_result=no
fi
echo "$ac_t""$ac_result"
test -n "$fax_command" && break
fi
done
if test -z "$fax_command" ; then
fax_command=none
fi
test $fax_command = "ksendfax" && fax_command="ksendfax \$\$FName"
# Search for LinuxDoc support # Search for LinuxDoc support
echo $ac_n "checking for SGML-tools 1.x (LinuxDoc)""... $ac_c" echo $ac_n "checking for SGML-tools 1.x (LinuxDoc)""... $ac_c"
echo "$ac_t""(sgml2lyx)" echo "$ac_t""(sgml2lyx)"
@ -1017,28 +1091,32 @@ cat >lyxrc.defaults <<EOF
\\Format pdf pdf PDF P \\Format pdf pdf PDF P
\\Format html html HTML H \\Format html html HTML H
\\Format text txt ASCII A \\Format text txt ASCII A
\\Format literate nw NoWeb W \\Format word doc Word W
\\Format literate nw NoWeb N
\\Format linuxdoc sgml LinuxDoc x \\Format linuxdoc sgml LinuxDoc x
\\Format docbook sgml DocBook B \\Format docbook sgml DocBook B
\\Format program run Program r \\Format program "" Program ""
\\Format fax "" Fax ""
\\converter latex lyx "$tex_to_lyx_command" ""
\\converter latex dvi "$LATEX" "latex,disable=linuxdoc&docbook" \\converter latex dvi "$LATEX" "latex,disable=linuxdoc&docbook"
\\converter latex pdf "$PDFLATEX" "latex,disable=linuxdoc&docbook" \\converter latex pdf "$PDFLATEX" "latex,disable=linuxdoc&docbook"
\\converter latex html "$latex_to_html_command" \\converter latex html "$latex_to_html_command"
"originaldir,needaux,disable=linuxdoc&docbook" "originaldir,needaux,disable=linuxdoc&docbook"
\\converter literate lyx "$literate_to_lyx_command" ""
\\converter literate latex "$literate_to_tex_command" "" \\converter literate latex "$literate_to_tex_command" ""
\\converter dvi ps "$dvi_to_ps_command" "" \\converter dvi ps "$dvi_to_ps_command" ""
\\converter ps pdf "$ps_to_pdf_command" "" \\converter ps pdf "$ps_to_pdf_command" ""
\\converter ps fax "$fax_command" ""
\\converter linuxdoc lyx "$linuxdoc_to_lyx_command" "" \\converter linuxdoc lyx "$linuxdoc_to_lyx_command" ""
\\converter linuxdoc latex "$linuxdoc_to_latex_command" "" \\converter linuxdoc latex "$linuxdoc_to_latex_command" ""
\\converter linuxdoc dvi "$linuxdoc_to_dvi_command" "" \\converter linuxdoc dvi "$linuxdoc_to_dvi_command" ""
\\converter linuxdoc html "$linuxdoc_to_html_command" "" \\converter linuxdoc html "$linuxdoc_to_html_command" ""
\\converter docbook dvi "$docbook_to_dvi_command" "" \\converter docbook dvi "$docbook_to_dvi_command" ""
\\converter docbook html "$docbook_to_html_command" "" \\converter docbook html "$docbook_to_html_command" ""
\\converter html latex "$html_to_latex_command"
"disable=latex&literate&linuxdoc&docbook" \\converter latex lyx "$tex_to_lyx_command" "importer"
\\converter literate lyx "$literate_to_lyx_command" "importer"
\\converter html latex "$html_to_latex_command" "importer"
\\converter word latex "$word_to_latex_command" "importer"
\converter gif eps "$image_command" "" \converter gif eps "$image_command" ""
\converter png eps "$image_command" "" \converter png eps "$image_command" ""

View File

@ -196,6 +196,10 @@ test $literate_to_tex_command = "noweave" && literate_to_tex_command="noweave -d
SEARCH_PROG([for a HTML -> Latex converter],html_to_latex_command,html2latex) SEARCH_PROG([for a HTML -> Latex converter],html_to_latex_command,html2latex)
test $html_to_latex_command = "html2latex" && html_to_latex_command="html2latex \$\$FName" test $html_to_latex_command = "html2latex" && html_to_latex_command="html2latex \$\$FName"
SEARCH_PROG([for a MSWord -> Latex converter],word_to_latex_command,wvCleanLatex word2x)
test $word_to_latex_command = "wvCleanLatex" && word_to_latex_command="wvCleanLatex \$\$FName \$\$OutName"
test $word_to_latex_command = "word2x" && word_to_latex_command="word2x -f latex \$\$FName"
SEARCH_PROG([for Image converter],image_command,convert) SEARCH_PROG([for Image converter],image_command,convert)
test $image_command = "convert" && image_command="convert \$\$FName \$\$OutName" test $image_command = "convert" && image_command="convert \$\$FName \$\$OutName"
@ -248,6 +252,10 @@ dnl else
dnl fax_command="none" dnl fax_command="none"
dnl fi dnl fi
# Search a GUI Fax program
SEARCH_PROG([for a fax program], fax_command, ksendfax)
test $fax_command = "ksendfax" && fax_command="ksendfax \$\$FName"
# Search for LinuxDoc support # Search for LinuxDoc support
SEARCH_PROG([for SGML-tools 1.x (LinuxDoc)], LINUXDOC, sgml2lyx) SEARCH_PROG([for SGML-tools 1.x (LinuxDoc)], LINUXDOC, sgml2lyx)
chk_linuxdoc=no chk_linuxdoc=no
@ -384,28 +392,32 @@ cat >lyxrc.defaults <<EOF
\\Format pdf pdf PDF P \\Format pdf pdf PDF P
\\Format html html HTML H \\Format html html HTML H
\\Format text txt ASCII A \\Format text txt ASCII A
\\Format literate nw NoWeb W \\Format word doc Word W
\\Format literate nw NoWeb N
\\Format linuxdoc sgml LinuxDoc x \\Format linuxdoc sgml LinuxDoc x
\\Format docbook sgml DocBook B \\Format docbook sgml DocBook B
\\Format program run Program r \\Format program "" Program ""
\\Format fax "" Fax ""
\\converter latex lyx "$tex_to_lyx_command" ""
\\converter latex dvi "$LATEX" "latex,disable=linuxdoc&docbook" \\converter latex dvi "$LATEX" "latex,disable=linuxdoc&docbook"
\\converter latex pdf "$PDFLATEX" "latex,disable=linuxdoc&docbook" \\converter latex pdf "$PDFLATEX" "latex,disable=linuxdoc&docbook"
\\converter latex html "$latex_to_html_command" \\converter latex html "$latex_to_html_command"
"originaldir,needaux,disable=linuxdoc&docbook" "originaldir,needaux,disable=linuxdoc&docbook"
\\converter literate lyx "$literate_to_lyx_command" ""
\\converter literate latex "$literate_to_tex_command" "" \\converter literate latex "$literate_to_tex_command" ""
\\converter dvi ps "$dvi_to_ps_command" "" \\converter dvi ps "$dvi_to_ps_command" ""
\\converter ps pdf "$ps_to_pdf_command" "" \\converter ps pdf "$ps_to_pdf_command" ""
\\converter ps fax "$fax_command" ""
\\converter linuxdoc lyx "$linuxdoc_to_lyx_command" "" \\converter linuxdoc lyx "$linuxdoc_to_lyx_command" ""
\\converter linuxdoc latex "$linuxdoc_to_latex_command" "" \\converter linuxdoc latex "$linuxdoc_to_latex_command" ""
\\converter linuxdoc dvi "$linuxdoc_to_dvi_command" "" \\converter linuxdoc dvi "$linuxdoc_to_dvi_command" ""
\\converter linuxdoc html "$linuxdoc_to_html_command" "" \\converter linuxdoc html "$linuxdoc_to_html_command" ""
\\converter docbook dvi "$docbook_to_dvi_command" "" \\converter docbook dvi "$docbook_to_dvi_command" ""
\\converter docbook html "$docbook_to_html_command" "" \\converter docbook html "$docbook_to_html_command" ""
\\converter html latex "$html_to_latex_command"
"disable=latex&literate&linuxdoc&docbook" \\converter latex lyx "$tex_to_lyx_command" "importer"
\\converter literate lyx "$literate_to_lyx_command" "importer"
\\converter html latex "$html_to_latex_command" "importer"
\\converter word latex "$word_to_latex_command" "importer"
\converter gif eps "$image_command" "" \converter gif eps "$image_command" ""
\converter png eps "$image_command" "" \converter png eps "$image_command" ""

View File

@ -335,7 +335,8 @@
# #
# The \converter command defines a converter between two formats. # The \converter command defines a converter between two formats.
# LyX uses the defined converters for generating output in varius formats. # LyX uses the defined converters for generating output in various formats,
# or for importing.
# The converter command has 4 arguments: The source format, the target format, # The converter command has 4 arguments: The source format, the target format,
# the command, and additional flags. # the command, and additional flags.
# For example, the following defines a DVI->Postscript converter: # For example, the following defines a DVI->Postscript converter:
@ -345,6 +346,7 @@
# The flags argument is a list of comma separated flags. # The flags argument is a list of comma separated flags.
# Known flags are # Known flags are
# - * : copy the previously defined flags # - * : copy the previously defined flags
# - importer : The converter is used for importing.
# - latex : The converter is latex or its derivatives (pdflatex). # - latex : The converter is latex or its derivatives (pdflatex).
# - originaldir : The converter must be invoked in the directory of the lyx # - originaldir : The converter must be invoked in the directory of the lyx
# file and not in the temporary directory. This is needed for tex->html # file and not in the temporary directory. This is needed for tex->html

View File

@ -52,6 +52,7 @@ Menuset
Separator Separator
Submenu "Export|E" "exportfile" Submenu "Export|E" "exportfile"
Item "Print...|P" "buffer-print" Item "Print...|P" "buffer-print"
Item "Fax...|F" "buffer-export fax"
Separator Separator
Item "Exit|x" "lyx-quit" Item "Exit|x" "lyx-quit"
Separator Separator
@ -59,12 +60,9 @@ Menuset
End End
Menu "fileimport" Menu "fileimport"
OptItem "LaTeX...|L" "buffer-import latex" Item "Ascii text as lines...|A" "buffer-import text"
OptItem "Ascii text as lines...|A" "buffer-import text" Item "Ascii text as paragraphs...|p" "buffer-import textparagraph"
OptItem "Ascii text as paragraphs...|p" "buffer-import textparagraph" ImportFormats
OptItem "HTML...|H" "buffer-import html"
OptItem "Noweb...|N" "buffer-import literate"
OptItem "LinuxDoc...|D" "buffer-import linuxdoc"
End End
Menu "fileinsert" Menu "fileinsert"

View File

@ -27,7 +27,7 @@ void ShowLatexLog()
if (!filename.empty()) { if (!filename.empty()) {
fname = OnlyFilename(ChangeExtension(filename, ".log")); fname = OnlyFilename(ChangeExtension(filename, ".log"));
bname = OnlyFilename(ChangeExtension(filename, bname = OnlyFilename(ChangeExtension(filename,
Formats::Extension("literate") + ".out")); formats.Extension("literate") + ".out"));
path = OnlyPath(filename); path = OnlyPath(filename);
if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
path = current_view->buffer()->tmppath; path = current_view->buffer()->tmppath;

View File

@ -55,6 +55,7 @@ MenuItem::MenuItem(Kind kind, string const & label,
case ViewFormats: case ViewFormats:
case UpdateFormats: case UpdateFormats:
case ExportFormats: case ExportFormats:
case ImportFormats:
break; break;
case Command: case Command:
action_ = lyxaction.LookupFunc(command); action_ = lyxaction.LookupFunc(command);
@ -88,6 +89,7 @@ Menu & Menu::read(LyXLex & lex)
md_documents, md_documents,
md_endmenu, md_endmenu,
md_exportformats, md_exportformats,
md_importformats,
md_lastfiles, md_lastfiles,
md_optitem, md_optitem,
md_references, md_references,
@ -103,6 +105,7 @@ Menu & Menu::read(LyXLex & lex)
{ "documents", md_documents }, { "documents", md_documents },
{ "end", md_endmenu }, { "end", md_endmenu },
{ "exportformats", md_exportformats }, { "exportformats", md_exportformats },
{ "importformats", md_importformats },
{ "item", md_item }, { "item", md_item },
{ "lastfiles", md_lastfiles }, { "lastfiles", md_lastfiles },
{ "optitem", md_optitem }, { "optitem", md_optitem },
@ -169,6 +172,10 @@ Menu & Menu::read(LyXLex & lex)
add(MenuItem(MenuItem::ExportFormats)); add(MenuItem(MenuItem::ExportFormats));
break; break;
case md_importformats:
add(MenuItem(MenuItem::ImportFormats));
break;
case md_submenu: { case md_submenu: {
lex.next(); lex.next();
string mlabel = _(lex.GetString()); string mlabel = _(lex.GetString());
@ -272,19 +279,21 @@ void Menu::expand(Menu & tomenu, Buffer * buf) const
vector<FormatPair> names; vector<FormatPair> names;
kb_action action; kb_action action;
if ((*cit).kind() == MenuItem::ViewFormats) { if ((*cit).kind() == MenuItem::ViewFormats) {
names = Exporter::GetViewableFormats(buf); names = Exporter::GetExportableFormats(buf, true);
action = LFUN_PREVIEW; action = LFUN_PREVIEW;
} else if ((*cit).kind() == MenuItem::UpdateFormats) { } else if ((*cit).kind() == MenuItem::UpdateFormats) {
names = Exporter::GetViewableFormats(buf); names = Exporter::GetExportableFormats(buf, true);
action = LFUN_UPDATE; action = LFUN_UPDATE;
} else { } else {
names = Exporter::GetExportableFormats(buf); names = Exporter::GetExportableFormats(buf, false);
action = LFUN_EXPORT; action = LFUN_EXPORT;
} }
sort(names.begin(), names.end(), compare_formatpair()); sort(names.begin(), names.end(), compare_formatpair());
for (vector<FormatPair>::const_iterator fit = names.begin(); for (vector<FormatPair>::const_iterator fit = names.begin();
fit != names.end() ; ++fit) { fit != names.end() ; ++fit) {
if ((*fit).format->dummy())
continue;
string fmt = (*fit).format->name; string fmt = (*fit).format->name;
string label = (*fit).format->prettyname; string label = (*fit).format->prettyname;
bool same_before = bool same_before =
@ -311,6 +320,24 @@ void Menu::expand(Menu & tomenu, Buffer * buf) const
} }
break; break;
case MenuItem::ImportFormats: {
vector<FormatPair> names = Converter::GetReachableTo("lyx");
sort(names.begin(), names.end(), compare_formatpair());
for (vector<FormatPair>::const_iterator fit = names.begin();
fit != names.end() ; ++fit) {
if ((*fit).format->dummy())
continue;
string fmt = (*fit).format->name;
string label = (*fit).format->prettyname;
if (!(*fit).format->shortcut.empty())
label += "|" + (*fit).format->shortcut;
int action2 = lyxaction.getPseudoAction(LFUN_IMPORT, fmt);
tomenu.add(MenuItem(MenuItem::Command,
label, action2));
}
}
break;
default: default:
tomenu.add(*cit); tomenu.add(*cit);

View File

@ -54,7 +54,10 @@ public:
UpdateFormats, UpdateFormats,
/** This is a list of exportable formats /** This is a list of exportable formats
typically for the File->Export menu. */ typically for the File->Export menu. */
ExportFormats ExportFormats,
/** This is a list of importable formats
typically for the File->Export menu. */
ImportFormats
}; };
/// Create a Command type MenuItem /// Create a Command type MenuItem
MenuItem(Kind kind, MenuItem(Kind kind,

View File

@ -38,7 +38,6 @@ using std::find_if;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
map<string, Format> Formats::formats;
vector<Command> Converter::commands; vector<Command> Converter::commands;
string Converter::latex_command; string Converter::latex_command;
@ -52,25 +51,41 @@ string const add_options(string const & command, string const & options)
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
bool Format::dummy() const
{
return extension.empty();
}
void Formats::Add(string const & name) void Formats::Add(string const & name)
{ {
if (formats.find(name) == formats.end()) if (formats.find(name) == formats.end())
formats[name] = Format(name, name, name, string()); formats[name] = Format(name, name, name, "", "");
} }
void Formats::Add(string const & name, string const & extension, void Formats::Add(string const & name, string const & extension,
string const & prettyname, string const & shortcut) string const & prettyname, string const & shortcut)
{ {
formats[name] = Format(name, extension, prettyname, shortcut);
if (prettyname.empty()) {
FormatList::iterator it = formats.find(name);
if (it != formats.end())
formats.erase(it);
return;
}
string old_viewer = formats[name].viewer;
formats[name] = Format(name, extension, prettyname, shortcut,
old_viewer);
} }
void Formats::SetViewer(string const & name, string const & command) void Formats::SetViewer(string const & name, string const & command)
{ {
string command2 = command; string command2 = command;
if (!contains(command2,"$$FName")) if (!command2.empty() && !contains(command2,"$$FName"))
command2 += " $$FName"; command2 += " $$FName";
Add(name); Add(name);
@ -88,7 +103,7 @@ bool Formats::View(Buffer const * buffer, string const & filename,
if (!format || format->viewer.empty()) { if (!format || format->viewer.empty()) {
WriteAlert(_("Can not view file"), WriteAlert(_("Can not view file"),
_("No information for viewing ") _("No information for viewing ")
+ Formats::PrettyName(format_name)); + PrettyName(format_name));
return false; return false;
} }
@ -124,9 +139,9 @@ bool Formats::View(Buffer const * buffer, string const & filename,
Format * Formats::GetFormat(string const & name) Format * Formats::GetFormat(string const & name)
{ {
map<string, Format>::iterator it = formats.find(name); FormatList::iterator it = formats.find(name);
if (it != formats.end()) if (it != formats.end())
return &(*it).second; return &it->second;
else else
return 0; return 0;
} }
@ -151,6 +166,18 @@ string const Formats::Extension(string const & name)
return name; return name;
} }
vector<Format>
const Formats::GetAllFormats()
{
vector<Format> result;
for (FormatList::iterator it = formats.begin();
it != formats.end(); ++it)
result.push_back(it->second);
return result;
}
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
class compare_Command { class compare_Command {
@ -167,9 +194,9 @@ private:
void Converter::Add(string const & from, string const & to, void Converter::Add(string const & from, string const & to,
string const & command, string const & flags) string const & command, string const & flags)
{ {
Formats::Add(from); formats.Add(from);
Formats::Add(to); formats.Add(to);
Command Com(Formats::GetFormat(from), Formats::GetFormat(to), command); Command Com(formats.GetFormat(from), formats.GetFormat(to), command);
vector<Command>::iterator it = find_if(commands.begin(), vector<Command>::iterator it = find_if(commands.begin(),
commands.end(), commands.end(),
compare_Command(Com)); compare_Command(Com));
@ -193,6 +220,8 @@ void Converter::Add(string const & from, string const & to,
Com.command = command; Com.command = command;
} }
} }
else if (flag_name == "importer")
Com.importer = true;
else if (flag_name == "latex") else if (flag_name == "latex")
Com.latex = true; Com.latex = true;
else if (flag_name == "originaldir") else if (flag_name == "originaldir")
@ -236,17 +265,47 @@ void Converter::Add(string const & from, string const & to,
inline inline
bool enable(vector<Command>::iterator it, string const & from) bool enable(vector<Command>::iterator it, string const & from)
{ {
return find((*it).disable.begin(), (*it).disable.end(), from) return find(it->disable.begin(), it->disable.end(), from)
== (*it).disable.end(); == it->disable.end();
} }
vector<FormatPair> const vector<FormatPair> const
Converter::GetReachable(string const & from, string const & stop_format, Converter::GetReachableTo(string const & target)
bool only_viewable)
{ {
vector<FormatPair> result; vector<FormatPair> result;
Format const * format = Formats::GetFormat(from);
queue< vector<Command>::iterator > Q;
for (vector<Command>::iterator it = commands.begin();
it != commands.end(); ++it)
if (it->to->name == target && it->importer) {
Q.push(it);
it->visited = true;
} else
it->visited = false;
while (!Q.empty()) {
vector<Command>::iterator it = Q.front();
Q.pop();
result.push_back(FormatPair(it->from, 0, ""));
for (vector<Command>::iterator it2 = commands.begin();
it2 != commands.end(); ++it2)
if (!it2->visited && it->from == it2->to &&
it2->importer) {
Q.push(it2);
it2->visited = true;
}
}
return result;
}
vector<FormatPair> const
Converter::GetReachable(string const & from, bool only_viewable)
{
vector<FormatPair> result;
Format const * format = formats.GetFormat(from);
if (!format) if (!format)
return result; return result;
@ -256,26 +315,25 @@ Converter::GetReachable(string const & from, string const & stop_format,
queue< vector<Command>::iterator > Q; queue< vector<Command>::iterator > Q;
for (vector<Command>::iterator it = commands.begin(); for (vector<Command>::iterator it = commands.begin();
it != commands.end(); ++it) it != commands.end(); ++it)
if ((*it).from->name == from && enable(it, from) if (it->from->name == from && enable(it, from)
&& (*it).to->name != stop_format) { && !it->importer) {
Q.push(it); Q.push(it);
(*it).visited = true; it->visited = true;
} else } else
(*it).visited = false; it->visited = false;
while (!Q.empty()) { while (!Q.empty()) {
vector<Command>::iterator it = Q.front(); vector<Command>::iterator it = Q.front();
Q.pop(); Q.pop();
if (!only_viewable || !(*it).to->viewer.empty()) if (!only_viewable || !it->to->viewer.empty())
result.push_back(FormatPair((*it).to, (*it).from, result.push_back(FormatPair(it->to, it->from,
(*it).command)); it->command));
for (vector<Command>::iterator it2 = commands.begin(); for (vector<Command>::iterator it2 = commands.begin();
it2 != commands.end(); ++it2) it2 != commands.end(); ++it2)
if (!(*it2).visited && (*it).to == (*it2).from && if (!it2->visited && it->to == it2->from &&
enable(it2, from) && enable(it2, from) && !it2->importer) {
(*it2).to->name != stop_format) {
Q.push(it2); Q.push(it2);
(*it2).visited = true; it2->visited = true;
} }
} }
@ -291,23 +349,23 @@ bool Converter::IsReachable(string const & from, string const & to)
queue< vector<Command>::iterator > Q; queue< vector<Command>::iterator > Q;
for (vector<Command>::iterator it = commands.begin(); for (vector<Command>::iterator it = commands.begin();
it != commands.end(); ++it) it != commands.end(); ++it)
if ((*it).from->name == from && enable(it, from)) { if (it->from->name == from && enable(it, from)) {
Q.push(it); Q.push(it);
(*it).visited = true; it->visited = true;
} else } else
(*it).visited = false; it->visited = false;
while (!Q.empty()) { while (!Q.empty()) {
vector<Command>::iterator it = Q.front(); vector<Command>::iterator it = Q.front();
Q.pop(); Q.pop();
if ((*it).to->name == to) if (it->to->name == to)
return true; return true;
for (vector<Command>::iterator it2 = commands.begin(); for (vector<Command>::iterator it2 = commands.begin();
it2 != commands.end(); ++it2) it2 != commands.end(); ++it2)
if (!(*it2).visited && (*it).to == (*it2).from && if (!it2->visited && it->to == it2->from &&
enable(it2, from)) { enable(it2, from)) {
Q.push(it2); Q.push(it2);
(*it2).visited = true; it2->visited = true;
} }
} }
return false; return false;
@ -320,7 +378,7 @@ bool Converter::Convert(Buffer const * buffer,
string const & using_format, string & to_file) string const & using_format, string & to_file)
{ {
to_file = ChangeExtension(to_file_base, to_file = ChangeExtension(to_file_base,
Formats::Extension(to_format)); formats.Extension(to_format));
if (from_format == to_format) if (from_format == to_format)
if (from_file != to_file) if (from_file != to_file)
@ -331,12 +389,12 @@ bool Converter::Convert(Buffer const * buffer,
queue< vector<Command>::iterator > Q; queue< vector<Command>::iterator > Q;
for (vector<Command>::iterator it = commands.begin(); for (vector<Command>::iterator it = commands.begin();
it != commands.end(); ++it) it != commands.end(); ++it)
if ((*it).from->name == from_format && enable(it, from_format)) { if (it->from->name == from_format && enable(it, from_format)) {
Q.push(it); Q.push(it);
(*it).visited = true; it->visited = true;
(*it).previous = commands.end(); it->previous = commands.end();
} else } else
(*it).visited = false; it->visited = false;
if (Q.empty()) { if (Q.empty()) {
WriteAlert(_("Can not convert file"), WriteAlert(_("Can not convert file"),
@ -348,34 +406,34 @@ bool Converter::Convert(Buffer const * buffer,
vector<Command>::iterator it; vector<Command>::iterator it;
while (!Q.empty()) { while (!Q.empty()) {
it = Q.front(); it = Q.front();
if ((*it).to->name == to_format && if (it->to->name == to_format &&
(using_format.empty() || using_format == (*it).from->name)) { (using_format.empty() || using_format == it->from->name)) {
found = true; found = true;
break; break;
} }
Q.pop(); Q.pop();
for (vector<Command>::iterator it2 = commands.begin(); for (vector<Command>::iterator it2 = commands.begin();
it2 != commands.end(); ++it2) it2 != commands.end(); ++it2)
if (!(*it2).visited && (*it).to == (*it2).from && if (!it2->visited && it->to == it2->from &&
enable(it2, from_format)) { enable(it2, from_format)) {
Q.push(it2); Q.push(it2);
(*it2).visited = true; it2->visited = true;
(*it2).previous = it; it2->previous = it;
} }
} }
if (!found) { if (!found) {
WriteAlert(_("Can not convert file"), WriteAlert(_("Can not convert file"),
_("No information for converting from ") _("No information for converting from ")
+ Formats::PrettyName(from_format) + _(" to ") + formats.PrettyName(from_format) + _(" to ")
+ Formats::PrettyName(to_format)); + formats.PrettyName(to_format));
return false; return false;
} }
vector< vector<Command>::iterator > S; vector< vector<Command>::iterator > S;
while (it != commands.end()) { while (it != commands.end()) {
S.push_back(it); S.push_back(it);
it = (*it).previous; it = it->previous;
} }
string path = OnlyPath(from_file); string path = OnlyPath(from_file);
@ -389,62 +447,66 @@ bool Converter::Convert(Buffer const * buffer,
for (vector< vector<Command>::iterator >::reverse_iterator rit = for (vector< vector<Command>::iterator >::reverse_iterator rit =
S.rbegin(); rit != S.rend(); ++rit) { S.rbegin(); rit != S.rend(); ++rit) {
it = *rit; it = *rit;
lyxerr << "Converting from " bool dummy = it->to->dummy() && it->to->name != "program";
<< (*it).from->name << " to " << (*it).to->name << endl; if (!dummy)
lyxerr << "Converting from "
<< it->from->name << " to " << it->to->name << endl;
infile = outfile; infile = outfile;
outfile = (*it).result_dir.empty() outfile = it->result_dir.empty()
? ChangeExtension(from_file, (*it).to->extension) ? ChangeExtension(from_file, it->to->extension)
: AddName(subst((*it).result_dir, : AddName(subst(it->result_dir,
"$$BaseName", from_base), "$$BaseName", from_base),
subst((*it).result_file, subst(it->result_file,
"$$BaseName", OnlyFilename(from_base))); "$$BaseName", OnlyFilename(from_base)));
if ((*it).latex) { if (it->latex) {
lyxrc.pdf_mode = (*it).to->name == "pdf"; lyxrc.pdf_mode = it->to->name == "pdf";
lyxerr << "Running " << (*it).command << endl; lyxerr << "Running " << it->command << endl;
run_latex = true; run_latex = true;
if (!runLaTeX(buffer, (*it).command)) if (!runLaTeX(buffer, it->command))
return false; return false;
} else { } else {
if ((*it).need_aux && !run_latex if (it->need_aux && !run_latex
&& !latex_command.empty()) { && !latex_command.empty()) {
lyxerr << "Running " << latex_command lyxerr << "Running " << latex_command
<< " to update aux file"<< endl; << " to update aux file"<< endl;
runLaTeX(buffer, latex_command); runLaTeX(buffer, latex_command);
} }
string infile2 = ((*it).original_dir) string infile2 = (it->original_dir)
? infile : MakeRelPath(infile, path); ? infile : MakeRelPath(infile, path);
string outfile2 = ((*it).original_dir) string outfile2 = (it->original_dir)
? outfile : MakeRelPath(outfile, path); ? outfile : MakeRelPath(outfile, path);
string command = (*it).command; string command = it->command;
command = subst(command, "$$FName", QuoteName(infile2)); command = subst(command, "$$FName", QuoteName(infile2));
command = subst(command, "$$BaseName", QuoteName(from_base)); command = subst(command, "$$BaseName", QuoteName(from_base));
command = subst(command, "$$OutName", QuoteName(outfile2)); command = subst(command, "$$OutName", QuoteName(outfile2));
if (!(*it).parselog.empty()) if (!it->parselog.empty())
command += " 2> " + QuoteName(infile2 + ".out"); command += " 2> " + QuoteName(infile2 + ".out");
if ((*it).from->name == "dvi" && (*it).to->name == "ps") if (it->from->name == "dvi" && it->to->name == "ps")
command = add_options(command, command = add_options(command,
dvips_options(buffer)); dvips_options(buffer));
lyxerr << "Calling " << command << endl; lyxerr << "Calling " << command << endl;
if (buffer) if (buffer)
ShowMessage(buffer, _("Executing command:"), command); ShowMessage(buffer, _("Executing command:"), command);
Systemcalls::Starttype type = (dummy)
? Systemcalls::SystemDontWait : Systemcalls::System;
Systemcalls one; Systemcalls one;
int res; int res;
if ((*it).original_dir && buffer) { if (it->original_dir && buffer) {
Path p(buffer->filepath); Path p(buffer->filepath);
res = one.startscript(Systemcalls::System, command); res = one.startscript(type, command);
} else } else
res = one.startscript(Systemcalls::System, command); res = one.startscript(type, command);
if (!(*it).parselog.empty()) { if (!it->parselog.empty()) {
string const logfile = infile2 + ".log"; string const logfile = infile2 + ".log";
string const command2 = (*it).parselog + string const command2 = it->parselog +
" < " + QuoteName(infile2 + ".out") + " < " + QuoteName(infile2 + ".out") +
" > " + QuoteName(logfile); " > " + QuoteName(logfile);
one.startscript(Systemcalls::System, command2); one.startscript(Systemcalls::System, command2);
@ -453,7 +515,7 @@ bool Converter::Convert(Buffer const * buffer,
} }
if (res) { if (res) {
if ((*it).to->name == "program") if (it->to->name == "program")
WriteAlert(_("There were errors during the Build process."), WriteAlert(_("There were errors during the Build process."),
_("You should try to fix them.")); _("You should try to fix them."));
else else
@ -465,23 +527,36 @@ bool Converter::Convert(Buffer const * buffer,
} }
} }
if (!(*it).result_dir.empty()) { if (it->to->dummy())
to_file = AddName(subst((*it).result_dir, return true;
if (!it->result_dir.empty()) {
to_file = AddName(subst(it->result_dir,
"$$BaseName", to_base), "$$BaseName", to_base),
subst((*it).result_file, subst(it->result_file,
"$$BaseName", OnlyFilename(to_base))); "$$BaseName", OnlyFilename(to_base)));
if (from_base != to_base) { if (from_base != to_base) {
string from = subst((*it).result_dir, string from = subst(it->result_dir,
"$$BaseName", from_base); "$$BaseName", from_base);
string to = subst((*it).result_dir, string to = subst(it->result_dir,
"$$BaseName", to_base); "$$BaseName", to_base);
return lyx::rename(from, to); if (!lyx::rename(from, to)) {
WriteAlert(_("Error while trying to move directory:"),
from, ("to ") + to);
return false;
}
} }
} else if (outfile != to_file) } else if (outfile != to_file) {
if ((*it).latex) bool moved = (it->latex)
return lyx::copy(outfile, to_file); ? lyx::copy(outfile, to_file)
else : lyx::rename(outfile, to_file);
return lyx::rename(outfile, to_file); if (!moved) {
WriteAlert(_("Error while trying to move file:"),
outfile, _("to ") + to_file);
return false;
}
}
return true; return true;
} }
@ -702,3 +777,9 @@ string const Converter::dvips_options(Buffer const * buffer)
void Converter::init() void Converter::init()
{ {
} }
/// The global instance
Formats formats;
// The global copy of the system lyxrc entries (everything except preferences)
Formats system_formats;

View File

@ -29,8 +29,9 @@ public:
Format() {} Format() {}
/// ///
Format(string const & n, string const & e, string const & p, Format(string const & n, string const & e, string const & p,
string const & s) : string const & s, string const & v) :
name(n), extension(e), prettyname(p), shortcut(s) {}; name(n), extension(e), prettyname(p), shortcut(s),
viewer(v) {};
/// ///
string name; string name;
/// ///
@ -41,13 +42,19 @@ public:
string shortcut; string shortcut;
/// ///
string viewer; string viewer;
///
bool dummy() const;
///
string const getname() const {
return name;
}
}; };
/// ///
struct Command { struct Command {
/// ///
Command(Format const * f, Format const * t, string const & c) Command(Format const * f, Format const * t, string const & c)
: from(f), to(t), command(c), : from(f), to(t), command(c), importer(false),
latex(false), original_dir(false), need_aux(false) {} latex(false), original_dir(false), need_aux(false) {}
/// ///
Format const * from; Format const * from;
@ -55,6 +62,8 @@ struct Command {
Format const * to; Format const * to;
/// ///
string command; string command;
/// The converter is used for importing
bool importer;
/// The converter is latex or its derivatives /// The converter is latex or its derivatives
bool latex; bool latex;
/// Do we need to run the converter in the original directory? /// Do we need to run the converter in the original directory?
@ -94,33 +103,29 @@ public:
/// ///
class Formats { class Formats {
public: public:
///
typedef std::map<string, Format> FormatList;
/// ///
static
void Add(string const & name); void Add(string const & name);
/// ///
static
void Add(string const & name, string const & extension, void Add(string const & name, string const & extension,
string const & prettyname, string const & shortcut); string const & prettyname, string const & shortcut);
/// ///
static
void SetViewer(string const & name, string const & command); void SetViewer(string const & name, string const & command);
/// ///
static
bool View(Buffer const * buffer, string const & filename, bool View(Buffer const * buffer, string const & filename,
string const & format_name); string const & format_name);
/// ///
static
Format * GetFormat(string const & name); Format * GetFormat(string const & name);
/// ///
static
string const PrettyName(string const & name); string const PrettyName(string const & name);
/// ///
static
string const Extension(string const & name); string const Extension(string const & name);
///
std::vector<Format> const GetAllFormats();
private: private:
/// ///
static FormatList formats;
std::map<string, Format> formats;
}; };
/// ///
@ -131,12 +136,12 @@ public:
void Add(string const & from, string const & to, void Add(string const & from, string const & to,
string const & command, string const & flags); string const & command, string const & flags);
/// ///
static
std::vector<FormatPair> const GetReachableTo(string const & target);
/// ///
static static
std::vector<FormatPair> const std::vector<FormatPair> const
GetReachable(string const & from, string const & stop_format, GetReachable(string const & from, bool only_viewable);
bool only_viewable);
/// ///
static static
bool IsReachable(string const & from, string const & to); bool IsReachable(string const & from, string const & to);
@ -180,4 +185,8 @@ private:
string latex_command; string latex_command;
}; };
extern Formats formats;
extern Formats system_formats;
#endif #endif

View File

@ -37,7 +37,7 @@ bool Exporter::Export(Buffer * buffer, string const & format0,
if (!buffer->tmppath.empty()) if (!buffer->tmppath.empty())
filename = AddName(buffer->tmppath, filename); filename = AddName(buffer->tmppath, filename);
filename = ChangeExtension(filename, filename = ChangeExtension(filename,
Formats::Extension(backend_format)); formats.Extension(backend_format));
// Ascii backend // Ascii backend
if (backend_format == "text") if (backend_format == "text")
@ -65,7 +65,7 @@ bool Exporter::Export(Buffer * buffer, string const & format0,
if (!put_in_tempdir) if (!put_in_tempdir)
ShowMessage(buffer, ShowMessage(buffer,
_("Document exported as ") _("Document exported as ")
+ Formats::PrettyName(format) + formats.PrettyName(format)
+ _(" to file `") + _(" to file `")
+ MakeDisplayPath(result_file) +'\''); + MakeDisplayPath(result_file) +'\'');
return true; return true;
@ -85,7 +85,7 @@ bool Exporter::Preview(Buffer * buffer, string const & format0)
return false; return false;
string format; string format;
Converter::SplitFormat(format0, format); Converter::SplitFormat(format0, format);
return Formats::View(buffer, result_file, format); return formats.View(buffer, result_file, format);
} }
@ -97,24 +97,12 @@ bool Exporter::IsExportable(Buffer const * buffer, string const & format)
vector<FormatPair> const vector<FormatPair> const
Exporter::GetExportableFormats(Buffer const * buffer) Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
{ {
vector<FormatPair> result = vector<FormatPair> result =
Converter::GetReachable(BufferFormat(buffer), "lyx", false); Converter::GetReachable(BufferFormat(buffer), only_viewable);
Format * format = Formats::GetFormat("text"); Format * format = formats.GetFormat("text");
if (format) if (format && (!only_viewable || !format->viewer.empty()))
result.push_back(FormatPair(format , 0, ""));
return result;
}
vector<FormatPair> const
Exporter::GetViewableFormats(Buffer const * buffer)
{
vector<FormatPair> result =
Converter::GetReachable(BufferFormat(buffer), "lyx", true);
Format * format = Formats::GetFormat("text");
if (format && !format->viewer.empty())
result.push_back(FormatPair(format , 0, "")); result.push_back(FormatPair(format , 0, ""));
return result; return result;
} }

View File

@ -41,11 +41,9 @@ public:
/// ///
static static
std::vector<FormatPair> const std::vector<FormatPair> const
GetExportableFormats(Buffer const * buffer); GetExportableFormats(Buffer const * buffer, bool only_viewable);
/// ///
static
std::vector<FormatPair> const
GetViewableFormats(Buffer const * buffer);
/// ///
static static
string const BufferFormat(Buffer const * buffer); string const BufferFormat(Buffer const * buffer);

View File

@ -29,6 +29,9 @@
#include "input_validators.h" #include "input_validators.h"
#include "xform_helpers.h" // formatted() #include "xform_helpers.h" // formatted()
#include "xform_macros.h" #include "xform_macros.h"
#include "converter.h"
#include "support/lyxfunctional.h"
#ifdef SIGC_CXX_NAMESPACES #ifdef SIGC_CXX_NAMESPACES
using SigC::slot; using SigC::slot;
@ -39,6 +42,7 @@ using std::getline;
using std::istream; using std::istream;
using std::pair; using std::pair;
using std::vector; using std::vector;
using std::find_if;
extern string fmt(char const * fmtstr ...); extern string fmt(char const * fmtstr ...);
extern Languages languages; extern Languages languages;
@ -48,7 +52,6 @@ typedef pair<string, FormPreferences::RGB> X11Colour;
static vector<X11Colour> colourDB; static vector<X11Colour> colourDB;
static string const colourFile("/usr/lib/X11/rgb.txt"); static string const colourFile("/usr/lib/X11/rgb.txt");
FormPreferences::FormPreferences(LyXView * lv, Dialogs * d) FormPreferences::FormPreferences(LyXView * lv, Dialogs * d)
: FormBaseBI(lv, d, _("Preferences"), new PreferencesPolicy), : FormBaseBI(lv, d, _("Preferences"), new PreferencesPolicy),
dialog_(0), dialog_(0),
@ -296,30 +299,24 @@ void FormPreferences::feedback( FL_OBJECT * ob )
bool FormPreferences::input(FL_OBJECT * ob, long) bool FormPreferences::input(FL_OBJECT * ob, long)
{ {
bool activate = true;
// whatever checks you need to ensure the user hasn't entered // whatever checks you need to ensure the user hasn't entered
// some totally ridiculous value somewhere. Change activate to suit. // some totally ridiculous value somewhere. Change activate to suit.
// comments before each test describe what is _valid_ // comments before each test describe what is _valid_
if (ob->form->fdui == colours_) { if (ob->form->fdui == colours_)
if (! inputColours( ob ) ) return inputColours(ob);
activate = false; else if (ob->form->fdui == language_)
} else if (ob->form->fdui == language_) { return inputLanguage(ob);
if (! inputLanguage( ob ) ) else if (ob->form->fdui == paths_)
activate = false; return inputPaths(ob);
} else if (ob->form->fdui == paths_) { else if (ob->form->fdui == screen_fonts_)
if (! inputPaths( ob ) ) return inputScreenFonts();
activate = false; else if (ob->form->fdui == spellchecker_)
} else if (ob->form->fdui == screen_fonts_) { return inputSpellChecker(ob);
if (! inputScreenFonts() ) else if (ob->form->fdui == formats_)
activate = false; return inputFormats(ob);
} else if (ob->form->fdui == spellchecker_) {
if (! inputSpellChecker( ob ) )
activate = false;
}
return activate; return true;
} }
@ -595,7 +592,23 @@ void FormPreferences::updateConverters()
void FormPreferences::applyFormats() const void FormPreferences::applyFormats() const
{} {
vector<Format> old = formats.GetAllFormats();
for (vector<Format>::const_iterator it = old.begin();
it != old.end(); ++it)
if (find_if(formats_vec.begin(),formats_vec.end(),
compare_memfun(&Format::getname, it->name))
== formats_vec.end()) {
formats.Add(it->name, string(), string(), string());
}
for (vector<Format>::const_iterator it = formats_vec.begin();
it != formats_vec.end(); ++it) {
formats.Add(it->name, it->extension, it->prettyname,
it->shortcut);
formats.SetViewer(it->name, it->viewer);
}
}
void FormPreferences::buildFormats() void FormPreferences::buildFormats()
@ -608,6 +621,11 @@ void FormPreferences::buildFormats()
fl_set_input_return(formats_->input_extension, FL_RETURN_CHANGED); fl_set_input_return(formats_->input_extension, FL_RETURN_CHANGED);
fl_set_input_filter(formats_->input_format, fl_lowercase_filter); fl_set_input_filter(formats_->input_format, fl_lowercase_filter);
formats_vec = formats.GetAllFormats();
for (vector<Format>::const_iterator it = formats_vec.begin();
it != formats_vec.end(); ++it)
fl_addto_browser(formats_->browser_formats, it->name.c_str());
} }
@ -619,8 +637,40 @@ string const FormPreferences::feedbackFormats( FL_OBJECT const * const ) const
} }
bool FormPreferences::inputFormats( FL_OBJECT const * const ) bool FormPreferences::inputFormats(FL_OBJECT const * const ob)
{ {
if (ob == formats_->browser_formats) {
int i = fl_get_browser(formats_->browser_formats);
if (i > 0) {
Format const & f = formats_vec[i-1];
fl_set_input(formats_->input_format, f.name.c_str());
fl_set_input(formats_->input_gui_name, f.prettyname.c_str());
fl_set_input(formats_->input_extension, f.extension.c_str());
fl_set_input(formats_->input_viewer, f.viewer.c_str());
}
} else if (ob == formats_->button_add) {
string name = fl_get_input(formats_->input_format);
string prettyname = fl_get_input(formats_->input_gui_name);
string extension = fl_get_input(formats_->input_extension);
string viewer = fl_get_input(formats_->input_viewer);
string shortcut;
if (prettyname.empty())
return false;
Format format(name, extension, prettyname, shortcut, viewer);
vector<Format>::iterator it = find_if(formats_vec.begin(),
formats_vec.end(),
compare_memfun(&Format::getname, name));
if (it == formats_vec.end()) {
formats_vec.push_back(format);
fl_add_browser_line(formats_->browser_formats,
name.c_str());
} else {
//if (*it == format)
// return false;
*it = format;
}
return true;
}
return true; return true;
} }

View File

@ -39,7 +39,8 @@ struct FD_form_preferences;
struct FD_form_printer; struct FD_form_printer;
struct FD_form_screen_fonts; struct FD_form_screen_fonts;
struct FD_form_spellchecker; struct FD_form_spellchecker;
class Combox; class Combox;
class Format;
/** This class provides an XForms implementation of the FormPreferences Dialog. /** This class provides an XForms implementation of the FormPreferences Dialog.
The preferences dialog allows users to set/save their preferences. The preferences dialog allows users to set/save their preferences.
@ -309,6 +310,9 @@ private:
Combox * combo_kbmap_2; Combox * combo_kbmap_2;
/// ///
FL_OBJECT * feedbackObj; FL_OBJECT * feedbackObj;
///
std::vector<Format> formats_vec;
}; };

View File

@ -608,6 +608,7 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view,
case MenuItem::ViewFormats: case MenuItem::ViewFormats:
case MenuItem::UpdateFormats: case MenuItem::UpdateFormats:
case MenuItem::ExportFormats: case MenuItem::ExportFormats:
case MenuItem::ImportFormats:
lyxerr << "Menubar::Pimpl::create_submenu: " lyxerr << "Menubar::Pimpl::create_submenu: "
"this should not happen" << endl; "this should not happen" << endl;
break; break;

View File

@ -462,7 +462,7 @@ FD_form_converters * FormPreferences::build_converters()
fdui->form = fl_bgn_form(FL_NO_BOX, 450, 360); fdui->form = fl_bgn_form(FL_NO_BOX, 450, 360);
fdui->form->u_vdata = this; fdui->form->u_vdata = this;
obj = fl_add_box(FL_FLAT_BOX, 0, 0, 450, 360, ""); obj = fl_add_box(FL_FLAT_BOX, 0, 0, 450, 360, "");
fdui->browser_converters = obj = fl_add_browser(FL_NORMAL_BROWSER, 30, 30, 160, 270, idex(_("All converters|#A"))); fdui->browser_converters = obj = fl_add_browser(FL_HOLD_BROWSER, 30, 30, 160, 270, idex(_("All converters|#A")));
fl_set_button_shortcut(obj, scex(_("All converters|#A")), 1); fl_set_button_shortcut(obj, scex(_("All converters|#A")), 1);
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_lalign(obj, FL_ALIGN_TOP); fl_set_object_lalign(obj, FL_ALIGN_TOP);
@ -510,7 +510,7 @@ FD_form_formats * FormPreferences::build_formats()
fdui->form = fl_bgn_form(FL_NO_BOX, 450, 360); fdui->form = fl_bgn_form(FL_NO_BOX, 450, 360);
fdui->form->u_vdata = this; fdui->form->u_vdata = this;
obj = fl_add_box(FL_FLAT_BOX, 0, 0, 450, 360, ""); obj = fl_add_box(FL_FLAT_BOX, 0, 0, 450, 360, "");
fdui->browser_formats = obj = fl_add_browser(FL_NORMAL_BROWSER, 30, 30, 160, 270, idex(_("All formats|#A"))); fdui->browser_formats = obj = fl_add_browser(FL_HOLD_BROWSER, 30, 30, 160, 270, idex(_("All formats|#A")));
fl_set_button_shortcut(obj, scex(_("All formats|#A")), 1); fl_set_button_shortcut(obj, scex(_("All formats|#A")), 1);
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_lalign(obj, FL_ALIGN_TOP); fl_set_object_lalign(obj, FL_ALIGN_TOP);

View File

@ -1357,7 +1357,7 @@ argument:
-------------------- --------------------
class: FL_BROWSER class: FL_BROWSER
type: NORMAL_BROWSER type: HOLD_BROWSER
box: 30 30 160 270 box: 30 30 160 270
boxtype: FL_DOWN_BOX boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_YELLOW colors: FL_COL1 FL_YELLOW
@ -1489,7 +1489,7 @@ argument:
-------------------- --------------------
class: FL_BROWSER class: FL_BROWSER
type: NORMAL_BROWSER type: HOLD_BROWSER
box: 30 30 160 270 box: 30 30 160 270
boxtype: FL_DOWN_BOX boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_YELLOW colors: FL_COL1 FL_YELLOW

View File

@ -1902,7 +1902,7 @@ void InsetFig::Preview(string const & p)
tfname += ".eps"; tfname += ".eps";
string buf1 = OnlyPath(owner->fileName()); string buf1 = OnlyPath(owner->fileName());
string buf2 = MakeAbsPath(tfname, buf1); string buf2 = MakeAbsPath(tfname, buf1);
if (!Formats::View(owner, buf2, "eps")) if (!formats.View(owner, buf2, "eps"))
lyxerr << "Can't view " << buf2 << endl; lyxerr << "Can't view " << buf2 << endl;
} }

View File

@ -400,6 +400,8 @@ void LyX::init(int */*argc*/, char **argv, bool gui)
ReadRcFile("lyxrc.defaults"); ReadRcFile("lyxrc.defaults");
system_lyxrc = lyxrc; system_lyxrc = lyxrc;
system_formats = formats;
// If there is a preferences file we read that instead // If there is a preferences file we read that instead
// of the old lyxrc file. // of the old lyxrc file.
if (!ReadRcFile("preferences")) if (!ReadRcFile("preferences"))

View File

@ -345,6 +345,11 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
disable = !Exporter::IsExportable(buf, "ps") disable = !Exporter::IsExportable(buf, "ps")
|| lyxrc.fax_command == "none"; || lyxrc.fax_command == "none";
break; break;
#else
case LFUN_EXPORT:
disable = argument == "fax" &&
!Exporter::IsExportable(buf, argument);
break;
#endif #endif
case LFUN_IMPORT: case LFUN_IMPORT:
disable = !Importer::IsImportable(argument); disable = !Importer::IsImportable(argument);
@ -3149,10 +3154,10 @@ void LyXFunc::doImport(string const & argument)
fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
fileDlg.SetButton(1, _("Examples"), fileDlg.SetButton(1, _("Examples"),
AddPath(system_lyxdir, "examples")); AddPath(system_lyxdir, "examples"));
string text = _("Select ") + Formats::PrettyName(format) string text = _("Select ") + formats.PrettyName(format)
+ _(" file to import"); + _(" file to import");
string format2 = (format == "textparagraph") ? "text" : format; string format2 = (format == "textparagraph") ? "text" : format;
string extension = "*." + Formats::Extension(format2); string extension = "*." + formats.Extension(format2);
filename = fileDlg.Select(text, initpath, extension); filename = fileDlg.Select(text, initpath, extension);
AllowInput(owner->view()); AllowInput(owner->view());

View File

@ -37,10 +37,7 @@ using std::ofstream;
using std::cout; using std::cout;
using std::ios; using std::ios;
using std::endl; using std::endl;
using std::vector;
// this is crappy... why are those colors command line arguments and
// not in lyxrc?? (Matthias)
// Because nobody put them there. (Asger)
extern LyXAction lyxaction; extern LyXAction lyxaction;
extern kb_keymap * toplevel_keymap; extern kb_keymap * toplevel_keymap;
@ -871,7 +868,7 @@ int LyXRC::read(string const & filename)
format = lexrc.GetString(); format = lexrc.GetString();
if (lexrc.next()) if (lexrc.next())
command = lexrc.GetString(); command = lexrc.GetString();
Formats::SetViewer(format, command); formats.SetViewer(format, command);
break; break;
} }
case RC_FORMAT: { case RC_FORMAT: {
@ -884,7 +881,7 @@ int LyXRC::read(string const & filename)
prettyname = lexrc.GetString(); prettyname = lexrc.GetString();
if (lexrc.next()) if (lexrc.next())
shortcut = lexrc.GetString(); shortcut = lexrc.GetString();
Formats::Add(format, extension, prettyname, shortcut); formats.Add(format, extension, prettyname, shortcut);
break; break;
} }
case RC_DEFAULT_LANGUAGE: case RC_DEFAULT_LANGUAGE:
@ -1473,6 +1470,44 @@ void LyXRC::output(ostream & os) const
if (default_language != system_lyxrc.default_language) { if (default_language != system_lyxrc.default_language) {
os << "\\default_language " << default_language << "\n"; os << "\\default_language " << default_language << "\n";
} }
os << "\n#\n"
<< "# FORMATS SECTION ##########################\n"
<< "#\n\n";
case RC_FORMAT: {
vector<Format> formats_vec = formats.GetAllFormats();
vector<Format> sys_formats_vec = system_formats.GetAllFormats();
for (vector<Format>::const_iterator it = formats_vec.begin();
it != formats_vec.end(); ++it) {
Format const * format = system_formats.GetFormat(it->name);
if (!format || format->extension != it->extension ||
format->prettyname != it->prettyname ||
format->shortcut != it->shortcut)
os << "\\format \"" << it->name << "\" \""
<< it->extension << "\" \""
<< it->prettyname << "\" \""
<< it->shortcut << "\"\n";
}
for (vector<Format>::const_iterator it = sys_formats_vec.begin();
it != sys_formats_vec.end(); ++it)
if (!formats.GetFormat(it->name))
os << "\\format \"" << it->name
<< "\" \"\" \"\" \"\"\n";
}
case RC_VIEWER: {
vector<Format> formats_vec = formats.GetAllFormats();
for (vector<Format>::const_iterator it = formats_vec.begin();
it != formats_vec.end(); ++it) {
Format const * format = system_formats.GetFormat(it->name);
if ((!format || format->viewer != it->viewer) &&
(format || !it->viewer.empty()))
os << "\\viewer \"" << it->name << "\" \""
<< it->viewer << "\"\n";
}
}
} }
os.flush(); os.flush();
} }

View File

@ -6,5 +6,7 @@
bool lyx::rename(string const & from, string const & to) bool lyx::rename(string const & from, string const & to)
{ {
return ::rename(from.c_str(), to.c_str()) != -1; if (::rename(from.c_str(), to.c_str()) == -1)
return lyx::copy(from, to);
return true;
} }