Realize Allan Rae's PreferencesPolicy correctly and return the

preferences dialogs of all three frontends to it. The 'Save' button
should now behave as expected when the dialog is closed and reopened.
Squashes bug 1274 for the 1.4.x tree.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8612 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-04-05 18:34:36 +00:00
parent 9f4d9b92b9
commit ceff8c17ef
11 changed files with 138 additions and 18 deletions

View File

@ -1,3 +1,11 @@
2004-04-05 Angus Leeming <leeming@lyx.org>
* LyXAction.C (init): set LFUN_DIALOG_UPDATE's atrib flag to NoBuffer.
* lyxfunc.C (getStatus): enable LFUN_DIALOG_UPDATE if no buffer is
present only for the preferences dialog.
(dispatch): handle LFUN_DIALOG_UPDATE for the preferences dialog.
2004-04-05 Angus Leeming <leeming@lyx.org> 2004-04-05 Angus Leeming <leeming@lyx.org>
* lyxrc.[Ch] (write): now takes a 'bool ignore_system_lyxrc' arg * lyxrc.[Ch] (write): now takes a 'bool ignore_system_lyxrc' arg

View File

@ -313,7 +313,7 @@ void LyXAction::init()
{ LFUN_DIALOG_SHOW, "dialog-show", NoBuffer }, { LFUN_DIALOG_SHOW, "dialog-show", NoBuffer },
{ LFUN_DIALOG_SHOW_NEW_INSET, "dialog-show-new-inset", Noop }, { LFUN_DIALOG_SHOW_NEW_INSET, "dialog-show-new-inset", Noop },
{ LFUN_DIALOG_SHOW_NEXT_INSET, "dialog-show-next-inset", Noop }, { LFUN_DIALOG_SHOW_NEXT_INSET, "dialog-show-next-inset", Noop },
{ LFUN_DIALOG_UPDATE, "dialog-update", Noop }, { LFUN_DIALOG_UPDATE, "dialog-update", NoBuffer },
{ LFUN_DIALOG_HIDE, "dialog-hide", Noop }, { LFUN_DIALOG_HIDE, "dialog-hide", Noop },
{ LFUN_DIALOG_DISCONNECT_INSET, "dialog-disconnect-inset", Noop }, { LFUN_DIALOG_DISCONNECT_INSET, "dialog-disconnect-inset", Noop },
{ LFUN_INSET_APPLY, "inset-apply", Noop }, { LFUN_INSET_APPLY, "inset-apply", Noop },

View File

