]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormTexinfo.C
Change the semantics of 'none' and 'auto' viewers/editors: 'none' means now
[lyx.git] / src / frontends / xforms / FormTexinfo.C
index a8357cd64da7e27ba92538ca861f750a17f278ce..98677ef2ce703776f2c2b5a200f43ff7dea1cb93 100644 (file)
 /**
  * \file FormTexinfo.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author Herbert Voss <voss@lyx.org>
- * \date 2001-10-01
+ * \author Herbert Voß
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
-#include <fstream>
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
-#include "xformsBC.h"
-#include "ControlTexinfo.h"
 #include "FormTexinfo.h"
-#include "form_texinfo.h"
-#include "gettext.h"
-#include "debug.h"
-#include "helper_funcs.h"
-#include "xforms_helpers.h"
-#include "support/lstrings.h"
-#include "support/filetools.h"
-#include "support/LAssert.h"
-
-extern string user_lyxdir; // home of *Files.lst
-    
-namespace {
+#include "forms/form_texinfo.h"
 
-string const bstFilename("bstFiles.lst");
-string const clsFilename("clsFiles.lst");
-string const styFilename("styFiles.lst");
-string const errorMessage =_("Missing filelist. try Rescan");
+#include "Tooltips.h"
+#include "xformsBC.h"
 
-// C function wrapper, required by xforms.
-extern "C"
-int C_FormTexinfoFeedbackCB(FL_OBJECT * ob, int event,
-                           FL_Coord, FL_Coord, int, void *)
-{
-       // Note that the return value is important in the pre-emptive handler.
-       // Don't return anything other than 0.
-
-       lyx::Assert(ob);
-       // Don't Assert this one, as it can happen quite reasonably when things
-       // are being deleted in the d-tor.
-       //Assert(ob->form);
-       if (!ob->form) return 0;
-
-       FormTexinfo * pre =
-               static_cast<FormTexinfo*>(ob->form->u_vdata);
-       pre->feedbackCB(ob, event);
-       return 0;
-}
-       
-void setPreHandler(FL_OBJECT * ob)
-{
-       lyx::Assert(ob);
-       fl_set_object_prehandler(ob, C_FormTexinfoFeedbackCB);
-}
-} // namespace anon
+#include "support/filetools.h"
 
+#include "lyx_forms.h"
 
-typedef FormCB<ControlTexinfo, FormDB<FD_form_texinfo> > base_class;
-FormTexinfo::FormTexinfo(ControlTexinfo & c)
-       : base_class(c, _("TeX Infos")),
-         warningPosted(false), activeStyle(FormTexinfo::cls)
-{}
+using std::string;
 
+namespace lyx {
 
-void FormTexinfo::build() {
-       dialog_.reset(build_texinfo());
-       // courier medium
-       fl_set_browser_fontstyle(dialog_->browser,FL_FIXED_STYLE);
-       // with Path is default
-       fl_set_button(dialog_->button_fullPath, 1);
-       updateStyles(FormTexinfo::cls);
-
-       setPreHandler(dialog_->button_rescan);
-       setPreHandler(dialog_->button_view);
-       setPreHandler(dialog_->button_texhash);
-       setPreHandler(dialog_->button_fullPath);
-       setPreHandler(dialog_->browser);
-       setPreHandler(dialog_->radio_cls);
-       setPreHandler(dialog_->radio_sty);
-       setPreHandler(dialog_->radio_bst);
-       setPreHandler(dialog_->message);
-       setPreHandler(dialog_->help);
-}
+namespace frontend {
 
 
-ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long) {
-       if (ob == dialog_->help) {
-               controller().help();
+typedef FormController<ControlTexinfo, FormView<FD_texinfo> > base_class;
 
-       } else if (ob == dialog_->radio_cls) {
-               updateStyles(FormTexinfo::cls); 
+FormTexinfo::FormTexinfo(Dialog & parent)
+       : base_class(parent, _("TeX Information")),
+         activeStyle(ControlTexinfo::cls)
+{}
 
-       } else if (ob == dialog_->radio_sty) {
-               updateStyles(FormTexinfo::sty); 
 
-       } else if (ob == dialog_->radio_bst) {
-               updateStyles(FormTexinfo::bst); 
+void FormTexinfo::build() {
+       dialog_.reset(build_texinfo(this));
 
-       } else if (ob == dialog_->button_rescan) {
-               // build new *Files.lst
-               controller().rescanStyles();
-               updateStyles(activeStyle);
+       // callback for double click in browser to view the selected file
+       fl_set_browser_dblclick_callback(dialog_->browser,
+                                        C_FormDialogView_InputCB, 2);
 
-       } else if (ob == dialog_->button_fullPath) {
-               setEnabled(dialog_->button_view,
-                          fl_get_button(dialog_->button_fullPath));
-               updateStyles(activeStyle);
+       string const classes_List = _("LaTeX classes|LaTeX styles|BibTeX styles");
+       fl_addto_choice(dialog_->choice_classes, classes_List.c_str());
 
-       } else if (ob == dialog_->button_texhash) {
-               // makes only sense if the rights are set well for
-               // users (/var/lib/texmf/ls-R)
-               controller().runTexhash();
-               // update files in fact of texhash
-               controller().rescanStyles();
-
-       } else if (ob == dialog_->button_view) {
-               unsigned int selection = fl_get_browser(dialog_->browser);
-               // a valid entry?
-               if (selection > 0) {
-                       controller().viewFile( 
-                               fl_get_browser_line(dialog_->browser,
-                                                   selection));
-               }
-       }
+       updateStyles(activeStyle);
 
-       return ButtonPolicy::SMI_VALID;
-}
+       // set up the tooltips
+       string str = _("Shows the installed classses and styles for LaTeX/BibTeX; "
+                       "available only if the corresponding LyX layout file exists.");
+       tooltips().init(dialog_->choice_classes, str);
 
+       str = _("Show full path or only file name.");
+       tooltips().init(dialog_->check_fullpath, str);
 
-namespace {
+       str = _("Runs the script \"TexFiles.sh\" to rebuild the file lists.");
+       tooltips().init(dialog_->button_rescan, str);
 
-string const sortEntries(string & str_in)
-{
-       std::vector<string> dbase = getVectorFromString(str_in,"\n");
-       std::sort(dbase.begin(), dbase.end());  // sort entries
-       return getStringFromVector(dbase,"\n");
-}
+       str = _("Double click to view contents of file.");
+       tooltips().init(dialog_->browser, str);
+#if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0)
+       // Work-around xforms' bug; enable tooltips for browser widgets.
+       setPrehandler(dialog_->browser);
+#endif
 
-string const getContents(string const filename, bool withFullPath)
-{
-       string fileContents = GetFileContents(AddName(user_lyxdir,filename));
-       // everything ok?
-       if (!fileContents.empty()) {
-               if (withFullPath)
-                       return(sortEntries(fileContents));
-               else {
-                       int Entries = 1;
-                       string dummy = OnlyFilename(token(fileContents,'\n',1));
-                       string contents = dummy;
-                       do {
-                               dummy = OnlyFilename(token(fileContents,'\n',++Entries));
-                               contents += ("\n"+dummy);
-                       } while (!dummy.empty());
-                       return(sortEntries(contents));
-               }
-       } else
-               return errorMessage;
+       str = _("Runs the script \"texhash\" which builds a new LaTeX tree. "
+               "Needed if you install a new TeX class or style. You need write "
+               "permissions for the TeX-dirs, often /var/lib/texmf and others.");
+       tooltips().init(dialog_->button_texhash, str);
 }
 
-} // namespace anon
 
+ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
 
-void FormTexinfo::updateStyles(FormTexinfo::texFileSuffix whichStyle)
-{
-       fl_clear_browser(dialog_->browser); 
+       if (ob == dialog_->button_texhash) {
+               // makes only sense if the rights are set well for
+               // users (/var/lib/texmf/ls-R)
+               texhash();
+               // texhash requires a rescan and an update of the styles
+               rescanTexStyles();
+               updateStyles(activeStyle);
 
-       bool const withFullPath = fl_get_button(dialog_->button_fullPath);
 
-       switch (whichStyle) {
-       case FormTexinfo::bst: 
-       {
-               string const str = getContents(bstFilename, withFullPath);
-               fl_add_browser_line(dialog_->browser, str.c_str());
-               break;
+       } else if (ob == dialog_->browser && ob_value == 2) {
+               // double click in browser: view selected file
+               ContentsType::size_type const sel = fl_get_browser(ob);
+               ContentsType const & data = texdata_[activeStyle];
+               string file = data[sel-1];
+               if (!fl_get_button(dialog_->check_fullpath))
+                       file = getTexFileFromList(data[sel-1],
+                               controller().getFileType(activeStyle));
+               if (sel >= 1 && sel <= data.size())
+                       controller().viewFile(file);
 
-       }
-       case FormTexinfo::cls: 
-       {
-               string const str = getContents(clsFilename, withFullPath);
-               fl_add_browser_line(dialog_->browser, str.c_str());
-               break;
-       }
-       case FormTexinfo::sty:
-       {
-               string const str = getContents(styFilename, withFullPath);
-               fl_add_browser_line(dialog_->browser, str.c_str());
-               break;
-       }
-       }
+               // reset the browser so that the following single-click
+               // callback doesn't do anything
+               fl_deselect_browser(dialog_->browser);
 
-       activeStyle = whichStyle;
-}
+       } else if (ob == dialog_->button_rescan) {
+               // build new *Files.lst
+               rescanTexStyles();
+               updateStyles(activeStyle);
 
+       } else if (ob == dialog_->check_fullpath) {
+               updateStyles(activeStyle);
 
-// preemptive handler for feedback messages
-void FormTexinfo::feedbackCB(FL_OBJECT * ob, int event)
-{
-       lyx::Assert(ob);
-
-       switch (event) {
-       case FL_ENTER:
-               warningPosted = false;
-               feedback(ob);
-               break;
-
-       case FL_LEAVE:
-               if (!warningPosted) {
-                       fl_set_object_label(dialog_->message, "");
-                       fl_redraw_object(dialog_->message);
+       } else if (ob == dialog_->choice_classes) {
+               switch (fl_get_choice(dialog_->choice_classes)) {
+               case 3:
+                       updateStyles(ControlTexinfo::bst);
+                       break;
+               case 2:
+                       updateStyles(ControlTexinfo::sty);
+                       break;
+               case 1:
+               default:
+                       updateStyles(ControlTexinfo::cls);
                }
-               break;
-
-       default:
-               break;
        }
+
+       return ButtonPolicy::SMI_VALID;
 }
 
 
-void FormTexinfo::feedback(FL_OBJECT * ob)
+void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
 {
-       lyx::Assert(ob);
+       ContentsType & data = texdata_[whichStyle];
+       bool const withFullPath = fl_get_button(dialog_->check_fullpath);
+       getTexFileList(whichStyle, data, withFullPath);
 
-       string str;
+       fl_clear_browser(dialog_->browser);
+       ContentsType::const_iterator it  = data.begin();
+       ContentsType::const_iterator end = data.end();
+       for (; it != end; ++it)
+               fl_add_browser_line(dialog_->browser, (*it).c_str());
 
-       if (ob == dialog_->button_rescan) {
-               str = _("run rescan ...");
-
-       } else if (ob == dialog_->button_fullPath) {
-               str = _("View full path or only file name");
-
-       } else if (ob == dialog_->button_texhash) {
-               str = _("run texhash and rescan...");
-
-       } else if (ob == dialog_->button_view) {
-               str = _("select a file to view");
-
-       }
-       
-       fl_set_object_label(dialog_->message, str.c_str());
-       fl_redraw_object(dialog_->message);
+       activeStyle = whichStyle;
 }
+
+} // namespace frontend
+} // namespace lyx