From 891bff2bfece699347ec8650478f3735db981d23 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 11 Dec 2000 09:46:09 +0000 Subject: [PATCH] A few patches I forgot to commit on friday. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1272 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 55 ++++++++++++++++ lib/languages | 1 + lib/lyxrc.example | 8 +++ src/BufferView.h | 2 + src/BufferView2.C | 11 ++++ src/frontends/xforms/FormBase.C | 3 +- src/frontends/xforms/FormGraphics.C | 86 +++++++------------------- src/frontends/xforms/FormGraphics.h | 2 - src/frontends/xforms/FormInset.C | 2 + src/frontends/xforms/FormPreferences.C | 72 ++++++++++----------- src/frontends/xforms/xform_helpers.C | 9 ++- src/insets/insetlabel.C | 5 +- src/lyx_cb.C | 71 ++++++++++++++++++++- src/lyxfunc.C | 23 ++++--- src/lyxrc.C | 18 +++++- src/lyxrc.h | 3 + src/mathed/formula.C | 60 ++++++++++++------ src/mathed/math_cursor.h | 4 ++ src/mathed/math_iter.C | 2 +- src/mathed/math_iter.h | 4 ++ 20 files changed, 296 insertions(+), 145 deletions(-) diff --git a/ChangeLog b/ChangeLog index af384fb035..fedb3ccc71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,58 @@ +2000-12-11 Jean-Marc Lasgouttes + + * lib/languages: Change description of german to "German (new + spelling)". + +2000-12-07 Angus Leeming + + * 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 + + * 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 + + * lib/languages: added ngerman. Patch courtesy of Andreas Gehlert + + + * 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 * src/converter.C (Move): New method. Used to move file or files diff --git a/lib/languages b/lib/languages index 2f3a1c3471..2c888b2b9a 100644 --- a/lib/languages +++ b/lib/languages @@ -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 "" diff --git a/lib/lyxrc.example b/lib/lyxrc.example index c79229b98c..71f5e6917e 100644 --- a/lib/lyxrc.example +++ b/lib/lyxrc.example @@ -156,6 +156,14 @@ # #\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 ################################################# # diff --git a/src/BufferView.h b/src/BufferView.h index 678d39a336..fbe29d70d2 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -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; diff --git a/src/BufferView2.C b/src/BufferView2.C index 606f2044e5..2f90faa753 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -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 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; diff --git a/src/frontends/xforms/FormBase.C b/src/frontends/xforms/FormBase.C index 90d9e4a98d..c1f17f9a4b 100644 --- a/src/frontends/xforms/FormBase.C +++ b/src/frontends/xforms/FormBase.C @@ -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_; } diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index e53be71957..170125430f 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -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 #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 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); } - } diff --git a/src/frontends/xforms/FormGraphics.h b/src/frontends/xforms/FormGraphics.h index e9aeb9002a..6c42fbbab8 100644 --- a/src/frontends/xforms/FormGraphics.h +++ b/src/frontends/xforms/FormGraphics.h @@ -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; diff --git a/src/frontends/xforms/FormInset.C b/src/frontends/xforms/FormInset.C index 4193cf3049..88dc3b5202 100644 --- a/src/frontends/xforms/FormInset.C +++ b/src/frontends/xforms/FormInset.C @@ -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(); } diff --git a/src/frontends/xforms/FormPreferences.C b/src/frontends/xforms/FormPreferences.C index 7723513d97..ea3ca55686 100644 --- a/src/frontends/xforms/FormPreferences.C +++ b/src/frontends/xforms/FormPreferences.C @@ -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 dir1(name, dir); - dir = user_lyxdir + string("bind"); - name = _("User Bind"); + dir = AddName(user_lyxdir, "bind"); + name = N_("User Bind"); pair 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 dir1(name, dir); - dir = user_lyxdir + string("ui"); - name = _("User UI"); + dir = AddName(user_lyxdir, "ui"); + name = N_("User UI"); pair 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 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 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 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! diff --git a/src/frontends/xforms/xform_helpers.C b/src/frontends/xforms/xform_helpers.C index 3bea5a68b6..61aac75dbb 100644 --- a/src/frontends/xforms/xform_helpers.C +++ b/src/frontends/xforms/xform_helpers.C @@ -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 }, diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index 80428c3b67..dc507c9752 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -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(); diff --git a/src/lyx_cb.C b/src/lyx_cb.C index dce423214f..d09de65bf4 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -518,8 +518,75 @@ void MenuInsertLabel(BufferView * bv, string const & arg) string label(arg); ProhibitInput(bv); if (label.empty()) { - pair - 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 result = + askForText(_("Enter new label to insert:"), text); +#else + pair result = + askForText(_("Enter new label to insert:")); +#endif if (result.first) { label = frontStrip(strip(result.second)); } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 242c756850..c08c037b31 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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; diff --git a/src/lyxrc.C b/src/lyxrc.C index db3b8c70bb..f4caddcd0b 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -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; diff --git a/src/lyxrc.h b/src/lyxrc.h index cc00c3fadb..831505e970 100644 --- a/src/lyxrc.h +++ b/src/lyxrc.h @@ -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; }; /// diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 1c7c4f9a82..c5c616177f 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -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 - 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 res = old_label.empty() + ? askForText(_("Enter new label to insert:"), default_label) +#else + pair 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; } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 96f1de14b6..91e4e6125e 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -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); diff --git a/src/mathed/math_iter.C b/src/mathed/math_iter.C index cf72b48bd5..446b8cba27 100644 --- a/src/mathed/math_iter.C +++ b/src/mathed/math_iter.C @@ -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; } diff --git a/src/mathed/math_iter.h b/src/mathed/math_iter.h index 9261ab3d2f..d714421939 100644 --- a/src/mathed/math_iter.h +++ b/src/mathed/math_iter.h @@ -222,6 +222,10 @@ class MathedXIter: public MathedIter { /// bool setLabel(string const & label); /// + string const & getLabel() const { + return crow->getLabel(); + } + /// bool setNumbered(bool); /// -- 2.39.2