2001-02-12 14:09:09 +00:00
|
|
|
/**
|
|
|
|
* \file FormInclude.C
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
2001-03-23 17:09:34 +00:00
|
|
|
* \author John Levon, moz@compsoc.man.ac.uk
|
|
|
|
* \author Angus Leeming, a.leeming@.ac.uk
|
2001-02-12 14:09:09 +00:00
|
|
|
*/
|
2001-03-23 17:09:34 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
#include <config.h>
|
2001-02-12 14:09:09 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
#include "xformsBC.h"
|
|
|
|
#include "ControlInclude.h"
|
2001-02-12 14:09:09 +00:00
|
|
|
#include "FormInclude.h"
|
2001-03-23 17:09:34 +00:00
|
|
|
#include "form_include.h"
|
2001-03-14 10:57:39 +00:00
|
|
|
#include "insets/insetinclude.h"
|
2001-03-23 17:09:34 +00:00
|
|
|
#include "xforms_helpers.h" // setEnabled
|
2001-06-12 12:39:26 +00:00
|
|
|
#include "support/lstrings.h" // strip
|
2001-02-12 14:09:09 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
typedef FormCB<ControlInclude, FormDB<FD_form_include> > base_class;
|
2001-02-12 14:09:09 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
FormInclude::FormInclude(ControlInclude & c)
|
|
|
|
: base_class(c, _("Include file"))
|
|
|
|
{}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
|
|
|
2001-02-12 14:09:09 +00:00
|
|
|
void FormInclude::build()
|
|
|
|
{
|
2001-03-15 13:37:04 +00:00
|
|
|
dialog_.reset(build_include());
|
2001-02-12 14:09:09 +00:00
|
|
|
|
2001-06-12 12:39:26 +00:00
|
|
|
fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
|
|
|
|
|
2001-02-12 14:09:09 +00:00
|
|
|
// Manage the ok and cancel buttons
|
2001-03-23 17:09:34 +00:00
|
|
|
bc().setOK(dialog_->button_ok);
|
|
|
|
bc().setCancel(dialog_->button_cancel);
|
|
|
|
|
|
|
|
bc().addReadOnly(dialog_->button_browse);
|
|
|
|
bc().addReadOnly(dialog_->check_verbatim);
|
|
|
|
bc().addReadOnly(dialog_->check_typeset);
|
|
|
|
bc().addReadOnly(dialog_->check_useinput);
|
|
|
|
bc().addReadOnly(dialog_->check_useinclude);
|
2001-02-12 14:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormInclude::update()
|
|
|
|
{
|
2001-03-23 17:09:34 +00:00
|
|
|
if (controller().params().noload) {
|
2001-03-14 10:57:39 +00:00
|
|
|
fl_set_input(dialog_->input_filename, "");
|
|
|
|
fl_set_button(dialog_->check_typeset, 0);
|
|
|
|
fl_set_button(dialog_->check_useinput, 0);
|
|
|
|
fl_set_button(dialog_->check_useinclude, 1);
|
|
|
|
fl_set_button(dialog_->check_verbatim, 0);
|
|
|
|
fl_set_button(dialog_->check_visiblespace, 0);
|
|
|
|
fl_deactivate_object(dialog_->check_visiblespace);
|
|
|
|
fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
|
2001-02-12 14:09:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
fl_set_input(dialog_->input_filename,
|
|
|
|
controller().params().cparams.getContents().c_str());
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
string const cmdname = controller().params().cparams.getCmdName();
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
fl_set_button(dialog_->check_typeset,
|
|
|
|
int(controller().params().noload));
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
|
|
fl_set_button(dialog_->check_useinput, cmdname == "input");
|
|
|
|
fl_set_button(dialog_->check_useinclude, cmdname == "include");
|
2001-02-12 14:09:09 +00:00
|
|
|
if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
|
2001-03-14 10:57:39 +00:00
|
|
|
fl_set_button(dialog_->check_verbatim, 1);
|
|
|
|
fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
|
|
|
|
setEnabled(dialog_->check_visiblespace, true);
|
2001-02-12 14:09:09 +00:00
|
|
|
} else {
|
2001-03-14 10:57:39 +00:00
|
|
|
fl_set_button(dialog_->check_visiblespace, 0);
|
|
|
|
setEnabled(dialog_->check_visiblespace, false);
|
2001-02-12 14:09:09 +00:00
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
|
|
if (cmdname.empty())
|
|
|
|
fl_set_button(dialog_->check_useinclude, 1);
|
2001-02-12 14:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormInclude::apply()
|
|
|
|
{
|
2001-03-23 17:09:34 +00:00
|
|
|
controller().params().noload = fl_get_button(dialog_->check_typeset);
|
2001-02-12 14:09:09 +00:00
|
|
|
|
2002-01-21 10:47:19 +00:00
|
|
|
string const file = fl_get_input(dialog_->input_filename);
|
|
|
|
if (controller().fileExists(file))
|
|
|
|
controller().params().cparams.setContents(file);
|
|
|
|
else
|
|
|
|
controller().params().cparams.setContents("");
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
|
|
if (fl_get_button(dialog_->check_useinput))
|
2001-03-23 17:09:34 +00:00
|
|
|
controller().params().flag = InsetInclude::INPUT;
|
2001-03-14 10:57:39 +00:00
|
|
|
else if (fl_get_button(dialog_->check_useinclude))
|
2001-03-23 17:09:34 +00:00
|
|
|
controller().params().flag = InsetInclude::INCLUDE;
|
2001-03-14 10:57:39 +00:00
|
|
|
else if (fl_get_button(dialog_->check_verbatim)) {
|
|
|
|
if (fl_get_button(dialog_->check_visiblespace))
|
2001-03-23 17:09:34 +00:00
|
|
|
controller().params().flag = InsetInclude::VERBAST;
|
2001-02-12 14:09:09 +00:00
|
|
|
else
|
2001-03-23 17:09:34 +00:00
|
|
|
controller().params().flag = InsetInclude::VERB;
|
2001-02-12 14:09:09 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
|
|
|
|
ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
|
2001-02-12 14:09:09 +00:00
|
|
|
{
|
2001-06-12 12:39:26 +00:00
|
|
|
ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
if (ob == dialog_->button_browse) {
|
|
|
|
ControlInclude::Type type;
|
|
|
|
if (fl_get_button(dialog_->check_useinput))
|
|
|
|
type = ControlInclude::INPUT;
|
|
|
|
else if (fl_get_button(dialog_->check_verbatim))
|
|
|
|
type = ControlInclude::VERBATIM;
|
|
|
|
else
|
|
|
|
type = ControlInclude::INCLUDE;
|
|
|
|
|
|
|
|
string const in_name = fl_get_input(dialog_->input_filename);
|
|
|
|
fl_freeze_form(form());
|
|
|
|
string const out_name = controller().Browse(in_name, type);
|
|
|
|
fl_set_input(dialog_->input_filename, out_name.c_str());
|
|
|
|
fl_unfreeze_form(form());
|
|
|
|
|
2001-06-12 12:39:26 +00:00
|
|
|
} else if (ob == dialog_->button_load) {
|
|
|
|
string const in_name = fl_get_input(dialog_->input_filename);
|
2002-01-21 10:47:19 +00:00
|
|
|
if (!strip(in_name).empty() && controller().fileExists(in_name)) {
|
|
|
|
// ApplyButton();
|
|
|
|
OKButton();
|
2001-07-25 12:37:43 +00:00
|
|
|
controller().load(strip(in_name));
|
2001-06-12 12:39:26 +00:00
|
|
|
action = ButtonPolicy::SMI_NOOP;
|
2001-03-23 17:09:34 +00:00
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2001-06-12 12:39:26 +00:00
|
|
|
} else if (ob == dialog_->check_verbatim) {
|
2001-03-23 17:09:34 +00:00
|
|
|
setEnabled(dialog_->check_visiblespace, true);
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
} else if (ob == dialog_->check_useinclude ||
|
|
|
|
ob == dialog_->check_useinput) {
|
|
|
|
fl_set_button(dialog_->check_visiblespace, 0);
|
|
|
|
setEnabled(dialog_->check_visiblespace, false);
|
2001-06-12 12:39:26 +00:00
|
|
|
|
|
|
|
} else if (ob == dialog_->input_filename) {
|
|
|
|
string const in_name = fl_get_input(dialog_->input_filename);
|
|
|
|
if (strip(in_name).empty())
|
|
|
|
action = ButtonPolicy::SMI_INVALID;
|
2001-03-23 17:09:34 +00:00
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2001-06-12 12:39:26 +00:00
|
|
|
return action;
|
2001-03-23 17:09:34 +00:00
|
|
|
}
|