]> git.lyx.org Git - lyx.git/commitdiff
- Clean FormRef
authorDekel Tsur <dekelts@tau.ac.il>
Sun, 21 Jan 2001 21:41:35 +0000 (21:41 +0000)
committerDekel Tsur <dekelts@tau.ac.il>
Sun, 21 Jan 2001 21:41:35 +0000 (21:41 +0000)
- Try to use more descriptive type names in FormRef

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1362 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/xforms/ChangeLog
src/frontends/xforms/FormRef.C
src/frontends/xforms/FormRef.h
src/insets/ChangeLog
src/insets/insetref.C
src/insets/insetref.h

index 8b8b7c1de39b1198a3644792f47cf94d9f4924ac..9280cfb33d0e0b03047c331ff1094f88357eeb43 100644 (file)
@@ -6,6 +6,7 @@
        (build): Uncomment calls to addReadOnly().
        (updateBrowser) Do not disable the update button when there are no 
        keys.
+       (build, getType, getName): Use InsetRef::types.
 
 2001-01-18  Angus Leeming  <a.leeming@ic.ac.uk>
 
index 365e844c61b052681f51d85598ea5d3eca45b756..685f8207ec8549781ecd3ea981017b2f6ce3da56 100644 (file)
@@ -24,6 +24,7 @@
 #include "buffer.h"
 #include "form_ref.h"
 #include "lyxfunc.h"
+#include "insets/insetref.h"
 
 #include <algorithm>
 
