]> git.lyx.org Git - features.git/commitdiff
A few patches I forgot to commit on friday.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 11 Dec 2000 09:46:09 +0000 (09:46 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 11 Dec 2000 09:46:09 +0000 (09:46 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1272 a592a061-630c-0410-9148-cb99ea01b6c8

20 files changed:
ChangeLog
lib/languages
lib/lyxrc.example
src/BufferView.h
src/BufferView2.C
src/frontends/xforms/FormBase.C
src/frontends/xforms/FormGraphics.C
src/frontends/xforms/FormGraphics.h
src/frontends/xforms/FormInset.C
src/frontends/xforms/FormPreferences.C
src/frontends/xforms/xform_helpers.C
src/insets/insetlabel.C
src/lyx_cb.C
src/lyxfunc.C
src/lyxrc.C
src/lyxrc.h
src/mathed/formula.C
src/mathed/math_cursor.h
src/mathed/math_iter.C
src/mathed/math_iter.h

index af384fb035ddfda8e2ed7a324ea8271068fe2c3f..fedb3ccc71e50c8c8d01f79f0d7d97d6a05e5434 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,58 @@
+2000-12-11  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
+
+       * lib/languages: Change description of german to "German (new
+       spelling)".
+
+2000-12-07  Angus Leeming <a.leeming@ic.ac.uk>
+
+       * src/frontends/xforms/FormInset.C (createInset): activate "Ok",
+       "Apply" buttons if arg is non-zero.
+
+       * src/lyxfunc.C (Dispatch): enable citation to be inserted without
+       launching the popup if sufficient info is passed to
+       LFUN_CITATION_CREATE.
+
+2000-11-23  Dekel Tsur  <dekelts@tau.ac.il>
+
+       * src/lyx_cb.C (MenuInsertLabel): Compute a default value for new
+       labels (disabled in 1.1.6).
+
+       * src/lyxrc.[Ch]: New variable label_init_length
+
+       * mathed/formula.C (LocalDispatch): Preserve the label when
+       changing from display math to eqnarray (however, the label
+       do not appear at the first line, as one might expects, but at the
+       second line).
+       (LocalDispatch): When inserting a label to a formula which already 
+       have a label, the old label is used as default value.
+       Also, if the label is changed, then all references to the label
+       are changed.
+
+       * src/mathed/math_iter.C (setLabel): Allow to set the label
+       even if it is empty. This is needed to allow deletion of a label
+       in an eqnarray.
+
+       * src/BufferView2.C (ChangeRefsIfUnique): New method. Changes the
+       refernces only if the old label appears once in the document.
+
+2000-12-07  Angus Leeming <a.leeming@ic.ac.uk>
+
+       * lib/languages: added ngerman. Patch courtesy of Andreas Gehlert
+       <gehlert@Rcs1.urz.tu-dresden.de>
+
+       * src/frontends/xforms/FormBase.C: comment out debug.h
+
+       * src/frontends/xforms/FormGraphics.[Ch] (browseFile): removed. Reuse
+       code in xform_helpers instead.
+       (d-tor): comment out "delete dialog;" and so prevent a crash on exit.
+
+       * src/frontends/xforms/FormPreferences.C: use AddName() in more places.
+       Use N_(), rather than _() when creating strings to pass to browseFile()
+       because browseFile calls gettext() itself now.
+
+       * src/frontends/xforms/xform_helpers.C (browseFile): call gettext() and
+       display the filename correctly.
+
 2000-12-09  Dekel Tsur  <dekelts@tau.ac.il>
 
        * src/converter.C (Move): New method. Used to move file or files
index 2f3a1c34719235c031e1de057729c5fdfd0db0a7..2c888b2b9aecb1d385ee826842bebde2eb689de7 100644 (file)
@@ -24,6 +24,7 @@ galician    galician  "Galician"      false  iso8859-1  gl_ES
 # There are two Galicia's one in Spain one in E.Europe. Because of
 # the font encoding I am assuming this is the one in Spain. (Garst)
 german      german     "German"        false  iso8859-1  de
+ngerman     ngerman    "German (new spelling)" false  iso8859-1  de
 greek       greek      "Greek"         false  iso8859-7  el_GR
 hebrew      hebrew     "Hebrew"        true   cp1255     he_IL
 #hungarian   hungarian "Hungarian"     false  iso8859-2  ""
index c79229b98c688d362625a4f20717622bb112c777..71f5e6917e98db7d01596adc7442e2e820c70d79 100644 (file)
 #
 #\date_insert_format "%A, %e. %B %Y"
 
+
+# Maximum number of words in the initialization string for a new label.
+# If it is set to 0, then the init. string will only contain the prefix
+# (e.g. "sec:"). If it is set to -1, the init. string will be empty. 
+# This feature is disabled in 1.1.6.
+#
+#\label_init_length 0
+
 #
 # SCREEN & FONTS SECTION #################################################
 #
index 678d39a33698c78592c0a033923b651608ad3250..fbe29d70d2e32117a6a5e591d07c67c33670e6e2 100644 (file)
@@ -249,6 +249,8 @@ public:
        ///
        bool ChangeRefs(string const & from, string const & to);
        ///
+       bool ChangeRefsIfUnique(string const & from, string const & to);
+       ///
        void pasteClipboard(bool asPara);
        ///
        void stuffClipboard(string const &) const;
index 606f2044e5ea75c767728a4bcbe4356484ffb700..2f90faa7533577e1e248cf0a0ab9e2bc461c19dc 100644 (file)
@@ -39,6 +39,7 @@ using std::endl;
 using std::ifstream;
 using std::vector;
 using std::find;
+using std::count;
 
 // Inserts a file into current document
 bool BufferView::insertLyXFile(string const & filen)
@@ -897,6 +898,16 @@ bool BufferView::ChangeRefs(string const & from, string const & to)
 }
 
 
+bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
+{
+       // Check if the label 'from' appears more than once
+       vector<string> labels = buffer()->getLabelList();
+       if (count(labels.begin(), labels.end(), from) > 1)
+               return false;
+
+       return ChangeRefs(from, to);
+}
+
 UpdatableInset * BufferView::theLockingInset() const
 {
     return text->the_locking_inset;
index 90d9e4a98d4272ee63a675f3dd683e4eb58a2a85..c1f17f9a4bf70c5560951f56631f3c76fd518724 100644 (file)
@@ -21,7 +21,7 @@
 #include "FormBase.h"
 #include "LyXView.h"
 #include "support/LAssert.h"
-#include "debug.h"
+//#include "debug.h"
 
 extern "C" int C_FormBaseWMHideCB(FL_FORM * ob, void * d)
 {
@@ -60,7 +60,6 @@ FormBase::FormBase(LyXView * lv, Dialogs * d, string const & t,
 
 FormBase::~FormBase()
 {
-       //lyxerr << "bp_[" << bp_ << "]" << endl;
        delete bp_;
 }
 
index e53be71957ab111a4b97d8f9d8e8dc6bbb86df94..170125430fc56fb33ce202823485a8fc8cbb6e6c 100644 (file)
@@ -2,13 +2,6 @@
  * FormGraphics Interface Class Implementation
  */
 
-/* TODO:
- *      * Handle the case when the buffer is read-only.
- *          Initial work is done, if we are read-only the ok/cancel are 
- *          disabled. Probably we need to find a better way to deal with it.
- *      
- */
-
 #include <config.h> 
 
 #ifdef __GNUG__
@@ -25,9 +18,9 @@
 
 #include "debug.h" // for lyxerr
 
-#include "support/lstrings.h" // for strToDbl & tostr
-#include "support/FileInfo.h" // for FileInfo
-#include "filedlg.h" // for LyXFileDlg
+#include "support/lstrings.h"  // for strToDbl & tostr
+#include "support/FileInfo.h"  // for FileInfo
+#include "xform_helpers.h"     // for browseFile
 #include "support/filetools.h" // for AddName
 #include "insets/insetgraphics.h"
 #include "insets/insetgraphicsParams.h"
@@ -37,7 +30,7 @@
 #include "support/LAssert.h"
 
 using std::endl;
-
+using std::make_pair;
 
 FormGraphics::FormGraphics(LyXView * lv, Dialogs * d)
        : FormInset(lv, d, _("Graphics"), new NoRepeatedApplyReadOnlyPolicy),
@@ -62,7 +55,7 @@ FormGraphics::~FormGraphics()
        displayButtons.reset();
        
        // Free the form.
-       delete dialog_;
+       // delete dialog_;
 }
 
 
@@ -357,68 +350,31 @@ bool FormGraphics::checkInput()
 // We need these in the file browser.
 extern string system_lyxdir;
 extern string user_lyxdir;
-//extern string system_tempdir;
-
-
-// Need to move this to the form_graphics
-string FormGraphics::browseFile(string const & filename)
-{
-       if (! filename.empty() )
-               last_image_path = OnlyPath(filename);
-
-       // Does user clipart directory exist?
-       string bufclip = AddName (user_lyxdir, "clipart");
-       FileInfo fileInfo(bufclip);
-       if (!(fileInfo.isOK() && fileInfo.isDir()))
-               // No - bail out to system clipart directory
-               bufclip = AddName (system_lyxdir, "clipart");
-
-       LyXFileDlg fileDlg;
-       fileDlg.SetButton(0, _("Clipart"), bufclip);
-
-       bool error = false;
-       string buf;
-       do {
-               string p = fileDlg.Select(_("Graphics"),
-                                         last_image_path,
-                                         "*(ps|png)", filename);
-
-               if (p.empty()) return p;
-
-               last_image_path = OnlyPath(p);
-
-               if (p.find_first_of("#~$% ") != string::npos) {
-                       WriteAlert(_("Filename can't contain any "
-                                    "of these characters:"),
-                                  // xgettext:no-c-format
-                                  _("space, '#', '~', '$' or '%'."));
-                       error = true;
-               } else {
-                       error = false;
-                       buf = p;
-               }
-       } while (error);
-
-       return buf;
-}
-
 
 void FormGraphics::browse()
 {
        // Get the filename from the dialog
        string const filename = fl_get_input(dialog_->input_filename);
 
+       string const title = N_("Graphics");
+       string const pattern = "*(ps|png)";
+
+       // Does user clipart directory exist?
+       string clipdir = AddName (user_lyxdir, "clipart");
+       FileInfo fileInfo(clipdir);
+       if (!(fileInfo.isOK() && fileInfo.isDir()))
+               // No - bail out to system clipart directory
+               clipdir = AddName (system_lyxdir, "clipart");
+       pair<string, string> dir1(N_("Clipart"), clipdir);
+       
        // Show the file browser dialog
-       string const new_filename = browseFile(filename);
+       string const new_filename =
+               browseFile(filename, title, pattern, dir1,
+                          make_pair(string(), string()));
 
        // Save the filename to the dialog
-       if (new_filename != filename && ! new_filename.empty()) {
-               fl_set_input(dialog_->input_filename,
-                            new_filename.c_str());
-               // The above set input doesn't cause an input event so we do
-               // it manually. Otherwise the user needs to cause an input event
-               // to get the ok/apply buttons to be activated.
+       if (new_filename != filename && !new_filename.empty()) {
+               fl_set_input(dialog_->input_filename, new_filename.c_str());
                input(0, 0);
        }
-
 }
index e9aeb9002a38918bfc1a7555595b401bf7949da7..6c42fbbab810c57cd9d884bdd1a6eb8d0065abc5 100644 (file)
@@ -90,8 +90,6 @@ private:
        bool checkInput();
        /// Open the file browse dialog to select an image file.
        void browse();
-       /// Display a file browser dialog and return the file chosen.
-       string browseFile(string const & filename);
 
        /// Pointer to the actual instantiation of the xform's form
        virtual FL_FORM * form() const;
index 4193cf3049626bf2f5bcc39813ede982cda16487..88dc3b5202ba3c8a60c1f5162640a9446d478d07 100644 (file)
@@ -94,5 +94,7 @@ void FormCommand::createInset(string const & arg)
        }
 
        params.setFromString(arg);
+       if ( !arg.empty() )
+               bc_.valid(); // so that the user can press Ok
        show();
 }
index 7723513d979c38ed3a7e406395d25ae660a1a66c..ea3ca5568689cf3e2144fab7c9eb221111202169 100644 (file)
@@ -1574,28 +1574,28 @@ FormPreferences::Interface::feedback(FL_OBJECT const * const ob) const
 bool FormPreferences::Interface::input(FL_OBJECT const * const ob)
 {
        if (ob == dialog_->button_bind_file_browse) {
-               string dir  = system_lyxdir + string("bind");
-               string name = _("Sys Bind");
+               string dir  = AddName(system_lyxdir, "bind");
+               string name = N_("Sys Bind");
                pair<string,string> dir1(name, dir);
 
-               dir = user_lyxdir + string("bind");
-               name = _("User Bind");
+               dir = AddName(user_lyxdir, "bind");
+               name = N_("User Bind");
                pair<string,string> dir2(name, dir);
 
                parent_.browse(dialog_->input_bind_file,
-                               _("Bind file"), "*.bind", dir1, dir2);
+                              N_("Bind file"), "*.bind", dir1, dir2);
                
        } else if (ob == dialog_->button_ui_file_browse) {
-               string dir  = system_lyxdir + string("ui");
-               string name = _("Sys UI");
+               string dir  = AddName(system_lyxdir, "ui");
+               string name = N_("Sys UI");
                pair<string,string> dir1(name, dir);
 
-               dir = user_lyxdir + string("ui");
-               name = _("User UI");
+               dir = AddName(user_lyxdir, "ui");
+               name = N_("User UI");
                pair<string,string> dir2(name, dir);
 
                parent_.browse(dialog_->input_ui_file,
-                               _("UI file"), "*.ui", dir1, dir2);
+                              N_("UI file"), "*.ui", dir1, dir2);
        }
        
        return true;
