+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>
* src/frontends/xforms/FormPreferences.h (operator=): move out of RGB
rendering when you do Ascii export if you have gifscii installed.
- The code which converts from LyX format to anything else (for
- viewing or exporting purposes) has been rewritten. In particular, the
- PDF format is now supported. In fact it's now possible to add
- new export formats without recompiling LyX by specifying external
- programs or scripts in lyxrc settings (note that the old export lyxrc
- settings no longer work).
+ viewing or exporting purposes) and from anything else to LyX has been
+ rewritten. In particular, it is now possible to export to PDF, and to
+ import from HTML/MSWord. In fact it's now possible to add new import/export
+ formats without recompiling LyX by specifying external programs or scripts
+ 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.
have differently encoded languages in the same paragraph.
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
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
mentioned here for your information
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_t""(convert)"
image_command=
+# 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
echo $ac_n "checking for SGML-tools 1.x (LinuxDoc)""... $ac_c"
echo "$ac_t""(sgml2lyx)"
\\Format pdf pdf PDF P
\\Format html html HTML H
\\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 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 pdf "$PDFLATEX" "latex,disable=linuxdoc&docbook"
\\converter latex html "$latex_to_html_command"
"originaldir,needaux,disable=linuxdoc&docbook"
-\\converter literate lyx "$literate_to_lyx_command" ""
\\converter literate latex "$literate_to_tex_command" ""
\\converter dvi ps "$dvi_to_ps_command" ""
\\converter ps pdf "$ps_to_pdf_command" ""
+\\converter ps fax "$fax_command" ""
\\converter linuxdoc lyx "$linuxdoc_to_lyx_command" ""
\\converter linuxdoc latex "$linuxdoc_to_latex_command" ""
\\converter linuxdoc dvi "$linuxdoc_to_dvi_command" ""
\\converter linuxdoc html "$linuxdoc_to_html_command" ""
\\converter docbook dvi "$docbook_to_dvi_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 png eps "$image_command" ""
SEARCH_PROG([for a HTML -> Latex converter],html_to_latex_command,html2latex)
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)
test $image_command = "convert" && image_command="convert \$\$FName \$\$OutName"
dnl fax_command="none"
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_PROG([for SGML-tools 1.x (LinuxDoc)], LINUXDOC, sgml2lyx)
chk_linuxdoc=no
\\Format pdf pdf PDF P
\\Format html html HTML H
\\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 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 pdf "$PDFLATEX" "latex,disable=linuxdoc&docbook"
\\converter latex html "$latex_to_html_command"
"originaldir,needaux,disable=linuxdoc&docbook"
-\\converter literate lyx "$literate_to_lyx_command" ""
\\converter literate latex "$literate_to_tex_command" ""
\\converter dvi ps "$dvi_to_ps_command" ""
\\converter ps pdf "$ps_to_pdf_command" ""
+\\converter ps fax "$fax_command" ""
\\converter linuxdoc lyx "$linuxdoc_to_lyx_command" ""
\\converter linuxdoc latex "$linuxdoc_to_latex_command" ""
\\converter linuxdoc dvi "$linuxdoc_to_dvi_command" ""
\\converter linuxdoc html "$linuxdoc_to_html_command" ""
\\converter docbook dvi "$docbook_to_dvi_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 png eps "$image_command" ""
#
# 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 command, and additional flags.
# For example, the following defines a DVI->Postscript converter:
# The flags argument is a list of comma separated flags.
# Known flags are
# - * : copy the previously defined flags
+# - importer : The converter is used for importing.
# - latex : The converter is latex or its derivatives (pdflatex).
# - 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
Separator
Submenu "Export|E" "exportfile"
Item "Print...|P" "buffer-print"
+ Item "Fax...|F" "buffer-export fax"
Separator
Item "Exit|x" "lyx-quit"
Separator
End
Menu "fileimport"
- OptItem "LaTeX...|L" "buffer-import latex"
- OptItem "Ascii text as lines...|A" "buffer-import text"
- OptItem "Ascii text as paragraphs...|p" "buffer-import textparagraph"
- OptItem "HTML...|H" "buffer-import html"
- OptItem "Noweb...|N" "buffer-import literate"
- OptItem "LinuxDoc...|D" "buffer-import linuxdoc"
+ Item "Ascii text as lines...|A" "buffer-import text"
+ Item "Ascii text as paragraphs...|p" "buffer-import textparagraph"
+ ImportFormats
End
Menu "fileinsert"
if (!filename.empty()) {
fname = OnlyFilename(ChangeExtension(filename, ".log"));
bname = OnlyFilename(ChangeExtension(filename,
- Formats::Extension("literate") + ".out"));
+ formats.Extension("literate") + ".out"));
path = OnlyPath(filename);
if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
path = current_view->buffer()->tmppath;
case ViewFormats:
case UpdateFormats:
case ExportFormats:
+ case ImportFormats:
break;
case Command:
action_ = lyxaction.LookupFunc(command);
md_documents,
md_endmenu,
md_exportformats,
+ md_importformats,
md_lastfiles,
md_optitem,
md_references,
{ "documents", md_documents },
{ "end", md_endmenu },
{ "exportformats", md_exportformats },
+ { "importformats", md_importformats },
{ "item", md_item },
{ "lastfiles", md_lastfiles },
{ "optitem", md_optitem },
add(MenuItem(MenuItem::ExportFormats));
break;
+ case md_importformats:
+ add(MenuItem(MenuItem::ImportFormats));
+ break;
+
case md_submenu: {
lex.next();
string mlabel = _(lex.GetString());
vector<FormatPair> names;
kb_action action;
if ((*cit).kind() == MenuItem::ViewFormats) {
- names = Exporter::GetViewableFormats(buf);
+ names = Exporter::GetExportableFormats(buf, true);
action = LFUN_PREVIEW;
} else if ((*cit).kind() == MenuItem::UpdateFormats) {
- names = Exporter::GetViewableFormats(buf);
+ names = Exporter::GetExportableFormats(buf, true);
action = LFUN_UPDATE;
} else {
- names = Exporter::GetExportableFormats(buf);
+ names = Exporter::GetExportableFormats(buf, false);
action = LFUN_EXPORT;
}
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;
bool same_before =
}
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:
tomenu.add(*cit);
UpdateFormats,
/** This is a list of exportable formats
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
MenuItem(Kind kind,
//////////////////////////////////////////////////////////////////////////////
-map<string, Format> Formats::formats;
vector<Command> Converter::commands;
string Converter::latex_command;
//////////////////////////////////////////////////////////////////////////////
+
+bool Format::dummy() const
+{
+ return extension.empty();
+}
+
+
void Formats::Add(string const & name)
{
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,
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)
{
-
string command2 = command;
- if (!contains(command2,"$$FName"))
+ if (!command2.empty() && !contains(command2,"$$FName"))
command2 += " $$FName";
Add(name);
if (!format || format->viewer.empty()) {
WriteAlert(_("Can not view file"),
_("No information for viewing ")
- + Formats::PrettyName(format_name));
+ + PrettyName(format_name));
return false;
}
Format * Formats::GetFormat(string const & name)
{
- map<string, Format>::iterator it = formats.find(name);
+ FormatList::iterator it = formats.find(name);
if (it != formats.end())
- return &(*it).second;
+ return &it->second;
else
return 0;
}
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 {
void Converter::Add(string const & from, string const & to,
string const & command, string const & flags)
{
- Formats::Add(from);
- Formats::Add(to);
- Command Com(Formats::GetFormat(from), Formats::GetFormat(to), command);
+ formats.Add(from);
+ formats.Add(to);
+ Command Com(formats.GetFormat(from), formats.GetFormat(to), command);
vector<Command>::iterator it = find_if(commands.begin(),
commands.end(),
compare_Command(Com));
Com.command = command;
}
}
+ else if (flag_name == "importer")
+ Com.importer = true;
else if (flag_name == "latex")
Com.latex = true;
else if (flag_name == "originaldir")
inline
bool enable(vector<Command>::iterator it, string const & from)
{
- return find((*it).disable.begin(), (*it).disable.end(), from)
- == (*it).disable.end();
+ return find(it->disable.begin(), it->disable.end(), from)
+ == it->disable.end();
+}
+
+
+vector<FormatPair> const
+Converter::GetReachableTo(string const & target)
+{
+ vector<FormatPair> result;
+
+ 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, string const & stop_format,
- bool only_viewable)
+Converter::GetReachable(string const & from, bool only_viewable)
{
vector<FormatPair> result;
- Format const * format = Formats::GetFormat(from);
+ Format const * format = formats.GetFormat(from);
if (!format)
return result;
queue< vector<Command>::iterator > Q;
for (vector<Command>::iterator it = commands.begin();
it != commands.end(); ++it)
- if ((*it).from->name == from && enable(it, from)
- && (*it).to->name != stop_format) {
+ if (it->from->name == from && enable(it, from)
+ && !it->importer) {
Q.push(it);
- (*it).visited = true;
+ it->visited = true;
} else
- (*it).visited = false;
+ it->visited = false;
while (!Q.empty()) {
vector<Command>::iterator it = Q.front();
Q.pop();
- if (!only_viewable || !(*it).to->viewer.empty())
- result.push_back(FormatPair((*it).to, (*it).from,
- (*it).command));
+ if (!only_viewable || !it->to->viewer.empty())
+ result.push_back(FormatPair(it->to, it->from,
+ it->command));
for (vector<Command>::iterator it2 = commands.begin();
it2 != commands.end(); ++it2)
- if (!(*it2).visited && (*it).to == (*it2).from &&
- enable(it2, from) &&
- (*it2).to->name != stop_format) {
+ if (!it2->visited && it->to == it2->from &&
+ enable(it2, from) && !it2->importer) {
Q.push(it2);
- (*it2).visited = true;
+ it2->visited = true;
}
}
queue< vector<Command>::iterator > Q;
for (vector<Command>::iterator it = commands.begin();
it != commands.end(); ++it)
- if ((*it).from->name == from && enable(it, from)) {
+ if (it->from->name == from && enable(it, from)) {
Q.push(it);
- (*it).visited = true;
+ it->visited = true;
} else
- (*it).visited = false;
+ it->visited = false;
while (!Q.empty()) {
vector<Command>::iterator it = Q.front();
Q.pop();
- if ((*it).to->name == to)
+ if (it->to->name == to)
return true;
for (vector<Command>::iterator it2 = commands.begin();
it2 != commands.end(); ++it2)
- if (!(*it2).visited && (*it).to == (*it2).from &&
+ if (!it2->visited && it->to == it2->from &&
enable(it2, from)) {
Q.push(it2);
- (*it2).visited = true;
+ it2->visited = true;
}
}
return false;
string const & using_format, string & to_file)
{
to_file = ChangeExtension(to_file_base,
- Formats::Extension(to_format));
+ formats.Extension(to_format));
if (from_format == to_format)
if (from_file != to_file)
queue< vector<Command>::iterator > Q;
for (vector<Command>::iterator it = commands.begin();
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);
- (*it).visited = true;
- (*it).previous = commands.end();
+ it->visited = true;
+ it->previous = commands.end();
} else
- (*it).visited = false;
+ it->visited = false;
if (Q.empty()) {
WriteAlert(_("Can not convert file"),
vector<Command>::iterator it;
while (!Q.empty()) {
it = Q.front();
- if ((*it).to->name == to_format &&
- (using_format.empty() || using_format == (*it).from->name)) {
+ if (it->to->name == to_format &&
+ (using_format.empty() || using_format == it->from->name)) {
found = true;
break;
}
Q.pop();
for (vector<Command>::iterator it2 = commands.begin();
it2 != commands.end(); ++it2)
- if (!(*it2).visited && (*it).to == (*it2).from &&
+ if (!it2->visited && it->to == it2->from &&
enable(it2, from_format)) {
Q.push(it2);
- (*it2).visited = true;
- (*it2).previous = it;
+ it2->visited = true;
+ it2->previous = it;
}
}
if (!found) {
WriteAlert(_("Can not convert file"),
_("No information for converting from ")
- + Formats::PrettyName(from_format) + _(" to ")
- + Formats::PrettyName(to_format));
+ + formats.PrettyName(from_format) + _(" to ")
+ + formats.PrettyName(to_format));
return false;
}
vector< vector<Command>::iterator > S;
while (it != commands.end()) {
S.push_back(it);
- it = (*it).previous;
+ it = it->previous;
}
string path = OnlyPath(from_file);
for (vector< vector<Command>::iterator >::reverse_iterator rit =
S.rbegin(); rit != S.rend(); ++rit) {
it = *rit;
- lyxerr << "Converting from "
- << (*it).from->name << " to " << (*it).to->name << endl;
+ bool dummy = it->to->dummy() && it->to->name != "program";
+ if (!dummy)
+ lyxerr << "Converting from "
+ << it->from->name << " to " << it->to->name << endl;
infile = outfile;
- outfile = (*it).result_dir.empty()
- ? ChangeExtension(from_file, (*it).to->extension)
- : AddName(subst((*it).result_dir,
+ outfile = it->result_dir.empty()
+ ? ChangeExtension(from_file, it->to->extension)
+ : AddName(subst(it->result_dir,
"$$BaseName", from_base),
- subst((*it).result_file,
+ subst(it->result_file,
"$$BaseName", OnlyFilename(from_base)));
- if ((*it).latex) {
- lyxrc.pdf_mode = (*it).to->name == "pdf";
- lyxerr << "Running " << (*it).command << endl;
+ if (it->latex) {
+ lyxrc.pdf_mode = it->to->name == "pdf";
+ lyxerr << "Running " << it->command << endl;
run_latex = true;
- if (!runLaTeX(buffer, (*it).command))
+ if (!runLaTeX(buffer, it->command))
return false;
} else {
- if ((*it).need_aux && !run_latex
+ if (it->need_aux && !run_latex
&& !latex_command.empty()) {
lyxerr << "Running " << latex_command
<< " to update aux file"<< endl;
runLaTeX(buffer, latex_command);
}
- string infile2 = ((*it).original_dir)
+ string infile2 = (it->original_dir)
? infile : MakeRelPath(infile, path);
- string outfile2 = ((*it).original_dir)
+ string outfile2 = (it->original_dir)
? outfile : MakeRelPath(outfile, path);
- string command = (*it).command;
+ string command = it->command;
command = subst(command, "$$FName", QuoteName(infile2));
command = subst(command, "$$BaseName", QuoteName(from_base));
command = subst(command, "$$OutName", QuoteName(outfile2));
- if (!(*it).parselog.empty())
+ if (!it->parselog.empty())
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,
dvips_options(buffer));
lyxerr << "Calling " << command << endl;
if (buffer)
ShowMessage(buffer, _("Executing command:"), command);
-
+
+ Systemcalls::Starttype type = (dummy)
+ ? Systemcalls::SystemDontWait : Systemcalls::System;
Systemcalls one;
int res;
- if ((*it).original_dir && buffer) {
+ if (it->original_dir && buffer) {
Path p(buffer->filepath);
- res = one.startscript(Systemcalls::System, command);
+ res = one.startscript(type, command);
} 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 command2 = (*it).parselog +
+ string const command2 = it->parselog +
" < " + QuoteName(infile2 + ".out") +
" > " + QuoteName(logfile);
one.startscript(Systemcalls::System, command2);
}
if (res) {
- if ((*it).to->name == "program")
+ if (it->to->name == "program")
WriteAlert(_("There were errors during the Build process."),
_("You should try to fix them."));
else
}
}
- if (!(*it).result_dir.empty()) {
- to_file = AddName(subst((*it).result_dir,
+ if (it->to->dummy())
+ return true;
+
+
+ if (!it->result_dir.empty()) {
+ to_file = AddName(subst(it->result_dir,
"$$BaseName", to_base),
- subst((*it).result_file,
+ subst(it->result_file,
"$$BaseName", OnlyFilename(to_base)));
if (from_base != to_base) {
- string from = subst((*it).result_dir,
+ string from = subst(it->result_dir,
"$$BaseName", from_base);
- string to = subst((*it).result_dir,
+ string to = subst(it->result_dir,
"$$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)
- if ((*it).latex)
- return lyx::copy(outfile, to_file);
- else
- return lyx::rename(outfile, to_file);
+ } else if (outfile != to_file) {
+ bool moved = (it->latex)
+ ? lyx::copy(outfile, to_file)
+ : lyx::rename(outfile, to_file);
+ if (!moved) {
+ WriteAlert(_("Error while trying to move file:"),
+ outfile, _("to ") + to_file);
+ return false;
+ }
+ }
return true;
}
void Converter::init()
{
}
+
+/// The global instance
+Formats formats;
+
+// The global copy of the system lyxrc entries (everything except preferences)
+Formats system_formats;
Format() {}
///
Format(string const & n, string const & e, string const & p,
- string const & s) :
- name(n), extension(e), prettyname(p), shortcut(s) {};
+ string const & s, string const & v) :
+ name(n), extension(e), prettyname(p), shortcut(s),
+ viewer(v) {};
///
string name;
///
string shortcut;
///
string viewer;
+ ///
+ bool dummy() const;
+ ///
+ string const getname() const {
+ return name;
+ }
};
///
struct Command {
///
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) {}
///
Format const * from;
Format const * to;
///
string command;
+ /// The converter is used for importing
+ bool importer;
/// The converter is latex or its derivatives
bool latex;
/// Do we need to run the converter in the original directory?
///
class Formats {
public:
+ ///
+ typedef std::map<string, Format> FormatList;
///
- static
void Add(string const & name);
///
- static
void Add(string const & name, string const & extension,
string const & prettyname, string const & shortcut);
///
- static
void SetViewer(string const & name, string const & command);
///
- static
bool View(Buffer const * buffer, string const & filename,
string const & format_name);
///
- static
Format * GetFormat(string const & name);
///
- static
string const PrettyName(string const & name);
///
- static
string const Extension(string const & name);
+ ///
+ std::vector<Format> const GetAllFormats();
private:
///
- static
- std::map<string, Format> formats;
+ FormatList formats;
};
///
void Add(string const & from, string const & to,
string const & command, string const & flags);
///
-
+ static
+ std::vector<FormatPair> const GetReachableTo(string const & target);
///
static
std::vector<FormatPair> const
- GetReachable(string const & from, string const & stop_format,
- bool only_viewable);
+ GetReachable(string const & from, bool only_viewable);
///
static
bool IsReachable(string const & from, string const & to);
string latex_command;
};
+extern Formats formats;
+extern Formats system_formats;
+
+
#endif
if (!buffer->tmppath.empty())
filename = AddName(buffer->tmppath, filename);
filename = ChangeExtension(filename,
- Formats::Extension(backend_format));
+ formats.Extension(backend_format));
// Ascii backend
if (backend_format == "text")
if (!put_in_tempdir)
ShowMessage(buffer,
_("Document exported as ")
- + Formats::PrettyName(format)
+ + formats.PrettyName(format)
+ _(" to file `")
+ MakeDisplayPath(result_file) +'\'');
return true;
return false;
string format;
Converter::SplitFormat(format0, format);
- return Formats::View(buffer, result_file, format);
+ return formats.View(buffer, result_file, format);
}
vector<FormatPair> const
-Exporter::GetExportableFormats(Buffer const * buffer)
+Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable)
{
vector<FormatPair> result =
- Converter::GetReachable(BufferFormat(buffer), "lyx", false);
- Format * format = Formats::GetFormat("text");
- if (format)
- 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())
+ Converter::GetReachable(BufferFormat(buffer), only_viewable);
+ Format * format = formats.GetFormat("text");
+ if (format && (!only_viewable || !format->viewer.empty()))
result.push_back(FormatPair(format , 0, ""));
return result;
}
///
static
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
string const BufferFormat(Buffer const * buffer);
#include "input_validators.h"
#include "xform_helpers.h" // formatted()
#include "xform_macros.h"
+#include "converter.h"
+#include "support/lyxfunctional.h"
+
#ifdef SIGC_CXX_NAMESPACES
using SigC::slot;
using std::istream;
using std::pair;
using std::vector;
+using std::find_if;
extern string fmt(char const * fmtstr ...);
extern Languages languages;
static vector<X11Colour> colourDB;
static string const colourFile("/usr/lib/X11/rgb.txt");
-
FormPreferences::FormPreferences(LyXView * lv, Dialogs * d)
: FormBaseBI(lv, d, _("Preferences"), new PreferencesPolicy),
dialog_(0),
bool FormPreferences::input(FL_OBJECT * ob, long)
{
- bool activate = true;
-
// whatever checks you need to ensure the user hasn't entered
// some totally ridiculous value somewhere. Change activate to suit.
// comments before each test describe what is _valid_
- if (ob->form->fdui == colours_) {
- if (! inputColours( ob ) )
- activate = false;
- } else if (ob->form->fdui == language_) {
- if (! inputLanguage( ob ) )
- activate = false;
- } else if (ob->form->fdui == paths_) {
- if (! inputPaths( ob ) )
- activate = false;
- } else if (ob->form->fdui == screen_fonts_) {
- if (! inputScreenFonts() )
- activate = false;
- } else if (ob->form->fdui == spellchecker_) {
- if (! inputSpellChecker( ob ) )
- activate = false;
- }
+ if (ob->form->fdui == colours_)
+ return inputColours(ob);
+ else if (ob->form->fdui == language_)
+ return inputLanguage(ob);
+ else if (ob->form->fdui == paths_)
+ return inputPaths(ob);
+ else if (ob->form->fdui == screen_fonts_)
+ return inputScreenFonts();
+ else if (ob->form->fdui == spellchecker_)
+ return inputSpellChecker(ob);
+ else if (ob->form->fdui == formats_)
+ return inputFormats(ob);
- return activate;
+ return true;
}
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()
fl_set_input_return(formats_->input_extension, FL_RETURN_CHANGED);
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());
}
}
-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;
}
struct FD_form_printer;
struct FD_form_screen_fonts;
struct FD_form_spellchecker;
-class Combox;
+class Combox;
+class Format;
/** This class provides an XForms implementation of the FormPreferences Dialog.
The preferences dialog allows users to set/save their preferences.
Combox * combo_kbmap_2;
///
FL_OBJECT * feedbackObj;
+ ///
+ std::vector<Format> formats_vec;
+
};
case MenuItem::ViewFormats:
case MenuItem::UpdateFormats:
case MenuItem::ExportFormats:
+ case MenuItem::ImportFormats:
lyxerr << "Menubar::Pimpl::create_submenu: "
"this should not happen" << endl;
break;
fdui->form = fl_bgn_form(FL_NO_BOX, 450, 360);
fdui->form->u_vdata = this;
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_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_lalign(obj, FL_ALIGN_TOP);
fdui->form = fl_bgn_form(FL_NO_BOX, 450, 360);
fdui->form->u_vdata = this;
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_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_lalign(obj, FL_ALIGN_TOP);
--------------------
class: FL_BROWSER
-type: NORMAL_BROWSER
+type: HOLD_BROWSER
box: 30 30 160 270
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_YELLOW
--------------------
class: FL_BROWSER
-type: NORMAL_BROWSER
+type: HOLD_BROWSER
box: 30 30 160 270
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_YELLOW
tfname += ".eps";
string buf1 = OnlyPath(owner->fileName());
string buf2 = MakeAbsPath(tfname, buf1);
- if (!Formats::View(owner, buf2, "eps"))
+ if (!formats.View(owner, buf2, "eps"))
lyxerr << "Can't view " << buf2 << endl;
}
ReadRcFile("lyxrc.defaults");
system_lyxrc = lyxrc;
+ system_formats = formats;
+
// If there is a preferences file we read that instead
// of the old lyxrc file.
if (!ReadRcFile("preferences"))
disable = !Exporter::IsExportable(buf, "ps")
|| lyxrc.fax_command == "none";
break;
+#else
+ case LFUN_EXPORT:
+ disable = argument == "fax" &&
+ !Exporter::IsExportable(buf, argument);
+ break;
#endif
case LFUN_IMPORT:
disable = !Importer::IsImportable(argument);
fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
fileDlg.SetButton(1, _("Examples"),
AddPath(system_lyxdir, "examples"));
- string text = _("Select ") + Formats::PrettyName(format)
+ string text = _("Select ") + formats.PrettyName(format)
+ _(" file to import");
string format2 = (format == "textparagraph") ? "text" : format;
- string extension = "*." + Formats::Extension(format2);
+ string extension = "*." + formats.Extension(format2);
filename = fileDlg.Select(text, initpath, extension);
AllowInput(owner->view());
using std::cout;
using std::ios;
using std::endl;
-
-// this is crappy... why are those colors command line arguments and
-// not in lyxrc?? (Matthias)
-// Because nobody put them there. (Asger)
+using std::vector;
extern LyXAction lyxaction;
extern kb_keymap * toplevel_keymap;
format = lexrc.GetString();
if (lexrc.next())
command = lexrc.GetString();
- Formats::SetViewer(format, command);
+ formats.SetViewer(format, command);
break;
}
case RC_FORMAT: {
prettyname = lexrc.GetString();
if (lexrc.next())
shortcut = lexrc.GetString();
- Formats::Add(format, extension, prettyname, shortcut);
+ formats.Add(format, extension, prettyname, shortcut);
break;
}
case RC_DEFAULT_LANGUAGE:
if (default_language != system_lyxrc.default_language) {
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();
}
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;
}