From ceff8c17ef3f0f4d504471e3231d468dfd9a3adc Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Mon, 5 Apr 2004 18:34:36 +0000 Subject: [PATCH] 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 --- src/ChangeLog | 8 ++ src/LyXAction.C | 2 +- src/frontends/controllers/ButtonPolicies.C | 106 ++++++++++++++++++--- src/frontends/controllers/ChangeLog | 9 ++ src/frontends/gtk/ChangeLog | 5 + src/frontends/gtk/Dialogs.C | 2 +- src/frontends/qt2/ChangeLog | 5 + src/frontends/qt2/Dialogs.C | 2 +- src/frontends/xforms/ChangeLog | 5 + src/frontends/xforms/Dialogs.C | 2 +- src/lyxfunc.C | 10 +- 11 files changed, 138 insertions(+), 18 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 618d0467dd..e5c1ca6b62 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2004-04-05 Angus Leeming + + * 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 * lyxrc.[Ch] (write): now takes a 'bool ignore_system_lyxrc' arg diff --git a/src/LyXAction.C b/src/LyXAction.C index fcf85954d4..5d2d637065 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -313,7 +313,7 @@ void LyXAction::init() { LFUN_DIALOG_SHOW, "dialog-show", NoBuffer }, { LFUN_DIALOG_SHOW_NEW_INSET, "dialog-show-new-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_DISCONNECT_INSET, "dialog-disconnect-inset", Noop }, { LFUN_INSET_APPLY, "inset-apply", Noop }, diff --git a/src/frontends/controllers/ButtonPolicies.C b/src/frontends/controllers/ButtonPolicies.C index a3f75b11cb..1b5e2ca9cc 100644 --- a/src/frontends/controllers/ButtonPolicies.C +++ b/src/frontends/controllers/ButtonPolicies.C @@ -12,13 +12,96 @@ #include "ButtonPolicies.h" #include "debug.h" +#include using std::endl; +using std::string; 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 -inline void nextState(ButtonPolicy::State & state, ButtonPolicy::SMInput in, ButtonPolicy::StateMachine const & s_m, @@ -29,17 +112,18 @@ void nextState(ButtonPolicy::State & state, ButtonPolicy::State tmp = s_m[state][in]; lyxerr[Debug::GUI] << "Transition from state " - << state << " to state " << tmp << " after input " - << in << std::endl; + << printState(state) << " to state " + << printState(tmp) << " after input " + << printInput(in) << std::endl; if (ButtonPolicy::BOGUS != tmp) { state = tmp; } else { lyxerr << function_name << ": No transition for input " - << in + << printInput(in) << " from state " - << state + << printState(state) << endl; } } @@ -102,16 +186,12 @@ PreferencesPolicy::PreferencesPolicy() void PreferencesPolicy::input(SMInput input) { - //lyxerr << "PreferencesPolicy::input" << endl; - // CANCEL and HIDE always take us to INITIAL for all cases. - // 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 + // The APPLIED state is persistent. Next time the dialog is opened, + // the user will be able to press 'Save'. if (SMI_CANCEL == input || SMI_HIDE == input) { - state_ = INITIAL; + if (state_ != APPLIED) + state_ = INITIAL; } else { nextState(state_, input, diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 207db79c34..0729b3599b 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,12 @@ +2004-04-05 Angus Leeming + + * 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 * ControlPrefs.C (dispatchParams): ignore system_lyxrc when writing diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index efae326009..9d13f0c15c 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,8 @@ +2004-04-05 Angus Leeming + + * Dialogs.C (build): set the preferences dialog button policy to + PreferencesPolicy. + 2004-04-05 Angus Leeming * GMenubar.C: wrap #warning calls inside #ifdef WITH_WARNINGS blocks. diff --git a/src/frontends/gtk/Dialogs.C b/src/frontends/gtk/Dialogs.C index 493dbf9bf8..e78b0ae72d 100644 --- a/src/frontends/gtk/Dialogs.C +++ b/src/frontends/gtk/Dialogs.C @@ -459,7 +459,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) } else if (name == "prefs") { dialog->setController(new ControlPrefs(*dialog)); dialog->setView(new FormPreferences(*dialog)); - dialog->bc().bp(new OkApplyCancelPolicy); + dialog->bc().bp(new PreferencesPolicy); } else if (name == "print") { dialog->setController(new ControlPrint(*dialog)); dialog->setView(new FormPrint(*dialog)); diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 4e41133d5a..0c30e049cf 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2004-04-05 Angus Leeming + + * Dialogs.C (build): set the preferences dialog button policy to + PreferencesPolicy. + 2004-04-05 Angus Leeming * QGraphics.C (getUnitNo): const-correct. diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index 7d652bb99a..24189d6a9d 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -263,7 +263,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) } else if (name == "prefs") { dialog->setController(new ControlPrefs(*dialog)); dialog->setView(new QPrefs(*dialog)); - dialog->bc().bp(new OkApplyCancelPolicy); + dialog->bc().bp(new PreferencesPolicy); } else if (name == "print") { dialog->setController(new ControlPrint(*dialog)); dialog->setView(new QPrint(*dialog)); diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index edbcf9c504..f1d4393a21 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2004-04-05 Angus Leeming + + * Dialogs.C (build): set the preferences dialog button policy to + PreferencesPolicy. + 2004-05-04 Angus Leeming * FormExternal.C (build): diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 1c0b78b1c6..e2b4a1360f 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -450,7 +450,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) } else if (name == "prefs") { dialog->setController(new ControlPrefs(*dialog)); dialog->setView(new FormPreferences(*dialog)); - dialog->bc().bp(new OkApplyCancelPolicy); + dialog->bc().bp(new PreferencesPolicy); } else if (name == "print") { dialog->setController(new ControlPrint(*dialog)); dialog->setView(new FormPrint(*dialog)); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 35cf569e33..a73ecde36a 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -430,6 +430,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const break; } + case LFUN_DIALOG_UPDATE: { + string const name = cmd.getArg(0); + if (!buf) + enable = name == "prefs"; + break; + } + case LFUN_MENUNEW: case LFUN_MENUNEWTMPLT: case LFUN_WORDFINDFORWARD: @@ -459,7 +466,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_GOTO_PARAGRAPH: case LFUN_DIALOG_SHOW_NEW_INSET: case LFUN_DIALOG_SHOW_NEXT_INSET: - case LFUN_DIALOG_UPDATE: case LFUN_DIALOG_HIDE: case LFUN_DIALOG_DISCONNECT_INSET: case LFUN_CHILDOPEN: @@ -1115,6 +1121,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) inset->dispatch(view()->cursor(), fr); } else if (name == "paragraph") { dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); + } else if (name == "prefs") { + owner->getDialogs().update(name, string()); } break; } -- 2.39.2