@ -12,13 +12,96 @@
#include "ButtonPolicies.h" #include "ButtonPolicies.h"
#include "debug.h" #include "debug.h"
#include <string>
using std::endl; using std::endl;
using std::string;
namespace { namespace {
string const printState(ButtonPolicy::State const & state)
{
string output;
switch(state) {
case ButtonPolicy::INITIAL:
output = "INITIAL";
break;
case ButtonPolicy::VALID:
output = "VALID";
break;
case ButtonPolicy::INVALID:
output = "INVALID";
break;
case ButtonPolicy::APPLIED:
output = "APPLIED";
break;
case ButtonPolicy::RO_INITIAL:
output = "RO_INITIAL";
break;
case ButtonPolicy::RO_VALID:
output = "RO_VALID";
break;
case ButtonPolicy::RO_INVALID:
output = "RO_INVALID";
break;
case ButtonPolicy::RO_APPLIED:
output = "RO_APPLIED";
break;
case ButtonPolicy::BOGUS:
output = "BOGUS";
break;
}
return output;
}
string const printInput(ButtonPolicy::SMInput const & input)
{
string output;
switch (input) {
case ButtonPolicy::SMI_VALID:
output = "SMI_VALID";
break;
case ButtonPolicy::SMI_INVALID:
output = "SMI_INVALID";
break;
case ButtonPolicy::SMI_OKAY:
output = "SMI_OKAY";
break;
case ButtonPolicy::SMI_APPLY:
output = "SMI_APPLY";
break;
case ButtonPolicy::SMI_CANCEL:
output = "SMI_CANCEL";
break;
case ButtonPolicy::SMI_RESTORE:
output = "SMI_RESTORE";
break;
case ButtonPolicy::SMI_HIDE:
output = "SMI_HIDE";
break;
case ButtonPolicy::SMI_READ_ONLY:
output = "SMI_READ_ONLY";
break;
case ButtonPolicy::SMI_READ_WRITE:
output = "SMI_READ_WRITE";
break;
case ButtonPolicy::SMI_NOOP:
output = "SMI_NOOP";
break;
case ButtonPolicy::SMI_TOTAL:
output = "SMI_TOTAL";
break;
}
return output;
}
/// Helper function /// Helper function
inline
void nextState(ButtonPolicy::State & state, void nextState(ButtonPolicy::State & state,
ButtonPolicy::SMInput in, ButtonPolicy::SMInput in,
ButtonPolicy::StateMachine const & s_m, ButtonPolicy::StateMachine const & s_m,
@ -29,17 +112,18 @@ void nextState(ButtonPolicy::State & state,
ButtonPolicy::State tmp = s_m[state][in]; ButtonPolicy::State tmp = s_m[state][in];
lyxerr[Debug::GUI] << "Transition from state " lyxerr[Debug::GUI] << "Transition from state "
<< state << " to state " << tmp << " after input " << printState(state) << " to state "
<< in << std::endl; << printState(tmp) << " after input "
<< printInput(in) << std::endl;
if (ButtonPolicy::BOGUS != tmp) { if (ButtonPolicy::BOGUS != tmp) {
state = tmp; state = tmp;
} else { } else {
lyxerr << function_name lyxerr << function_name
<< ": No transition for input " << ": No transition for input "
<< in << printInput(in)
<< " from state " << " from state "
<< state << printState(state)
<< endl; << endl;
} }
} }
@ -102,15 +186,11 @@ PreferencesPolicy::PreferencesPolicy()
void PreferencesPolicy::input(SMInput input) void PreferencesPolicy::input(SMInput input)
{ {
//lyxerr << "PreferencesPolicy::input" << endl; // The APPLIED state is persistent. Next time the dialog is opened,
// CANCEL and HIDE always take us to INITIAL for all cases. // the user will be able to press 'Save'.
// Note that I didn't put that special case in the helper function
// because it doesn't belong there. Some other
// This is probably optimising for the wrong case since it occurs as the
// dialog will be hidden. It would have saved a little memory in the
// state machine if I could have gotten map working. ARRae 20000813
if (SMI_CANCEL == input if (SMI_CANCEL == input
|| SMI_HIDE == input) { || SMI_HIDE == input) {
if (state_ != APPLIED)
state_ = INITIAL; state_ = INITIAL;
} else { } else {
nextState(state_, nextState(state_,

View File

@ -1,3 +1,12 @@
2004-04-05 Angus Leeming <leeming@lyx.org>
* ButtonPolicies.C (printState, printInput): human-readable output
of ButtonPolicy::State, ButtonPolicy::SMInput.
(PreferencesPolicy::input): change the behaviour of the Preferences
state machine on receipt of SMI_CANCEL/SMI_HIDE if the existing
state is APPLIED, then let this state persist. Next time that the
dialog is opened, the user will be able to press 'Save'.
2004-04-05 Angus Leeming <leeming@lyx.org> 2004-04-05 Angus Leeming <leeming@lyx.org>
* ControlPrefs.C (dispatchParams): ignore system_lyxrc when writing * ControlPrefs.C (dispatchParams): ignore system_lyxrc when writing

View File

@ -1,3 +1,8 @@
2004-04-05 Angus Leeming <leeming@lyx.org>
* Dialogs.C (build): set the preferences dialog button policy to
PreferencesPolicy.
2004-04-05 Angus Leeming <leeming@lyx.org> 2004-04-05 Angus Leeming <leeming@lyx.org>
* GMenubar.C: wrap #warning calls inside #ifdef WITH_WARNINGS blocks. * GMenubar.C: wrap #warning calls inside #ifdef WITH_WARNINGS blocks.

View File

@ -459,7 +459,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name)
} else if (name == "prefs") { } else if (name == "prefs") {
dialog->setController(new ControlPrefs(*dialog)); dialog->setController(new ControlPrefs(*dialog));
dialog->setView(new FormPreferences(*dialog)); dialog->setView(new FormPreferences(*dialog));
dialog->bc().bp(new OkApplyCancelPolicy); dialog->bc().bp(new PreferencesPolicy);
} else if (name == "print") { } else if (name == "print") {
dialog->setController(new ControlPrint(*dialog)); dialog->setController(new ControlPrint(*dialog));
dialog->setView(new FormPrint(*dialog)); dialog->setView(new FormPrint(*dialog));

View File

@ -1,3 +1,8 @@
2004-04-05 Angus Leeming <leeming@lyx.org>
* Dialogs.C (build): set the preferences dialog button policy to
PreferencesPolicy.
2004-04-05 Angus Leeming <leeming@lyx.org> 2004-04-05 Angus Leeming <leeming@lyx.org>
* QGraphics.C (getUnitNo): const-correct. * QGraphics.C (getUnitNo): const-correct.

View File

@ -263,7 +263,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name)
} else if (name == "prefs") { } else if (name == "prefs") {
dialog->setController(new ControlPrefs(*dialog)); dialog->setController(new ControlPrefs(*dialog));
dialog->setView(new QPrefs(*dialog)); dialog->setView(new QPrefs(*dialog));
dialog->bc().bp(new OkApplyCancelPolicy); dialog->bc().bp(new PreferencesPolicy);
} else if (name == "print") { } else if (name == "print") {
dialog->setController(new ControlPrint(*dialog)); dialog->setController(new ControlPrint(*dialog));
dialog->setView(new QPrint(*dialog)); dialog->setView(new QPrint(*dialog));

View File

@ -1,3 +1,8 @@
2004-04-05 Angus Leeming <leeming@lyx.org>
* Dialogs.C (build): set the preferences dialog button policy to
PreferencesPolicy.
2004-05-04 Angus Leeming <leeming@lyx.org> 2004-05-04 Angus Leeming <leeming@lyx.org>
* FormExternal.C (build): * FormExternal.C (build):

View File

@ -450,7 +450,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name)
} else if (name == "prefs") { } else if (name == "prefs") {
dialog->setController(new ControlPrefs(*dialog)); dialog->setController(new ControlPrefs(*dialog));
dialog->setView(new FormPreferences(*dialog)); dialog->setView(new FormPreferences(*dialog));
dialog->bc().bp(new OkApplyCancelPolicy); dialog->bc().bp(new PreferencesPolicy);
} else if (name == "print") { } else if (name == "print") {
dialog->setController(new ControlPrint(*dialog)); dialog->setController(new ControlPrint(*dialog));
dialog->setView(new FormPrint(*dialog)); dialog->setView(new FormPrint(*dialog));

View File

@ -430,6 +430,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
break; break;
} }
case LFUN_DIALOG_UPDATE: {
string const name = cmd.getArg(0);
if (!buf)
enable = name == "prefs";
break;
}
case LFUN_MENUNEW: case LFUN_MENUNEW:
case LFUN_MENUNEWTMPLT: case LFUN_MENUNEWTMPLT:
case LFUN_WORDFINDFORWARD: case LFUN_WORDFINDFORWARD:
@ -459,7 +466,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
case LFUN_GOTO_PARAGRAPH: case LFUN_GOTO_PARAGRAPH:
case LFUN_DIALOG_SHOW_NEW_INSET: case LFUN_DIALOG_SHOW_NEW_INSET:
case LFUN_DIALOG_SHOW_NEXT_INSET: case LFUN_DIALOG_SHOW_NEXT_INSET:
case LFUN_DIALOG_UPDATE:
case LFUN_DIALOG_HIDE: case LFUN_DIALOG_HIDE:
case LFUN_DIALOG_DISCONNECT_INSET: case LFUN_DIALOG_DISCONNECT_INSET:
case LFUN_CHILDOPEN: case LFUN_CHILDOPEN:
@ -1115,6 +1121,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
inset->dispatch(view()->cursor(), fr); inset->dispatch(view()->cursor(), fr);
} else if (name == "paragraph") { } else if (name == "paragraph") {
dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
} else if (name == "prefs") {
owner->getDialogs().update(name, string());
} }
break; break;
} }