@@ -68,8 +69,9 @@ void FormRef::build()
 {
        dialog_ = build_ref();
 
-       fl_addto_choice(dialog_->type,
-                       _(" Ref | Page | TextRef | TextPage | PrettyRef "));
+       for (int i = 0; !InsetRef::types[i].latex_name.empty(); ++i)
+               fl_addto_choice(dialog_->type,
+                               _(InsetRef::types[i].gui_name.c_str()));
 
        // Workaround dumb xforms sizing bug
        minw_ = form()->w;
@@ -110,7 +112,7 @@ void FormRef::update()
                fl_activate_object(dialog_->type);
                fl_set_object_lcol(dialog_->type, FL_BLACK);
        } else {
-               fl_set_choice(dialog_->type, REF+1);
+               fl_set_choice(dialog_->type, 1);
 
                fl_activate_object(dialog_->name);
                fl_set_object_lcol(dialog_->name, FL_BLACK);
@@ -144,6 +146,7 @@ void FormRef::updateBrowser(vector<string> const & akeys) const
                fl_deactivate_object(dialog_->sort);
                fl_set_object_lcol(dialog_->browser, FL_INACTIVE);
                fl_set_object_lcol(dialog_->sort, FL_INACTIVE);
+               fl_set_input(dialog_->ref, "");
        } else {
                fl_activate_object(dialog_->browser);
                fl_set_object_lcol(dialog_->browser, FL_BLACK);
@@ -155,6 +158,8 @@ void FormRef::updateBrowser(vector<string> const & akeys) const
                        find(keys.begin(), keys.end(), ref);
                if (cit == keys.end())
                        cit = keys.begin();
+               if (ref.empty())
+                       fl_set_input(dialog_->ref, (*cit).c_str());
 
                int const i = static_cast<int>(cit - keys.begin());
                fl_set_browser_topline(dialog_->browser, max(i-5, 1));
@@ -168,7 +173,7 @@ void FormRef::apply()
        if (!lv_->view()->available())
                return;
 
-       Type const type = static_cast<Type>(fl_get_choice(dialog_->type) - 1);
+       int const type = fl_get_choice(dialog_->type) - 1;
        params.setCmdName(getName(type));
 
        params.setOptions(fl_get_input(dialog_->name));
@@ -261,10 +266,8 @@ bool FormRef::input(FL_OBJECT *, long data)
        // changed reference type
        case 5:
        {
-               Type type = static_cast<Type>( 
-                       fl_get_choice(dialog_->type) - 1);
-               if (params.getCmdName() == getName(type)
-                   && inset_) {
+               int const type = fl_get_choice(dialog_->type) - 1;
+               if (params.getCmdName() == getName(type) && inset_) {
                        activate = false;
                }
        }
@@ -278,50 +281,17 @@ bool FormRef::input(FL_OBJECT *, long data)
 }
 
 
-FormRef::Type FormRef::getType() const
+int FormRef::getType() const
 {
-       Type type;
-
-       if (params.getCmdName() == "ref" )
-               type = REF;
-
-       else if (params.getCmdName() == "pageref" )
-               type = PAGEREF;
-
-       else if (params.getCmdName() == "vref" )
-               type = VREF;
-
-       else if (params.getCmdName() == "vpageref" )
-               type = VPAGEREF;
-
-       else
-               type = PRETTYREF;
-       
-       return type;
+       string const & command = params.getCmdName();
+       for (int i = 0; !InsetRef::types[i].latex_name.empty(); ++i)
+               if (command == InsetRef::types[i].latex_name)
+                       return i;
+       return 0;
 }
 
 
-string const FormRef::getName(Type type) const
+string const FormRef::getName(int type) const
 {
-       string name;
-
-       switch (type) {
-       case REF:
-               name = "ref";
-               break;
-       case PAGEREF:
-               name = "pageref";
-               break;
-       case VREF:
-               name = "vref";
-               break;
-       case VPAGEREF:
-               name = "vpageref";
-               break;
-       case PRETTYREF:
-               name = "prettyref";
-               break;
-       }
-       
-       return name;
+       return InsetRef::types[type].latex_name;
 }
index ca2023011444e8a60229b5d956943f54f564a5b7..3ebc1c89fc7ccb0fa78eec78590799b81af7bdcf 100644 (file)
@@ -27,20 +27,8 @@ public:
        FormRef(LyXView *, Dialogs *);
        ///
        ~FormRef();
-private:
        ///
-       enum Type {
-               ///
-               REF,
-               ///
-               PAGEREF,
-               ///
-               VREF,
-               ///
-               VPAGEREF,
-               ///
-               PRETTYREF
-       };
+private:
        ///
        enum Goto {
                ///
@@ -70,9 +58,9 @@ private:
        ///
        FD_form_ref * build_ref();
        ///
-       Type getType() const;
+       int getType() const;
        ///
-       string const getName(Type type) const;
+       string const getName(int type) const;
 
        ///
        Goto toggle;
index d2610ba92902fe533412128173a55f6bd5277cd5..27ac9d34cd34e5241e9072ce6aa9534fbbce6b1c 100644 (file)
@@ -1,3 +1,8 @@
+2001-01-21  Dekel Tsur  <dekelts@tau.ac.il>
+
+       * insetref.C: Add the array InsetRef::types that contains
+       information about all supported reference types.
+
 2001-01-19  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * lyxinset.h: remove trailing comma in enum.
index b936e53ad941b1301fba6f4c22964f94cabc9d8f..da9df59036151ad55b183248b54118fe4c0e20d7 100644 (file)
@@ -34,17 +34,11 @@ void InsetRef::Edit(BufferView * bv, int, int, unsigned int button)
 string const InsetRef::getScreenLabel() const
 {
        string temp;
-       if (getCmdName() == "ref")
-               temp = _( "Ref: " );
-       else if (getCmdName() == "pageref")
-               temp = _( "Page: " );
-       else if (getCmdName() == "vref")
-               temp = _( "TextRef: " );
-       else if (getCmdName() == "vpageref")
-               temp = _( "TextPage: " );
-       else
-               temp = _( "PrettyRef: " );
-
+       for (int i = 0; !types[i].latex_name.empty(); ++ i)
+               if (getCmdName() == types[i].latex_name) {
+                       temp = _(types[i].short_gui_name);
+                       break;
+               }
        temp += getContents();
 
        if (!isLatex
@@ -120,3 +114,12 @@ void InsetRef::Validate(LaTeXFeatures & features) const
        else if (getCmdName() == "prettyref")
                features.prettyref = true;
 }
+
+InsetRef::type_info InsetRef::types[] = {
+       { "ref",        N_("Standard"),                 N_("Ref: ")},
+       { "pageref",    N_("Page Number"),              N_("Page: ")},
+       { "vpageref",   N_("Textual Page Number"),      N_("TextPage: ")},
+       { "vref",       N_("Standard+Textual Page"),    N_("Ref+Text: ")},
+       { "prettyref",  N_("PrettyRef"),                N_("PrettyRef: ")},
+       { "", "", "" }
+};
index 392b80a36fc6af7fc053565dc79add0c7eda02e4..51f2ffdd59a0b3b1998f635da47419d842381d77 100644 (file)
@@ -23,6 +23,16 @@ struct LaTeXFeatures;
  */
 class InsetRef : public InsetCommand {
 public:
+       struct type_info {
+               ///
+               string latex_name;
+               ///
+               string gui_name;
+               ///
+               string short_gui_name;
+       };
+       static type_info types[];
+
        ///
        InsetRef(InsetCommandParams const &, Buffer const &);
        ///