]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormTexinfo.C
remove defaults stuff, let Qt handle no toolbar
[lyx.git] / src / frontends / xforms / FormTexinfo.C
index 8a3abec274e6a5189908d6152d0718e1fea71bab..c16d4402087357bdbd9765cf402933f14db2f660 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>
+ * \author Herbert Voss
+ *
+ * Full author contact details are available in file CREDITS
  * \date 2001-10-01
  */
 
 #include <config.h>
 #include <fstream>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include "xformsBC.h"
 #include "FormTexinfo.h"
-#include "form_texinfo.h"
+#include "forms/form_texinfo.h"
+#include "Tooltips.h"
 #include "gettext.h"
-#include "debug.h"
 #include "xforms_helpers.h"
 #include "support/LAssert.h"
-    
-namespace {
+#include "support/lstrings.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 FORMS_H_LOCATION
 
+using std::vector;
 
-typedef FormCB<ControlTexinfo, FormDB<FD_form_texinfo> > base_class;
-FormTexinfo::FormTexinfo(ControlTexinfo & c)
-       : base_class(c, _("TeX Infos")),
-         warningPosted(false), activeStyle(ControlTexinfo::cls)
+typedef FormCB<ControlTexinfo, FormDB<FD_texinfo> > base_class;
+FormTexinfo::FormTexinfo()
+       : base_class(_("LaTeX Information")),
+         activeStyle(ControlTexinfo::cls)
 {}
 
 
 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(ControlTexinfo::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);
+       dialog_.reset(build_texinfo(this));
+
+       // callback for double click in browser to view the selected file
+       fl_set_browser_dblclick_callback(dialog_->browser, C_FormBaseInputCB, 2);
+
+       string const classes_List = _("LaTeX classes|LaTeX styles|BibTeX styles");
+       fl_addto_choice(dialog_->choice_classes, classes_List.c_str());
+
+       updateStyles(activeStyle);
+
+       // 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);
+
+       str = _("Runs the script \"TexFiles.sh\" to build new file lists.");
+       tooltips().init(dialog_->button_rescan, str);
+
+       str = _("Double click to view contents of file.");
+       tooltips().init(dialog_->browser, str);
+       // Work-around xforms' bug; enable tooltips for browser widgets.
+       setPrehandler(dialog_->browser);
+
+       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);
 }
 
 
-ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long) {
-       if (ob == dialog_->help) {
-               controller().help();
+ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
 
-       } else if (ob == dialog_->radio_cls) {
-               updateStyles(ControlTexinfo::cls); 
+       if (ob == dialog_->button_texhash) {
+               // makes only sense if the rights are set well for
+               // users (/var/lib/texmf/ls-R)
+               controller().runTexhash();
+               // texhash requires a rescan and an update of the styles
+               controller().rescanStyles();
+               updateStyles(activeStyle);
 
-       } else if (ob == dialog_->radio_sty) {
-               updateStyles(ControlTexinfo::sty); 
 
-       } else if (ob == dialog_->radio_bst) {
-               updateStyles(ControlTexinfo::bst); 
+       } else if (ob == dialog_->browser && ob_value == 2) {
+               // double click in browser: view selected file
+               string selection = getString(dialog_->browser);
+               if (!fl_get_button(dialog_->check_fullpath)) {
+                       // contents in browser has filenames without path
+                       // reconstruct path from controller getContents
+                       string const files = controller().getContents(activeStyle, true);
+                       vector<string> const vec = getVectorFromString(files, "\n");
+
+                       // find line in files vector
+                       vector<string>::const_iterator it = vec.begin();
+                       for (; it != vec.end(); ++it) {
+                               if ((*it).find(selection) != string::npos) {
+                                       selection = *it;
+                                       break;
+                               }
+                       }
+               }
+               if (!selection.empty()) {
+                       controller().viewFile(selection);
+               }
+
+               // reset the browser so that the following single-click callback doesn't do anything
+               fl_deselect_browser(dialog_->browser);
 
        } else if (ob == dialog_->button_rescan) {
                // build new *Files.lst
                controller().rescanStyles();
                updateStyles(activeStyle);
 
-       } else if (ob == dialog_->button_fullPath) {
-               setEnabled(dialog_->button_view,
-                          fl_get_button(dialog_->button_fullPath));
+       } else if (ob == dialog_->check_fullpath) {
                updateStyles(activeStyle);
 
-       } 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));
+       } 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);
                }
        }
 
        return ButtonPolicy::SMI_VALID;
 }
 
+
 void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
 {
-       fl_clear_browser(dialog_->browser); 
+       fl_clear_browser(dialog_->browser);
 
-       bool const withFullPath = fl_get_button(dialog_->button_fullPath);
+       bool const withFullPath = fl_get_button(dialog_->check_fullpath);
 
-       string const str = 
+       string const str =
                controller().getContents(whichStyle, withFullPath);
        fl_add_browser_line(dialog_->browser, str.c_str());
 
        activeStyle = whichStyle;
 }
-
-
-// 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);
-               }
-               break;
-
-       default:
-               break;
-       }
-}
-
-
-void FormTexinfo::feedback(FL_OBJECT * ob)
-{
-       lyx::Assert(ob);
-
-       string str;
-
-       if (ob == dialog_->button_rescan) {
-               str = _("starts rescan ...");
-
-       } else if (ob == dialog_->button_fullPath) {
-               str = _("View full path or only file name");
-
-       } else if (ob == dialog_->button_texhash) {
-               str = _("starts texhash and rescan...");
-
-       } else if (ob == dialog_->button_view) {
-               str = _("views a selected file");
-
-       }
-       
-       fl_set_object_label(dialog_->message, str.c_str());
-       fl_redraw_object(dialog_->message);
-}