mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
De-serialization of the paragraph settings dialog step 1: use current paragraph directly.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20510 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
2c885f9a6d
commit
38421f8022
@ -31,106 +31,26 @@ namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
ControlParagraph::ControlParagraph(Dialog & parent)
|
||||
: Controller(parent), ininset_(false)
|
||||
: Controller(parent)
|
||||
{}
|
||||
|
||||
|
||||
bool ControlParagraph::initialiseParams(string const & data)
|
||||
ParagraphParameters & ControlParagraph::params()
|
||||
{
|
||||
istringstream is(data);
|
||||
Lexer lex(0,0);
|
||||
lex.setStream(is);
|
||||
|
||||
// Set tri-state flag:
|
||||
// action == 0: show dialog
|
||||
// action == 1: update dialog, accept changes
|
||||
// action == 2: update dialog, do not accept changes
|
||||
int action = 0;
|
||||
|
||||
if (lex.isOK()) {
|
||||
lex.next();
|
||||
string const token = lex.getString();
|
||||
|
||||
if (token == "show") {
|
||||
action = 0;
|
||||
} else if (token == "update") {
|
||||
lex.next();
|
||||
bool const accept = lex.getBool();
|
||||
if (lex) {
|
||||
action = accept ? 1 : 2;
|
||||
} else {
|
||||
// Unrecognised update option
|
||||
return false;
|
||||
}
|
||||
} else if (!token.empty()) {
|
||||
// Unrecognised token
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ParagraphParameters tmp;
|
||||
tmp.read(lex);
|
||||
|
||||
// For now, only reset the params on "show".
|
||||
// Don't bother checking if the params are different on "update"
|
||||
if (action == 0)
|
||||
params_ = tmp;
|
||||
|
||||
// Read the rest of the data irrespective of "show" or "update"
|
||||
int nset = 0;
|
||||
while (lex.isOK()) {
|
||||
lex.next();
|
||||
string const token = lex.getString();
|
||||
|
||||
if (token.empty())
|
||||
continue;
|
||||
|
||||
int Int = 0;
|
||||
if (token == "\\alignpossible" ||
|
||||
token == "\\aligndefault" ||
|
||||
token == "\\ininset") {
|
||||
lex.next();
|
||||
Int = lex.getInteger();
|
||||
} else {
|
||||
// Unrecognised token
|
||||
return false;
|
||||
}
|
||||
|
||||
++nset;
|
||||
|
||||
if (token == "\\alignpossible") {
|
||||
alignpossible_ = static_cast<LyXAlignment>(Int);
|
||||
} else if (token == "\\aligndefault") {
|
||||
aligndefault_ = static_cast<LyXAlignment>(Int);
|
||||
} else {
|
||||
ininset_ = Int;
|
||||
}
|
||||
}
|
||||
if (nset != 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If "update", then set the activation status of the button controller
|
||||
if (action > 0) {
|
||||
bool const accept = action == 1;
|
||||
dialog().setButtonsValid(accept);
|
||||
}
|
||||
return true;
|
||||
return bufferview()->cursor().paragraph().params();
|
||||
}
|
||||
|
||||
|
||||
void ControlParagraph::clearParams()
|
||||
ParagraphParameters const & ControlParagraph::params() const
|
||||
{
|
||||
params_ = ParagraphParameters();
|
||||
return bufferview()->cursor().paragraph().params();
|
||||
}
|
||||
|
||||
|
||||
void ControlParagraph::dispatchParams()
|
||||
{
|
||||
ostringstream data;
|
||||
params().write(data);
|
||||
FuncRequest const fr(LFUN_PARAGRAPH_PARAMS_APPLY, data.str());
|
||||
dispatch(fr);
|
||||
bufferview()->updateMetrics(false);
|
||||
bufferview()->buffer().changed();
|
||||
}
|
||||
|
||||
|
||||
@ -150,13 +70,13 @@ bool ControlParagraph::canIndent() const
|
||||
|
||||
LyXAlignment ControlParagraph::alignPossible() const
|
||||
{
|
||||
return alignpossible_;
|
||||
return bufferview()->cursor().paragraph().layout()->alignpossible;
|
||||
}
|
||||
|
||||
|
||||
LyXAlignment ControlParagraph::alignDefault() const
|
||||
{
|
||||
return aligndefault_;
|
||||
return bufferview()->cursor().paragraph().layout()->align;
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
|
@ -25,37 +25,25 @@ public:
|
||||
///
|
||||
ControlParagraph(Dialog &);
|
||||
///
|
||||
virtual bool initialiseParams(std::string const & data);
|
||||
virtual bool initialiseParams(std::string const & data) { return true; }
|
||||
/// clean-up on hide.
|
||||
virtual void clearParams();
|
||||
virtual void clearParams() {}
|
||||
///
|
||||
virtual void dispatchParams();
|
||||
///
|
||||
virtual bool isBufferDependent() const { return true; }
|
||||
///
|
||||
ParagraphParameters & params() { return params_; }
|
||||
ParagraphParameters & params();
|
||||
///
|
||||
ParagraphParameters const & params() const { return params_; }
|
||||
ParagraphParameters const & params() const;
|
||||
///
|
||||
bool haveMulitParSelection();
|
||||
///
|
||||
bool inInset() const { return ininset_; }
|
||||
///
|
||||
bool canIndent() const;
|
||||
///
|
||||
LyXAlignment alignPossible() const;
|
||||
///
|
||||
LyXAlignment alignDefault() const;
|
||||
|
||||
private:
|
||||
///
|
||||
ParagraphParameters params_;
|
||||
///
|
||||
bool ininset_;
|
||||
///
|
||||
LyXAlignment alignpossible_;
|
||||
///
|
||||
LyXAlignment aligndefault_;
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
|
@ -166,6 +166,11 @@ LyXAlignment GuiParagraphDialog::getAlignmentFromDialog()
|
||||
|
||||
void GuiParagraphDialog::applyView()
|
||||
{
|
||||
// FIXME: We should not access params() at all!
|
||||
// we should just pass the relevant GUI information
|
||||
// and let the controller do the rest.
|
||||
// With this architecture, only current parent paragraph will be
|
||||
// modified when we have a multi-paragraph selection.
|
||||
ParagraphParameters & params = controller().params();
|
||||
|
||||
params.align(getAlignmentFromDialog());
|
||||
|
Loading…
Reference in New Issue
Block a user