My final commit of the year? pair<bool, string> askForText

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@398 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Allan Rae 1999-12-30 02:35:43 +00:00
parent 3dea2c51df
commit 3499732aae
7 changed files with 50 additions and 22 deletions

View File

@ -1,3 +1,14 @@
1999-12-30 Allan Rae <rae@lyx.org>
* lib/templates/IEEEtran.lyx: minor change
* src/lyxvc.C (registrer, checkIn), src/lyx_cb.C (MenuInsertLabel),
src/mathed/formula.C (LocalDispatch): askForText changes
* src/lyx_gui_misc.[Ch] (askForText): now returns a bool also so we
know when a user has cancelled input. Fixes annoying problems with
inserting labels and version control.
1999-12-28 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/buffer.C (Dispatch): remove an extraneous break statement.

View File

@ -1,4 +1,4 @@
#This file was created by <rae> Mon Dec 20 11:39:44 1999
#This file was created by <rae> Mon Dec 20 11:59:31 1999
#LyX 1.0 (C) 1995-1999 Matthias Ettrich and the LyX Team
\lyxformat 2.15
\textclass IEEEtran

View File

@ -1244,9 +1244,13 @@ void MenuInsertLabel(char const * arg)
{
string label = arg;
ProhibitInput();
//string label = fl_show_input(_("Enter new label to insert:"), "");
if (label.empty())
label = frontStrip(strip(askForText(_("Enter new label to insert:"))));
if (label.empty()) {
pair<bool, string>
result = askForText(_("Enter new label to insert:"));
if (result.first) {
label = frontStrip(strip(result.second));
}
}
if (!label.empty()) {
InsetLabel * new_inset = new InsetLabel;
new_inset->setContents(label);

View File

@ -400,7 +400,7 @@ int AskConfirmation(string const & s1, string const & s2, string const & s3)
// Asks for a text
string askForText(string const & msg, string const & dflt)
pair<bool, string> askForText(string const & msg, string const & dflt)
{
char const * tmp;
fl_set_resource("flInput.cancel.label", idex(_("Cancel|^[")));
@ -408,9 +408,9 @@ string askForText(string const & msg, string const & dflt)
fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
tmp = fl_show_input(msg.c_str(), dflt.c_str());
if (tmp != 0)
return tmp;
return make_pair<bool, string>(true, tmp);
else
return string();
return make_pair<bool, string>(false, string());
}

View File

@ -16,6 +16,7 @@
#include FORMS_H_LOCATION
#include "LString.h"
#include <utility> /* needed for pair<> definition */
/// Prevents LyX from being killed when the close box is pressed in a popup.
extern "C" int CancelCloseBoxCB(FL_FORM *, void *);
@ -53,8 +54,9 @@ bool AskQuestion(string const & s1, string const & s2 = string(),
int AskConfirmation(string const & s1, string const & s2 = string(),
string const & s3 = string());
/// returns a text
string askForText(string const & msg, string const & dflt = string());
/// returns a bool: false=cancelled, true=okay. string contains returned text
pair<bool, string> askForText(string const & msg,
string const & dflt = string());
/// Informs the user that changes in the coming form will be ignored
void WarnReadonly(string const & file);

View File

@ -98,15 +98,17 @@ void LyXVC::registrer()
}
lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
string tmp = askForText(_("LyX VC: Initial description"),
_("(no initial description)"));
if (tmp.empty()) {
pair<bool, string> tmp = askForText(_("LyX VC: Initial description"),
_("(no initial description)"));
if (!tmp.first || tmp.second.empty()) {
// should we insist on checking tmp.second.empty()?
lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
WriteAlert(_("Info"), _("This document has NOT been registered."));
WriteAlert(_("Info"),
_("This document has NOT been registered."));
return;
}
vcs->registrer(tmp);
vcs->registrer(tmp.second);
}
@ -128,11 +130,15 @@ void LyXVC::checkIn()
}
lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
string tmp = askForText(_("LyX VC: Log Message"));
if (tmp.empty()) tmp = "(no log msg)";
vcs->checkIn(tmp);
pair<bool, string> tmp = askForText(_("LyX VC: Log Message"));
if (tmp.first) {
if (tmp.second.empty()) {
tmp.second = _("(no log message)");
}
vcs->checkIn(tmp.second);
} else {
lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
}
}

View File

@ -1043,11 +1043,16 @@ bool InsetFormula::LocalDispatch(int action, char const * arg)
case LFUN_INSERT_LABEL:
{
LockedInsetStoreUndo(Undo::INSERT);
LockedInsetStoreUndo(Undo::INSERT);
if (par->GetType() < LM_OT_PAR) break;
string lb = arg;
if (lb.empty())
lb = string(askForText(_("Enter new label to insert:")));
if (lb.empty()) {
pair<bool, string>
result = askForText(_("Enter new label to insert:"));
if (result.first) {
lb = result.second;
}
}
if (!lb.empty() && lb[0] > ' ') {
SetNumber(true);
if (par->GetType() == LM_OT_MPARN) {