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
This commit is contained in:
Jean-Marc Lasgouttes 2000-12-11 09:46:09 +00:00
parent 4abaf6ab91
commit 891bff2bfe
20 changed files with 296 additions and 145 deletions

View File

@ -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> 2000-12-09 Dekel Tsur <dekelts@tau.ac.il>
* src/converter.C (Move): New method. Used to move file or files * src/converter.C (Move): New method. Used to move file or files

View 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 # 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) # the font encoding I am assuming this is the one in Spain. (Garst)
german german "German" false iso8859-1 de german german "German" false iso8859-1 de
ngerman ngerman "German (new spelling)" false iso8859-1 de
greek greek "Greek" false iso8859-7 el_GR greek greek "Greek" false iso8859-7 el_GR
hebrew hebrew "Hebrew" true cp1255 he_IL hebrew hebrew "Hebrew" true cp1255 he_IL
#hungarian hungarian "Hungarian" false iso8859-2 "" #hungarian hungarian "Hungarian" false iso8859-2 ""

View File

@ -156,6 +156,14 @@
# #
#\date_insert_format "%A, %e. %B %Y" #\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 ################################################# # SCREEN & FONTS SECTION #################################################
# #

View File

@ -249,6 +249,8 @@ public:
/// ///
bool ChangeRefs(string const & from, string const & to); bool ChangeRefs(string const & from, string const & to);
/// ///
bool ChangeRefsIfUnique(string const & from, string const & to);
///
void pasteClipboard(bool asPara); void pasteClipboard(bool asPara);
/// ///
void stuffClipboard(string const &) const; void stuffClipboard(string const &) const;

View File

@ -39,6 +39,7 @@ using std::endl;
using std::ifstream; using std::ifstream;
using std::vector; using std::vector;
using std::find; using std::find;
using std::count;
// Inserts a file into current document // Inserts a file into current document
bool BufferView::insertLyXFile(string const & filen) 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 UpdatableInset * BufferView::theLockingInset() const
{ {
return text->the_locking_inset; return text->the_locking_inset;

View File

@ -21,7 +21,7 @@
#include "FormBase.h" #include "FormBase.h"
#include "LyXView.h" #include "LyXView.h"
#include "support/LAssert.h" #include "support/LAssert.h"
#include "debug.h" //#include "debug.h"
extern "C" int C_FormBaseWMHideCB(FL_FORM * ob, void * d) 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() FormBase::~FormBase()
{ {
//lyxerr << "bp_[" << bp_ << "]" << endl;
delete bp_; delete bp_;
} }

View File

@ -2,13 +2,6 @@
* FormGraphics Interface Class Implementation * 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> #include <config.h>
#ifdef __GNUG__ #ifdef __GNUG__
@ -25,9 +18,9 @@
#include "debug.h" // for lyxerr #include "debug.h" // for lyxerr
#include "support/lstrings.h" // for strToDbl & tostr #include "support/lstrings.h" // for strToDbl & tostr
#include "support/FileInfo.h" // for FileInfo #include "support/FileInfo.h" // for FileInfo
#include "filedlg.h" // for LyXFileDlg #include "xform_helpers.h" // for browseFile
#include "support/filetools.h" // for AddName #include "support/filetools.h" // for AddName
#include "insets/insetgraphics.h" #include "insets/insetgraphics.h"
#include "insets/insetgraphicsParams.h" #include "insets/insetgraphicsParams.h"
@ -37,7 +30,7 @@
#include "support/LAssert.h" #include "support/LAssert.h"
using std::endl; using std::endl;
using std::make_pair;
FormGraphics::FormGraphics(LyXView * lv, Dialogs * d) FormGraphics::FormGraphics(LyXView * lv, Dialogs * d)
: FormInset(lv, d, _("Graphics"), new NoRepeatedApplyReadOnlyPolicy), : FormInset(lv, d, _("Graphics"), new NoRepeatedApplyReadOnlyPolicy),
@ -62,7 +55,7 @@ FormGraphics::~FormGraphics()
displayButtons.reset(); displayButtons.reset();
// Free the form. // Free the form.
delete dialog_; // delete dialog_;
} }
@ -357,68 +350,31 @@ bool FormGraphics::checkInput()
// We need these in the file browser. // We need these in the file browser.
extern string system_lyxdir; extern string system_lyxdir;
extern string user_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() void FormGraphics::browse()
{ {
// Get the filename from the dialog // Get the filename from the dialog
string const filename = fl_get_input(dialog_->input_filename); 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 // 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 // Save the filename to the dialog
if (new_filename != filename && ! new_filename.empty()) { if (new_filename != filename && !new_filename.empty()) {
fl_set_input(dialog_->input_filename, fl_set_input(dialog_->input_filename, new_filename.c_str());
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.
input(0, 0); input(0, 0);
} }
} }

View File

@ -90,8 +90,6 @@ private:
bool checkInput(); bool checkInput();
/// Open the file browse dialog to select an image file. /// Open the file browse dialog to select an image file.
void browse(); 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 /// Pointer to the actual instantiation of the xform's form
virtual FL_FORM * form() const; virtual FL_FORM * form() const;

View File

@ -94,5 +94,7 @@ void FormCommand::createInset(string const & arg)
} }
params.setFromString(arg); params.setFromString(arg);
if ( !arg.empty() )
bc_.valid(); // so that the user can press Ok
show(); show();
} }

