/**
* \file FormInclude.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
* \author Alejandro Aguilar Sierra
* \author John Levon
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
*/
-#include <config.h>
-#include <algorithm>
-#include <utility>
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include <config.h>
-#include "Dialogs.h"
#include "FormInclude.h"
-#include "insets/insetinclude.h"
-#include "frontends/FileDialog.h"
-#include "support/filetools.h"
-#include "support/lstrings.h"
-#include "LyXView.h"
-#include "buffer.h"
-#include "lyxrc.h"
-#include "lyxfunc.h"
-#include "xforms_helpers.h"
-
-#include "form_include.h"
-
-using std::make_pair;
-using std::pair;
-
-FormInclude::FormInclude(LyXView * lv, Dialogs * d)
- : FormCommand(lv, d, _("Include file"), new OkCancelPolicy),
- dialog_(0)
-{
- d->showInclude.connect(slot(this, &FormInclude::showInset));
- d->createInclude.connect(slot(this, &FormInclude::createInset));
-}
+#include "ControlInclude.h"
+#include "forms/form_include.h"
+#include "Tooltips.h"
+#include "xforms_helpers.h" // setEnabled
+#include "xformsBC.h"
-FormInclude::~FormInclude()
-{
- delete dialog_;
-}
+#include "support/lstrings.h" // strip
+#include "lyx_forms.h"
-FL_FORM * FormInclude::form() const
-{
- if (dialog_)
- return dialog_->form;
- return 0;
-}
+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"))
+{}
void FormInclude::build()
{
- dialog_ = build_include();
-
- // Workaround dumb xforms sizing bug
- minw_ = form()->w;
- minh_ = form()->h;
+ dialog_.reset(build_include(this));
// Manage the ok and cancel buttons
- bc_.setOK(dialog_->button_ok);
- bc_.setCancel(dialog_->button_cancel);
- bc_.refresh();
-
- bc_.addReadOnly(dialog_->browsebt);
- bc_.addReadOnly(dialog_->flag1);
- bc_.addReadOnly(dialog_->flag2);
- bc_.addReadOnly(dialog_->flag3);
- bc_.addReadOnly(dialog_->flag4);
- bc_.addReadOnly(dialog_->filename);
- bc_.addReadOnly(dialog_->flag41);
+ 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);
+
+ fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
+
+ // disable for read-only documents
+ 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);
+ type_.init(dialog_->radio_verbatim, ControlInclude::VERBATIM);
+
+ // set up the tooltips
+ string str = _("File name to include.");
+ tooltips().init(dialog_->input_filename, str);
+ str = _("Browse directories for file name.");
+ tooltips().init(dialog_->button_browse, str);
+ str = _("Use LaTeX \\input.");
+ tooltips().init(dialog_->radio_useinput, str);
+ str = _("Use LaTeX \\include.");
+ tooltips().init(dialog_->radio_useinclude, str);
+ str = _("Use LaTeX \\verbatiminput.");
+ tooltips().init(dialog_->radio_verbatim, str);
+ str = _("Underline spaces in generated output.");
+ tooltips().init(dialog_->check_visiblespace, str);
+ str = _("Show LaTeX preview.");
+ tooltips().init(dialog_->check_preview, str);
+ str = _("Load the file.");
+ tooltips().init(dialog_->button_load, str);
}
void FormInclude::update()
{
- bc_.readOnly(lv_->buffer()->isReadonly());
-
- if (!inset_) {
- fl_set_input(dialog_->filename, "");
- fl_set_button(dialog_->flag1, 0);
- fl_set_button(dialog_->flag2, 0);
- fl_set_button(dialog_->flag3, 1);
- fl_set_button(dialog_->flag4, 0);
- fl_set_button(dialog_->flag41, 0);
- fl_deactivate_object(dialog_->flag41);
- fl_set_object_lcol(dialog_->flag41, FL_INACTIVE);
- return;
- }
-
- fl_set_input(dialog_->filename, params.getContents().c_str());
-
- string const cmdname = params.getCmdName();
-
- /* FIXME: what do with Don't typeset here ... */
- //fl_set_button(dialog_->flag1, int(inset_->isNoLoad()));
-
- fl_set_button(dialog_->flag2, cmdname == "input");
- fl_set_button(dialog_->flag3, cmdname == "include");
- if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
- fl_set_button(dialog_->flag4, 1);
- fl_set_button(dialog_->flag41, cmdname == "verbatiminput*");
+ 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());
+
+ bool const inputCommand = cmdname == "input";
+ bool const includeCommand = cmdname == "include";
+ bool const verbatimStarCommand = cmdname == "verbatiminput*";
+ bool const verbatimCommand = cmdname == "verbatiminput";
+
+ setEnabled(dialog_->check_preview, inputCommand);
+ fl_set_button(dialog_->check_preview, inputCommand ? preview : 0);
+
+ if (cmdname.empty())
+ type_.set(ControlInclude::INPUT);
+
+ if (includeCommand)
+ type_.set(ControlInclude::INCLUDE);
+
+ if (verbatimCommand || verbatimStarCommand) {
+ type_.set(ControlInclude::VERBATIM);
+ fl_set_button(dialog_->check_visiblespace, verbatimStarCommand);
+ setEnabled(dialog_->check_visiblespace, true);
+ setEnabled(dialog_->button_load, false);
} else {
- fl_set_button(dialog_->flag41, 0);
- fl_deactivate_object(dialog_->flag41);
- fl_set_object_lcol(dialog_->flag41, FL_INACTIVE);
+ fl_set_button(dialog_->check_visiblespace, 0);
+ setEnabled(dialog_->check_visiblespace, false);
+ setEnabled(dialog_->button_load, true);
}
}
void FormInclude::apply()
{
- if (lv_->buffer()->isReadonly())
- return;
+ InsetCommandParams params = controller().params();
- /* FIXME: no way to update internal flags of inset ??? */
-
- //inset_->setNoLoad(fl_get_button(dialog_->flag1));
-
- params.setContents(fl_get_input(dialog_->filename));
+ params.preview(fl_get_button(dialog_->check_preview));
+ params.setContents(getString(dialog_->input_filename));
- if (fl_get_button(dialog_->flag2))
+ ControlInclude::Type const type = ControlInclude::Type(type_.get());
+ if (type == ControlInclude::INPUT)
params.setCmdName("input");
- else if (fl_get_button(dialog_->flag3))
+ else if (type == ControlInclude::INCLUDE)
params.setCmdName("include");
- else if (fl_get_button(dialog_->flag4)) {
- if (fl_get_button(dialog_->flag41))
+ else if (type == ControlInclude::VERBATIM) {
+ if (fl_get_button(dialog_->check_visiblespace))
params.setCmdName("verbatiminput*");
else
- params.setCmdName("verbatiminput");
+ params.setCmdName("verbatiminput");
}
-
- if (inset_) {
- if (params != inset_->params()) {
- inset_->setParams(params);
- lv_->view()->updateInset(inset_, true);
- }
- } else
- lv_->getLyXFunc()->Dispatch(LFUN_CHILD_INSERT, params.getAsString());
+
+ controller().setParams(params);
}
-
-#ifdef WITH_WARNINGS
-#warning convert this to use the buttoncontroller
-#endif
-bool FormInclude::input(FL_OBJECT *, long data)
+
+
+ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
{
- State state = static_cast<State>(data);
-
- switch (state) {
- case BROWSE: {
- // Should browsing too be disabled in RO-mode?
- FileDialog fileDlg(lv_, _("Select document to include"),
- LFUN_SELECT_FILE_SYNC,
- make_pair(string(_("Documents")), string(lyxrc.document_path)));
-
- string ext;
-
- /* input TeX, verbatim, or LyX file ? */
- if (fl_get_button(dialog_->flag2))
- ext = _("*.tex| LaTeX Documents (*.tex)");
- else if (fl_get_button(dialog_->flag4))
- ext = _("*| All files ");
- else
- ext = _("*.lyx| LyX Documents (*.lyx)");
-
- string mpath;
-
- /* FIXME: what do I do here ? */
- //if (inset_)
- // mpath = OnlyPath(inset_->getMasterFilename());
-
- FileDialog::Result result = fileDlg.Select(mpath, ext, fl_get_input(dialog_->filename));
-
- // check selected filename
- if (result.second.empty())
- break;
-
- string const filename2 = MakeRelPath(result.second, mpath);
-
- if (prefixIs(filename2, ".."))
- fl_set_input(dialog_->filename, result.second.c_str());
- else
- fl_set_input(dialog_->filename, filename2.c_str());
-
- } break;
-
- case LOAD:
- apply();
- lv_->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, params.getContents());
- break;
-
- case VERBATIM:
- setEnabled(dialog_->flag41, true);
- break;
-
- case INPUTINCLUDE:
- /* FIXME: huh ? why doesn't this work ? */
- setEnabled(dialog_->flag41, false);
- fl_set_button(dialog_->flag41, 0);
- break;
+ ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
+
+ if (ob == dialog_->button_browse) {
+ 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);
+ fl_set_input(dialog_->input_filename, out_name.c_str());
+ fl_unfreeze_form(form());
+
+ } else if (ob == dialog_->button_load) {
+ string const in_name = getString(dialog_->input_filename);
+ if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
+ dialog().OKButton();
+ controller().load(rtrim(in_name));
+ action = ButtonPolicy::SMI_NOOP;
+ }
+
+ } else if (ob == dialog_->radio_verbatim) {
+ setEnabled(dialog_->check_visiblespace, true);
+ setEnabled(dialog_->button_load, false);
+
+ } else if (ob == dialog_->radio_useinclude ||
+ ob == dialog_->radio_useinput) {
+ fl_set_button(dialog_->check_visiblespace, 0);
+ setEnabled(dialog_->check_visiblespace, false);
+ setEnabled(dialog_->button_load, true);
+
+ } else if (ob == dialog_->input_filename) {
+ string const in_name = getString(dialog_->input_filename);
+ if (rtrim(in_name).empty())
+ action = ButtonPolicy::SMI_INVALID;
}
- return true;
+
+ if (ob == dialog_->radio_useinput) {
+ setEnabled(dialog_->check_preview, true);
+ } else if (ob == dialog_->radio_verbatim ||
+ ob == dialog_->radio_useinclude) {
+ fl_set_button(dialog_->check_preview, 0);
+ setEnabled(dialog_->check_preview, false);
+ }
+
+ return action;
}
+
+} // namespace frontend
+} // namespace lyx