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> 1999-12-28 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* src/buffer.C (Dispatch): remove an extraneous break statement. * 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 #LyX 1.0 (C) 1995-1999 Matthias Ettrich and the LyX Team
\lyxformat 2.15 \lyxformat 2.15
\textclass IEEEtran \textclass IEEEtran

View File

@ -1244,9 +1244,13 @@ void MenuInsertLabel(char const * arg)
{ {
string label = arg; string label = arg;
ProhibitInput(); ProhibitInput();
//string label = fl_show_input(_("Enter new label to insert:"), ""); if (label.empty()) {
if (label.empty()) pair<bool, string>
label = frontStrip(strip(askForText(_("Enter new label to insert:")))); result = askForText(_("Enter new label to insert:"));
if (result.first) {
label = frontStrip(strip(result.second));
}
}
if (!label.empty()) { if (!label.empty()) {
InsetLabel * new_inset = new InsetLabel; InsetLabel * new_inset = new InsetLabel;
new_inset->setContents(label); 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 // 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; char const * tmp;
fl_set_resource("flInput.cancel.label", idex(_("Cancel|^["))); 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"))); fl_set_resource("flInput.clear.label", idex(_("Clear|#e")));
tmp = fl_show_input(msg.c_str(), dflt.c_str()); tmp = fl_show_input(msg.c_str(), dflt.c_str());
if (tmp != 0) if (tmp != 0)
return tmp; return make_pair<bool, string>(true, tmp);
else else
return string(); return make_pair<bool, string>(false, string());
} }

View File

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

View File

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

View File

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