View File

@ -1574,28 +1574,28 @@ FormPreferences::Interface::feedback(FL_OBJECT const * const ob) const
bool FormPreferences::Interface::input(FL_OBJECT const * const ob) bool FormPreferences::Interface::input(FL_OBJECT const * const ob)
{ {
if (ob == dialog_->button_bind_file_browse) { if (ob == dialog_->button_bind_file_browse) {
string dir = system_lyxdir + string("bind"); string dir = AddName(system_lyxdir, "bind");
string name = _("Sys Bind"); string name = N_("Sys Bind");
pair<string,string> dir1(name, dir); pair<string,string> dir1(name, dir);
dir = user_lyxdir + string("bind"); dir = AddName(user_lyxdir, "bind");
name = _("User Bind"); name = N_("User Bind");
pair<string,string> dir2(name, dir); pair<string,string> dir2(name, dir);
parent_.browse(dialog_->input_bind_file, 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) { } else if (ob == dialog_->button_ui_file_browse) {
string dir = system_lyxdir + string("ui"); string dir = AddName(system_lyxdir, "ui");
string name = _("Sys UI"); string name = N_("Sys UI");
pair<string,string> dir1(name, dir); pair<string,string> dir1(name, dir);
dir = user_lyxdir + string("ui"); dir = AddName(user_lyxdir, "ui");
name = _("User UI"); name = N_("User UI");
pair<string,string> dir2(name, dir); pair<string,string> dir2(name, dir);
parent_.browse(dialog_->input_ui_file, parent_.browse(dialog_->input_ui_file,
_("UI file"), "*.ui", dir1, dir2); N_("UI file"), "*.ui", dir1, dir2);
} }
return true; return true;
@ -1790,21 +1790,21 @@ bool FormPreferences::Language::input(FL_OBJECT const * const ob)
} }
if (ob == dialog_->button_kbmap1_browse) { 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"); string const name = N_("Key maps");
pair<string, string> dir1(name, dir); pair<string, string> dir1(name, dir);
parent_.browse(dialog_->input_kbmap1, parent_.browse(dialog_->input_kbmap1,
_("Keyboard map"), "*.kmap", dir1, N_("Keyboard map"), "*.kmap", dir1,
make_pair(string(), string())); make_pair(string(), string()));
} else if (ob == dialog_->button_kbmap2_browse) { } 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"); string const name = N_("Key maps");
pair<string, string> dir1(name, dir); pair<string, string> dir1(name, dir);
parent_.browse(dialog_->input_kbmap2, parent_.browse(dialog_->input_kbmap2,
_("Keyboard map"), "*.kmap", dir1, N_("Keyboard map"), "*.kmap", dir1,
make_pair(string(), string())); make_pair(string(), string()));
} }
return activate; return activate;
@ -2228,35 +2228,35 @@ bool FormPreferences::Paths::input(FL_OBJECT const * const ob)
if (ob == dialog_->button_default_path_browse) { if (ob == dialog_->button_default_path_browse) {
parent_.browse(dialog_->input_default_path, parent_.browse(dialog_->input_default_path,
_("Default path"), string(), N_("Default path"), string(),
make_pair(string(), string()), make_pair(string(), string()),
make_pair(string(), string())); make_pair(string(), string()));
} else if (ob == dialog_->button_template_path_browse) { } else if (ob == dialog_->button_template_path_browse) {
parent_.browse(dialog_->input_template_path, parent_.browse(dialog_->input_template_path,
_("Template path"), string(), N_("Template path"), string(),
make_pair(string(), string()), make_pair(string(), string()),
make_pair(string(), string())); make_pair(string(), string()));
} else if (ob == dialog_->button_temp_dir_browse) { } else if (ob == dialog_->button_temp_dir_browse) {
parent_.browse(dialog_->input_temp_dir, parent_.browse(dialog_->input_temp_dir,
_("Temp dir"), string(), N_("Temp dir"), string(),
make_pair(string(), string()), make_pair(string(), string()),
make_pair(string(), string())); make_pair(string(), string()));
} else if (ob == dialog_->button_lastfiles_browse) { } else if (ob == dialog_->button_lastfiles_browse) {
pair<string, string> dir(_("User"), user_lyxdir); pair<string, string> dir(_("User"), user_lyxdir);
parent_.browse(dialog_->input_lastfiles, parent_.browse(dialog_->input_lastfiles,
_("Lastfiles"), string(), dir, N_("Lastfiles"), string(), dir,
make_pair(string(), string())); make_pair(string(), string()));
} else if (ob == dialog_->button_backup_path_browse) { } else if (ob == dialog_->button_backup_path_browse) {
parent_.browse(dialog_->input_backup_path, parent_.browse(dialog_->input_backup_path,
_("Backup path"), string(), N_("Backup path"), string(),
make_pair(string(), string()), make_pair(string(), string()),
make_pair(string(), string())); make_pair(string(), string()));
} else if (ob == dialog_->button_serverpipe_browse) { } else if (ob == dialog_->button_serverpipe_browse) {
parent_.browse(dialog_->input_serverpipe, parent_.browse(dialog_->input_serverpipe,
_("LyX Server pipes"), string(), N_("LyX Server pipes"), string(),
make_pair(string(), string()), make_pair(string(), string()),
make_pair(string(), string())); make_pair(string(), string()));
} }
return activate; return activate;
@ -2949,9 +2949,9 @@ bool FormPreferences::SpellChecker::input(FL_OBJECT const * const ob)
if (ob == dialog_->button_personal_dict) { if (ob == dialog_->button_personal_dict) {
parent_.browse(dialog_->input_personal_dict, parent_.browse(dialog_->input_personal_dict,
_("Personal dictionary"), "*.ispell", N_("Personal dictionary"), "*.ispell",
make_pair(string(), string()), make_pair(string(), string()),
make_pair(string(), string())); make_pair(string(), string()));
} }
return true; // All input is valid! return true; // All input is valid!

