]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormInclude.C
get rid of broken_header.h and some unneeded tests
[lyx.git] / src / frontends / xforms / FormInclude.C
index 7cab61e6a0ffae5dfb6827100c2c9fb6afb7ea76..57bbb468e5fab34ad7f0fc43344aae83e535dec6 100644 (file)
@@ -7,29 +7,35 @@
  * \author John Levon
  * \author Angus Leeming
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
-#include <algorithm>
 
-
-#include "debug.h"
-
-#include "xformsBC.h"
-#include "ControlInclude.h"
 #include "FormInclude.h"
+#include "ControlInclude.h"
 #include "forms/form_include.h"
-#include "insets/insetinclude.h"
+
 #include "Tooltips.h"
 #include "xforms_helpers.h" // setEnabled
+#include "xformsBC.h"
+
 #include "support/lstrings.h" // strip
-#include FORMS_H_LOCATION
 
-typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
+#include "lyx_forms.h"
 
-FormInclude::FormInclude()
-       : base_class(_("Include file"))
+using std::string;
+
+namespace lyx {
+
+using support::rtrim;
+
+namespace frontend {
+
+typedef FormController<ControlInclude, FormView<FD_include> > base_class;
+
+FormInclude::FormInclude(Dialog & parent)
+       : base_class(parent, _("Child Document"))
 {}
 
 
@@ -38,8 +44,8 @@ void FormInclude::build()
        dialog_.reset(build_include(this));
 
        // Manage the ok and cancel buttons
-       bc().setOK(dialog_->button_ok);
-       bc().setCancel(dialog_->button_close);
+       bcview().setOK(dialog_->button_ok);
+       bcview().setCancel(dialog_->button_close);
 
        // trigger an input event for cut&paste with middle mouse button.
        setPrehandler(dialog_->input_filename);
@@ -47,10 +53,10 @@ void FormInclude::build()
        fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
 
        // disable for read-only documents
-       bc().addReadOnly(dialog_->button_browse);
-       bc().addReadOnly(dialog_->radio_useinput);
-       bc().addReadOnly(dialog_->radio_useinclude);
-       bc().addReadOnly(dialog_->radio_verbatim);
+       bcview().addReadOnly(dialog_->button_browse);
+       bcview().addReadOnly(dialog_->radio_useinput);
+       bcview().addReadOnly(dialog_->radio_useinclude);
+       bcview().addReadOnly(dialog_->radio_verbatim);
 
        type_.init(dialog_->radio_useinput,   ControlInclude::INPUT);
        type_.init(dialog_->radio_useinclude, ControlInclude::INCLUDE);
@@ -78,9 +84,9 @@ void FormInclude::build()
 
 void FormInclude::update()
 {
-       string const filename = controller().params().cparams.getContents();
-       string const cmdname = controller().params().cparams.getCmdName();
-       bool const preview = static_cast<bool>((controller().params().cparams.preview()));
+       string const filename = controller().params().getContents();
+       string const cmdname = controller().params().getCmdName();
+       bool const preview = static_cast<bool>((controller().params().preview()));
 
        fl_set_input(dialog_->input_filename, filename.c_str());
 
@@ -113,26 +119,24 @@ void FormInclude::update()
 
 void FormInclude::apply()
 {
-       controller().params().cparams
-               .preview(fl_get_button(dialog_->check_preview));
+       InsetCommandParams params = controller().params();
 
-       string const file = fl_get_input(dialog_->input_filename);
-       if (controller().fileExists(file))
-               controller().params().cparams.setContents(file);
-       else
-               controller().params().cparams.setContents("");
+       params.preview(fl_get_button(dialog_->check_preview));
+       params.setContents(getString(dialog_->input_filename));
 
        ControlInclude::Type const type = ControlInclude::Type(type_.get());
        if (type == ControlInclude::INPUT)
-               controller().params().flag = InsetInclude::INPUT;
+               params.setCmdName("input");
        else if (type == ControlInclude::INCLUDE)
-               controller().params().flag = InsetInclude::INCLUDE;
+               params.setCmdName("include");
        else if (type == ControlInclude::VERBATIM) {
                if (fl_get_button(dialog_->check_visiblespace))
-                       controller().params().flag = InsetInclude::VERBAST;
+                       params.setCmdName("verbatiminput*");
                else
-                       controller().params().flag = InsetInclude::VERB;
+                       params.setCmdName("verbatiminput");
        }
+
+       controller().setParams(params);
 }
 
 
@@ -141,17 +145,17 @@ ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
        ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
 
        if (ob == dialog_->button_browse) {
-               string const in_name = fl_get_input(dialog_->input_filename);
+               string const in_name = getString(dialog_->input_filename);
                fl_freeze_form(form());
                ControlInclude::Type const type = ControlInclude::Type(type_.get());
-               string const out_name = controller().Browse(in_name, type);
+               string const out_name = controller().browse(in_name, type);
                fl_set_input(dialog_->input_filename, out_name.c_str());
                fl_unfreeze_form(form());
 
        } else if (ob == dialog_->button_load) {
-               string const in_name = fl_get_input(dialog_->input_filename);
+               string const in_name = getString(dialog_->input_filename);
                if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
-                       controller().OKButton();
+                       dialog().OKButton();
                        controller().load(rtrim(in_name));
                        action = ButtonPolicy::SMI_NOOP;
                }
@@ -167,7 +171,7 @@ ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
                setEnabled(dialog_->button_load, true);
 
        } else if (ob == dialog_->input_filename) {
-               string const in_name = fl_get_input(dialog_->input_filename);
+               string const in_name = getString(dialog_->input_filename);
                if (rtrim(in_name).empty())
                        action = ButtonPolicy::SMI_INVALID;
        }
@@ -182,3 +186,6 @@ ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
 
        return action;
 }
+
+} // namespace frontend
+} // namespace lyx