@@ -1790,21 +1790,21 @@ bool FormPreferences::Language::input(FL_OBJECT const * const ob)
        }
 
        if (ob == dialog_->button_kbmap1_browse) {
-               string const dir  = system_lyxdir + string("kbd");
+               string const dir  = AddName(system_lyxdir, "kbd");
                string const name = N_("Key maps");
                pair<string, string> dir1(name, dir);
 
                parent_.browse(dialog_->input_kbmap1,
-                               _("Keyboard map"), "*.kmap", dir1,
-                               make_pair(string(), string()));
+                              N_("Keyboard map"), "*.kmap", dir1,
+                              make_pair(string(), string()));
        } else if (ob == dialog_->button_kbmap2_browse) {
-               string const dir  = system_lyxdir + string("kbd");
+               string const dir  = AddName(system_lyxdir, "kbd");
                string const name = N_("Key maps");
                pair<string, string> dir1(name, dir);
 
                parent_.browse(dialog_->input_kbmap2,
-                               _("Keyboard map"), "*.kmap", dir1,
-                               make_pair(string(), string()));
+                              N_("Keyboard map"), "*.kmap", dir1,
+                              make_pair(string(), string()));
        }
 
        return activate;
@@ -2228,35 +2228,35 @@ bool FormPreferences::Paths::input(FL_OBJECT const * const ob)
 
        if (ob == dialog_->button_default_path_browse) {
                parent_.browse(dialog_->input_default_path,
-                               _("Default path"), string(),
-                               make_pair(string(), string()),
-                               make_pair(string(), string()));
+                              N_("Default path"), string(),
+                              make_pair(string(), string()),
+                              make_pair(string(), string()));
        } else if (ob == dialog_->button_template_path_browse) {
                parent_.browse(dialog_->input_template_path,
-                               _("Template path"), string(),
-                               make_pair(string(), string()),
-                               make_pair(string(), string()));
+                              N_("Template path"), string(),
+                              make_pair(string(), string()),
+                              make_pair(string(), string()));
        } else if (ob == dialog_->button_temp_dir_browse) {
                parent_.browse(dialog_->input_temp_dir,
-                               _("Temp dir"), string(),
-                               make_pair(string(), string()),
-                               make_pair(string(), string()));
+                              N_("Temp dir"), string(),
+                              make_pair(string(), string()),
+                              make_pair(string(), string()));
        } else if (ob == dialog_->button_lastfiles_browse) {
                pair<string, string> dir(_("User"), user_lyxdir);
 
                parent_.browse(dialog_->input_lastfiles,
-                               _("Lastfiles"), string(), dir,
-                               make_pair(string(), string()));
+                              N_("Lastfiles"), string(), dir,
+                              make_pair(string(), string()));
        } else if (ob == dialog_->button_backup_path_browse) {
                parent_.browse(dialog_->input_backup_path,
-                               _("Backup path"), string(),
-                               make_pair(string(), string()),
-                               make_pair(string(), string()));
+                              N_("Backup path"), string(),
+                              make_pair(string(), string()),
+                              make_pair(string(), string()));
        } else if (ob == dialog_->button_serverpipe_browse) {
                parent_.browse(dialog_->input_serverpipe,
-                               _("LyX Server pipes"), string(),
-                               make_pair(string(), string()),
-                               make_pair(string(), string()));
+                              N_("LyX Server pipes"), string(),
+                              make_pair(string(), string()),
+                              make_pair(string(), string()));
        }
        
        return activate;