View File

@ -83,21 +83,21 @@ string const browseFile( string const & filename,
if( !dir1.second.empty() ) { if( !dir1.second.empty() ) {
FileInfo fileInfo( dir1.second ); FileInfo fileInfo( dir1.second );
if( fileInfo.isOK() && fileInfo.isDir() ) if( fileInfo.isOK() && fileInfo.isDir() )
fileDlg.SetButton( 0, dir1.first, dir1.second ); fileDlg.SetButton( 0, _(dir1.first), dir1.second );
} }
if( !dir2.second.empty() ) { if( !dir2.second.empty() ) {
FileInfo fileInfo( dir2.second ); FileInfo fileInfo( dir2.second );
if( fileInfo.isOK() && fileInfo.isDir() ) if( fileInfo.isOK() && fileInfo.isDir() )
fileDlg.SetButton( 1, dir2.first, dir2.second ); fileDlg.SetButton( 1, _(dir2.first), dir2.second );
} }
bool error = false; bool error = false;
string buf; string buf;
do { do {
string p = fileDlg.Select(title, string p = fileDlg.Select(_(title),
lastPath, lastPath,
pattern, filename ); pattern, OnlyFilename(filename) );
if (p.empty()) return p; 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(). // sorted by hand to prevent LyXLex from complaining on read().
static static
keyword_item xformTags[] = { keyword_item xformTags[] = {
// { "\\gui_active_tab", FL_LIGHTER_COL1 },
{ "\\gui_background", FL_COL1 }, { "\\gui_background", FL_COL1 },
{ "\\gui_buttonbottom", FL_BOTTOM_BCOL }, { "\\gui_buttonbottom", FL_BOTTOM_BCOL },
{ "\\gui_buttonleft", FL_LEFT_BCOL }, { "\\gui_buttonleft", FL_LEFT_BCOL },

View File

@ -52,8 +52,9 @@ void InsetLabel::Edit(BufferView * bv, int, int, unsigned int)
if (!new_contents.empty() && if (!new_contents.empty() &&
getContents() != new_contents) { getContents() != new_contents) {
bv->buffer()->markDirty(); bv->buffer()->markDirty();
bool flag = bv->ChangeRefs(getContents(),new_contents); bool flag = bv->ChangeRefsIfUnique(getContents(),
setContents( new_contents ); new_contents);
setContents(new_contents);
bv->text->RedoParagraph(bv); bv->text->RedoParagraph(bv);
if (flag) { if (flag) {
bv->redraw(); bv->redraw();

View File

@ -518,8 +518,75 @@ void MenuInsertLabel(BufferView * bv, string const & arg)
string label(arg); string label(arg);
ProhibitInput(bv); ProhibitInput(bv);
if (label.empty()) { if (label.empty()) {
pair<bool, string> #ifdef LABEL_INIT
result = askForText(_("Enter new label to insert:")); #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) { if (result.first) {
label = frontStrip(strip(result.second)); label = frontStrip(strip(result.second));
} }

View File

@ -2529,17 +2529,22 @@ string const LyXFunc::Dispatch(int ac,
case LFUN_CITATION_CREATE: case LFUN_CITATION_CREATE:
{ {
// Should do this "at source"
InsetCommandParams p( "cite" ); InsetCommandParams p( "cite" );
if (contains(argument, "|")) { if (!argument.empty()) {
p.setContents( token(argument, '|', 0) ); // This should be set at source, ie when typing
p.setOptions( token(argument, '|', 1) ); // "citation-insert foo" in the minibuffer.
} else { // Question: would pybibliographer also need to be
p.setContents( argument ); // changed. Suspect so. Leave as-is therefore.
} if (contains(argument, "|")) {
p.setContents( token(argument, '|', 0) );
owner->getDialogs()->createCitation( p.getAsString() ); p.setOptions( token(argument, '|', 1) );
} else {
p.setContents( argument );
}
Dispatch(LFUN_CITATION_INSERT, p.getAsString());
} else
owner->getDialogs()->createCitation( p.getAsString() );
} }
break; break;

View File

@ -78,6 +78,7 @@ keyword_item lyxrcTags[] = {
{ "\\kbmap", LyXRC::RC_KBMAP }, { "\\kbmap", LyXRC::RC_KBMAP },
{ "\\kbmap_primary", LyXRC::RC_KBMAP_PRIMARY }, { "\\kbmap_primary", LyXRC::RC_KBMAP_PRIMARY },
{ "\\kbmap_secondary", LyXRC::RC_KBMAP_SECONDARY }, { "\\kbmap_secondary", LyXRC::RC_KBMAP_SECONDARY },
{ "\\label_init_length", LyXRC::RC_LABEL_INIT_LENGTH },
{ "\\language_auto_begin", LyXRC::RC_LANGUAGE_AUTO_BEGIN }, { "\\language_auto_begin", LyXRC::RC_LANGUAGE_AUTO_BEGIN },
{ "\\language_auto_end", LyXRC::RC_LANGUAGE_AUTO_END }, { "\\language_auto_end", LyXRC::RC_LANGUAGE_AUTO_END },
{ "\\language_command_begin", LyXRC::RC_LANGUAGE_COMMAND_BEGIN }, { "\\language_command_begin", LyXRC::RC_LANGUAGE_COMMAND_BEGIN },
@ -238,6 +239,7 @@ void LyXRC::setDefaults() {
date_insert_format = "%A, %e %B %Y"; date_insert_format = "%A, %e %B %Y";
show_banner = true; show_banner = true;
cursor_follows_scrollbar = false; cursor_follows_scrollbar = false;
label_init_length = 3;
/// These variables are not stored on disk (perhaps they /// These variables are not stored on disk (perhaps they
// should be moved from the LyXRC class). // should be moved from the LyXRC class).
@ -901,6 +903,11 @@ int LyXRC::read(string const & filename)
default_language = lexrc.GetString(); default_language = lexrc.GetString();
break; break;
case RC_LABEL_INIT_LENGTH:
if (lexrc.next())
label_init_length = lexrc.GetInteger();
break;
case RC_LAST: break; // this is just a dummy case RC_LAST: break; // this is just a dummy
} }
} }
@ -1062,6 +1069,11 @@ void LyXRC::output(ostream & os) const
os << "\\date_insert_format \"" << date_insert_format os << "\\date_insert_format \"" << date_insert_format
<< "\"\n"; << "\"\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" os << "\n#\n"
<< "# SCREEN & FONTS SECTION ############################\n" << "# SCREEN & FONTS SECTION ############################\n"
@ -1896,6 +1908,10 @@ string const LyXRC::getDescription(LyXRCTags tag)
str = N_("New documents will be assigned this language."); str = N_("New documents will be assigned this language.");
break; break;
case RC_LABEL_INIT_LENGTH:
str = N_("Maximum number of words in the initialization string for a new label");
break;
default: default:
break; break;
} }

View File

@ -118,6 +118,7 @@ enum LyXRCTags {
RC_FORMAT, RC_FORMAT,
RC_NEW_ASK_FILENAME, RC_NEW_ASK_FILENAME,
RC_DEFAULT_LANGUAGE, RC_DEFAULT_LANGUAGE,
RC_LABEL_INIT_LENGTH,
RC_LAST RC_LAST
}; };
@ -331,6 +332,8 @@ enum LyXRCTags {
string default_language; string default_language;
/// ///
bool cursor_follows_scrollbar; bool cursor_follows_scrollbar;
///
int label_init_length;
}; };
/// ///

View File

@ -38,6 +38,7 @@
#include "Painter.h" #include "Painter.h"
#include "font.h" #include "font.h"
#include "support/lyxlib.h" #include "support/lyxlib.h"
#include "lyxrc.h"
using std::ostream; using std::ostream;
using std::istream; using std::istream;
@ -794,6 +795,10 @@ InsetFormula::LocalDispatch(BufferView * bv,
case LFUN_BREAKLINE: case LFUN_BREAKLINE:
bv->lockedInsetStoreUndo(Undo::INSERT); bv->lockedInsetStoreUndo(Undo::INSERT);
mathcursor->Insert(' ', LM_TC_CR); mathcursor->Insert(' ', LM_TC_CR);
if (!label.empty()) {
mathcursor->setLabel(label);
label.erase();
}
par = mathcursor->GetPar(); par = mathcursor->GetPar();
UpdateLocal(bv); UpdateLocal(bv);
break; break;
@ -1047,28 +1052,43 @@ InsetFormula::LocalDispatch(BufferView * bv,
case LFUN_INSERT_LABEL: case LFUN_INSERT_LABEL:
{ {
bv->lockedInsetStoreUndo(Undo::INSERT); bv->lockedInsetStoreUndo(Undo::INSERT);
if (par->GetType() < LM_OT_PAR) break; if (par->GetType() < LM_OT_PAR)
string lb = arg; break;
if (lb.empty()) {
pair<bool, string> string old_label = (par->GetType() == LM_OT_MPARN)
res = askForText(_("Enter new label to insert:")); ? mathcursor->getLabel() : label;
if (res.first) { string new_label = arg;
lb = res.second; 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); SetNumber(true);
if (par->GetType() == LM_OT_MPARN) {
mathcursor->setLabel(lb); if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
// MathMatrixInset *mt = (MathMatrixInset*)par; bv->redraw();
// mt->SetLabel(lb);
} else { if (par->GetType() == LM_OT_MPARN)
//if (label.notEmpty()) delete label; mathcursor->setLabel(new_label);
label = lb; // MathMatrixInset *mt = (MathMatrixInset*)par;
} // mt->SetLabel(new_label);
UpdateLocal(bv); else
} else label = new_label;
label.erase(); UpdateLocal(bv);
break; break;
} }

View File

@ -84,6 +84,10 @@ class MathedCursor {
/// ///
void setLabel(string const &); void setLabel(string const &);
/// ///
string const & getLabel() const {
return cursor->getLabel();
}
///
bool Limits(); bool Limits();
/// Set accent: if argument = 0 it's considered consumed /// Set accent: if argument = 0 it's considered consumed
void setAccent(int ac = 0); void setAccent(int ac = 0);

View File

@ -964,7 +964,7 @@ bool MathedXIter::setNumbered(bool numb)
bool MathedXIter::setLabel(string const & label) bool MathedXIter::setLabel(string const & label)
{ {
if (!label.empty() && crow) { if (crow) {
crow->setLabel(label); crow->setLabel(label);
return true; return true;
} }

View File

@ -222,6 +222,10 @@ class MathedXIter: public MathedIter {
/// ///
bool setLabel(string const & label); bool setLabel(string const & label);
/// ///
string const & getLabel() const {
return crow->getLabel();
}
///
bool setNumbered(bool); bool setNumbered(bool);
/// ///