From 0a16442310eda0baee85054b2b331061a0d90a76 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 13 Nov 2000 10:35:02 +0000 Subject: [PATCH] Converter patch from Dekel, Preference patch from Angus, menu patch from Rob git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1212 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 58 +- lib/configure | 85 +-- lib/configure.m4 | 85 +-- lib/lyxrc.example | 43 +- lib/ui/default.ui | 30 +- po/POTFILES.in | 1 + src/MenuBackend.C | 85 +-- src/buffer.C | 9 + src/converter.C | 725 ++++++++++++++----------- src/converter.h | 259 +++++---- src/exporter.C | 78 ++- src/exporter.h | 10 +- src/frontends/Liason.C | 2 +- src/frontends/xforms/Color.C | 96 +++- src/frontends/xforms/Color.h | 36 +- src/frontends/xforms/Dialogs.C | 12 +- src/frontends/xforms/FormPreferences.C | 705 +++++++++--------------- src/frontends/xforms/FormPreferences.h | 30 +- src/importer.C | 96 +++- src/importer.h | 14 +- src/insets/insetgraphics.C | 8 +- src/lyx_gui.C | 9 + src/lyx_main.C | 4 +- src/lyxfunc.C | 6 +- src/lyxrc.C | 102 ++-- src/support/rename.C | 6 +- 26 files changed, 1425 insertions(+), 1169 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9dd6c6b9d9..67621279cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,59 @@ +2000-11-13 Jean-Marc Lasgouttes + + * src/converter.C: add "using" directive. + + * src/frontends/xforms/FormPreferences.C: add "using" directive. + (compare_converter): add "int" as return type. + + * src/frontends/xforms/Color.C: comment out FL_LIGHTER_COL1 here + too. + +2000-11-11 Angus Leeming + + * src/lyx_gui.C (create_forms): map the xform colours, should a + mapping exist. Ie, call XformColor::read(). + + * src/frontends/xforms/Color.[Ch] renamed struct RGB as RGBColor + and struct HSV as HSVColor. + (XformColor::read, XformColor::write) : new methods that + input/output any changes to the cform GUI colors. + + * src/frontends/xforms/Dialogs.C: FORMS_H_LOCATION no longer + included. + + * src/frontends/xforms/FormPreferences.C Lots of little changes + associated with the changed name of the RGB and HSV structs. Can + now save changes to xforms GUI to file. Commented out + FL_LIGHTER_COL1 to allow compilation with xforms 0.88. It isn't + used currently anyway. + +2000-11-11 Dekel Tsur + + * src/converter.C: A lot of changes: + - It is no longer possible to choose between two or more ways to + export to some format (the new code uses only the shortest path). + However, it is still possible to choose between pdflatex/ps2pdf + for creating a PDF file, by defining two PDF formats: pdf & pdf2. + - Added several methods that makes the FormPreferences code simpler. + - Changed the tokens $$FName and $$OutName to $$i and $$o. + + * src/exporter.C (Export): lyxrc.use_pdf is set before + makeLaTeXFile is called. This works but not very nice. + + * src/frontends/xforms/FormPreferences.C: The formats/converters + tabs are now fully functional. + + * src/buffer.C (getTocList): Add numbers to the captions. + + * lib/lyxrc.example: Removed fax section + + * src/support/rename.C (rename): Delete the old file if lyx::copy + is called. + +2000-11-13 Rob Lahaye + + * lib/ui/default.ui: minor polishing. + 2000-11-10 Jean-Marc Lasgouttes * src/frontends/xforms/Color.C: include and @@ -105,7 +161,7 @@ 2000-11-08 Dekel Tsur - * src/frontends/xforms/FormParagraph.C (updateLanguage): Check + * src/frontends/xforms/FormPreferences.C (updateLanguage): Check iterators to prevent crash. 2000-11-08 Angus Leeming diff --git a/lib/configure b/lib/configure index c6d83d0db8..08f5e40edc 100755 --- a/lib/configure +++ b/lib/configure @@ -222,7 +222,7 @@ if test -z "$tex_to_lyx_command" ; then fi PATH=${save_PATH} -test $tex_to_lyx_command = "reLyX" && tex_to_lyx_command="reLyX -f \$\$FName" +test $tex_to_lyx_command = "reLyX" && tex_to_lyx_command="reLyX -f \$\$i" echo $ac_n "checking for a Noweb -> LyX converter""... $ac_c" echo "$ac_t""(noweb2lyx)" @@ -258,7 +258,7 @@ if test -z "$literate_to_lyx_command" ; then literate_to_lyx_command=none fi -test $literate_to_lyx_command = "noweb2lyx" && literate_to_lyx_command="noweb2lyx \$\$FName \$\$OutName" +test $literate_to_lyx_command = "noweb2lyx" && literate_to_lyx_command="noweb2lyx \$\$i \$\$o" # Search something to process a literate document echo $ac_n "checking for a Noweb -> LaTeX converter""... $ac_c" @@ -295,7 +295,7 @@ if test -z "$literate_to_tex_command" ; then literate_to_tex_command=none fi -test $literate_to_tex_command = "noweave" && literate_to_tex_command="noweave -delay -index \$\$FName > \$\$OutName" +test $literate_to_tex_command = "noweave" && literate_to_tex_command="noweave -delay -index \$\$i > \$\$o" echo $ac_n "checking for a HTML -> Latex converter""... $ac_c" echo "$ac_t""(html2latex)" @@ -331,7 +331,7 @@ if test -z "$html_to_latex_command" ; then html_to_latex_command=none fi -test $html_to_latex_command = "html2latex" && html_to_latex_command="html2latex \$\$FName" +test $html_to_latex_command = "html2latex" && html_to_latex_command="html2latex \$\$i" echo $ac_n "checking for a MSWord -> Latex converter""... $ac_c" echo "$ac_t""(wvCleanLatex word2x)" @@ -367,8 +367,8 @@ 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" +test $word_to_latex_command = "wvCleanLatex" && word_to_latex_command="wvCleanLatex \$\$i \$\$o" +test $word_to_latex_command = "word2x" && word_to_latex_command="word2x -f latex \$\$i" echo $ac_n "checking for Image converter""... $ac_c" echo "$ac_t""(convert)" @@ -404,7 +404,7 @@ if test -z "$image_command" ; then image_command=none fi -test $image_command = "convert" && image_command="convert \$\$FName \$\$OutName" +test $image_command = "convert" && image_command="convert \$\$i \$\$o" # Search for a Postscript interpreter echo $ac_n "checking for a Postscript interpreter""... $ac_c" @@ -621,7 +621,7 @@ if test -z "$ps_to_pdf_command" ; then ps_to_pdf_command=none fi -test $ps_to_pdf_command = "ps2pdf" && ps_to_pdf_command="ps2pdf \$\$FName" +test $ps_to_pdf_command = "ps2pdf" && ps_to_pdf_command="ps2pdf \$\$i" # Search for a program to convert dvi to ps echo $ac_n "checking for a DVI to PS converter""... $ac_c" @@ -658,7 +658,7 @@ if test -z "$dvi_to_ps_command" ; then dvi_to_ps_command=none fi -test $dvi_to_ps_command = "dvips" && dvi_to_ps_command="dvips -o \$\$OutName \$\$FName" +test $dvi_to_ps_command = "dvips" && dvi_to_ps_command="dvips -o \$\$o \$\$i" # Search a *roff program (used to translate tables in ASCII export) echo $ac_n "checking for a *roff formatter""... $ac_c" @@ -809,7 +809,7 @@ if test -z "$fax_command" ; then fax_command=none fi -test $fax_command = "ksendfax" && fax_command="ksendfax \$\$FName" +test $fax_command = "ksendfax" && fax_command="ksendfax \$\$i" # Search for LinuxDoc support echo $ac_n "checking for SGML-tools 1.x (LinuxDoc)""... $ac_c" @@ -854,10 +854,10 @@ fi case $LINUXDOC in sgml2lyx) - linuxdoc_to_latex_command="sgml2latex \$\$FName" - linuxdoc_to_dvi_command="sgml2latex -o dvi \$\$FName" - linuxdoc_to_html_command="sgml2html \$\$FName" - linuxdoc_to_lyx_command="sgml2lyx \$\$FName";; + linuxdoc_to_latex_command="sgml2latex \$\$i" + linuxdoc_to_dvi_command="sgml2latex -o dvi \$\$i" + linuxdoc_to_html_command="sgml2html \$\$i" + linuxdoc_to_lyx_command="sgml2lyx \$\$i";; none) linuxdoc_to_latex_command="none" linuxdoc_to_dvi_command="none" @@ -908,11 +908,11 @@ fi case $DOCBOOK in sgmltools) - docbook_to_dvi_command="sgmltools -b dvi \$\$FName" - docbook_to_html_command="sgmltools -b html \$\$FName";; + docbook_to_dvi_command="sgmltools -b dvi \$\$i" + docbook_to_html_command="sgmltools -b html \$\$i";; db2dvi) - docbook_to_dvi_command="db2dvi \$\$FName" - docbook_to_html_command="db2html \$\$FName";; + docbook_to_dvi_command="db2dvi \$\$i" + docbook_to_html_command="db2html \$\$i";; none) docbook_to_dvi_command="none" docbook_to_html_command="none";; @@ -997,9 +997,9 @@ fi latex_to_html_command=$TOHTML case $TOHTML in - tth) latex_to_html_command="tth -t -e2 -L\$\$BaseName < \$\$FName > \$\$OutName";; - latex2html) latex_to_html_command="latex2html -no_subdir -split 0 -show_section_numbers \$\$FName";; - hevea) latex_to_html_command="hevea -s \$\$FName";; + tth) latex_to_html_command="tth -t -e2 -L\$\$b < \$\$i > \$\$o";; + latex2html) latex_to_html_command="latex2html -no_subdir -split 0 -show_section_numbers \$\$i";; + hevea) latex_to_html_command="hevea -s \$\$i";; esac #### Explore the LaTeX configuration @@ -1085,23 +1085,30 @@ cat >lyxrc.defaults <lyxrc.defaults < LyX converter],tex_to_lyx_command,reLyX) PATH=${save_PATH} -test $tex_to_lyx_command = "reLyX" && tex_to_lyx_command="reLyX -f \$\$FName" +test $tex_to_lyx_command = "reLyX" && tex_to_lyx_command="reLyX -f \$\$i" SEARCH_PROG([for a Noweb -> LyX converter],literate_to_lyx_command,noweb2lyx) -test $literate_to_lyx_command = "noweb2lyx" && literate_to_lyx_command="noweb2lyx \$\$FName \$\$OutName" +test $literate_to_lyx_command = "noweb2lyx" && literate_to_lyx_command="noweb2lyx \$\$i \$\$o" # Search something to process a literate document SEARCH_PROG([for a Noweb -> LaTeX converter],literate_to_tex_command,noweave) -test $literate_to_tex_command = "noweave" && literate_to_tex_command="noweave -delay -index \$\$FName > \$\$OutName" +test $literate_to_tex_command = "noweave" && literate_to_tex_command="noweave -delay -index \$\$i > \$\$o" 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 \$\$i" 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" +test $word_to_latex_command = "wvCleanLatex" && word_to_latex_command="wvCleanLatex \$\$i \$\$o" +test $word_to_latex_command = "word2x" && word_to_latex_command="word2x -f latex \$\$i" SEARCH_PROG([for Image converter],image_command,convert) -test $image_command = "convert" && image_command="convert \$\$FName \$\$OutName" +test $image_command = "convert" && image_command="convert \$\$i \$\$o" # Search for a Postscript interpreter SEARCH_PROG([for a Postscript interpreter],GS, gs) @@ -220,11 +220,11 @@ SEARCH_PROG([for a HTML previewer],HTML_VIEWER, netscape) # Search for a program to convert ps to pdf SEARCH_PROG([for a PS to PDF converter],ps_to_pdf_command,ps2pdf) -test $ps_to_pdf_command = "ps2pdf" && ps_to_pdf_command="ps2pdf \$\$FName" +test $ps_to_pdf_command = "ps2pdf" && ps_to_pdf_command="ps2pdf \$\$i" # Search for a program to convert dvi to ps SEARCH_PROG([for a DVI to PS converter],dvi_to_ps_command,dvips) -test $dvi_to_ps_command = "dvips" && dvi_to_ps_command="dvips -o \$\$OutName \$\$FName" +test $dvi_to_ps_command = "dvips" && dvi_to_ps_command="dvips -o \$\$o \$\$i" # Search a *roff program (used to translate tables in ASCII export) SEARCH_PROG([for a *roff formatter],ROFF,groff nroff) @@ -254,7 +254,7 @@ dnl fi # Search a GUI Fax program SEARCH_PROG([for a fax program], fax_command, ksendfax) -test $fax_command = "ksendfax" && fax_command="ksendfax \$\$FName" +test $fax_command = "ksendfax" && fax_command="ksendfax \$\$i" # Search for LinuxDoc support SEARCH_PROG([for SGML-tools 1.x (LinuxDoc)], LINUXDOC, sgml2lyx) @@ -266,10 +266,10 @@ fi case $LINUXDOC in sgml2lyx) - linuxdoc_to_latex_command="sgml2latex \$\$FName" - linuxdoc_to_dvi_command="sgml2latex -o dvi \$\$FName" - linuxdoc_to_html_command="sgml2html \$\$FName" - linuxdoc_to_lyx_command="sgml2lyx \$\$FName";; + linuxdoc_to_latex_command="sgml2latex \$\$i" + linuxdoc_to_dvi_command="sgml2latex -o dvi \$\$i" + linuxdoc_to_html_command="sgml2html \$\$i" + linuxdoc_to_lyx_command="sgml2lyx \$\$i";; none) linuxdoc_to_latex_command="none" linuxdoc_to_dvi_command="none" @@ -287,11 +287,11 @@ fi case $DOCBOOK in sgmltools) - docbook_to_dvi_command="sgmltools -b dvi \$\$FName" - docbook_to_html_command="sgmltools -b html \$\$FName";; + docbook_to_dvi_command="sgmltools -b dvi \$\$i" + docbook_to_html_command="sgmltools -b html \$\$i";; db2dvi) - docbook_to_dvi_command="db2dvi \$\$FName" - docbook_to_html_command="db2html \$\$FName";; + docbook_to_dvi_command="db2dvi \$\$i" + docbook_to_html_command="db2html \$\$i";; none) docbook_to_dvi_command="none" docbook_to_html_command="none";; @@ -310,9 +310,9 @@ esac SEARCH_PROG([for a LaTeX -> HTML converter], TOHTML, tth latex2html hevea) latex_to_html_command=$TOHTML case $TOHTML in - tth) latex_to_html_command="tth -t -e2 -L\$\$BaseName < \$\$FName > \$\$OutName";; - latex2html) latex_to_html_command="latex2html -no_subdir -split 0 -show_section_numbers \$\$FName";; - hevea) latex_to_html_command="hevea -s \$\$FName";; + tth) latex_to_html_command="tth -t -e2 -L\$\$b < \$\$i > \$\$o";; + latex2html) latex_to_html_command="latex2html -no_subdir -split 0 -show_section_numbers \$\$i";; + hevea) latex_to_html_command="hevea -s \$\$i";; esac #### Explore the LaTeX configuration @@ -386,23 +386,30 @@ cat >lyxrc.defaults <lyxrc.defaults <Postscript converter: -#\converter dvi ps "dvips -o $$OutName $$FName" "" -# The variable name $$FName is replaced with the name of the source file, -# and $$OutName is replaced with the name of the target file. +#\converter dvi ps "dvips -o $$o $$i" "" +# The variable name $$i is replaced with the name of the source file, +# and $$o is replaced with the name of the target file. # 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 @@ -354,26 +353,24 @@ # - needaux : The converted uses the .aux file, so we need to call latex # before running the converter. # - resultdir=dir : The converter put all the files in dir. -# Using "resultdir" is same as "resultdir=$$Basename". +# Using "resultdir" is same as "resultdir=$$b". # Note: When exporting, the whole directory will be moved from the temporary # directory to the target directory. # - resultfile=file : Name of main file in the result directory, for example -# "index.html" or "$$BaseName.html" +# "index.html" or "$$b.html" # If "resultfile" is omitted, the name of this file is assumed to be # "index.format" # - parselog=filtername : filtername is a name of a filter command that takes # the converter error log (from stderr), and converts it to a fake latex .log # file. -# - disable=backends : A list of & seperated backend in which the converter -# should not be used. # For example: -#\converter latex html "latex2html -split 0 $$FName" -# "originaldir,needaux,resultdir,disable=linuxdoc&docbook" +#\converter latex html "latex2html -split 0 $$i" +# "originaldir,needaux,resultdir" # # For literate programming, use something like -#\converter literate latex "noweave -delay -index $$FName >$$OutName" +#\converter literate latex "noweave -delay -index $$i >$$o" # "parselog=listerrors g" -#\converter literate program "build-script $$FName" +#\converter literate program "build-script $$i" # "originaldir,parselog=listerrors g" # The format command is used to define file formats. It has 4 arguments: @@ -459,28 +456,6 @@ # Default is "". #\backupdir_path "~/Desktop/Trash/" - -# -# FAX SECTION ############################################################# -# - -# In the following, the <$$something> strings are substituted by -# reasonable values by LyX. The 's are important as there may be spaces in -# the string. The default is auto-detected. -# This one is what is used with HylaFax: -#\fax_command "sendfax -n -h '$$Host' -c '$$Comment' -x '$$Enterprise' -d '$$Name'@'$$Phone' '$$FName'" -# Use this for the efax-command: -#\fax_command "faxsend '$$Phone' '$$FName'" - -# This is the name of your phone book. It's per default situated in ~/.lyx/, -# but you can override that with an absolute path. -#\phone_book phonebook - -# This is how to call an external FAX-program instead of the built-in. -# You may also insert $$FName to reference the PostScript file. -#\fax_program "myfaxprg '$$FName'" -#\fax_program tkhylafax - # # ASCII EXPORT SECTION ################################################### # diff --git a/lib/ui/default.ui b/lib/ui/default.ui index 4045818567..a99805e4d0 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -45,11 +45,11 @@ Menuset Item "Close|C" "buffer-close" Item "Save|S" "buffer-write" Item "Save As...|A" "buffer-write-as" - Item "Revert to saved|R" "buffer-reload" + Item "Revert to saved|d" "buffer-reload" Submenu "Version control|V" "file_vc" Separator - Submenu "Import|m" "file_import" - Submenu "Insert|I" "file_insert" + Submenu "Import|I" "file_import" + Submenu "Insert|r" "file_insert" Separator Submenu "Export|E" "file_export" Item "Print...|P" "buffer-print" @@ -70,8 +70,6 @@ Menuset End Menu "file_import" - Item "Ascii text as lines...|A" "buffer-import text" - Item "Ascii text as paragraphs...|p" "buffer-import textparagraph" ImportFormats End @@ -98,23 +96,23 @@ Menuset Menu "edit" Item "Undo|U" "undo" - Item "Redo|R" "redo" + Item "Redo|d" "redo" Separator Item "Cut|C" "cut" Item "Copy|o" "copy" - Item "Paste|P" "paste" + Item "Paste|a" "paste" Submenu "Paste external selection|x" "edit_paste" Separator Item "Find & Replace...|F" "find-replace" - Separator Submenu "Tabular|T" "edit_tabular" Submenu "Floats & Insets|I" "edit_floats" + Separator Item "Spellchecker...|S" "spellchecker" Item "Check TeX|h" "buffer-chktex" Item "Remove all Error boxes|E" "error-remove-all" Separator - Item "Preferences...|n" "dialog-preferences" - Item "Reconfigure|g" "reconfigure" + Item "Preferences...|P" "dialog-preferences" + Item "Reconfigure|R" "reconfigure" End Menu "edit_paste" @@ -158,7 +156,7 @@ Menuset # INSERT MENU # Menu "insert" - Item "Math text|M" "math-mode" + Item "Math text|t" "math-mode" Item "Math display|d" "math-display" Item "Math panel...|p" "math-panel" Separator @@ -167,17 +165,17 @@ Menuset Item "Cross reference...|r" "reference-insert" Item "Label...|L" "label-insert" Item "Footnote|F" "footnote-insert" - Item "Marginal note|n" "marginpar-insert" - Item "Index entry...|x" "index-insert" + Item "Marginal note|M" "marginpar-insert" + Item "Index entry...|I" "index-insert" Item "Index entry of last word|w" "index-insert-last" Item "URL...|U" "url-insert" - Item "Note...|o" "note-insert" + Item "Note...|N" "note-insert" Separator Item "Figure...|g" "figure-insert" - Item "Tabular...|T" "dialog-tabular-insert" + Item "Tabular...|b" "dialog-tabular-insert" Submenu "Floats|a" "insert_floats" Separator - Submenu "Lists & TOC|i" "insert_toc" + Submenu "Lists & TOC|O" "insert_toc" End Menu "insert_special" diff --git a/po/POTFILES.in b/po/POTFILES.in index 34bedb079b..cfcf301617 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -11,6 +11,7 @@ src/credits.C src/credits_form.C src/CutAndPaste.C src/exporter.C +src/ext_l10n.h src/filedlg.C src/FontLoader.C src/form1.C diff --git a/src/MenuBackend.C b/src/MenuBackend.C index eaf88f28fe..455a49c3db 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -25,6 +25,7 @@ #include "bufferlist.h" #include "converter.h" #include "exporter.h" +#include "importer.h" #include "support/filetools.h" #include "support/lyxfunctional.h" @@ -199,11 +200,6 @@ Menu & Menu::read(LyXLex & lex) return *this; } -struct compare_formatpair { - bool operator()(FormatPair const & a, FormatPair const & b) { - return a.format->prettyname < b.format->prettyname; - } -}; void Menu::checkShortcuts() const { @@ -273,66 +269,45 @@ void Menu::expand(Menu & tomenu, Buffer * buf) const } break; + case MenuItem::ImportFormats: case MenuItem::ViewFormats: case MenuItem::UpdateFormats: case MenuItem::ExportFormats: { - vector names; + vector formats; kb_action action; - if ((*cit).kind() == MenuItem::ViewFormats) { - names = Exporter::GetExportableFormats(buf, true); + switch ((*cit).kind()) { + case MenuItem::ImportFormats: + formats = Importer::GetImportableFormats(); + action = LFUN_IMPORT; + break; + case MenuItem::ViewFormats: + formats = Exporter::GetExportableFormats(buf, true); action = LFUN_PREVIEW; - } else if ((*cit).kind() == MenuItem::UpdateFormats) { - names = Exporter::GetExportableFormats(buf, true); + break; + case MenuItem::UpdateFormats: + formats = Exporter::GetExportableFormats(buf, true); action = LFUN_UPDATE; - } else { - names = Exporter::GetExportableFormats(buf, false); + break; + default: + formats = 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 = - fit != names.begin() && - (*fit).format == (*(fit-1)).format; - bool same_after = - fit+1 != names.end() && - (*fit).format == (*(fit+1)).format; - if ((*fit).from && - (same_before || same_after)) { - fmt += ":" + (*fit).from->name; - string head; - split((*fit).command, head, ' '); - label += _(" (using ") + head + ")"; - if (!(*fit).format->shortcut.empty() && - !same_before) - label += "|" + (*fit).format->shortcut; - } else if (!(*fit).format->shortcut.empty()) - label += "|" + (*fit).format->shortcut; - int action2 = lyxaction.getPseudoAction(action, fmt); - tomenu.add(MenuItem(MenuItem::Command, - label, action2)); - } - } - break; - - case MenuItem::ImportFormats: { - vector names = Converter::GetReachableTo("lyx"); - sort(names.begin(), names.end(), compare_formatpair()); + sort(formats.begin(), formats.end()); - for (vector::const_iterator fit = names.begin(); - fit != names.end() ; ++fit) { - if ((*fit).format->dummy()) + for (vector::const_iterator fit = formats.begin(); + fit != formats.end() ; ++fit) { + if ((*fit)->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); + string label = (*fit)->prettyname(); + if ((*cit).kind() == MenuItem::ImportFormats) + if ((*fit)->name() == "text") + label = _("Ascii text as lines"); + else if ((*fit)->name() == "textparagraph") + label = _("Ascii text as paragraphs"); + if (!(*fit)->shortcut().empty()) + label += "|" + (*fit)->shortcut(); + int action2 = lyxaction. + getPseudoAction(action, (*fit)->name()); tomenu.add(MenuItem(MenuItem::Command, label, action2)); } diff --git a/src/buffer.C b/src/buffer.C index 62750128c6..1d7973a8ff 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -3547,6 +3547,9 @@ vector const Buffer::getLabelList() vector > const Buffer::getTocList() { + int figs = 0; + int tables = 0; + int algs = 0; vector > l(4); LyXParagraph * par = paragraph; while (par) { @@ -3562,13 +3565,19 @@ vector > const Buffer::getTocList() switch (par->footnotekind) { case LyXParagraph::FIG: case LyXParagraph::WIDE_FIG: + tmp.str = tostr(++figs) + ". " + + tmp.str; l[TOC_LOF].push_back(tmp); break; case LyXParagraph::TAB: case LyXParagraph::WIDE_TAB: + tmp.str = tostr(++tables) + ". " + + tmp.str; l[TOC_LOT].push_back(tmp); break; case LyXParagraph::ALGORITHM: + tmp.str = tostr(++algs) + ". " + + tmp.str; l[TOC_LOA].push_back(tmp); break; case LyXParagraph::FOOTNOTE: diff --git a/src/converter.C b/src/converter.C index 75d1808f4c..90babcaa0d 100644 --- a/src/converter.C +++ b/src/converter.C @@ -14,7 +14,7 @@ #pragma implementation #endif -#include +#include #include "converter.h" #include "lyxrc.h" @@ -28,19 +28,21 @@ #include "minibuffer.h" #include "lyx_gui_misc.h" #include "lyx_cb.h" // ShowMessage() +#include "support/lyxfunctional.h" -using std::map; using std::vector; using std::queue; -using std::pair; using std::endl; -using std::find; +using std::fill; using std::find_if; +using std::reverse; +using std::sort; -////////////////////////////////////////////////////////////////////////////// +static string const token_from("$$i"); +static string const token_base("$$b"); +static string const token_to("$$o"); -vector Converter::commands; -string Converter::latex_command; +////////////////////////////////////////////////////////////////////////////// static inline string const add_options(string const & command, string const & options) @@ -52,253 +54,361 @@ string const add_options(string const & command, string const & options) ////////////////////////////////////////////////////////////////////////////// - bool Format::dummy() const { - return extension.empty(); + return extension().empty(); +} + + +bool Format::IsChildFormat() const +{ + if (name_.empty()) + return false; + return isdigit(name_[name_.length() - 1]); +} + + +string const Format::ParentFormat() const +{ + return name_.substr(0, name_.length() - 1); +} + +////////////////////////////////////////////////////////////////////////////// + +// This method should return a reference, and throw an exception +// if the format named name cannot be found (Lgb) +Format const * Formats::GetFormat(string const & name) const +{ + FormatList::const_iterator cit = + find_if(formatlist.begin(), formatlist.end(), + compare_memfun(&Format::name, name)); + if (cit != formatlist.end()) + return &(*cit); + else + return 0; +} + + +int Formats::GetNumber(string const & name) const +{ + FormatList::const_iterator cit = + find_if(formatlist.begin(), formatlist.end(), + compare_memfun(&Format::name, name)); + if (cit != formatlist.end()) + return cit - formatlist.begin(); + else + return -1; } void Formats::Add(string const & name) { - if (formats.find(name) == formats.end()) - formats[name] = Format(name, name, name, "", ""); + if (!GetFormat(name)) + Add(name, name, name, string()); } void Formats::Add(string const & name, string const & extension, string const & prettyname, string const & shortcut) { - - if (prettyname.empty()) { - FormatList::iterator it = formats.find(name); - if (it != formats.end()) - formats.erase(it); - return; + FormatList::iterator it = + find_if(formatlist.begin(), formatlist.end(), + compare_memfun(&Format::name, name)); + if (it == formatlist.end()) + formatlist.push_back(Format(name, extension, prettyname, + shortcut, "")); + else { + string viewer = it->viewer(); + *it = Format(name, extension, prettyname, shortcut, viewer); } +} + - string const old_viewer = formats[name].viewer; - formats[name] = Format(name, extension, prettyname, shortcut, - old_viewer); +void Formats::Delete(string const & name) +{ + FormatList::iterator it = + find_if(formatlist.begin(), formatlist.end(), + compare_memfun(&Format::name, name)); + if (it != formatlist.end()) + formatlist.erase(it); } -void Formats::SetViewer(string const & name, string const & command) +void Formats::Sort() { - string command2 = command; - if (!command2.empty() && !contains(command2,"$$FName")) - command2 += " $$FName"; + sort(formatlist.begin(), formatlist.end()); +} + +void Formats::SetViewer(string const & name, string const & command) +{ Add(name); - GetFormat(name)->viewer = command2; + FormatList::iterator it = + find_if(formatlist.begin(), formatlist.end(), + compare_memfun(&Format::name, name)); + if (it != formatlist.end()) + it->setViewer(command); } bool Formats::View(Buffer const * buffer, string const & filename, - string const & format_name) + string const & format_name) const { if (filename.empty()) return false; Format const * format = GetFormat(format_name); - if (!format || format->viewer.empty()) { + if (format && format->viewer().empty() && + format->IsChildFormat()) + format = GetFormat(format->ParentFormat()); + if (!format || format->viewer().empty()) { WriteAlert(_("Can not view file"), _("No information for viewing ") + PrettyName(format_name)); return false; } - string command = format->viewer; + string command = format->viewer(); if (format_name == "dvi" && !lyxrc.view_dvi_paper_option.empty()) { - string options = lyxrc.view_dvi_paper_option; - options += " " + Converter::dvi_papersize(buffer); + command += " " + lyxrc.view_dvi_paper_option; + command += " " + converters.dvi_papersize(buffer); if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) - options += 'r'; - command = add_options(command, options); + command += 'r'; } - string command2 = subst(command, "$$FName", OnlyFilename(filename)); + string command2 = command + " " + OnlyFilename(filename); lyxerr << "Executing command: " << command2 << endl; ShowMessage(buffer, _("Executing command:"), command2); - command = subst(command, "$$FName", QuoteName(filename)); + command += " " + QuoteName(filename); Systemcalls one; int res = one.startscript(Systemcalls::SystemDontWait, command); if (res) { WriteAlert(_("Can not view file"), _("Error while executing"), - command.substr(0, 50)); + command2.substr(0, 50)); return false; } return true; } -// This method should return a reference, and throw an exception -// if the format named name cannot be found (Lgb) -Format * Formats::GetFormat(string const & name) -{ - FormatList::iterator it = formats.find(name); - if (it != formats.end()) - return &it->second; - else - return 0; -} - - -string const Formats::PrettyName(string const & name) +string const Formats::PrettyName(string const & name) const { Format const * format = GetFormat(name); if (format) - return format->prettyname; + return format->prettyname(); else return name; } -string const Formats::Extension(string const & name) +string const Formats::Extension(string const & name) const { Format const * format = GetFormat(name); if (format) - return format->extension; + return format->extension(); else return name; } +////////////////////////////////////////////////////////////////////////////// -vector -const Formats::GetAllFormats() const +void Converter::ReadFlags() { - vector result; - for (FormatList::const_iterator cit = formats.begin(); - cit != formats.end(); ++cit) - result.push_back(cit->second); - return result; + string flag_list(flags); + while (!flag_list.empty()) { + string flag_name, flag_value; + flag_list = split(flag_list, flag_value, ','); + flag_value = split(flag_value, flag_name, '='); + if (flag_name == "latex") + latex = true; + else if (flag_name == "originaldir") + original_dir = true; + else if (flag_name == "needaux") + need_aux = true; + else if (flag_name == "resultdir") + result_dir = (flag_value.empty()) + ? token_base : flag_value; + else if (flag_name == "resultfile") + result_file = flag_value; + else if (flag_name == "parselog") + parselog = flag_value; + } + if (!result_dir.empty() && result_file.empty()) + result_file = "index." + formats.Extension(to); + //if (!contains(command, token_from)) + // latex = true; } +bool operator<(Converter const & a, Converter const & b) +{ + int i = compare_no_case(a.From->prettyname(), b.From->prettyname()); + if (i == 0) + return compare_no_case(a.To->prettyname(), b.To->prettyname()) + < 0; + else + return i < 0; +} + ////////////////////////////////////////////////////////////////////////////// -// Instead of storing an object we could just store an const reference. -// _but_ that is not guaranteed to work in all cases. (Lgb) -class compare_Command { +class compare_Converter { public: - compare_Command(Command const & c) : com(c) {} - bool operator()(Command const & c) { - return c.from == com.from && c.to == com.to; + compare_Converter(string const & f, string const & t) + : from(f), to(t) {} + bool operator()(Converter const & c) { + return c.from == from && c.to == to; } private: - Command com; + string from; + string to; }; -void Converter::Add(string const & from, string const & to, - string const & command, string const & flags) +Converter const * Converters::GetConverter(string const & from, + string const & to) { - 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)); - - if (command.empty() || command == "none") { - if (it != commands.end()) - commands.erase(it); - return; - } + ConverterList::const_iterator cit = + find_if(converterlist.begin(), converterlist.end(), + compare_Converter(from, to)); + if (cit != converterlist.end()) + return &(*cit); + else + return 0; +} - // Read the flags - string flag_list(flags); - while (!flag_list.empty()) { - string flag_name, flag_value; - flag_list = split(flag_list, flag_value, ','); - flag_value = split(flag_value, flag_name, '='); - if (flag_name == "*") { - if (it != commands.end()) { - Com = *it; - Com.command = command; - } - } - else if (flag_name == "importer") - Com.importer = true; - else if (flag_name == "latex") - Com.latex = true; - else if (flag_name == "originaldir") - Com.original_dir = true; - else if (flag_name == "needaux") - Com.need_aux = true; - else if (flag_name == "resultdir") - Com.result_dir = (flag_value.empty()) - ? "$$BaseName" : flag_value; - else if (flag_name == "resultfile") - Com.result_file = flag_value; - else if (flag_name == "parselog") - Com.parselog = flag_value; - else if (flag_name == "disable") { - while (!flag_value.empty()) { - string tmp; - flag_value = split(flag_value, tmp, '&'); - Com.disable.push_back(tmp); - } - } - } - if (!Com.result_dir.empty() && Com.result_file.empty()) - Com.result_file = "index." + to; - //if (!contains(command, "$$FName")) - // Com.latex = true; +int Converters::GetNumber(string const & from, string const & to) +{ + ConverterList::const_iterator cit = + find_if(converterlist.begin(), converterlist.end(), + compare_Converter(from, to)); + if (cit != converterlist.end()) + return cit - converterlist.begin(); + else + return -1; +} + - if (Com.latex && (latex_command.empty() || to == "dvi")) +void Converters::Add(string const & from, string const & to, + string const & command, string const & flags) +{ + formats.Add(from); + formats.Add(to); + ConverterList::iterator it = find_if(converterlist.begin(), + converterlist.end(), + compare_Converter(from, to)); + + Converter converter(from, to, command, flags); + if (it != converterlist.end() && !flags.empty() && flags[0] == '*') { + converter = *it; + converter.command = command; + converter.flags = flags; + } + converter.ReadFlags(); + + if (converter.latex && (latex_command.empty() || to == "dvi")) latex_command = command; // If we have both latex & pdflatex, we set latex_command to latex. // The latex_command is used to update the .aux file when running // a converter that uses it. - if (it != commands.end()) { - *it = Com; - return; + if (it == converterlist.end()) + converterlist.push_back(converter); + else { + converter.From = it->From; + converter.To = it->To; + *it = converter; } - commands.push_back(Com); } -static inline -bool enable(vector::iterator it, string const & from) +void Converters::Delete(string const & from, string const & to) { - return find(it->disable.begin(), it->disable.end(), from) - == it->disable.end(); + ConverterList::iterator it = find_if(converterlist.begin(), + converterlist.end(), + compare_Converter(from, to)); + if (it != converterlist.end()) + converterlist.erase(it); } -vector const -Converter::GetReachableTo(string const & target) +// This method updates the pointers From and To in all the converters. +// The code is not very efficient, but it doesn't matter as the number +// of formats and converters is small. +// Furthermore, this method is called only on startup, or after +// adding/deleting a format in FormPreferences (the latter calls can be +// eliminated if the formats in the Formats class are stored using a map or +// a list (instead of a vector), but this will cause other problems). +void Converters::Update(Formats const & formats) { - vector result; + for (ConverterList::iterator it = converterlist.begin(); + it != converterlist.end(); ++it) { + it->From = formats.GetFormat(it->from); + it->To = formats.GetFormat(it->to); + } +} - 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; + +// This method updates the pointers From and To in the last converter. +// It is called when adding a new converter in FormPreferences +void Converters::UpdateLast(Formats const & formats) +{ + if (converterlist.begin() != converterlist.end()) { + ConverterList::iterator it = converterlist.end()-1; + it->From = formats.GetFormat(it->from); + it->To = formats.GetFormat(it->to); + } +} + + +void Converters::Sort() +{ + sort(converterlist.begin(), converterlist.end()); +} + + +int Converters::BFS_init(string const & start, bool clear_visited) +{ + int s = formats.GetNumber(start); + if (s < 0) + return s; + + Q = queue(); + if (clear_visited) + fill(visited.begin(), visited.end(), false); + if (visited[s] == false) { + Q.push(s); + visited[s] = true; + } + return s; +} + + +vector const +Converters::GetReachableTo(string const & target, bool clear_visited) +{ + vector result; + int s = BFS_init(target, clear_visited); + if (s < 0) + return result; while (!Q.empty()) { - vector::iterator it = Q.front(); + int i = 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; + if (i != s || target != "lyx") + result.push_back(&formats.Get(i)); + for (vector::iterator it = vertices[i].in_vertices.begin(); + it != vertices[i].in_vertices.end(); ++it) + if (!visited[*it]) { + visited[*it] = true; + Q.push(*it); } } @@ -306,39 +416,29 @@ Converter::GetReachableTo(string const & target) } -vector const -Converter::GetReachable(string const & from, bool only_viewable) +vector const +Converters::GetReachable(string const & from, bool only_viewable, + bool clear_visited) { - vector result; - Format const * format = formats.GetFormat(from); - if (!format) - return result; - - if (!only_viewable || !format->viewer.empty()) - result.push_back(FormatPair(format, 0, "")); + vector result; - queue< vector::iterator > Q; - for (vector::iterator it = commands.begin(); - it != commands.end(); ++it) - if (it->from->name == from && enable(it, from) - && !it->importer) { - Q.push(it); - it->visited = true; - } else - it->visited = false; + if (BFS_init(from, clear_visited) < 0) + return result; while (!Q.empty()) { - vector::iterator it = Q.front(); + int i = Q.front(); Q.pop(); - 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->importer) { - Q.push(it2); - it2->visited = true; + Format const & format = formats.Get(i); + if (format.name() == "lyx") + continue; + if (!only_viewable || !format.viewer().empty() || + format.IsChildFormat()) + result.push_back(&format); + for (vector::iterator it = vertices[i].out_vertices.begin(); + it != vertices[i].out_vertices.end(); ++it) + if (!visited[*it]) { + visited[*it] = true; + Q.push(*it); } } @@ -346,88 +446,107 @@ Converter::GetReachable(string const & from, bool only_viewable) } -bool Converter::IsReachable(string const & from, string const & to) +bool Converters::IsReachable(string const & from, string const & to) { if (from == to) return true; - queue< vector::iterator > Q; - for (vector::iterator it = commands.begin(); - it != commands.end(); ++it) - if (it->from->name == from && enable(it, from)) { - Q.push(it); - it->visited = true; - } else - it->visited = false; + int s = BFS_init(from); + int t = formats.GetNumber(to); + if (s < 0 || t < 0) + return false; while (!Q.empty()) { - vector::iterator it = Q.front(); + int i = Q.front(); Q.pop(); - if (it->to->name == to) + if (i == t) return true; - for (vector::iterator it2 = commands.begin(); - it2 != commands.end(); ++it2) - if (!it2->visited && it->to == it2->from && - enable(it2, from)) { - Q.push(it2); - it2->visited = true; + for (vector::iterator it = vertices[i].out_vertices.begin(); + it != vertices[i].out_vertices.end(); ++it) + if (!visited[*it]) { + visited[*it] = true; + Q.push(*it); } } + return false; } -bool Converter::Convert(Buffer const * buffer, - string const & from_file, string const & to_file_base, - string const & from_format, string const & to_format, - string const & using_format, string & to_file) +Converters::EdgePath const +Converters::GetPath(string const & from, string const & to) { - to_file = ChangeExtension(to_file_base, - formats.Extension(to_format)); + EdgePath path; + if (from == to) + return path; - if (from_format == to_format) - if (from_file != to_file) - return lyx::rename(from_file, to_file); - else - return true; + int s = BFS_init(from); + int t = formats.GetNumber(to); + if (s < 0 || t < 0) + return path; - queue< vector::iterator > Q; - for (vector::iterator it = commands.begin(); - it != commands.end(); ++it) - if (it->from->name == from_format && enable(it, from_format)) { - Q.push(it); - it->visited = true; - it->previous = commands.end(); - } else - it->visited = false; - - if (Q.empty()) { - WriteAlert(_("Can not convert file"), - ("Unknown format ") + from_format); - return false; - } + vector prev_edge(formats.size()); + vector prev_vertex(formats.size()); bool found = false; - vector::iterator it; while (!Q.empty()) { - it = Q.front(); - if (it->to->name == to_format && - (using_format.empty() || using_format == it->from->name)) { + int i = Q.front(); + Q.pop(); + if (i == t) { found = true; break; } - Q.pop(); - for (vector::iterator it2 = commands.begin(); - it2 != commands.end(); ++it2) - if (!it2->visited && it->to == it2->from && - enable(it2, from_format)) { - Q.push(it2); - it2->visited = true; - it2->previous = it; + for (vector::iterator it = vertices[i].out_vertices.begin(); + it != vertices[i].out_vertices.end(); ++it) + if (!visited[*it]) { + int j = *it; + visited[j] = true; + Q.push(j); + int k = it - vertices[i].out_vertices.begin(); + prev_edge[j] = vertices[i].out_edges[k]; + prev_vertex[j] = i; } } + if (!found) + return path; - if (!found) { + while (t != s) { + path.push_back(prev_edge[t]); + t = prev_vertex[t]; + } + reverse(path.begin(), path.end()); + return path; +} + + +bool Converters::UsePdflatex(EdgePath const & path) +{ + for (EdgePath::const_iterator cit = path.begin(); + cit != path.end(); ++cit) { + Converter const & conv = converterlist[*cit]; + if (conv.latex) + return contains(conv.to, "pdf"); + } + return false; +} + + +bool Converters::Convert(Buffer const * buffer, + string const & from_file, string const & to_file_base, + string const & from_format, string const & to_format, + string & to_file) +{ + to_file = ChangeExtension(to_file_base, + formats.Extension(to_format)); + + if (from_format == to_format) + if (from_file != to_file) + return lyx::rename(from_file, to_file); + else + return true; + + EdgePath edgepath = GetPath(from_format, to_format); + if (edgepath.empty()) { WriteAlert(_("Can not convert file"), _("No information for converting from ") + formats.PrettyName(from_format) + _(" to ") @@ -435,12 +554,6 @@ bool Converter::Convert(Buffer const * buffer, return false; } - vector< vector::iterator > S; - while (it != commands.end()) { - S.push_back(it); - it = it->previous; - } - string path = OnlyPath(from_file); Path p(path); @@ -449,49 +562,49 @@ bool Converter::Convert(Buffer const * buffer, string to_base = ChangeExtension(to_file, ""); string infile; string outfile = from_file; - for (vector< vector::iterator >::reverse_iterator rit = - S.rbegin(); rit != S.rend(); ++rit) { - it = *rit; - bool dummy = it->to->dummy() && it->to->name != "program"; + for (EdgePath::const_iterator cit = edgepath.begin(); + cit != edgepath.end(); ++cit) { + Converter const & conv = converterlist[*cit]; + bool dummy = conv.To->dummy() && conv.to != "program"; if (!dummy) lyxerr << "Converting from " - << it->from->name << " to " << it->to->name << endl; + << conv.from << " to " << conv.to << endl; infile = outfile; - outfile = it->result_dir.empty() - ? ChangeExtension(from_file, it->to->extension) - : AddName(subst(it->result_dir, - "$$BaseName", from_base), - subst(it->result_file, - "$$BaseName", OnlyFilename(from_base))); - - if (it->latex) { - lyxrc.pdf_mode = it->to->name == "pdf"; - lyxerr << "Running " << it->command << endl; + outfile = conv.result_dir.empty() + ? ChangeExtension(from_file, conv.To->extension()) + : AddName(subst(conv.result_dir, + token_base, from_base), + subst(conv.result_file, + token_base, OnlyFilename(from_base))); + + if (conv.latex) { run_latex = true; - if (!runLaTeX(buffer, it->command)) + string command = subst(conv.command, token_from, ""); + lyxerr << "Running " << command << endl; + if (!runLaTeX(buffer, command)) return false; } else { - if (it->need_aux && !run_latex + if (conv.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 = (conv.original_dir) ? infile : MakeRelPath(infile, path); - string outfile2 = (it->original_dir) + string outfile2 = (conv.original_dir) ? outfile : MakeRelPath(outfile, path); - string command = it->command; - command = subst(command, "$$FName", QuoteName(infile2)); - command = subst(command, "$$BaseName", QuoteName(from_base)); - command = subst(command, "$$OutName", QuoteName(outfile2)); + string command = conv.command; + command = subst(command, token_from, QuoteName(infile2)); + command = subst(command, token_base, QuoteName(from_base)); + command = subst(command, token_to, QuoteName(outfile2)); - if (!it->parselog.empty()) + if (!conv.parselog.empty()) command += " 2> " + QuoteName(infile2 + ".out"); - if (it->from->name == "dvi" && it->to->name == "ps") + if (conv.from == "dvi" && conv.to == "ps") command = add_options(command, dvips_options(buffer)); @@ -503,15 +616,15 @@ bool Converter::Convert(Buffer const * buffer, ? Systemcalls::SystemDontWait : Systemcalls::System; Systemcalls one; int res; - if (it->original_dir && buffer) { + if (conv.original_dir && buffer) { Path p(buffer->filepath); res = one.startscript(type, command); } else res = one.startscript(type, command); - if (!it->parselog.empty()) { + if (!conv.parselog.empty()) { string const logfile = infile2 + ".log"; - string const command2 = it->parselog + + string const command2 = conv.parselog + " < " + QuoteName(infile2 + ".out") + " > " + QuoteName(logfile); one.startscript(Systemcalls::System, command2); @@ -520,7 +633,7 @@ bool Converter::Convert(Buffer const * buffer, } if (res) { - if (it->to->name == "program") + if (conv.to == "program") WriteAlert(_("There were errors during the Build process."), _("You should try to fix them.")); else @@ -532,20 +645,20 @@ bool Converter::Convert(Buffer const * buffer, } } - if (it->to->dummy()) + Converter const & conv = converterlist[edgepath.back()]; + if (conv.To->dummy()) return true; - if (!it->result_dir.empty()) { - to_file = AddName(subst(it->result_dir, - "$$BaseName", to_base), - subst(it->result_file, - "$$BaseName", OnlyFilename(to_base))); + if (!conv.result_dir.empty()) { + to_file = AddName(subst(conv.result_dir, token_base, to_base), + subst(conv.result_file, + token_base, OnlyFilename(to_base))); if (from_base != to_base) { - string from = subst(it->result_dir, - "$$BaseName", from_base); - string to = subst(it->result_dir, - "$$BaseName", to_base); + string from = subst(conv.result_dir, + token_base, from_base); + string to = subst(conv.result_dir, + token_base, to_base); if (!lyx::rename(from, to)) { WriteAlert(_("Error while trying to move directory:"), from, ("to ") + to); @@ -553,7 +666,7 @@ bool Converter::Convert(Buffer const * buffer, } } } else if (outfile != to_file) { - bool moved = (it->latex) + bool moved = (conv.latex) ? lyx::copy(outfile, to_file) : lyx::rename(outfile, to_file); if (!moved) { @@ -567,27 +680,43 @@ bool Converter::Convert(Buffer const * buffer, } -bool Converter::Convert(Buffer const * buffer, +bool Converters::Convert(Buffer const * buffer, string const & from_file, string const & to_file_base, - string const & from_format, string const & to_format, - string const & using_format) + string const & from_format, string const & to_format) { string to_file; return Convert(buffer, from_file, to_file_base, from_format, to_format, - using_format, to_file); + to_file); +} + + +void Converters::BuildGraph() +{ + vertices = vector(formats.size()); + visited.resize(formats.size()); + + for (ConverterList::iterator it = converterlist.begin(); + it != converterlist.end(); ++it) { + int s = formats.GetNumber(it->from); + int t = formats.GetNumber(it->to); + vertices[t].in_vertices.push_back(s); + vertices[s].out_vertices.push_back(t); + vertices[s].out_edges.push_back(it - converterlist.begin()); + } } -string const Converter::SplitFormat(string const & str, string & format) +bool Converters::FormatIsUsed(string const & format) { - string const using_format = split(str, format, ':'); - if (format.empty()) - format = "dvi"; - return using_format; + for (ConverterList::const_iterator cit = converterlist.begin(); + cit != converterlist.end(); ++cit) + if (cit->from == format || cit->to == format) + return true; + return false; } -bool Converter::scanLog(Buffer const * buffer, string const & command, +bool Converters::scanLog(Buffer const * buffer, string const & command, string const & filename) { if (!buffer) @@ -644,7 +773,7 @@ bool Converter::scanLog(Buffer const * buffer, string const & command, } -bool Converter::runLaTeX(Buffer const * buffer, string const & command) +bool Converters::runLaTeX(Buffer const * buffer, string const & command) { if (!buffer) return false; @@ -720,7 +849,7 @@ bool Converter::runLaTeX(Buffer const * buffer, string const & command) } -string const Converter::dvi_papersize(Buffer const * buffer) +string const Converters::dvi_papersize(Buffer const * buffer) { char real_papersize = buffer->params.papersize; if (real_papersize == BufferParams::PAPER_DEFAULT) @@ -746,7 +875,7 @@ string const Converter::dvi_papersize(Buffer const * buffer) } -string const Converter::dvips_options(Buffer const * buffer) +string const Converters::dvips_options(Buffer const * buffer) { string result; if (!buffer) @@ -778,23 +907,13 @@ string const Converter::dvips_options(Buffer const * buffer) return result; } - -void Converter::init() -{ -} - -vector const Converter::GetAllCommands() -{ - vector result; - for (vector::iterator it = commands.begin(); - it != commands.end(); ++it) - result.push_back(*it); - return result; -} +vector Converters::vertices; /// The global instance Formats formats; +Converters converters; -// The global copy of the system lyxrc entries (everything except preferences) +// The global copy after reading lyxrc.defaults Formats system_formats; +Converters system_converters; diff --git a/src/converter.h b/src/converter.h index 9ac0a271f2..1b8b85556e 100644 --- a/src/converter.h +++ b/src/converter.h @@ -16,58 +16,142 @@ #pragma interface #endif -#include #include +#include #include "LString.h" +#include "support/lstrings.h" class Buffer; /// class Format { public: - /// - Format() {} /// Format(string const & n, string const & e, string const & p, string const & s, string const & v) : - name(n), extension(e), prettyname(p), shortcut(s), - viewer(v) {}; + name_(n), extension_(e), prettyname_(p), shortcut_(s), + viewer_(v) {}; + /// + bool dummy() const; /// - string name; + bool IsChildFormat() const; /// - string extension; + string const ParentFormat() const; /// - string prettyname; + string const & name() const { + return name_; + } /// - string shortcut; + string const & extension() const { + return extension_; + } /// - string viewer; + string const & prettyname() const { + return prettyname_; + } /// - bool dummy() const; + string const & shortcut() const { + return shortcut_; + } + /// + string const & viewer() const { + return viewer_; + } + /// + void setViewer(string const & v) { + viewer_ = v; + } + friend bool operator<(Format const & a, Format const & b) { + return compare_no_case(a.prettyname(),b.prettyname()) < 0; + } +private: + string name_; + /// + string extension_; + /// + string prettyname_; + /// + string shortcut_; + /// + string viewer_; +}; + + +/// +class Formats { +public: + /// + typedef std::vector FormatList; + /// + typedef FormatList::const_iterator const_iterator; + /// + Format const & Get(int i) const { + return formatlist[i]; + } + /// + Format const * GetFormat(string const & name) const; /// - string const getname() const { - return name; + int GetNumber(string const & name) const; + /// + void Add(string const & name); + /// + void Add(string const & name, string const & extension, + string const & prettyname, string const & shortcut); + /// + void Delete(string const & name); + /// + void Sort(); + /// + void SetViewer(string const & name, string const & command); + /// + bool View(Buffer const * buffer, string const & filename, + string const & format_name) const; + /// + string const PrettyName(string const & name) const; + /// + string const Extension(string const & name) const; + /// + const_iterator begin() const { + return formatlist.begin(); } /// - string const getprettyname() const { - return prettyname; + const_iterator end() const { + return formatlist.end(); } + /// + FormatList::size_type size() const { + return formatlist.size(); + } +private: + /// + FormatList formatlist; }; +/////////////////////////////////////////////////////////////////////// + /// -struct Command { +class Converter { +public: /// - Command(Format const * f, Format const * t, string const & c) - : from(f), to(t), command(c), importer(false), + Converter(string const & f, string const & t, string const & c, + string const & l) + : from(f), to(t), command(c), flags(l), From(0), To(0), latex(false), original_dir(false), need_aux(false) {} /// - Format const * from; + void ReadFlags(); + /// + string from; /// - Format const * to; + string to; /// string command; - /// The converter is used for importing - bool importer; + /// + string flags; + /// + Format const * From; + /// + Format const * To; + /// The converter is latex or its derivatives bool latex; /// Do we need to run the converter in the original directory? @@ -82,123 +166,104 @@ struct Command { string result_file; /// Command to convert the program output to a LaTeX log file format string parselog; - /// Backends in which the converter is not used - std::vector disable; - - /// Used by the BFS algorithm - bool visited; - /// Used by the BFS algorithm - std::vector::iterator previous; - /// - std::pair const getFromToPrettyname() const { - return std::pair(from->prettyname, - to->prettyname); - } }; -class FormatPair { -public: - /// - Format const * format; - /// - Format const * from; - /// - string command; - /// - FormatPair(Format const * f1, Format const * f2, string c) - : format(f1), from(f2), command(c) {} -}; /// -class Formats { +class Converters { public: - /// - typedef std::map FormatList; + typedef std::vector ConverterList; /// - void Add(string const & name); - /// - void Add(string const & name, string const & extension, - string const & prettyname, string const & shortcut); + typedef ConverterList::const_iterator const_iterator; /// - void SetViewer(string const & name, string const & command); - /// - bool View(Buffer const * buffer, string const & filename, - string const & format_name); + typedef std::vector EdgePath; /// - Format * GetFormat(string const & name); - /// - string const PrettyName(string const & name); - /// - string const Extension(string const & name); + Converter const & Get(int i) const { + return converterlist[i]; + } /// - std::vector const GetAllFormats() const; -private: + Converter const * GetConverter(string const & from, string const & to); /// - FormatList formats; -}; - -/// -class Converter { -public: + int GetNumber(string const & from, string const & to); /// - static void Add(string const & from, string const & to, string const & command, string const & flags); + // + void Delete(string const & from, string const & to); /// - static - std::vector const GetReachableTo(string const & target); + void Sort(); /// - static - std::vector const - GetReachable(string const & from, bool only_viewable); + std::vector const + GetReachableTo(string const & target, bool clear_visited); + /// + std::vector const + GetReachable(string const & from, bool only_viewable, + bool clear_visited); /// - static bool IsReachable(string const & from, string const & to); /// - static + EdgePath const GetPath(string const & from, string const & to); + /// + bool UsePdflatex(EdgePath const & path); + /// bool Convert(Buffer const * buffer, string const & from_file, string const & to_file_base, string const & from_format, string const & to_format, - string const & using_format, string & to_file); + string & to_file); /// - static bool Convert(Buffer const * buffer, string const & from_file, string const & to_file_base, - string const & from_format, string const & to_format, - string const & using_format = string()); - /// - static - string const SplitFormat(string const & str, string & format); + string const & from_format, string const & to_format); /// - static string const dvi_papersize(Buffer const * buffer); /// - static string const dvips_options(Buffer const * buffer); /// - static - void init(); + void Update(Formats const & formats); /// - static - std::vector const GetAllCommands(); + void UpdateLast(Formats const & formats); + /// + void BuildGraph(); + /// + bool FormatIsUsed(string const & format); + /// + const_iterator begin() const { + return converterlist.begin(); + } + const_iterator end() const { + return converterlist.end(); + } private: /// - static bool scanLog(Buffer const * buffer, string const & command, string const & filename); /// - static bool runLaTeX(Buffer const * buffer, string const & command); /// - static - std::vector commands; + ConverterList converterlist; /// - static string latex_command; + /// + struct Vertex { + std::vector in_vertices; + std::vector out_vertices; + std::vector out_edges; + }; + /// + static + std::vector vertices; + /// + std::vector visited; + /// + std::queue Q; + /// + int BFS_init(string const & start, bool clear_visited = true); }; extern Formats formats; -extern Formats system_formats; +extern Converters converters; +extern Formats system_formats; +extern Converters system_converters; #endif diff --git a/src/exporter.C b/src/exporter.C index df330952c7..26952a7b64 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -14,24 +14,43 @@ #pragma implementation #endif +#include + #include "exporter.h" #include "buffer.h" #include "lyx_cb.h" //ShowMessage() #include "support/filetools.h" #include "lyxrc.h" #include "converter.h" +#include "lyx_gui_misc.h" //WriteAlert using std::vector; +using std::find; -bool Exporter::Export(Buffer * buffer, string const & format0, +bool Exporter::Export(Buffer * buffer, string const & format, bool put_in_tempdir, string & result_file) { - string format; - string using_format = Converter::SplitFormat(format0, format); - - string backend_format = (format == "text") - ? format : BufferFormat(buffer); - bool only_backend = backend_format == format; + string backend_format; + vector backends = Backends(buffer); + if (find(backends.begin(), backends.end(), format) == backends.end()) { + for (vector::const_iterator it = backends.begin(); + it != backends.end(); ++it) { + Converters::EdgePath p = + converters.GetPath(*it, format); + if (!p.empty()) { + lyxrc.pdf_mode = converters.UsePdflatex(p); + backend_format = *it; + break; + } + } + if (backend_format.empty()) { + WriteAlert(_("Can not export file"), + _("No information for exporting to ") + + formats.PrettyName(format)); + return false; + } + } else + backend_format = format; string filename = buffer->getLatexName(false); if (!buffer->tmppath.empty()) @@ -49,7 +68,7 @@ bool Exporter::Export(Buffer * buffer, string const & format0, else if (buffer->isDocBook()) buffer->makeDocBookFile(filename, true); // LaTeX backend - else if (only_backend) + else if (backend_format == format) buffer->makeLaTeXFile(filename, string(), true); else buffer->makeLaTeXFile(filename, buffer->filepath, false); @@ -57,9 +76,8 @@ bool Exporter::Export(Buffer * buffer, string const & format0, string outfile_base = (put_in_tempdir) ? filename : buffer->getLatexName(false); - if (!Converter::Convert(buffer, filename, outfile_base, - backend_format, format, using_format, - result_file)) + if (!converters.Convert(buffer, filename, outfile_base, + backend_format, format, result_file)) return false; if (!put_in_tempdir) @@ -78,32 +96,38 @@ bool Exporter::Export(Buffer * buffer, string const & format, return Export(buffer, format, put_in_tempdir, result_file); } -bool Exporter::Preview(Buffer * buffer, string const & format0) +bool Exporter::Preview(Buffer * buffer, string const & format) { string result_file; - if (!Export(buffer, format0, true, result_file)) + if (!Export(buffer, format, true, result_file)) return false; - string format; - Converter::SplitFormat(format0, format); return formats.View(buffer, result_file, format); } bool Exporter::IsExportable(Buffer const * buffer, string const & format) { - return format == "text" || - Converter::IsReachable(BufferFormat(buffer), format); + vector backends = Backends(buffer); + for (vector::const_iterator it = backends.begin(); + it != backends.end(); ++it) + if (converters.IsReachable(*it, format)) + return true; + return false; } -vector const +vector const Exporter::GetExportableFormats(Buffer const * buffer, bool only_viewable) { - vector result = - Converter::GetReachable(BufferFormat(buffer), only_viewable); - Format * format = formats.GetFormat("text"); - if (format && (!only_viewable || !format->viewer.empty())) - result.push_back(FormatPair(format , 0, "")); + vector backends = Backends(buffer); + vector result = + converters.GetReachable(backends[0], only_viewable, true); + for (vector::const_iterator it = backends.begin() + 1; + it != backends.end(); ++it) { + vector r = + converters.GetReachable(*it, only_viewable, false); + result.insert(result.end(), r.begin(), r.end()); + } return result; } @@ -119,3 +143,11 @@ string const Exporter::BufferFormat(Buffer const * buffer) else return "latex"; } + +vector const Exporter::Backends(Buffer const * buffer) +{ + vector v; + v.push_back(BufferFormat(buffer)); + v.push_back("text"); + return v; +} diff --git a/src/exporter.h b/src/exporter.h index 76a3257ea8..6d95507d59 100644 --- a/src/exporter.h +++ b/src/exporter.h @@ -20,7 +20,7 @@ #include "LString.h" class Buffer; -class FormatPair; +class Format; class Exporter { public: @@ -40,12 +40,14 @@ public: bool IsExportable(Buffer const * buffer, string const & format); /// static - std::vector const + std::vector const GetExportableFormats(Buffer const * buffer, bool only_viewable); /// - - /// +private: static string const BufferFormat(Buffer const * buffer); + /// + static + std::vector const Backends(Buffer const * buffer); }; #endif diff --git a/src/frontends/Liason.C b/src/frontends/Liason.C index 14d7fd3dda..f4f09dea4e 100644 --- a/src/frontends/Liason.C +++ b/src/frontends/Liason.C @@ -103,7 +103,7 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp) command += lyxrc.print_extra_options + ' '; } - command += Converter::dvips_options(buffer) + ' '; + command += converters.dvips_options(buffer) + ' '; if (!Exporter::Export(buffer, "dvi", true)) return false; diff --git a/src/frontends/xforms/Color.C b/src/frontends/xforms/Color.C index e69f91fe00..ba09d4d833 100644 --- a/src/frontends/xforms/Color.C +++ b/src/frontends/xforms/Color.C @@ -10,6 +10,7 @@ *======================================================*/ #include +#include FORMS_H_LOCATION #ifdef __GNUG_ #pragma implementation @@ -17,14 +18,17 @@ #include // max #include // floor +#include // ofstream #include "Color.h" +#include "lyxlex.h" using std::max; using std::min; +using std::ofstream; static int const nohue = -1; -RGB::RGB( HSV const & hsv ) +RGBColor::RGBColor( HSVColor const & hsv ) { double h = hsv.h; double s = hsv.s; @@ -91,7 +95,7 @@ RGB::RGB( HSV const & hsv ) } -HSV::HSV( RGB const & rgb ) +HSVColor::HSVColor( RGBColor const & rgb ) { // r, g, b lie in the range 0-1, not 0-255. double r = rgb.r / 255.0; @@ -128,3 +132,91 @@ HSV::HSV( RGB const & rgb ) } } + +// sorted by hand to prevent LyXLex from complaining on read(). +static +keyword_item xformTags[] = { +// { "\\gui_active_tab", FL_LIGHTER_COL1 }, + { "\\gui_background", FL_COL1 }, + { "\\gui_buttonbottom", FL_BOTTOM_BCOL }, + { "\\gui_buttonleft", FL_LEFT_BCOL }, + { "\\gui_buttonright", FL_RIGHT_BCOL }, + { "\\gui_buttontop", FL_TOP_BCOL }, + { "\\gui_inactive", FL_INACTIVE }, + { "\\gui_push_button", FL_YELLOW }, + { "\\gui_selected", FL_MCOL }, + { "\\gui_text", FL_BLACK } +}; + + +static const int xformCount = sizeof(xformTags) / sizeof(keyword_item); + + +bool XformColor::read(string const & filename) +{ + LyXLex lexrc( xformTags, xformCount ); + if( !lexrc.setFile( filename ) ) + return false; + + while( lexrc.IsOK() ) { + int le = lexrc.lex(); + + switch( le ) { + case LyXLex::LEX_UNDEF: + lexrc.printError("Unknown tag `$$Token'"); + continue; + case LyXLex::LEX_FEOF: + continue; + default: break; + } + + RGBColor col; + + if( !lexrc.next() ) break; + col.r = lexrc.GetInteger(); + + if( !lexrc.next() ) break; + col.g = lexrc.GetInteger(); + + if( !lexrc.next() ) break; + col.b = lexrc.GetInteger(); + + fl_mapcolor(le, col.r, col.g, col.b); + } + + return true; +} + + +bool XformColor::write(string const & filename) +{ + ofstream os(filename.c_str()); + if (!os) + return false; + + os << "### This file is part of\n" + << "### ========================================================\n" + << "### LyX, The Document Processor\n" + << "###\n" + << "### Copyright 1995 Matthias Ettrich\n" + << "### Copyright 1995-2000 The LyX Team.\n" + << "###\n" + << "### ========================================================\n" + << "\n" + << "# This file is written by LyX, if you want to make your own\n" + << "# modifications you should do them from inside LyX and save\n" + << "\n"; + + for( int i = 0; i < xformCount; ++i ) { + string tag = xformTags[i].tag; + int colorID = xformTags[i].code; + RGBColor color; + + fl_getmcolor(colorID, &color.r, &color.g, &color.b); + + os << tag + " " + << color.r << " " << color.g << " " << color.b << "\n"; + } + + return true; +} diff --git a/src/frontends/xforms/Color.h b/src/frontends/xforms/Color.h index 50ca142571..768b6ef3c0 100644 --- a/src/frontends/xforms/Color.h +++ b/src/frontends/xforms/Color.h @@ -12,7 +12,7 @@ #ifndef COLOR_H #define COLOR_H -#include // for pair +#include // for pair #ifdef __GNUG_ #pragma interface @@ -20,47 +20,49 @@ #include "LString.h" -class HSV; -class RGB; +class HSVColor; +class RGBColor; -struct HSV { +struct HSVColor { double h; double s; double v; - HSV() : h(0.0), s(0.0), v(0.0) {} - HSV(double hue, double sat, double val) : h(hue), s(sat), v(val) {} - HSV( RGB const & ); + HSVColor() : h(0.0), s(0.0), v(0.0) {} + HSVColor(double hue, double sat, double val) : h(hue), s(sat), v(val) {} + HSVColor( RGBColor const & ); }; -struct RGB { +struct RGBColor { int r; int g; int b; - RGB() : r(0), g(0), b(0) {} - RGB(int red, int green, int blue) : r(red), g(green), b(blue) {} - RGB( HSV const & ); + RGBColor() : r(0), g(0), b(0) {} + RGBColor(int red, int green, int blue) : r(red), g(green), b(blue) {} + RGBColor( HSVColor const & ); }; -typedef std::pair X11Color; +typedef std::pair X11Color; /// struct holding xform-specific colors -struct XFormColor { +struct XformColor { string name; int colorID; - RGB col; - XFormColor() : colorID(0) {} + RGBColor col; + XformColor() : colorID(0) {} string const getname() { return name; } + static bool read( string const & ); + static bool write( string const & ); }; inline -bool operator==(RGB const & c1, RGB const & c2) +bool operator==(RGBColor const & c1, RGBColor const & c2) { return (c1.r == c2.r && c1.g == c2.g && c1.b == c2.b); } inline -bool operator!=(RGB const & c1, RGB const & c2) +bool operator!=(RGBColor const & c1, RGBColor const & c2) { return !(c1 == c2); } diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 4b272397c9..5384eda325 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -1,5 +1,15 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2000 The LyX Team. + * + * ====================================================== + */ + #include -#include FORMS_H_LOCATION #include "Dialogs.h" #include "FormCitation.h" diff --git a/src/frontends/xforms/FormPreferences.C b/src/frontends/xforms/FormPreferences.C index 84abfb0595..095e6b9a8d 100644 --- a/src/frontends/xforms/FormPreferences.C +++ b/src/frontends/xforms/FormPreferences.C @@ -1,3 +1,13 @@ +// -*- C++ -*- +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2000 The LyX Team. + * + *======================================================*/ /* FormPreferences.C * FormPreferences Interface Class Implementation */ @@ -40,34 +50,23 @@ using SigC::slot; using std::find; using std::find_if; using std::pair; +using std::max; using std::sort; using std::vector; +using std::endl; extern string fmt(char const * fmtstr ...); extern string system_lyxdir; +extern string user_lyxdir; extern Languages languages; static string const colorFile("/usr/lib/X11/rgb.txt"); vector FormPreferences::colorDB; -vector FormPreferences::xformColorDB; +vector FormPreferences::xformColorDB; pair, vector > FormPreferences::dirlist; -// Two functions used to help sort a vector and a vector. -// Only used in this file, so no need to declare them globally. -bool CommandsCompare( Command const & a, Command const & b ) -{ - if( a.from->prettyname == b.from->prettyname ) - return( a.to->prettyname < b.to->prettyname ); - else - return( a.from->prettyname < b.from->prettyname ); -} - - -bool FormatsCompare( Format const & a, Format const & b ) -{ - return( a.name < b.name ); -} - +Formats local_formats; +Converters local_converters; FormPreferences::FormPreferences(LyXView * lv, Dialogs * d) : FormBaseBI(lv, d, _("Preferences"), new PreferencesPolicy), @@ -78,7 +77,8 @@ FormPreferences::FormPreferences(LyXView * lv, Dialogs * d) interface_(0), language_(0), lnf_misc_(0), outputs_misc_(0), paths_(0), printer_(0), screen_fonts_(0), spellchecker_(0), combo_default_lang(0), combo_kbmap_1(0), combo_kbmap_2(0), - warningPosted(false) + warningPosted(false), modifiedXformPrefs(false) + { // let the dialog be shown // This is a permanent connection so we won't bother @@ -118,37 +118,33 @@ FormPreferences::~FormPreferences() void FormPreferences::redraw() { - if( form() && form()->visible ) - fl_redraw_form( form() ); - else + if( !(form() && form()->visible) ) return; + fl_redraw_form( form() ); - FL_FORM * outer_form = fl_get_active_folder(dialog_->tabfolder_prefs); - if (outer_form && outer_form->visible) - fl_redraw_form( outer_form ); - else + FL_FORM * form2 = fl_get_active_folder(dialog_->tabfolder_prefs); + if( !(form2 && form2->visible) ) return; + fl_redraw_form( form2 ); - if( outer_form == converters_tab_->form ) - outer_form = - fl_get_active_folder(converters_tab_->tabfolder_outer); + FL_FORM * form3 = 0; + if( form2 == converters_tab_->form ) + form3 = fl_get_active_folder(converters_tab_->tabfolder_outer); - else if( outer_form == look_n_feel_tab_->form ) - outer_form = - fl_get_active_folder(look_n_feel_tab_->tabfolder_outer); + else if( form2 == look_n_feel_tab_->form ) + form3 = fl_get_active_folder(look_n_feel_tab_->tabfolder_outer); - else if( outer_form == inputs_tab_->form ) - outer_form = fl_get_active_folder(inputs_tab_->tabfolder_outer); + else if( form2 == inputs_tab_->form ) + form3 = fl_get_active_folder(inputs_tab_->tabfolder_outer); - else if( outer_form == outputs_tab_->form ) - outer_form = - fl_get_active_folder(outputs_tab_->tabfolder_outer); + else if( form2 == outputs_tab_->form ) + form3 = fl_get_active_folder(outputs_tab_->tabfolder_outer); - else if( outer_form == usage_tab_->form ) - outer_form = fl_get_active_folder(usage_tab_->tabfolder_outer); + else if( form2 == usage_tab_->form ) + form3 = fl_get_active_folder(usage_tab_->tabfolder_outer); - if (outer_form && outer_form->visible) - fl_redraw_form( outer_form ); + if (form3 && form3->visible) + fl_redraw_form( form3 ); } @@ -162,6 +158,12 @@ FL_FORM * FormPreferences::form() const void FormPreferences::ok() { FormBase::ok(); + + if( modifiedXformPrefs ) { + string filename = user_lyxdir + "/preferences.xform"; + modifiedXformPrefs = ! XformColor::write( filename ); + } + lv_->getLyXFunc()->Dispatch(LFUN_SAVEPREFERENCES); } @@ -296,8 +298,8 @@ void FormPreferences::apply() // and other stuff which may cost us a lot on slower/high-load machines. applyColors(); + applyFormats(); /// Must be before applyConverters() applyConverters(); - applyFormats(); applyInputsMisc(); applyInterface(); applyLanguage(); @@ -383,8 +385,8 @@ void FormPreferences::update() // read lyxrc entries updateColors(); + updateFormats(); /// Must be before updateConverters() updateConverters(); - updateFormats(); updateInputsMisc(); updateInterface(); updateLanguage(); @@ -397,18 +399,17 @@ void FormPreferences::update() } -void FormPreferences::applyColors() const +void FormPreferences::applyColors() { - bool modifiedXForms = false; bool modifiedText = false; bool modifiedBackground = false; - for( vector::const_iterator cit = xformColorDB.begin(); + for( vector::const_iterator cit = xformColorDB.begin(); cit != xformColorDB.end(); ++cit ) { - RGB col; + RGBColor col; fl_getmcolor((*cit).colorID, &col.r, &col.g, &col.b); if( col != (*cit).col ) { - modifiedXForms = true; + modifiedXformPrefs = true; if( (*cit).colorID == FL_BLACK ) modifiedText = true; if( (*cit).colorID == FL_COL1 ) @@ -416,8 +417,8 @@ void FormPreferences::applyColors() const } } - if( modifiedXForms ) { - vector::const_iterator cit; + if( modifiedXformPrefs ) { + vector::const_iterator cit; for( cit = xformColorDB.begin(); cit != xformColorDB.end(); ++cit ) { fl_mapcolor((*cit).colorID, @@ -472,10 +473,6 @@ void FormPreferences::buildColors() ColorsLoadBrowserLyX(); - // deactivate the browse button because it isn't implemented - fl_deactivate_object(colors_->button_browse); - fl_set_object_lcol(colors_->button_browse, FL_INACTIVE); - // set up the feedback mechanism setPreHandler( colors_->browser_x11 ); setPreHandler( colors_->input_name ); @@ -527,6 +524,9 @@ bool FormPreferences::inputColors( FL_OBJECT const * const ob ) } else if (ob == colors_->input_name) { return ColorsDatabase(); + } else if (ob == colors_->button_browse) { + return ColorsBrowseDatabase(); + } else if (ob == colors_->browser_lyx_objs) { return ColorsBrowserLyX(); @@ -541,17 +541,17 @@ bool FormPreferences::inputColors( FL_OBJECT const * const ob ) void FormPreferences::ColorsAdjustVal( int colAdjust, int colParent, double addVal ) const { - RGB rgb; + RGBColor rgb; fl_getmcolor( colParent, &rgb.r, &rgb.g, &rgb.b); - HSV hsv = HSV( rgb ); + HSVColor hsv = HSVColor( rgb ); hsv.v += addVal; if( hsv.v > 1.0 ) hsv.v = 1.0; else if( hsv.v < 0.0 ) hsv.v = 0.0; - rgb = RGB( hsv ); + rgb = RGBColor( hsv ); fl_mapcolor( colAdjust, rgb.r, rgb.g, rgb.b ); } @@ -564,9 +564,9 @@ bool FormPreferences::ColorsBrowserLyX() const string name = fl_get_browser_line( colors_->browser_lyx_objs, i ); - vector::const_iterator cit = + vector::const_iterator cit = find_if(xformColorDB.begin(), xformColorDB.end(), - compare_memfun(&XFormColor::getname, name)); + compare_memfun(&XformColor::getname, name)); if( cit != xformColorDB.end() ) { fl_freeze_form( colors_->form ); @@ -594,7 +594,7 @@ bool FormPreferences::ColorsBrowserX11() const fl_freeze_form( colors_->form ); - RGB col = colorDB[i-1].second; + RGBColor col = colorDB[i-1].second; fl_mapcolor( FL_FREE_COL4 + i, col.r, col.g, col.b ); fl_mapcolor( FL_FREE_COL4, col.r, col.g, col.b ); @@ -621,6 +621,12 @@ bool FormPreferences::ColorsBrowserX11() const } +bool FormPreferences::ColorsBrowseDatabase() const +{ + return true; +} + + bool FormPreferences::ColorsDatabase() const { string file = fl_get_input(colors_->input_name); @@ -636,7 +642,8 @@ bool FormPreferences::ColorsDatabase() const void FormPreferences::ColorsLoadBrowserLyX() { - XFormColor xcol; + // First, define the modifiable xform colors + XformColor xcol; xcol.name = "GUI background"; xcol.colorID = FL_COL1; @@ -650,11 +657,12 @@ void FormPreferences::ColorsLoadBrowserLyX() xformColorDB.push_back( xcol ); - xcol.name = "GUI active tab"; - xcol.colorID = FL_LIGHTER_COL1; - fl_getmcolor(FL_LIGHTER_COL1, &xcol.col.r, &xcol.col.g, &xcol.col.b); + // FL_LIGHTER_COL1 does not exist in xforms 0.88 +// xcol.name = "GUI active tab"; +// xcol.colorID = FL_LIGHTER_COL1; +// fl_getmcolor(FL_LIGHTER_COL1, &xcol.col.r, &xcol.col.g, &xcol.col.b); - xformColorDB.push_back( xcol ); +// xformColorDB.push_back( xcol ); xcol.name = "GUI push button"; xcol.colorID = FL_YELLOW; @@ -664,12 +672,15 @@ void FormPreferences::ColorsLoadBrowserLyX() FL_OBJECT * colbr = colors_->browser_lyx_objs; fl_clear_browser( colbr ); - for( vector::const_iterator cit = xformColorDB.begin(); + for( vector::const_iterator cit = xformColorDB.begin(); cit != xformColorDB.end(); ++cit ) { fl_addto_browser(colbr, (*cit).name.c_str() ); } - fl_deselect_browser(colors_->browser_lyx_objs); + // Now load the LyX LColors + + // just to be safe... + fl_deselect_browser( colors_->browser_lyx_objs ); fl_deactivate_object( colors_->button_modify ); fl_set_object_lcol( colors_->button_modify, FL_INACTIVE ); } @@ -683,11 +694,11 @@ bool FormPreferences::ColorsLoadBrowserX11(string const & filename) const if (!lex.setFile(filename)) return true; - vector cols; + vector cols; vector names; while (lex.next()) { - RGB col; + RGBColor col; col.r = lex.GetInteger(); lex.next(); col.g = lex.GetInteger(); @@ -699,20 +710,21 @@ bool FormPreferences::ColorsLoadBrowserX11(string const & filename) const // remove redundant entries on the fly bool add = cols.empty(); if (!add) { - vector::const_iterator cit = + vector::const_iterator cit = find( cols.begin(), cols.end(), col ); add = (cit == cols.end()); } if (add) { - if( col == RGB(0,0,0) ) + if( col == RGBColor(0,0,0) ) name = "black"; - else if( col == RGB(255,255,255) ) + else if( col == RGBColor(255,255,255) ) name = "white"; else name = lowercase( name ); - if ( col == RGB(0,0,0) || col == RGB(255,255,255) ) { + if ( col == RGBColor(0,0,0) || + col == RGBColor(255,255,255) ) { cols.insert(cols.begin(), col); names.insert(names.begin(), name); } else { @@ -727,7 +739,7 @@ bool FormPreferences::ColorsLoadBrowserX11(string const & filename) const fl_clear_browser( colbr ); vector::const_iterator sit = names.begin(); - for (vector::const_iterator iit = cols.begin(); + for (vector::const_iterator iit = cols.begin(); iit != cols.end(); ++iit, ++sit) { colorDB.push_back( X11Color(*sit, *iit) ); fl_addto_browser(colbr, (*sit).c_str()); @@ -750,9 +762,9 @@ bool FormPreferences::ColorsModify() const string name = fl_get_browser_line( colors_->browser_lyx_objs, i ); - vector::iterator it = // non-const; it's modified below + vector::iterator it = // non-const; it's modified below find_if(xformColorDB.begin(), xformColorDB.end(), - compare_memfun(&XFormColor::getname, name)); + compare_memfun(&XformColor::getname, name)); if( it == xformColorDB.end() ) return true; @@ -777,7 +789,7 @@ bool FormPreferences::ColorsRGB() const { fl_freeze_form(colors_->form); - RGB col; + RGBColor col; col.r = int(fl_get_slider_value(colors_->valslider_red)); col.g = int(fl_get_slider_value(colors_->valslider_green)); col.b = int(fl_get_slider_value(colors_->valslider_blue)); @@ -814,15 +826,15 @@ bool FormPreferences::ColorsRGB() const } -int FormPreferences::ColorsSearchEntry(RGB const & col) const +int FormPreferences::ColorsSearchEntry(RGBColor const & col) const { int mindiff = 0x7fffffff; vector::const_iterator mincit = colorDB.begin(); for (vector::const_iterator cit = colorDB.begin(); cit != colorDB.end(); ++cit) { - RGB colDB = (*cit).second; - RGB diff; + RGBColor colDB = (*cit).second; + RGBColor diff; diff.r = col.r - colDB.r; diff.g = col.g - colDB.g; diff.b = col.b - colDB.b; @@ -846,33 +858,9 @@ void FormPreferences::updateColors() void FormPreferences::applyConverters() const { - /* Uncomment once Converter is a "real" class. - - vector old = Converter::GetAllCommands(); - for (vector::const_iterator cit = old.begin(); - cit != old.end(); ++cit) { - pair FromTo = - pair((*cit).from->prettyname, - (*cit).to->prettyname); - - vector::const_iterator cit2 = - find_if(commands_vec.begin(), commands_vec.end(), - compare_memfun(&Command::getFromToPrettyname, - FromTo)); - - // Ie, converter exists in old, but is removed now. - // Can't actually Delete it, because old will contain - // system defauts. - if (cit2 == commands_vec.end()) - commands.Add((*cit).from, (*cit).to, string()); - } - - // Add new converters. - for (vector::const_iterator cit = commands_vec.begin(); - cit != commands_vec.end(); ++cit) { - commands.Add((*cit).from, (*cit).to, (*cit).command); - } - */ + converters = local_converters; + converters.Update(formats); + converters.BuildGraph(); } @@ -906,9 +894,9 @@ FormPreferences::feedbackConverters( FL_OBJECT const * const ob ) const } else if (ob == converters_->choice_to) { str = N_("Convert \"to\" this format"); } else if (ob == converters_->input_converter) { - str = N_("The conversion command. \"$$FName\" is the input file name, \"$$BaseName\" is the file name without its extension and $$OutName is the name of the output file."); + str = N_("The conversion command. $$i is the input file name, $$b is the file name without its extension and $$o is the name of the output file."); } else if (ob == converters_->input_flags) { - str = N_("I have no idea what this field is to be used for!"); + str = N_("Flags that control the converter behavior"); } else if (ob == converters_->button_delete) { str = N_("Remove the current converter from the list of available converters."); } else if (ob == converters_->button_add) { @@ -943,46 +931,58 @@ bool FormPreferences::inputConverters( FL_OBJECT const * const ob ) void FormPreferences::updateConverters() { - commands_vec = Converter::GetAllCommands(); - sort( commands_vec.begin(), commands_vec.end(), &CommandsCompare ); - - ConvertersClear(); + local_converters = converters; + local_converters.Update(local_formats); + ConvertersUpdateBrowser(); } -bool FormPreferences::ConvertersAdd() -{ - Command command( 0, 0, "" ); - if( !ConvertersSetCommand( command ) ) - return false; +struct compare_converter { + int operator()(Converter const & a, Converter const & b) { + int i = compare_no_case(a.From->prettyname(), + b.From->prettyname()); + if (i == 0) + return compare_no_case(a.To->prettyname(), + b.To->prettyname()) < 0; + else + return i < 0; + } +}; - string from = command.from->prettyname; - string to = command.to->prettyname; - pair FromTo = pair(from, to); - - vector::iterator it = // non-const; it's modified below - find_if(commands_vec.begin(), commands_vec.end(), - compare_memfun(&Command::getFromToPrettyname, FromTo)); + +void FormPreferences::ConvertersUpdateBrowser() +{ + local_converters.Sort(); fl_freeze_form(converters_->form); + fl_clear_browser(converters_->browser_all); + for (Converters::const_iterator cit = local_converters.begin(); + cit != local_converters.end(); ++cit) { + string name = (*cit).From->prettyname() + " -> " + + (*cit).To->prettyname(); + fl_addto_browser(converters_->browser_all, name.c_str()); + } + ConvertersInput(); + fl_unfreeze_form(converters_->form); +} - if (it == commands_vec.end()) { - // Unable to find command. Add to list. - commands_vec.push_back(command); - sort( commands_vec.begin(), commands_vec.end(), - &CommandsCompare ); - } else { - // Command found. Modify it. - (*it).from = command.from; - (*it).to = command.to; - (*it).command = command.command; +bool FormPreferences::ConvertersAdd() +{ + string from = ConverterGetFrom(); + string to = ConverterGetTo(); + string command = fl_get_input(converters_->input_converter); + string flags = fl_get_input(converters_->input_flags); + + Converter const * old = local_converters.GetConverter(from, to); + local_converters.Add(from, to, command, flags); + if (!old) { + local_converters.UpdateLast(local_formats); + ConvertersUpdateBrowser(); } - - // Clear input - ConvertersClear(); - - fl_unfreeze_form(converters_->form); + fl_deactivate_object(converters_->button_add); + fl_set_object_lcol(converters_->button_add, FL_INACTIVE); + return true; } @@ -994,41 +994,17 @@ bool FormPreferences::ConvertersBrowser() fl_freeze_form( converters_->form ); - Command const & c = commands_vec[i-1]; - - int sel = 0; - for( i = 1; - i <= fl_get_choice_maxitems( converters_->choice_from ); ++i ) { - string str = - fl_get_choice_item_text( converters_->choice_from, i ); - str = strip( frontStrip( str ) ); - - if( str == c.from->prettyname ) { - sel = i; - break; - } - } + Converter const & c = local_converters.Get(i-1); + int j = local_formats.GetNumber(c.from); + if (j >= 0) + fl_set_choice(converters_->choice_from, j+1); - if( sel != 0 ) - fl_set_choice( converters_->choice_from, sel ); + j = local_formats.GetNumber(c.to); + if (j >= 0) + fl_set_choice(converters_->choice_to, j+1); - sel = 0; - for( int i = 1; - i <= fl_get_choice_maxitems( converters_->choice_to ); ++i ) { - string str = - fl_get_choice_item_text( converters_->choice_to, i ); - str = strip( frontStrip( str ) ); - - if( str == c.to->prettyname ) { - sel = i; - break; - } - } - - if( sel != 0 ) - fl_set_choice( converters_->choice_to, sel ); - - fl_set_input( converters_->input_converter, c.command.c_str() ); + fl_set_input(converters_->input_converter, c.command.c_str()); + fl_set_input(converters_->input_flags, c.flags.c_str()); fl_set_object_label( converters_->button_add, idex(_("Modify|#M")) ); fl_set_button_shortcut( converters_->button_add, @@ -1045,120 +1021,31 @@ bool FormPreferences::ConvertersBrowser() } -void FormPreferences::ConvertersClear() const -{ - // Re-create browser - fl_clear_browser( converters_->browser_all ); - for (vector::const_iterator cit = commands_vec.begin(); - cit != commands_vec.end(); ++cit) { - string from = (*cit).from->prettyname; - string to = (*cit).to->prettyname; - string name = from + " -> " + to; - fl_addto_browser( converters_->browser_all, name.c_str() ); - } - - fl_set_input(converters_->input_converter, ""); - fl_set_input(converters_->input_flags, ""); - - fl_deselect_browser(formats_->browser_all); - - fl_set_object_label( converters_->button_add, idex(_("Add|#A")) ); - fl_set_button_shortcut( converters_->button_add, scex(_("Add|#A")), 1); - - fl_deactivate_object(converters_->button_add); - fl_set_object_lcol(converters_->button_add, FL_INACTIVE); - - fl_deactivate_object(converters_->button_delete); - fl_set_object_lcol(converters_->button_delete, FL_INACTIVE); -} - - -bool FormPreferences::ConvertersContainFormat( Format const & format ) const -{ - for( vector::const_iterator cit = commands_vec.begin(); - cit != commands_vec.end(); ++cit ) { - if( format.name == (*cit).from->name ) return true; - if( format.name == (*cit).to->name ) return true; - } - return false; -} - - bool FormPreferences::ConvertersDelete() { - Command command( 0, 0, "" ); - if( !ConvertersSetCommand( command ) ) - return false; - - string from = command.from->prettyname; - string to = command.to->prettyname; - pair FromTo = pair(from, to); - - vector::iterator it = // non-const; it's modified below - find_if(commands_vec.begin(), commands_vec.end(), - compare_memfun(&Command::getFromToPrettyname, FromTo)); - - fl_freeze_form(converters_->form); - - if (it == commands_vec.end()) { - fl_deactivate_object(converters_->button_delete); - fl_set_object_lcol(converters_->button_delete, FL_INACTIVE); - - fl_unfreeze_form(converters_->form); - return false; - } + string from = ConverterGetFrom(); + string to = ConverterGetTo(); - commands_vec.erase(it); - ConvertersClear(); - - fl_unfreeze_form(converters_->form); + local_converters.Delete(from, to); + ConvertersUpdateBrowser(); return true; } bool FormPreferences::ConvertersInput() { - string from = fl_get_choice_text( converters_->choice_from ); - from = strip( frontStrip( from ) ); - - string to = fl_get_choice_text( converters_->choice_to ); - to = strip( frontStrip( to ) ); - - string name; - if( !from.empty() && !to.empty() ) - name = from + " -> " + to; - - int sel = 0; - if( !name.empty() ) { - for( int i = 0; - i < fl_get_browser_maxline(converters_->browser_all); - ++i ) { - string str = - fl_get_browser_line( converters_->browser_all, - i+1 ); - if( str == name ) { - sel = i+1; - break; - } - } - } + string from = ConverterGetFrom(); + string to = ConverterGetTo(); + int sel = local_converters.GetNumber(from, to); fl_freeze_form(converters_->form); - if( sel == 0 ) { + if (sel < 0) { fl_set_object_label( converters_->button_add, idex(_("Add|#A")) ); fl_set_button_shortcut( converters_->button_add, scex(_("Add|#A")), 1); - if( name.empty() ) { - fl_deactivate_object(converters_->button_add); - fl_set_object_lcol(converters_->button_add, FL_INACTIVE); - } else { - fl_activate_object(converters_->button_add); - fl_set_object_lcol(converters_->button_add, FL_BLACK); - } - fl_deselect_browser(converters_->browser_all); fl_deactivate_object(converters_->button_delete); @@ -1170,68 +1057,62 @@ bool FormPreferences::ConvertersInput() fl_set_button_shortcut( converters_->button_add, scex(_("Modify|#M")), 1); - int top = sel-6; - if( top < 1 ) top = 0; + int top = max(sel-5, 0); fl_set_browser_topline(converters_->browser_all, top); - fl_select_browser_line(converters_->browser_all, sel); + fl_select_browser_line(converters_->browser_all, sel+1); - fl_activate_object(converters_->button_add); - fl_set_object_lcol(converters_->button_add, FL_BLACK); - fl_activate_object(converters_->button_delete); fl_set_object_lcol(converters_->button_delete, FL_BLACK); } + string command = fl_get_input(converters_->input_converter); + if (command.empty() || from == to) { + fl_deactivate_object(converters_->button_add); + fl_set_object_lcol(converters_->button_add, FL_INACTIVE); + } else { + fl_activate_object(converters_->button_add); + fl_set_object_lcol(converters_->button_add, FL_BLACK); + } + fl_unfreeze_form(converters_->form); - return true; + return false; } -bool FormPreferences::ConvertersSetCommand( Command & command ) const +string const FormPreferences::ConverterGetFrom() const { - string from = fl_get_choice_text( converters_->choice_from ); - from = strip( frontStrip( from ) ); - if( from.empty() ) - return false; - - vector::const_iterator fit = - find_if(formats_vec.begin(), formats_vec.end(), - compare_memfun(&Format::getprettyname, from)); - if( fit == formats_vec.end() ) - return false; - - string to = fl_get_choice_text( converters_->choice_to ); - to = strip( frontStrip( to ) ); - if( to.empty() ) - return false; - - vector::const_iterator tit = - find_if(formats_vec.begin(), formats_vec.end(), - compare_memfun(&Format::getprettyname, to)); - if( tit == formats_vec.end() ) - return false; - - string converter = fl_get_input( converters_->input_converter ); - string flags = fl_get_input( converters_->input_flags ); - - command.from = fit; - command.to = tit; - command.command = converter; + int i = fl_get_choice(converters_->choice_from); + if (i > 0) + return local_formats.Get(i-1).name(); + else { + lyxerr << "FormPreferences::ConvertersGetFrom: No choice!" << endl; + return "???"; + } +} - return true; + +string const FormPreferences::ConverterGetTo() const +{ + int i = fl_get_choice(converters_->choice_to); + if (i > 0) + return local_formats.Get(i-1).name(); + else { + lyxerr << "FormPreferences::ConvertersGetTo: No choice!" << endl; + return "???"; + } } -void FormPreferences::ConvertersUpdateChoices() +void FormPreferences::ConvertersUpdateChoices() const { string choice; - for( vector::iterator cit = formats_vec.begin(); - cit != formats_vec.end(); ++cit ) { - if( !choice.empty() ) + for (Formats::const_iterator cit = local_formats.begin(); + cit != local_formats.end(); ++cit ) { + if (!choice.empty()) choice += " | "; else choice += " "; - choice += (*cit).prettyname; + choice += (*cit).prettyname(); } choice += " "; @@ -1245,28 +1126,7 @@ void FormPreferences::ConvertersUpdateChoices() void FormPreferences::applyFormats() const { - vector old = formats.GetAllFormats(); - for (vector::const_iterator cit = old.begin(); - cit != old.end(); ++cit) { - - vector::const_iterator cit2 = - find_if(formats_vec.begin(),formats_vec.end(), - compare_memfun(&Format::getname, (*cit).name)); - - // Ie, format exists in old, but is removed now. - // Can't actually Delete it, because old will contain - // system defauts. - if (cit2 == formats_vec.end()) - formats.Add((*cit).name, string(), string(), string()); - } - - // Add new formats. - for (vector::const_iterator cit = formats_vec.begin(); - cit != formats_vec.end(); ++cit) { - formats.Add((*cit).name, (*cit).extension, (*cit).prettyname, - (*cit).shortcut); - formats.SetViewer((*cit).name, (*cit).viewer); - } + formats = local_formats; } @@ -1310,7 +1170,7 @@ FormPreferences::feedbackFormats( FL_OBJECT const * const ob ) const } else if (ob == formats_->input_extension) { str = N_("Used to recognize the file. E.g., ps, pdf, tex."); } else if (ob == formats_->input_viewer) { - str = N_("The command used to launch the viwer application\nE.g. \"netscape $$FName\" where $$FName is the name of the file."); + str = N_("The command used to launch the viewer application."); } else if (ob == formats_->button_delete) { str = N_("Remove the current format from the list of available formats."); } else if (ob == formats_->button_add) { @@ -1346,13 +1206,29 @@ bool FormPreferences::inputFormats(FL_OBJECT const * const ob) void FormPreferences::updateFormats() { - formats_vec = formats.GetAllFormats(); - sort( formats_vec.begin(), formats_vec.end(), &FormatsCompare ); + local_formats = formats; + FormatsUpdateBrowser(); +} + + +void FormPreferences::FormatsUpdateBrowser() +{ + local_formats.Sort(); + + fl_freeze_form(formats_->form); + fl_deselect_browser(formats_->browser_all); + fl_clear_browser(formats_->browser_all); + for (Formats::const_iterator cit = local_formats.begin(); + cit != local_formats.end(); ++cit) + fl_addto_browser(formats_->browser_all, + (*cit).prettyname().c_str()); + + FormatsInput(); + fl_unfreeze_form(formats_->form); // Mustn't forget to update the Formats available to the converters ConvertersUpdateChoices(); - - FormatsClear(); + local_converters.Update(local_formats); } @@ -1363,44 +1239,19 @@ bool FormPreferences::FormatsAdd() string extension = fl_get_input(formats_->input_extension); string shortcut = fl_get_input(formats_->input_shrtcut); string viewer = fl_get_input(formats_->input_viewer); - if (prettyname.empty()) - return false; - - Format format(name, extension, prettyname, shortcut, viewer); - vector::iterator it = // non-const; it's modified below - find_if(formats_vec.begin(), formats_vec.end(), - compare_memfun(&Format::getname, name)); - fl_freeze_form(formats_->form); + Format const * old = local_formats.GetFormat(name); + string old_prettyname = old ? old->prettyname() : string(); + local_formats.Add(name, extension, prettyname, shortcut); + local_formats.SetViewer(name, viewer); + if (!old || prettyname != old_prettyname) { + FormatsUpdateBrowser(); + if (old) + ConvertersUpdateBrowser(); + } + fl_deactivate_object(formats_->button_add); + fl_set_object_lcol(formats_->button_add, FL_INACTIVE); - if (it == formats_vec.end()) { - // Unable to find format. Add to list. - formats_vec.push_back(format); - sort( formats_vec.begin(), formats_vec.end(), &FormatsCompare ); - - // Mustn't forget to update the Formats available to the - // converters - ConvertersUpdateChoices(); - - // Re-create browser - fl_clear_browser( formats_->browser_all ); - for (vector::const_iterator cit = formats_vec.begin(); - cit != formats_vec.end(); ++cit) - fl_addto_browser(formats_->browser_all, - (*cit).name.c_str()); - } else { - // Format found. Modify it. - (*it).name = name; - (*it).prettyname = prettyname; - (*it).extension = extension; - (*it).shortcut = shortcut; - (*it).viewer = viewer; - } - - // Clear input - FormatsClear(); - - fl_unfreeze_form(formats_->form); return true; } @@ -1412,13 +1263,13 @@ bool FormPreferences::FormatsBrowser() fl_freeze_form(formats_->form); - Format const & f = formats_vec[i-1]; + Format const & f = local_formats.Get(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_shrtcut, f.shortcut.c_str()); - fl_set_input(formats_->input_extension, f.extension.c_str()); - fl_set_input(formats_->input_viewer, f.viewer.c_str()); + 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_shrtcut, f.shortcut().c_str()); + fl_set_input(formats_->input_extension, f.extension().c_str()); + fl_set_input(formats_->input_viewer, f.viewer().c_str()); fl_set_object_label( formats_->button_add, idex(_("Modify|#M")) ); fl_set_button_shortcut( formats_->button_add, scex(_("Modify|#M")), 1); @@ -1434,63 +1285,19 @@ bool FormPreferences::FormatsBrowser() } -void FormPreferences::FormatsClear() const -{ - // Re-create browser - fl_clear_browser(formats_->browser_all); - for (vector::const_iterator cit = formats_vec.begin(); - cit != formats_vec.end(); ++cit) - fl_addto_browser( formats_->browser_all, (*cit).name.c_str() ); - - fl_deselect_browser(formats_->browser_all); - - fl_set_input(formats_->input_format, ""); - fl_set_input(formats_->input_gui_name, ""); - fl_set_input(formats_->input_shrtcut, ""); - fl_set_input(formats_->input_extension, ""); - fl_set_input(formats_->input_viewer, ""); - - fl_set_object_label( formats_->button_add, idex(_("Add|#A")) ); - fl_set_button_shortcut( formats_->button_add, scex(_("Add|#A")), 1); - - fl_deactivate_object(formats_->button_add); - fl_set_object_lcol(formats_->button_add, FL_INACTIVE); - - fl_deactivate_object(formats_->button_delete); - fl_set_object_lcol(formats_->button_delete, FL_INACTIVE); -} - - bool FormPreferences::FormatsDelete() { string name = fl_get_input(formats_->input_format); - vector::iterator it = // non-const; it's modified below - find_if(formats_vec.begin(), formats_vec.end(), - compare_memfun(&Format::getname, name)); - fl_freeze_form(formats_->form); - - bool warning = ConvertersContainFormat( *it ); - if( warning ) { - string str = N_("WARNING! Cannot remove a Format used by a Converter. Remove the converter first."); - printWarning( str ); - } - - if (it == formats_vec.end() || warning) { + if (local_converters.FormatIsUsed(name)) { + printWarning(_("WARNING! Cannot remove a Format used by a Converter. Remove the converter first.")); fl_deactivate_object(formats_->button_delete); fl_set_object_lcol(formats_->button_delete, FL_INACTIVE); - - fl_unfreeze_form(formats_->form); return false; } - formats_vec.erase(it); - FormatsClear(); - - // Mustn't forget to update the Formats available to the converters - ConvertersUpdateChoices(); - - fl_unfreeze_form(formats_->form); + local_formats.Delete(name); + FormatsUpdateBrowser(); return true; } @@ -1498,37 +1305,15 @@ bool FormPreferences::FormatsDelete() bool FormPreferences::FormatsInput() { string name = fl_get_input(formats_->input_format); - - int sel = 0; - if( !name.empty() ) { - for( int i = 0; - i < fl_get_browser_maxline(formats_->browser_all); ++i ) { - string str = - fl_get_browser_line( formats_->browser_all, - i+1 ); - if( str == name ) { - sel = i+1; - break; - } - } - } - + int sel = local_formats.GetNumber(name); fl_freeze_form(formats_->form); - if( sel == 0 ) { + if (sel < 0) { fl_set_object_label( formats_->button_add, idex(_("Add|#A")) ); fl_set_button_shortcut( formats_->button_add, scex(_("Add|#A")), 1); - if( name.empty() ) { - fl_deactivate_object(formats_->button_add); - fl_set_object_lcol(formats_->button_add, FL_INACTIVE); - } else { - fl_activate_object(formats_->button_add); - fl_set_object_lcol(formats_->button_add, FL_BLACK); - } - fl_deselect_browser(formats_->browser_all); fl_deactivate_object(formats_->button_delete); @@ -1540,10 +1325,9 @@ bool FormPreferences::FormatsInput() fl_set_button_shortcut( formats_->button_add, scex(_("Modify|#M")), 1); - int top = sel-6; - if( top < 1 ) top = 0; + int top = max(sel-5, 0); fl_set_browser_topline(formats_->browser_all, top); - fl_select_browser_line(formats_->browser_all, sel); + fl_select_browser_line(formats_->browser_all, sel+1); fl_activate_object(formats_->button_add); fl_set_object_lcol(formats_->button_add, FL_BLACK); @@ -1552,8 +1336,17 @@ bool FormPreferences::FormatsInput() fl_set_object_lcol(formats_->button_delete, FL_BLACK); } + string prettyname = fl_get_input(formats_->input_gui_name); + if (name.empty() || prettyname.empty()) { + fl_deactivate_object(formats_->button_add); + fl_set_object_lcol(formats_->button_add, FL_INACTIVE); + } else { + fl_activate_object(formats_->button_add); + fl_set_object_lcol(formats_->button_add, FL_BLACK); + } + fl_unfreeze_form(formats_->form); - return true; + return false; } diff --git a/src/frontends/xforms/FormPreferences.h b/src/frontends/xforms/FormPreferences.h index 5ecc138eef..2e58da727e 100644 --- a/src/frontends/xforms/FormPreferences.h +++ b/src/frontends/xforms/FormPreferences.h @@ -46,6 +46,7 @@ struct FD_form_printer; struct FD_form_screen_fonts; struct FD_form_spellchecker; + /** This class provides an XForms implementation of the FormPreferences Dialog. The preferences dialog allows users to set/save their preferences. */ @@ -88,7 +89,7 @@ private: */ /// - void applyColors() const; + void applyColors(); // not const as modifies modifiedXformPrefs. /// void applyConverters() const; /// @@ -224,6 +225,8 @@ private: /// bool ColorsBrowserX11() const; /// + bool ColorsBrowseDatabase() const; + /// bool ColorsDatabase() const; /// void ColorsLoadBrowserLyX(); @@ -234,30 +237,30 @@ private: /// bool ColorsRGB() const; /// - int ColorsSearchEntry(RGB const &) const; + int ColorsSearchEntry(RGBColor const &) const; /// bool ConvertersAdd(); /// bool ConvertersBrowser(); /// - void ConvertersClear() const; - /// - bool ConvertersContainFormat( Format const &) const; + void ConvertersUpdateBrowser(); /// bool ConvertersDelete(); /// bool ConvertersInput(); /// - bool ConvertersSetCommand( Command & ) const; + string const ConverterGetFrom() const; /// - void ConvertersUpdateChoices(); + string const ConverterGetTo() const; + /// + void ConvertersUpdateChoices() const; bool FormatsAdd(); /// bool FormatsBrowser(); /// - void FormatsClear() const; + void FormatsUpdateBrowser(); /// bool FormatsDelete(); /// @@ -347,22 +350,21 @@ private: /// Combox * combo_kbmap_2; - /// A vector of Formats, to be manipulated in the Format browser. - std::vector formats_vec; - /// A vector of Commands, to be manipulated in the Converter browser. - std::vector commands_vec; /// A vector of RGB colors and associated name. static std::vector colorDB; /// A vector of xform RGB colors and associated name. - static std::vector xformColorDB; + static std::vector xformColorDB; /** A collection of kmap files. First entry is the file name, full path. Second entry is the shorthand, as appears in the fl_choice. Eg, system_lyxdir/kbd/american2.kmap, american2 */ static std::pair, std::vector > dirlist; - /// + /** Flag whether a warning has been posted to the text window. + If so, don't redraw the window when the mouse leaves an object. */ bool warningPosted; + /// Flag whether Xforms colors have been changed since last file save. + bool modifiedXformPrefs; }; #endif diff --git a/src/importer.C b/src/importer.C index 73a503f9c6..ff506f62ab 100644 --- a/src/importer.C +++ b/src/importer.C @@ -14,6 +14,8 @@ #pragma implementation #endif +#include + #include "importer.h" #include "converter.h" #include "LyXView.h" @@ -21,12 +23,16 @@ #include "minibuffer.h" #include "bufferlist.h" #include "support/filetools.h" +#include "lyx_gui_misc.h" //WriteAlert + +using std::vector; +using std::find; extern BufferList bufferlist; extern void InsertAsciiFile(BufferView *, string const &, bool); -void Importer::Import(LyXView * lv, string const & filename, +bool Importer::Import(LyXView * lv, string const & filename, string const & format) { string displaypath = MakeDisplayPath(filename); @@ -34,36 +40,80 @@ void Importer::Import(LyXView * lv, string const & filename, string lyxfile = ChangeExtension(filename, ".lyx"); - bool result = true; - if (format == "text" || format == "textparagraph") { + string loader_format; + vector loaders = Loaders(); + if (find(loaders.begin(), loaders.end(), format) == loaders.end()) { + for (vector::const_iterator it = loaders.begin(); + it != loaders.end(); ++it) { + if (converters.IsReachable(format, *it)) { + if (!converters.Convert(0, filename, filename, + format, *it)) + return false; + loader_format = *it; + break; + } + } + if (loader_format.empty()) { + WriteAlert(_("Can not import file"), + _("No information for importing from ") + + formats.PrettyName(format)); + return false; + } + } else + loader_format = format; + + + if (loader_format == "lyx") { + Buffer * buffer = bufferlist.loadLyXFile(lyxfile); + if (buffer) + lv->view()->buffer(buffer); + } else { lv->view()->buffer(bufferlist.newFile(lyxfile, string(), true)); - bool as_paragraphs = format == "textparagraph"; - InsertAsciiFile(lv->view(), filename, as_paragraphs); + bool as_paragraphs = loader_format == "textparagraph"; + string filename2 = (loader_format == format) ? filename + : ChangeExtension(filename, + formats.Extension(loader_format)); + InsertAsciiFile(lv->view(), filename2, as_paragraphs); lv->getLyXFunc()->Dispatch(LFUN_MARK_OFF); - } else { - result = Converter::Convert(0, filename, filename, format, "lyx"); - if (result) { - Buffer * buffer = bufferlist.loadLyXFile(lyxfile); - if (buffer) - lv->view()->buffer(buffer); - else - result = false; - } } // we are done - if (result) - lv->getMiniBuffer()->Set(displaypath, _("imported.")); - else - lv->getMiniBuffer()->Set(displaypath, _(": import failed.")); + lv->getMiniBuffer()->Set(displaypath, _("imported.")); + return true; +} +#if 0 +bool Importer::IsImportable(string const & format) +{ + vector loaders = Loaders(); + for (vector::const_iterator it = loaders.begin(); + it != loaders.end(); ++it) + if (converters.IsReachable(format, *it)) + return true; + return false; } +#endif +vector const Importer::GetImportableFormats() +{ + vector loaders = Loaders(); + vector result = + converters.GetReachableTo(loaders[0], true); + for (vector::const_iterator it = loaders.begin() + 1; + it != loaders.end(); ++it) { + vector r = + converters.GetReachableTo(*it, false); + result.insert(result.end(), r.begin(), r.end()); + } + return result; +} -bool Importer::IsImportable(string const & format) + +vector const Importer::Loaders() { - if (format == "text" || format == "textparagraph") - return true; - else - return Converter::IsReachable(format, "lyx"); + vector v; + v.push_back("lyx"); + v.push_back("text"); + v.push_back("textparagraph"); + return v; } diff --git a/src/importer.h b/src/importer.h index a505e44f4a..b12fd6559b 100644 --- a/src/importer.h +++ b/src/importer.h @@ -16,17 +16,29 @@ #pragma interface #endif +#include #include "LString.h" class LyXView; +class Format; class Importer { public: /// static - void Import(LyXView * lv, string const & filename, + bool Import(LyXView * lv, string const & filename, string const & format); +#if 0 + /// static bool IsImportable(string const & format); +#endif + /// + static + std::vector const GetImportableFormats(); +private: + /// + static + std::vector const Loaders(); }; #endif diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index cf212a5db2..fe979c1779 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -657,13 +657,13 @@ int InsetGraphics::Latex(Buffer const *buf, ostream & os, // How do we decide to what format should we export? string extension = GetExtension(params.filename); - //if (pdf) { + if (lyxrc.pdf_mode) { if (extension != "jpg") - Converter::Convert(buf, + converters.Convert(buf, params.filename, params.filename, extension, "png"); - //} else - Converter::Convert(buf, params.filename, params.filename, + } else + converters.Convert(buf, params.filename, params.filename, extension, "eps"); return 1; diff --git a/src/lyx_gui.C b/src/lyx_gui.C index cd81b5ee20..de20292b77 100644 --- a/src/lyx_gui.C +++ b/src/lyx_gui.C @@ -42,6 +42,7 @@ #include "language.h" #include "ColorHandler.h" #include "frontends/GUIRunTime.h" +#include "frontends/xforms/Color.h" using std::endl; @@ -58,6 +59,7 @@ extern LyXServer * lyxserver; extern bool finished; // flag, that we are quitting the program extern BufferList bufferlist; extern GUIRunTime guiruntime; +extern string user_lyxdir; FL_CMD_OPT cmdopt[] = { @@ -368,6 +370,13 @@ void LyXGUI::create_forms() fl_set_form_atclose(fd_latex_log->LaTeXLog, CancelCloseBoxCB, 0); + // This is probably as good a time as any to map the xform colours, + // should a mapping exist. + { + string filename = user_lyxdir + "/preferences.xform"; + XformColor::read( filename ); + } + // Show the main & title form int main_placement = FL_PLACE_CENTER | FL_FREE_SIZE; int title_placement = FL_PLACE_CENTER; diff --git a/src/lyx_main.C b/src/lyx_main.C index 3c8b6845f5..07d6af3ea9 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -401,6 +401,7 @@ void LyX::init(int */*argc*/, char **argv, bool gui) ReadRcFile("lyxrc.defaults"); system_lyxrc = lyxrc; system_formats = formats; + system_converters = converters; // If there is a preferences file we read that instead // of the old lyxrc file. @@ -408,7 +409,8 @@ void LyX::init(int */*argc*/, char **argv, bool gui) ReadRcFile("lyxrc"); /// Init Converter - Converter::init(); + converters.Update(formats); + converters.BuildGraph(); // Read encodings ReadEncodingsFile("encodings"); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 9a78e88860..720624e6f0 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -351,9 +351,6 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const !Exporter::IsExportable(buf, argument); break; #endif - case LFUN_IMPORT: - disable = !Importer::IsImportable(argument); - break; case LFUN_UNDO: disable = buf->undostack.empty(); break; @@ -3156,8 +3153,7 @@ void LyXFunc::doImport(string const & argument) AddPath(system_lyxdir, "examples")); string text = _("Select ") + formats.PrettyName(format) + _(" file to import"); - string format2 = (format == "textparagraph") ? "text" : format; - string extension = "*." + formats.Extension(format2); + string extension = "*." + formats.Extension(format); filename = fileDlg.Select(text, initpath, extension); AllowInput(owner->view()); diff --git a/src/lyxrc.C b/src/lyxrc.C index 76c6fabd04..8ce86d9394 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -859,7 +859,10 @@ int LyXRC::read(string const & filename) command = lexrc.GetString(); if (lexrc.next()) flags = lexrc.GetString(); - Converter::Add(from, to, command, flags); + if (command.empty() || command == "none") + converters.Delete(from, to); + else + converters.Add(from, to, command, flags); break; } case RC_VIEWER: { @@ -881,7 +884,16 @@ int LyXRC::read(string const & filename) prettyname = lexrc.GetString(); if (lexrc.next()) shortcut = lexrc.GetString(); - formats.Add(format, extension, prettyname, shortcut); + if (prettyname.empty()) { + if (converters.FormatIsUsed(format)) + lyxerr << "Can't delete format " + << format << endl; + else + formats.Delete(format); + + } else + formats.Add(format, extension, prettyname, + shortcut); break; } case RC_DEFAULT_LANGUAGE: @@ -1475,39 +1487,65 @@ void LyXRC::output(ostream & os) const << "# 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 + case RC_FORMAT: + // Look for deleted formats + for (Formats::const_iterator cit = formats.begin(); + cit != formats.end(); ++cit) { + Format const * format = + system_formats.GetFormat(cit->name()); + if (!format || + format->extension() != cit->extension() || + format->prettyname() != cit->prettyname() || + format->shortcut() != cit->shortcut()) + os << "\\format \"" << cit->name() << "\" \"" + << cit->extension() << "\" \"" + << cit->prettyname() << "\" \"" + << cit->shortcut() << "\"\n"; + } + + // New/modifed formats + for (Formats::const_iterator cit = system_formats.begin(); + cit != system_formats.end(); ++cit) + if (!formats.GetFormat(cit->name())) + os << "\\format \"" << cit->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"; + case RC_VIEWER: + for (Formats::const_iterator cit = formats.begin(); + cit != formats.end(); ++cit) { + Format const * format = + system_formats.GetFormat(cit->name()); + if ((!format || format->viewer() != cit->viewer()) && + (format || !cit->viewer().empty())) + os << "\\viewer \"" << cit->name() << "\" \"" + << cit->viewer() << "\"\n"; } - } + os << "\n#\n" + << "# CONVERTERS SECTION ##########################\n" + << "#\n\n"; + + case RC_CONVERTER: + // Look for new converters + for (Converters::const_iterator cit = converters.begin(); + cit != converters.end(); ++cit) { + Converter const * converter = + system_converters.GetConverter(cit->from, + cit->to); + if (!converter || + converter->command != cit->command || + converter->flags != cit->flags) + os << "\\converter \"" << cit->from << "\" \"" + << cit->to << "\" \"" + << cit->command << "\" \"" + << cit->flags << "\"\n"; + } + + // New/modifed converters + for (Converters::const_iterator cit = system_converters.begin(); + cit != system_converters.end(); ++cit) + if (!converters.GetConverter(cit->from, cit->to)) + os << "\\converter \"" << cit->from + << "\" \"" << cit->to << "\" \"\" \"\"\n"; } os.flush(); } diff --git a/src/support/rename.C b/src/support/rename.C index 97c4ca0562..f6a3367062 100644 --- a/src/support/rename.C +++ b/src/support/rename.C @@ -7,6 +7,10 @@ bool lyx::rename(string const & from, string const & to) { if (::rename(from.c_str(), to.c_str()) == -1) - return lyx::copy(from, to); + if (lyx::copy(from, to)) { + lyx::unlink(from); + return true; + } else + return false; return true; } -- 2.39.2