@@ -2949,9 +2949,9 @@ bool FormPreferences::SpellChecker::input(FL_OBJECT const * const ob)
 
        if (ob == dialog_->button_personal_dict) {
                parent_.browse(dialog_->input_personal_dict,
-                               _("Personal dictionary"), "*.ispell",
-                               make_pair(string(), string()),
-                               make_pair(string(), string()));
+                              N_("Personal dictionary"), "*.ispell",
+                              make_pair(string(), string()),
+                              make_pair(string(), string()));
        }
        
        return true; // All input is valid!
index 3bea5a68b63b43169877d92431d4aac94275f32c..61aac75dbbd9fe0cfbc55fa7db746eb1b7bc7f9e 100644 (file)
@@ -83,21 +83,21 @@ string const browseFile( string const & filename,
        if( !dir1.second.empty() ) {
                FileInfo fileInfo( dir1.second );
                if( fileInfo.isOK() && fileInfo.isDir() )
-                       fileDlg.SetButton( 0, dir1.first, dir1.second );
+                       fileDlg.SetButton( 0, _(dir1.first), dir1.second );
        }
 
        if( !dir2.second.empty() ) {
                FileInfo fileInfo( dir2.second );
                if( fileInfo.isOK() && fileInfo.isDir() )
-                   fileDlg.SetButton( 1, dir2.first, dir2.second );
+                   fileDlg.SetButton( 1, _(dir2.first), dir2.second );
        }
 
        bool error = false;
        string buf;
        do {
-               string p = fileDlg.Select(title,
+               string p = fileDlg.Select(_(title),
                                          lastPath,
-                                         pattern, filename );
+                                         pattern, OnlyFilename(filename) );
 
                if (p.empty()) return p;
 
@@ -121,7 +121,6 @@ string const browseFile( string const & filename,
 // 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 },
index 80428c3b67c8d32db976cca5d35ad7fc78a29f2a..dc507c9752b8466b22a1ee1379d115be9f262e52 100644 (file)
@@ -52,8 +52,9 @@ void InsetLabel::Edit(BufferView * bv, int, int, unsigned int)
                if (!new_contents.empty() &&
                    getContents() != new_contents) {
                        bv->buffer()->markDirty();
-                       bool flag = bv->ChangeRefs(getContents(),new_contents);
-                       setContents( new_contents );
+                       bool flag = bv->ChangeRefsIfUnique(getContents(),
+                                                          new_contents);
+                       setContents(new_contents);
                        bv->text->RedoParagraph(bv);
                        if (flag) {
                                bv->redraw();
index dce423214f4f7431c808650683c1d44b5a359462..d09de65bf4baeb549d447785a33771772f0443ec 100644 (file)
@@ -518,8 +518,75 @@ void MenuInsertLabel(BufferView * bv, string const & arg)
        string label(arg);
        ProhibitInput(bv);
        if (label.empty()) {
-               pair<bool, string>
-                       result = askForText(_("Enter new label to insert:"));
+#ifdef LABEL_INIT
+#ifndef NEW_INSETS
+               LyXParagraph * par =
+                       bv->text->cursor.par()->FirstPhysicalPar();
+#else
+               LyXParagraph * par = bv->text->cursor.par();
+#endif
+               LyXLayout const * layout =
+                       &textclasslist.Style(bv->buffer()->params.textclass,
+                                            par->GetLayout());
+
+               if (layout->latextype == LATEX_PARAGRAPH && par->previous) {
+#ifndef NEW_INSETS
+                       LyXParagraph * par2 = par->previous->FirstPhysicalPar();
+#else
+                       LyXParagraph * par2 = par->previous;
+#endif
+                       LyXLayout const * layout2 =
+                               &textclasslist.Style(bv->buffer()->params.textclass,
+                                                    par2->GetLayout());
+                       if (layout2->latextype != LATEX_PARAGRAPH) {
+                               par = par2;
+                               layout = layout2;
+                       }
+               }
+               string text = layout->latexname().substr(0, 3);
+               if (layout->latexname() == "theorem")
+                       text = "thm"; // Create a correct prefix for prettyref
+#ifndef NEW_INSETS
+               if (par->footnoteflag==LyXParagraph::OPEN_FOOTNOTE)
+                       switch (par->footnotekind) {
+                       case LyXParagraph::FIG:
+                       case LyXParagraph::WIDE_FIG:
+                               text = "fig";
+                               break;
+                       case LyXParagraph::TAB:
+                       case LyXParagraph::WIDE_TAB:
+                               text = "tab";
+                               break;
+                       case LyXParagraph::ALGORITHM:
+                               text = "alg";
+                               break;
+                       case LyXParagraph::FOOTNOTE:    
+                       case LyXParagraph::MARGIN:
+                               break;
+                       }
+#endif
+               text += ":";
+               if (layout->latextype == LATEX_PARAGRAPH ||
+                   lyxrc.label_init_length < 0)
+                       text.erase();
+               string par_text = par->String(bv->buffer(), false);
+               for (int i = 0; i < lyxrc.label_init_length; ++i) {
+                       if (par_text.empty())
+                               break;
+                       string head;
+                       par_text = split(par_text, head, ' ');
+                       if (i > 0)
+                               text += '_'; // Is it legal to use spaces in
+                                            // labels ?
+                       text += head;
+               }
+
+               pair<bool, string> result =
+                       askForText(_("Enter new label to insert:"), text);
+#else
+               pair<bool, string> result =
+                       askForText(_("Enter new label to insert:"));
+#endif
                if (result.first) {
                        label = frontStrip(strip(result.second));
                }
index 242c756850c9da2d917b4c53fa1b3c6b23d19fcf..c08c037b3169f6ae3aefe9996796e5c402e2b177 100644 (file)
@@ -2529,17 +2529,22 @@ string const LyXFunc::Dispatch(int ac,
        
        case LFUN_CITATION_CREATE:
        {
-               // Should do this "at source"
                InsetCommandParams p( "cite" );
                
-               if (contains(argument, "|")) {
-                       p.setContents( token(argument, '|', 0) );
-                       p.setOptions(  token(argument, '|', 1) );
-               } else {
-                       p.setContents( argument );
-               }
-
-               owner->getDialogs()->createCitation( p.getAsString() );
+               if (!argument.empty()) {
+                       // This should be set at source, ie when typing
+                       // "citation-insert foo" in the minibuffer.
+                       // Question: would pybibliographer also need to be
+                       // changed. Suspect so. Leave as-is therefore.
+                       if (contains(argument, "|")) {
+                               p.setContents( token(argument, '|', 0) );
+                               p.setOptions(  token(argument, '|', 1) );
+                       } else {
+                               p.setContents( argument );
+                       }
+                       Dispatch(LFUN_CITATION_INSERT, p.getAsString());
+               } else
+                       owner->getDialogs()->createCitation( p.getAsString() );
        }
        break;
                    
index db3b8c70bb9769bcc3e05a6cf95dc8f1775a8899..f4caddcd0b627abb4c836a7207553053b7cb29e7 100644 (file)
@@ -78,6 +78,7 @@ keyword_item lyxrcTags[] = {
        { "\\kbmap", LyXRC::RC_KBMAP },
        { "\\kbmap_primary", LyXRC::RC_KBMAP_PRIMARY },
        { "\\kbmap_secondary", LyXRC::RC_KBMAP_SECONDARY },
+       { "\\label_init_length", LyXRC::RC_LABEL_INIT_LENGTH },
        { "\\language_auto_begin", LyXRC::RC_LANGUAGE_AUTO_BEGIN },
        { "\\language_auto_end", LyXRC::RC_LANGUAGE_AUTO_END },
        { "\\language_command_begin", LyXRC::RC_LANGUAGE_COMMAND_BEGIN },
@@ -238,6 +239,7 @@ void LyXRC::setDefaults() {
        date_insert_format = "%A, %e %B %Y";
        show_banner = true;
        cursor_follows_scrollbar = false;
+       label_init_length = 3;
 
        /// These variables are not stored on disk (perhaps they
        // should be moved from the LyXRC class).
@@ -901,6 +903,11 @@ int LyXRC::read(string const & filename)
                                default_language = lexrc.GetString();
                        break;
 
+               case RC_LABEL_INIT_LENGTH:
+                       if (lexrc.next())
+                               label_init_length = lexrc.GetInteger();
+                       break;
+
                case RC_LAST: break; // this is just a dummy
                }
        }
@@ -1062,7 +1069,12 @@ void LyXRC::output(ostream & os) const
                        os << "\\date_insert_format \"" << date_insert_format
                           << "\"\n";
                }
-               
+       case RC_LABEL_INIT_LENGTH:
+               if (label_init_length != system_lyxrc.label_init_length) {
+                       os << "\\label_init_length " << label_init_length
+                          << "\n";
+               }
+
                os << "\n#\n"
                   << "# SCREEN & FONTS SECTION ############################\n"
                   << "#\n\n";
@@ -1895,6 +1907,10 @@ string const LyXRC::getDescription(LyXRCTags tag)
        case RC_DEFAULT_LANGUAGE:
                str = N_("New documents will be assigned this language.");
                break;
+
+       case RC_LABEL_INIT_LENGTH:
+               str = N_("Maximum number of words in the initialization string for a new label");
+               break;
                
        default:
                break;
index cc00c3fadb5afe48fee1b2eecfd5c1f6ca716149..831505e9704008a8938cf93a98fd17bbcced5097 100644 (file)
@@ -118,6 +118,7 @@ enum LyXRCTags {
        RC_FORMAT,
        RC_NEW_ASK_FILENAME,
        RC_DEFAULT_LANGUAGE,
+       RC_LABEL_INIT_LENGTH,
        RC_LAST
 };
 
@@ -331,6 +332,8 @@ enum LyXRCTags {
        string default_language;
        ///
        bool cursor_follows_scrollbar;
+       ///
+       int label_init_length;
 };
 
 ///
index 1c7c4f9a82fd7969d5ff110d72c841f301b3222f..c5c616177f2120b7261fce58d6cd8dbe26009368 100644 (file)
@@ -38,6 +38,7 @@
 #include "Painter.h"
 #include "font.h"
 #include "support/lyxlib.h"
+#include "lyxrc.h"
 
 using std::ostream;
 using std::istream;
@@ -794,6 +795,10 @@ InsetFormula::LocalDispatch(BufferView * bv,
     case LFUN_BREAKLINE:
       bv->lockedInsetStoreUndo(Undo::INSERT);
       mathcursor->Insert(' ', LM_TC_CR);
+      if (!label.empty()) {
+        mathcursor->setLabel(label);
+        label.erase();
+      }
       par = mathcursor->GetPar();
       UpdateLocal(bv);
       break;
@@ -1047,28 +1052,43 @@ InsetFormula::LocalDispatch(BufferView * bv,
     case LFUN_INSERT_LABEL:
     {
        bv->lockedInsetStoreUndo(Undo::INSERT);
-       if (par->GetType() < LM_OT_PAR) break;
-       string lb = arg;
-       if (lb.empty()) {
-         pair<bool, string>
-               res = askForText(_("Enter new label to insert:"));
-         if (res.first) {
-            lb = res.second;
-         }
+       if (par->GetType() < LM_OT_PAR)
+             break;
+
+       string old_label = (par->GetType() == LM_OT_MPARN)
+              ?  mathcursor->getLabel() : label;
+       string new_label = arg;
+       if (new_label.empty()) {
+#ifdef LABEL_INIT
+         string default_label = (lyxrc.label_init_length >= 0) ? "eq:" : "";
+         pair<bool, string> res = old_label.empty()
+                 ? askForText(_("Enter new label to insert:"), default_label)
+#else
+         pair<bool, string> res = old_label.empty()
+                 ? askForText(_("Enter new label to insert:"))
+#endif
+                 : askForText(_("Enter label:"), old_label);
+         if (!res.first)
+            break;
+         new_label = frontStrip(strip(res.second));
        }
-       if (!lb.empty() && lb[0] > ' ') {
+
+       if (new_label == old_label)
+              break;  // Nothing to do
+
+       if (!new_label.empty())
          SetNumber(true);
-         if (par->GetType() == LM_OT_MPARN) {
-             mathcursor->setLabel(lb);
-//           MathMatrixInset *mt = (MathMatrixInset*)par;
-//           mt->SetLabel(lb);
-         } else {
-                 //if (label.notEmpty()) delete label;
-             label = lb;
-         }
-         UpdateLocal(bv);
-       } else
-              label.erase();
+
+       if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
+             bv->redraw();
+
+       if (par->GetType() == LM_OT_MPARN)
+         mathcursor->setLabel(new_label);
+//       MathMatrixInset *mt = (MathMatrixInset*)par;
+//       mt->SetLabel(new_label);
+       else
+         label = new_label;
+       UpdateLocal(bv);
        break;
     }
     
index 96f1de14b6ca75248530959146a73ae64a67b924..91e4e6125efeb29ac3c50ba9ff34d1b498ee4793 100644 (file)
@@ -84,6 +84,10 @@ class MathedCursor {
     ///
     void setLabel(string const &);
     ///
+    string const & getLabel() const {
+           return cursor->getLabel();
+    }
+    ///
     bool Limits();
     /// Set accent: if argument = 0 it's considered consumed 
     void setAccent(int ac = 0);
index cf72b48bd59654bb9aa7af92643649996346abc8..446b8cba27c63d0d5b9bca29bf813a6ad8091312 100644 (file)
@@ -964,7 +964,7 @@ bool MathedXIter::setNumbered(bool numb)
 
 bool MathedXIter::setLabel(string const & label)
 {  
-    if (!label.empty() && crow) {
+    if (crow) {
        crow->setLabel(label);
        return true;
     }
index 9261ab3d2f4b1270e0c602d5c58b0f4b3669b909..d714421939b533292608b925db54ce91e1ab2163 100644 (file)
@@ -222,6 +222,10 @@ class MathedXIter: public MathedIter {
     ///
     bool setLabel(string const & label);
     ///
+    string const & getLabel() const {
+           return crow->getLabel();
+    }
+    ///
     bool setNumbered(bool);
        
     ///