Angus Leeming wrote:
Abdelrazak Younes <[EMAIL PROTECTED]> writes:
The pain point as I see it is the serialization of data to and from the dialogs, not *my* attempt at a model/view split at a dialog.
Right, I am actually replacing the serialisation with direct calls in ControlParagraph.

Hang on. My understanding is that all actions from the dialogs must go through the LFUN dispatch mechanism and that uses strings.
More exactly, an action from a View (a dialog) use a controller method. The Controller method might (best) or might not use the dispatch machinery depending on the operation.

Similarly, updating the dialog is a "push" action from the kernal that gives the dialog a string.
When it's absolutely necessary yes. In the case of the Paragraph dialog, it should be update at each new cursor location. The serialisation is only good for one-shot dialog showing not for real-time update.

Now I understand that Lars was proposing at one time refactoring this latter updating of the dialog (which currently parses a string of data) with some call to boost::any to essentially cast the paragraphparams object (or any other data store) to void and then unpack it on receipt by the dialog.
This is not the point in this case. I don't need this data on initialisation, I need it on _update_
However, I don't think that anyone was proposing changing the LFUN dispatch mechanism.
I don't either.

So what exactly are you proposing to change with direct calls?

See patch (not finished),

Cheers,
Abdel.

Index: ControlParagraph.C
===================================================================
--- ControlParagraph.C  (revision 17776)
+++ ControlParagraph.C  (working copy)
@@ -12,11 +12,12 @@
 #include <config.h>
 
 #include "ControlParagraph.h"
-#include "ButtonController.h"
+
+#include "buffer.h"
+#include "BufferView.h"
 #include "funcrequest.h"
 #include "lyxlex.h"
 #include "paragraph.h"
-#include "ParagraphParameters.h"
 
 #include <sstream>
 
@@ -29,99 +30,18 @@
 
 ControlParagraph::ControlParagraph(Dialog & parent)
        : Dialog::Controller(parent), ininset_(false)
-{}
+{
+}
 
 
 bool ControlParagraph::initialiseParams(string const & data)
 {
-       istringstream is(data);
-       LyXLex 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 = new ParagraphParameters;
-       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_.reset(tmp);
-       } else {
-               delete 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().bc().valid(accept);
-       }
        return true;
 }
 
 
 void ControlParagraph::clearParams()
 {
-       params_.reset();
 }
 
 
@@ -136,15 +56,13 @@
 
 ParagraphParameters & ControlParagraph::params()
 {
-       BOOST_ASSERT(params_.get());
-       return *params_;
+       return kernel().bufferview()->cursor().paragraph().params();
 }
 
 
 ParagraphParameters const & ControlParagraph::params() const
 {
-       BOOST_ASSERT(params_.get());
-       return *params_;
+       return kernel().bufferview()->cursor().paragraph().params();
 }
 
 
@@ -165,5 +83,35 @@
        return aligndefault_;
 }
 
+
+void ControlParagraph::setAlignment(LyXAlignment const alignment)
+{
+       kernel().bufferview()->cursor().paragraph().params().align(alignment);
+       kernel().bufferview()->buffer()->changed();
+}
+
+
+void ControlParagraph::setLineSpacing(Spacing::Space const linespacing, string 
const & other)
+{
+       Spacing const spacing(linespacing, other);
+       kernel().bufferview()->cursor().paragraph().params().spacing(spacing);
+       kernel().bufferview()->buffer()->changed();
+}
+
+
+void ControlParagraph::setLabelWidthString(docstring const & width)
+{
+       
kernel().bufferview()->cursor().paragraph().params().labelWidthString(width);
+       kernel().bufferview()->buffer()->changed();
+}
+
+
+void ControlParagraph::setIndentation(bool set)
+{
+       kernel().bufferview()->cursor().paragraph().params().noindent(!set);
+       kernel().bufferview()->buffer()->changed();
+}
+
 } // namespace frontend
+
 } // namespace lyx
Index: ControlParagraph.h
===================================================================
--- ControlParagraph.h  (revision 17776)
+++ ControlParagraph.h  (working copy)
@@ -14,11 +14,11 @@
 
 #include "Dialog.h"
 #include "layout.h" // for LyXAlignment
+#include "Spacing.h"
+#include "ParagraphParameters.h"
 
 namespace lyx {
 
-class ParagraphParameters;
-
 namespace frontend {
 
 class ControlParagraph : public Dialog::Controller {
@@ -26,6 +26,8 @@
        ///
        ControlParagraph(Dialog &);
        ///
+       virtual ~ControlParagraph() {}
+       ///
        virtual bool initialiseParams(std::string const & data);
        /// clean-up on hide.
        virtual void clearParams();
@@ -43,11 +45,17 @@
        LyXAlignment alignPossible() const;
        ///
        LyXAlignment alignDefault() const;
+       ///
+       void setAlignment(LyXAlignment const alignment);
+       ///
+       void setLineSpacing(Spacing::Space const spacing, std::string const & 
value);
+       ///
+       void setLabelWidthString(docstring const & width);
+       ///
+       void setIndentation(bool set);
 
 private:
        ///
-       boost::scoped_ptr<ParagraphParameters> params_;
-       ///
        bool ininset_;
        ///
        LyXAlignment alignpossible_;

Reply via email to