From 29f7055e9527314060b4a74c31a46155ff264a63 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 6 Nov 2000 11:20:22 +0000 Subject: [PATCH] Import patch from Dekel. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1199 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 40 +++ NEWS | 16 +- lib/configure | 90 ++++++- lib/configure.m4 | 24 +- lib/lyxrc.example | 4 +- lib/ui/default.ui | 10 +- src/LaTeXLog.C | 2 +- src/MenuBackend.C | 33 ++- src/MenuBackend.h | 5 +- src/converter.C | 241 ++++++++++++------ src/converter.h | 39 +-- src/exporter.C | 26 +- src/exporter.h | 6 +- src/frontends/xforms/FormPreferences.C | 94 +++++-- src/frontends/xforms/FormPreferences.h | 6 +- src/frontends/xforms/Menubar_pimpl.C | 1 + src/frontends/xforms/form_preferences.C | 4 +- .../xforms/forms/form_preferences.fd | 4 +- src/insets/figinset.C | 2 +- src/lyx_main.C | 2 + src/lyxfunc.C | 9 +- src/lyxrc.C | 47 +++- src/support/rename.C | 4 +- 23 files changed, 524 insertions(+), 185 deletions(-) diff --git a/ChangeLog b/ChangeLog index dccc44daf8..a11c45e674 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,43 @@ +2000-11-06 Jean-Marc Lasgouttes + + * 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 + + * 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 * src/frontends/xforms/FormPreferences.h (operator=): move out of RGB diff --git a/NEWS b/NEWS index 8d64d63a06..c4e3c0d2ce 100644 --- a/NEWS +++ b/NEWS @@ -52,11 +52,12 @@ Other major changes in 1.1.6 include: 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. @@ -67,11 +68,14 @@ Other major changes in 1.1.6 include: 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 diff --git a/lib/configure b/lib/configure index a558d0a821..f97358fd9b 100755 --- a/lib/configure +++ b/lib/configure @@ -333,6 +333,43 @@ fi 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= @@ -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 echo $ac_n "checking for SGML-tools 1.x (LinuxDoc)""... $ac_c" echo "$ac_t""(sgml2lyx)" @@ -1017,28 +1091,32 @@ cat >lyxrc.defaults < 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" @@ -248,6 +252,10 @@ dnl else 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 @@ -384,28 +392,32 @@ cat >lyxrc.defaults <Postscript converter: @@ -345,6 +346,7 @@ # 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 diff --git a/lib/ui/default.ui b/lib/ui/default.ui index ca97dff7cb..f88364c6f7 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -52,6 +52,7 @@ Menuset Separator Submenu "Export|E" "exportfile" Item "Print...|P" "buffer-print" + Item "Fax...|F" "buffer-export fax" Separator Item "Exit|x" "lyx-quit" Separator @@ -59,12 +60,9 @@ Menuset 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" diff --git a/src/LaTeXLog.C b/src/LaTeXLog.C index 9327c29f7e..a791546c5a 100644 --- a/src/LaTeXLog.C +++ b/src/LaTeXLog.C @@ -27,7 +27,7 @@ void ShowLatexLog() 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; diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 18d39b90b8..eaf88f28fe 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -55,6 +55,7 @@ MenuItem::MenuItem(Kind kind, string const & label, case ViewFormats: case UpdateFormats: case ExportFormats: + case ImportFormats: break; case Command: action_ = lyxaction.LookupFunc(command); @@ -88,6 +89,7 @@ Menu & Menu::read(LyXLex & lex) md_documents, md_endmenu, md_exportformats, + md_importformats, md_lastfiles, md_optitem, md_references, @@ -103,6 +105,7 @@ Menu & Menu::read(LyXLex & lex) { "documents", md_documents }, { "end", md_endmenu }, { "exportformats", md_exportformats }, + { "importformats", md_importformats }, { "item", md_item }, { "lastfiles", md_lastfiles }, { "optitem", md_optitem }, @@ -169,6 +172,10 @@ Menu & Menu::read(LyXLex & lex) add(MenuItem(MenuItem::ExportFormats)); break; + case md_importformats: + add(MenuItem(MenuItem::ImportFormats)); + break; + case md_submenu: { lex.next(); string mlabel = _(lex.GetString()); @@ -272,19 +279,21 @@ void Menu::expand(Menu & tomenu, Buffer * buf) const vector 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::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 = @@ -311,6 +320,24 @@ void Menu::expand(Menu & tomenu, Buffer * buf) const } break; + case MenuItem::ImportFormats: { + vector names = Converter::GetReachableTo("lyx"); + sort(names.begin(), names.end(), compare_formatpair()); + + for (vector::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); diff --git a/src/MenuBackend.h b/src/MenuBackend.h index 2c09e4ee48..169b9d5618 100644 --- a/src/MenuBackend.h +++ b/src/MenuBackend.h @@ -54,7 +54,10 @@ public: 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, diff --git a/src/converter.C b/src/converter.C index fab51433f8..ac91f7cf7f 100644 --- a/src/converter.C +++ b/src/converter.C @@ -38,7 +38,6 @@ using std::find_if; ////////////////////////////////////////////////////////////////////////////// -map Formats::formats; vector Converter::commands; 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) { 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); @@ -88,7 +103,7 @@ bool Formats::View(Buffer const * buffer, string const & filename, if (!format || format->viewer.empty()) { WriteAlert(_("Can not view file"), _("No information for viewing ") - + Formats::PrettyName(format_name)); + + PrettyName(format_name)); return false; } @@ -124,9 +139,9 @@ bool Formats::View(Buffer const * buffer, string const & filename, Format * Formats::GetFormat(string const & name) { - map::iterator it = formats.find(name); + FormatList::iterator it = formats.find(name); if (it != formats.end()) - return &(*it).second; + return &it->second; else return 0; } @@ -151,6 +166,18 @@ string const Formats::Extension(string const & name) return name; } + +vector +const Formats::GetAllFormats() +{ + vector result; + for (FormatList::iterator it = formats.begin(); + it != formats.end(); ++it) + result.push_back(it->second); + return result; +} + + ////////////////////////////////////////////////////////////////////////////// class compare_Command { @@ -167,9 +194,9 @@ private: 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::iterator it = find_if(commands.begin(), commands.end(), compare_Command(Com)); @@ -193,6 +220,8 @@ void Converter::Add(string const & from, string const & to, Com.command = command; } } + else if (flag_name == "importer") + Com.importer = true; else if (flag_name == "latex") Com.latex = true; else if (flag_name == "originaldir") @@ -236,17 +265,47 @@ void Converter::Add(string const & from, string const & to, inline bool enable(vector::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 const +Converter::GetReachableTo(string const & target) +{ + vector result; + + queue< vector::iterator > Q; + for (vector::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::iterator it = Q.front(); + Q.pop(); + result.push_back(FormatPair(it->from, 0, "")); + for (vector::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 const -Converter::GetReachable(string const & from, string const & stop_format, - bool only_viewable) +Converter::GetReachable(string const & from, bool only_viewable) { vector result; - Format const * format = Formats::GetFormat(from); + Format const * format = formats.GetFormat(from); if (!format) return result; @@ -256,26 +315,25 @@ Converter::GetReachable(string const & from, string const & stop_format, queue< vector::iterator > Q; for (vector::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::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::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; } } @@ -291,23 +349,23 @@ bool Converter::IsReachable(string const & from, string const & to) queue< vector::iterator > Q; for (vector::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::iterator it = Q.front(); Q.pop(); - if ((*it).to->name == to) + if (it->to->name == to) return true; for (vector::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; @@ -320,7 +378,7 @@ bool Converter::Convert(Buffer const * buffer, 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) @@ -331,12 +389,12 @@ bool Converter::Convert(Buffer const * buffer, queue< vector::iterator > Q; for (vector::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"), @@ -348,34 +406,34 @@ bool Converter::Convert(Buffer const * buffer, vector::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::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::iterator > S; while (it != commands.end()) { S.push_back(it); - it = (*it).previous; + it = it->previous; } string path = OnlyPath(from_file); @@ -389,62 +447,66 @@ bool Converter::Convert(Buffer const * buffer, for (vector< vector::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); @@ -453,7 +515,7 @@ bool Converter::Convert(Buffer const * buffer, } 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 @@ -465,23 +527,36 @@ bool Converter::Convert(Buffer const * buffer, } } - 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; } @@ -702,3 +777,9 @@ string const Converter::dvips_options(Buffer const * buffer) void Converter::init() { } + +/// The global instance +Formats formats; + +// The global copy of the system lyxrc entries (everything except preferences) +Formats system_formats; diff --git a/src/converter.h b/src/converter.h index 91f1444aff..37ac7d5ca5 100644 --- a/src/converter.h +++ b/src/converter.h @@ -29,8 +29,9 @@ public: 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; /// @@ -41,13 +42,19 @@ public: 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; @@ -55,6 +62,8 @@ struct Command { 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? @@ -94,33 +103,29 @@ public: /// class Formats { public: + /// + typedef std::map 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 const GetAllFormats(); private: /// - static - std::map formats; + FormatList formats; }; /// @@ -131,12 +136,12 @@ public: void Add(string const & from, string const & to, string const & command, string const & flags); /// - + static + std::vector const GetReachableTo(string const & target); /// static std::vector 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); @@ -180,4 +185,8 @@ private: string latex_command; }; +extern Formats formats; +extern Formats system_formats; + + #endif diff --git a/src/exporter.C b/src/exporter.C index a5ebfbe540..df330952c7 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -37,7 +37,7 @@ bool Exporter::Export(Buffer * buffer, string const & format0, 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") @@ -65,7 +65,7 @@ bool Exporter::Export(Buffer * buffer, string const & format0, if (!put_in_tempdir) ShowMessage(buffer, _("Document exported as ") - + Formats::PrettyName(format) + + formats.PrettyName(format) + _(" to file `") + MakeDisplayPath(result_file) +'\''); return true; @@ -85,7 +85,7 @@ bool Exporter::Preview(Buffer * buffer, string const & format0) return false; string 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 const -Exporter::GetExportableFormats(Buffer const * buffer) +Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable) { vector result = - Converter::GetReachable(BufferFormat(buffer), "lyx", false); - Format * format = Formats::GetFormat("text"); - if (format) - result.push_back(FormatPair(format , 0, "")); - return result; -} - - -vector const -Exporter::GetViewableFormats(Buffer const * buffer) -{ - vector 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; } diff --git a/src/exporter.h b/src/exporter.h index 43a2ee2ef4..76a3257ea8 100644 --- a/src/exporter.h +++ b/src/exporter.h @@ -41,11 +41,9 @@ public: /// static std::vector const - GetExportableFormats(Buffer const * buffer); + GetExportableFormats(Buffer const * buffer, bool only_viewable); /// - static - std::vector const - GetViewableFormats(Buffer const * buffer); + /// static string const BufferFormat(Buffer const * buffer); diff --git a/src/frontends/xforms/FormPreferences.C b/src/frontends/xforms/FormPreferences.C index b7b3b5e13b..3724c564b0 100644 --- a/src/frontends/xforms/FormPreferences.C +++ b/src/frontends/xforms/FormPreferences.C @@ -29,6 +29,9 @@ #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; @@ -39,6 +42,7 @@ using std::getline; using std::istream; using std::pair; using std::vector; +using std::find_if; extern string fmt(char const * fmtstr ...); extern Languages languages; @@ -48,7 +52,6 @@ typedef pair X11Colour; static vector colourDB; static string const colourFile("/usr/lib/X11/rgb.txt"); - FormPreferences::FormPreferences(LyXView * lv, Dialogs * d) : FormBaseBI(lv, d, _("Preferences"), new PreferencesPolicy), dialog_(0), @@ -296,30 +299,24 @@ void FormPreferences::feedback( FL_OBJECT * ob ) 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; } @@ -595,7 +592,23 @@ void FormPreferences::updateConverters() void FormPreferences::applyFormats() const -{} +{ + vector old = formats.GetAllFormats(); + for (vector::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::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() @@ -608,6 +621,11 @@ 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::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::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; } diff --git a/src/frontends/xforms/FormPreferences.h b/src/frontends/xforms/FormPreferences.h index 8abec739bd..538946d363 100644 --- a/src/frontends/xforms/FormPreferences.h +++ b/src/frontends/xforms/FormPreferences.h @@ -39,7 +39,8 @@ struct FD_form_preferences; 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. @@ -309,6 +310,9 @@ private: Combox * combo_kbmap_2; /// FL_OBJECT * feedbackObj; + /// + std::vector formats_vec; + }; diff --git a/src/frontends/xforms/Menubar_pimpl.C b/src/frontends/xforms/Menubar_pimpl.C index 07fc2cabbf..cbc3174269 100644 --- a/src/frontends/xforms/Menubar_pimpl.C +++ b/src/frontends/xforms/Menubar_pimpl.C @@ -608,6 +608,7 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view, case MenuItem::ViewFormats: case MenuItem::UpdateFormats: case MenuItem::ExportFormats: + case MenuItem::ImportFormats: lyxerr << "Menubar::Pimpl::create_submenu: " "this should not happen" << endl; break; diff --git a/src/frontends/xforms/form_preferences.C b/src/frontends/xforms/form_preferences.C index cd2225d6a6..3a213a29f5 100644 --- a/src/frontends/xforms/form_preferences.C +++ b/src/frontends/xforms/form_preferences.C @@ -462,7 +462,7 @@ FD_form_converters * FormPreferences::build_converters() 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); @@ -510,7 +510,7 @@ FD_form_formats * FormPreferences::build_formats() 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); diff --git a/src/frontends/xforms/forms/form_preferences.fd b/src/frontends/xforms/forms/form_preferences.fd index 796851c97c..cb04797960 100644 --- a/src/frontends/xforms/forms/form_preferences.fd +++ b/src/frontends/xforms/forms/form_preferences.fd @@ -1357,7 +1357,7 @@ argument: -------------------- class: FL_BROWSER -type: NORMAL_BROWSER +type: HOLD_BROWSER box: 30 30 160 270 boxtype: FL_DOWN_BOX colors: FL_COL1 FL_YELLOW @@ -1489,7 +1489,7 @@ argument: -------------------- class: FL_BROWSER -type: NORMAL_BROWSER +type: HOLD_BROWSER box: 30 30 160 270 boxtype: FL_DOWN_BOX colors: FL_COL1 FL_YELLOW diff --git a/src/insets/figinset.C b/src/insets/figinset.C index a82b9deb1b..d4f5c9bc6d 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -1902,7 +1902,7 @@ void InsetFig::Preview(string const & p) 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; } diff --git a/src/lyx_main.C b/src/lyx_main.C index 324f2000c6..3c8b6845f5 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -400,6 +400,8 @@ void LyX::init(int */*argc*/, char **argv, bool gui) 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")) diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 893dc3b652..1e4c7d1d64 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -345,6 +345,11 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const 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); @@ -3149,10 +3154,10 @@ void LyXFunc::doImport(string const & 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()); diff --git a/src/lyxrc.C b/src/lyxrc.C index 36ba4f501c..f653cf01b7 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -37,10 +37,7 @@ using std::ofstream; 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; @@ -871,7 +868,7 @@ int LyXRC::read(string const & filename) format = lexrc.GetString(); if (lexrc.next()) command = lexrc.GetString(); - Formats::SetViewer(format, command); + formats.SetViewer(format, command); break; } case RC_FORMAT: { @@ -884,7 +881,7 @@ int LyXRC::read(string const & filename) 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: @@ -1473,6 +1470,44 @@ void LyXRC::output(ostream & os) const 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 formats_vec = formats.GetAllFormats(); + vector sys_formats_vec = system_formats.GetAllFormats(); + for (vector::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::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 formats_vec = formats.GetAllFormats(); + for (vector::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(); } diff --git a/src/support/rename.C b/src/support/rename.C index bd619347e0..97c4ca0562 100644 --- a/src/support/rename.C +++ b/src/support/rename.C @@ -6,5 +6,7 @@ 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; } -- 2.39.5