From c7f0b54771b3317925ead33bd99f0a373a1c32d9 Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Sun, 21 Jan 2001 21:41:35 +0000 Subject: [PATCH] - Clean FormRef - 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 | 1 + src/frontends/xforms/FormRef.C | 68 ++++++++++------------------------ src/frontends/xforms/FormRef.h | 18 ++------- src/insets/ChangeLog | 5 +++ src/insets/insetref.C | 25 +++++++------ src/insets/insetref.h | 10 +++++ 6 files changed, 52 insertions(+), 75 deletions(-) diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 8b8b7c1de3..9280cfb33d 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -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 diff --git a/src/frontends/xforms/FormRef.C b/src/frontends/xforms/FormRef.C index 365e844c61..685f8207ec 100644 --- a/src/frontends/xforms/FormRef.C +++ b/src/frontends/xforms/FormRef.C @@ -24,6 +24,7 @@ #include "buffer.h" #include "form_ref.h" #include "lyxfunc.h" +#include "insets/insetref.h" #include @@ -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 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 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(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(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( - 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; } diff --git a/src/frontends/xforms/FormRef.h b/src/frontends/xforms/FormRef.h index ca20230114..3ebc1c89fc 100644 --- a/src/frontends/xforms/FormRef.h +++ b/src/frontends/xforms/FormRef.h @@ -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; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index d2610ba929..27ac9d34cd 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2001-01-21 Dekel Tsur + + * insetref.C: Add the array InsetRef::types that contains + information about all supported reference types. + 2001-01-19 Jean-Marc Lasgouttes * lyxinset.h: remove trailing comma in enum. diff --git a/src/insets/insetref.C b/src/insets/insetref.C index b936e53ad9..da9df59036 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -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: ")}, + { "", "", "" } +}; diff --git a/src/insets/insetref.h b/src/insets/insetref.h index 392b80a36f..51f2ffdd59 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -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 &); /// -- 2.39.2